Skip to content

Commit 7b2e0d4

Browse files
ars18wrwiText-CI
authored andcommitted
If anchor delta is not zero, follow special xPlacement logic even if it's 0
DEVSIX-4472 DEVSIX-4473 Autoported commit. Original commit hash: [d9124554d]
1 parent dddcb59 commit 7b2e0d4

File tree

5 files changed

+59
-4
lines changed

5 files changed

+59
-4
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2020 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
using iText.Test;
24+
25+
namespace iText.IO.Font.Otf {
26+
public class GlyphTest : ExtendedITextTest {
27+
[NUnit.Framework.Test]
28+
public virtual void HasPlacementIfAnchorDeltaNonZeroTest() {
29+
Glyph glyph = CreateDummyGlyph();
30+
NUnit.Framework.Assert.AreEqual(0, glyph.GetXPlacement());
31+
NUnit.Framework.Assert.AreEqual(0, glyph.GetYPlacement());
32+
NUnit.Framework.Assert.AreEqual(0, glyph.GetAnchorDelta());
33+
NUnit.Framework.Assert.IsFalse(glyph.HasPlacement());
34+
glyph.SetAnchorDelta((short)10);
35+
NUnit.Framework.Assert.IsTrue(glyph.HasPlacement());
36+
}
37+
38+
[NUnit.Framework.Test]
39+
public virtual void HasOffsetsIfAnchorDeltaNonZeroTest() {
40+
Glyph glyph = CreateDummyGlyph();
41+
NUnit.Framework.Assert.AreEqual(0, glyph.GetXPlacement());
42+
NUnit.Framework.Assert.AreEqual(0, glyph.GetYPlacement());
43+
NUnit.Framework.Assert.AreEqual(0, glyph.GetAnchorDelta());
44+
NUnit.Framework.Assert.IsFalse(glyph.HasOffsets());
45+
glyph.SetAnchorDelta((short)10);
46+
NUnit.Framework.Assert.IsTrue(glyph.HasOffsets());
47+
}
48+
49+
private static Glyph CreateDummyGlyph() {
50+
return new Glyph(0, 0, 0);
51+
}
52+
}
53+
}

itext/itext.io/itext/io/font/otf/Glyph.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,12 @@ public virtual void SetAnchorDelta(short anchorDelta) {
252252
}
253253

254254
public virtual bool HasOffsets() {
255-
return xPlacement != 0 || yPlacement != 0 || xAdvance != 0 || yAdvance != 0;
255+
return HasAdvance() || HasPlacement();
256256
}
257257

258+
// In case some of placement values are not zero we always expect anchorDelta to be non-zero
258259
public virtual bool HasPlacement() {
259-
return xPlacement != 0 || yPlacement != 0;
260+
return anchorDelta != 0;
260261
}
261262

262263
public virtual bool HasAdvance() {

itext/itext.kernel/itext/kernel/pdf/canvas/PdfCanvas.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,8 @@ public virtual iText.Kernel.Pdf.Canvas.PdfCanvas ShowText(GlyphLine text, IEnume
678678
float xPlacementAddition = 0;
679679
int currentGlyphIndex = i;
680680
Glyph currentGlyph = text.Get(i);
681-
while (currentGlyph != null && currentGlyph.GetXPlacement() != 0) {
681+
// if xPlacement is not zero, anchorDelta is expected to be non-zero as well
682+
while (currentGlyph != null && (currentGlyph.GetAnchorDelta() != 0)) {
682683
xPlacementAddition += currentGlyph.GetXPlacement();
683684
if (currentGlyph.GetAnchorDelta() == 0) {
684685
break;

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0422805c51ffab04203f1d95e8ceb947396b92ab
1+
d9124554d47651e9e06599badc036bb2d359921e

0 commit comments

Comments
 (0)