Skip to content

Commit d912455

Browse files
committed
If anchor delta is not zero, follow special xPlacement logic even if it's 0
DEVSIX-4472 DEVSIX-4473
1 parent 0422805 commit d912455

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

io/src/main/java/com/itextpdf/io/font/otf/Glyph.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,12 @@ public void setAnchorDelta(short anchorDelta) {
270270
}
271271

272272
public boolean hasOffsets() {
273-
return xPlacement != 0 || yPlacement != 0 || xAdvance != 0 || yAdvance != 0;
273+
return hasAdvance() || hasPlacement();
274274
}
275275

276+
// In case some of placement values are not zero we always expect anchorDelta to be non-zero
276277
public boolean hasPlacement() {
277-
return xPlacement != 0 || yPlacement != 0;
278+
return anchorDelta != 0;
278279
}
279280

280281
public boolean hasAdvance() {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
package com.itextpdf.io.font.otf;
24+
25+
import com.itextpdf.test.ExtendedITextTest;
26+
import com.itextpdf.test.annotations.type.UnitTest;
27+
28+
import java.io.IOException;
29+
import org.junit.Assert;
30+
import org.junit.Test;
31+
import org.junit.experimental.categories.Category;
32+
33+
@Category(UnitTest.class)
34+
public class GlyphTest extends ExtendedITextTest {
35+
36+
@Test
37+
public void hasPlacementIfAnchorDeltaNonZeroTest() {
38+
Glyph glyph = createDummyGlyph();
39+
40+
Assert.assertEquals(0, glyph.getXPlacement());
41+
Assert.assertEquals(0, glyph.getYPlacement());
42+
Assert.assertEquals(0, glyph.getAnchorDelta());
43+
Assert.assertFalse(glyph.hasPlacement());
44+
45+
glyph.setAnchorDelta((short) 10);
46+
47+
Assert.assertTrue(glyph.hasPlacement());
48+
}
49+
50+
@Test
51+
public void hasOffsetsIfAnchorDeltaNonZeroTest() {
52+
Glyph glyph = createDummyGlyph();
53+
54+
Assert.assertEquals(0, glyph.getXPlacement());
55+
Assert.assertEquals(0, glyph.getYPlacement());
56+
Assert.assertEquals(0, glyph.getAnchorDelta());
57+
Assert.assertFalse(glyph.hasOffsets());
58+
59+
glyph.setAnchorDelta((short) 10);
60+
61+
Assert.assertTrue(glyph.hasOffsets());
62+
}
63+
64+
private static Glyph createDummyGlyph() {
65+
return new Glyph(0, 0, 0);
66+
}
67+
}

kernel/src/main/java/com/itextpdf/kernel/pdf/canvas/PdfCanvas.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,8 @@ public PdfCanvas showText(GlyphLine text, Iterator<GlyphLine.GlyphLinePart> iter
765765
float xPlacementAddition = 0;
766766
int currentGlyphIndex = i;
767767
Glyph currentGlyph = text.get(i);
768-
while (currentGlyph != null && currentGlyph.getXPlacement() != 0) {
768+
// if xPlacement is not zero, anchorDelta is expected to be non-zero as well
769+
while (currentGlyph != null && (currentGlyph.getAnchorDelta() != 0)) {
769770
xPlacementAddition += currentGlyph.getXPlacement();
770771
if (currentGlyph.getAnchorDelta() == 0) {
771772
break;

0 commit comments

Comments
 (0)