Skip to content

Commit 064080c

Browse files
committed
Quick fix for unsupported OpenType gdef class.
SUP-2076
1 parent 930a1c8 commit 064080c

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

io/src/main/java/com/itextpdf/io/LogMessageConstant.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,5 @@ public final class LogMessageConstant {
113113
public static final String WRITER_ENCRYPTION_IS_IGNORED_APPEND = "Writer encryption will be ignored, because append mode is used. Document will preserve the original encryption (or will stay unencrypted)";
114114
public static final String WRITER_ENCRYPTION_IS_IGNORED_PRESERVE = "Writer encryption will be ignored, because preservation of encryption is enabled. Document will preserve the original encryption (or will stay unencrypted)";
115115
public static final String XREF_ERROR = "Error occurred while reading cross reference table. Cross reference table will be rebuilt.";
116+
public static final String OPENTYPE_GDEF_TABLE_ERROR = "OpenType GDEF table error: {0}";
116117
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ protected abstract OpenTableLookup readLookupTable(int lookupType, int lookupFla
188188
throws java.io.IOException;
189189

190190
protected final OtfClass readClassDefinition(int classLocation) throws java.io.IOException {
191-
return new OtfClass(rf, classLocation);
191+
return OtfClass.create(rf, classLocation);
192192
}
193193

194194
protected final int[] readUShortArray(int size, int location) throws java.io.IOException {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ public void readTable() throws java.io.IOException {
7373
rf.readUnsignedShort(); //skip Ligature Caret List Table
7474
int markAttachClassDefOffset = rf.readUnsignedShort();
7575
if (glyphClassDefOffset > 0) {
76-
glyphClass = new OtfClass(rf, glyphClassDefOffset + tableLocation);
76+
glyphClass = OtfClass.create(rf, glyphClassDefOffset + tableLocation);
7777
}
7878
if (markAttachClassDefOffset > 0) {
79-
markAttachmentClass = new OtfClass(rf, markAttachClassDefOffset + tableLocation);
79+
markAttachmentClass = OtfClass.create(rf, markAttachClassDefOffset + tableLocation);
8080
}
8181
}
8282
}

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ This file is part of the iText (R) project.
4343
*/
4444
package com.itextpdf.io.font.otf;
4545

46+
import com.itextpdf.io.LogMessageConstant;
4647
import com.itextpdf.io.util.IntHashtable;
4748
import com.itextpdf.io.source.RandomAccessFileOrArray;
49+
import org.slf4j.Logger;
50+
import org.slf4j.LoggerFactory;
4851

52+
import java.io.IOException;
4953
import java.io.Serializable;
5054

5155
public class OtfClass implements Serializable {
@@ -57,7 +61,11 @@ public class OtfClass implements Serializable {
5761

5862
//key is glyph, value is class inside all 2
5963
private IntHashtable mapClass = new IntHashtable();
60-
64+
65+
/**
66+
* @deprecated use {@link #create(RandomAccessFileOrArray, int)} instead.
67+
*/
68+
@Deprecated
6169
public OtfClass(RandomAccessFileOrArray rf, int classLocation) throws java.io.IOException {
6270
rf.seek(classLocation);
6371
int classFormat = rf.readUnsignedShort();
@@ -83,6 +91,18 @@ public OtfClass(RandomAccessFileOrArray rf, int classLocation) throws java.io.IO
8391
throw new java.io.IOException("Invalid class format " + classFormat);
8492
}
8593
}
94+
95+
public static OtfClass create(RandomAccessFileOrArray rf, int classLocation) {
96+
OtfClass otfClass;
97+
try {
98+
otfClass = new OtfClass(rf, classLocation);
99+
} catch (IOException e) {
100+
Logger logger = LoggerFactory.getLogger(OtfClass.class);
101+
logger.error(LogMessageConstant.OPENTYPE_GDEF_TABLE_ERROR);
102+
otfClass = null;
103+
}
104+
return otfClass;
105+
}
86106

87107
public int getOtfClass(int glyph) {
88108
return mapClass.get(glyph);

0 commit comments

Comments
 (0)