Skip to content

Commit c1b379a

Browse files
author
dmitry.radchuk
committed
Resolve several TODOs in font processing logic
DEVSIX-6849
1 parent 58cadfc commit c1b379a

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public GsubLookupType4(OpenTypeFontTableReader openReader, int lookupFlag, int[]
6767

6868
@Override
6969
public boolean transformOne(GlyphLine line) {
70-
//TODO >
7170
if (line.idx >= line.end)
7271
return false;
7372
boolean changed = false;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ public List<OpenTableLookup> getLookups(FeatureRecord[] features) {
149149
}
150150

151151
public List<OpenTableLookup> getLookups(FeatureRecord feature) {
152-
//TODO see getLookups(FeatureRecord[]) method. Is it realy make sense to order features?
153152
List<OpenTableLookup> ret = new ArrayList<>(feature.lookups.length);
154153
for (int idx : feature.lookups) {
155154
ret.add(lookupList.get(idx));
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.itextpdf.io.font.otf;
2+
3+
import com.itextpdf.io.font.FontProgramFactory;
4+
import com.itextpdf.io.font.TrueTypeFont;
5+
import com.itextpdf.test.ExtendedITextTest;
6+
import com.itextpdf.test.annotations.type.IntegrationTest;
7+
8+
import java.io.IOException;
9+
import java.util.Arrays;
10+
import java.util.List;
11+
import org.junit.Assert;
12+
import org.junit.Test;
13+
import org.junit.experimental.categories.Category;
14+
15+
@Category(IntegrationTest.class)
16+
public class GsubLookupType4Test extends ExtendedITextTest {
17+
18+
private static final String RESOURCE_FOLDER = "./src/test/resources/com/itextpdf/io/font/otf/GsubLookupType4Test/";
19+
20+
@Test
21+
public void testNoIndexOutOfBound() throws IOException {
22+
TrueTypeFont fontProgram = (TrueTypeFont) FontProgramFactory.createFont(RESOURCE_FOLDER + "DejaVuSansMono.ttf");
23+
GlyphSubstitutionTableReader gsubTableReader = fontProgram.getGsubTable();
24+
25+
List<Glyph> glyphs = Arrays.asList(new Glyph(1, 1, 1),
26+
new Glyph(1, 1, 1),
27+
new Glyph(1, 1, 1),
28+
new Glyph(1, 1, 1),
29+
new Glyph(1, 1, 1),
30+
new Glyph(1, 1, 1));
31+
32+
GlyphLine gl = new GlyphLine(glyphs);
33+
gl.idx = gl.end;
34+
35+
GsubLookupType4 lookup = (GsubLookupType4) gsubTableReader.getLookupTable(6);
36+
37+
//Assert that no exception is thrown if gl.idx = gl.end
38+
Assert.assertFalse(lookup.transformOne(gl));
39+
}
40+
}

io/src/test/java/com/itextpdf/io/font/otf/OpenTypeFontTableReaderTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ This file is part of the iText (R) project.
2626
import com.itextpdf.io.font.TrueTypeFont;
2727
import com.itextpdf.test.ExtendedITextTest;
2828
import com.itextpdf.test.annotations.type.UnitTest;
29+
30+
import java.util.List;
2931
import org.junit.Assert;
3032
import org.junit.Test;
3133
import org.junit.experimental.categories.Category;
@@ -54,4 +56,26 @@ public void testFetchLangSysByTag() throws IOException {
5456
Assert.assertNull(gsub.getLanguageRecord("mym3"));
5557
Assert.assertNull(gsub.getLanguageRecord("mym3", LanguageTags.SGAW_KAREN));
5658
}
59+
60+
61+
@Test
62+
public void testGetLookupsArray() throws IOException {
63+
TrueTypeFont fontProgram = (TrueTypeFont) FontProgramFactory.createFont(RESOURCE_FOLDER + "NotoSansMyanmar-Regular.ttf");
64+
GlyphSubstitutionTableReader gsub = fontProgram.getGsubTable();
65+
FeatureRecord firstRecord = new FeatureRecord();
66+
firstRecord.lookups = new int[]{5, 2};
67+
firstRecord.tag = "1";
68+
FeatureRecord secondRecord = new FeatureRecord();
69+
secondRecord.lookups = new int[]{4, 10};
70+
secondRecord.tag = "2";
71+
FeatureRecord[] records = new FeatureRecord[]{firstRecord, secondRecord};
72+
73+
int[] lookupsLocations = gsub.getLookups(firstRecord).stream().mapToInt(record -> record.subTableLocations[0]).toArray();
74+
int[] expected = new int[]{142610, 142436};
75+
Assert.assertArrayEquals(expected, lookupsLocations);
76+
77+
lookupsLocations = gsub.getLookups(records).stream().mapToInt(record -> record.subTableLocations[0]).toArray();
78+
expected = new int[]{142436, 142538, 142610, 143908};
79+
Assert.assertArrayEquals(expected, lookupsLocations);
80+
}
5781
}

0 commit comments

Comments
 (0)