Skip to content

Commit a5bb161

Browse files
committed
Fix issue with subsetting fonts and form fields editing
DEVSIX-437
1 parent 56486c3 commit a5bb161

27 files changed

+12
-23
lines changed

io/src/main/java/com/itextpdf/io/font/TrueTypeFontSubset.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import java.util.ArrayList;
77
import java.util.Arrays;
8+
import java.util.Collections;
89
import java.util.HashMap;
9-
1010
import java.util.List;
1111
import java.util.Map;
1212
import java.util.Set;
@@ -18,12 +18,9 @@
1818
*/
1919
class TrueTypeFontSubset {
2020

21-
static final String tableNamesSimple[] = {"cvt ", "fpgm", "glyf", "head",
22-
"hhea", "hmtx", "loca", "maxp", "prep"};
23-
static final String tableNamesCmap[] = {"cmap", "cvt ", "fpgm", "glyf", "head",
24-
"hhea", "hmtx", "loca", "maxp", "prep"};
25-
static final String tableNamesExtra[] = {"OS/2", "cmap", "cvt ", "fpgm", "glyf", "head",
26-
"hhea", "hmtx", "loca", "maxp", "name, prep"};
21+
static final String[] tableNamesSimple = {"cvt ", "fpgm", "glyf", "head", "hhea", "hmtx", "loca", "maxp", "prep"};
22+
static final String[] tableNamesCmap = {"cmap", "OS/2"};
23+
static final String[] tableNamesExtra = {"cmap", "OS/2", "name"};
2724
static final int entrySelectors[] = {0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4};
2825
static final int TABLE_CHECKSUM = 0;
2926
static final int TABLE_OFFSET = 1;
@@ -106,15 +103,12 @@ byte[] process() throws java.io.IOException {
106103
protected void assembleFont() throws java.io.IOException {
107104
int[] tableLocation;
108105
int fullFontSize = 0;
109-
String[] tableNames;
106+
List<String> tableNames = new ArrayList<>();
107+
Collections.addAll(tableNames, tableNamesSimple);
110108
if (includeExtras) {
111-
tableNames = tableNamesExtra;
112-
} else {
113-
if (includeCmap) {
114-
tableNames = tableNamesCmap;
115-
} else {
116-
tableNames = tableNamesSimple;
117-
}
109+
Collections.addAll(tableNames, tableNamesExtra);
110+
} else if (includeCmap) {
111+
Collections.addAll(tableNames, tableNamesCmap);
118112
}
119113
int tablesUsed = 2;
120114
for (String name : tableNames) {

kernel/src/main/java/com/itextpdf/kernel/font/PdfType0Font.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public GlyphLine createGlyphLine(String content) {
285285
//TODO different with type0 and type2 could be removed after simplifying longTag
286286
if (cidFontType == CidFontType0) {
287287
int len = content.length();
288-
if (isIdentity()) {
288+
if (cmapEncoding.isDirect()) {
289289
for (int k = 0; k < len; ++k) {
290290
Glyph glyph = fontProgram.getGlyphByCode((int) content.charAt(k));
291291
if (glyph != null) {
@@ -397,11 +397,6 @@ protected PdfDictionary getFontDescriptor(String fontName) {
397397
return fontDescriptor;
398398
}
399399

400-
public boolean isIdentity() {
401-
//TODO strange property
402-
return cmapEncoding.isDirect();
403-
}
404-
405400
@Override
406401
public void flush() {
407402
if (newFont) {
@@ -410,7 +405,7 @@ public void flush() {
410405
super.flush();
411406
}
412407

413-
@Override //TODO
408+
@Override //TODO remove
414409
protected void addFontStream(PdfDictionary fontDescriptor) {
415410
}
416411

@@ -522,7 +517,7 @@ protected PdfDictionary getCidFontType2(TrueTypeFont ttf, PdfDictionary fontDesc
522517
PdfDictionary cidInfo = new PdfDictionary();
523518
cidInfo.put(PdfName.Registry, new PdfString(cmapEncoding.getRegistry()));
524519
cidInfo.put(PdfName.Ordering, new PdfString(cmapEncoding.getOrdering()));
525-
cidInfo.put(PdfName.Supplement, new PdfNumber(cmapEncoding.getSupplement()));//0
520+
cidInfo.put(PdfName.Supplement, new PdfNumber(cmapEncoding.getSupplement()));
526521
cidFont.put(PdfName.CIDSystemInfo, cidInfo);
527522
if (!vertical) {
528523
cidFont.put(PdfName.DW, new PdfNumber(FontProgram.DEFAULT_WIDTH));

0 commit comments

Comments
 (0)