aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2017-10-05 10:50:48 +0000
committerSimon Steiner <ssteiner@apache.org>2017-10-05 10:50:48 +0000
commitade0e4ebd6ce8f92e9a19878e838a5a75226801d (patch)
tree9f40efd6cf09dbee3e7fdabe02d0f521c2c9eb1f
parent6f8ace54a845f4ddba9fb2c3f46405f04bd2b407 (diff)
downloadxmlgraphics-fop-ade0e4ebd6ce8f92e9a19878e838a5a75226801d.tar.gz
xmlgraphics-fop-ade0e4ebd6ce8f92e9a19878e838a5a75226801d.zip
FOP-2747: OTF subsetting: Resize entry to fit value
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1811185 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--fop-core/src/main/java/org/apache/fop/fonts/truetype/OTFSubSetFile.java20
-rw-r--r--fop-core/src/test/java/org/apache/fop/fonts/truetype/OTFSubSetFileTestCase.java36
2 files changed, 37 insertions, 19 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/fonts/truetype/OTFSubSetFile.java b/fop-core/src/main/java/org/apache/fop/fonts/truetype/OTFSubSetFile.java
index d8e8c2843..0487c6127 100644
--- a/fop-core/src/main/java/org/apache/fop/fonts/truetype/OTFSubSetFile.java
+++ b/fop-core/src/main/java/org/apache/fop/fonts/truetype/OTFSubSetFile.java
@@ -296,6 +296,10 @@ public class OTFSubSetFile extends OTFSubSetWriter {
} else if (dictKey.equals("CIDCount")) {
dict.write(writeCIDCount(entry));
} else if (topDictStringEntries.contains(dictKey)) {
+ if (entry.getOperandLength() < 2) {
+ entry.setOperandLength(2);
+ offsetExtra++;
+ }
dict.write(writeTopDictStringEntry(entry));
} else {
dict.write(entry.getByteData());
@@ -339,7 +343,6 @@ public class OTFSubSetFile extends OTFSubSetWriter {
if (sid > 391) {
stringIndexData.add(cffReader.getStringIndex().getValue(sid - 391));
}
-
byte[] newDictEntry = createNewRef(stringIndexData.size() + 390, dictEntry.getOperator(),
dictEntry.getOperandLength(), true);
return newDictEntry;
@@ -896,9 +899,6 @@ public class OTFSubSetFile extends OTFSubSetWriter {
if ((forceLength == -1 && newRef >= -107 && newRef <= 107) || forceLength == 1) {
//The index values are 0 indexed
newRefBytes.write(newRef + 139);
- for (int i : operatorCode) {
- newRefBytes.write(i);
- }
} else if ((forceLength == -1 && newRef >= -1131 && newRef <= 1131) || forceLength == 2) {
if (newRef <= -876) {
newRefBytes.write(254);
@@ -922,16 +922,10 @@ public class OTFSubSetFile extends OTFSubSetWriter {
} else {
newRefBytes.write(-newRef - 108);
}
- for (int i : operatorCode) {
- newRefBytes.write(i);
- }
} else if ((forceLength == -1 && newRef >= -32768 && newRef <= 32767) || forceLength == 3) {
newRefBytes.write(28);
newRefBytes.write(newRef >> 8);
newRefBytes.write(newRef);
- for (int i : operatorCode) {
- newRefBytes.write(i);
- }
} else {
if (isDict) {
newRefBytes.write(29);
@@ -942,9 +936,9 @@ public class OTFSubSetFile extends OTFSubSetWriter {
newRefBytes.write(newRef >> 16);
newRefBytes.write(newRef >> 8);
newRefBytes.write(newRef);
- for (int i : operatorCode) {
- newRefBytes.write(i);
- }
+ }
+ for (int i : operatorCode) {
+ newRefBytes.write(i);
}
return newRefBytes.toByteArray();
}
diff --git a/fop-core/src/test/java/org/apache/fop/fonts/truetype/OTFSubSetFileTestCase.java b/fop-core/src/test/java/org/apache/fop/fonts/truetype/OTFSubSetFileTestCase.java
index 186f99a54..8f15edde0 100644
--- a/fop-core/src/test/java/org/apache/fop/fonts/truetype/OTFSubSetFileTestCase.java
+++ b/fop-core/src/test/java/org/apache/fop/fonts/truetype/OTFSubSetFileTestCase.java
@@ -312,7 +312,7 @@ public class OTFSubSetFileTestCase extends OTFFileTestCase {
private class Operator extends BytesNumber {
private String opName = "";
- public Operator(int number, int numBytes, String opName) {
+ Operator(int number, int numBytes, String opName) {
super(number, numBytes);
this.opName = opName;
}
@@ -544,7 +544,7 @@ public class OTFSubSetFileTestCase extends OTFFileTestCase {
int offset;
int fdFontCount = 128;
- public OTFSubSetFileFDArraySize() throws IOException {
+ OTFSubSetFileFDArraySize() throws IOException {
super();
}
@@ -600,7 +600,7 @@ public class OTFSubSetFileTestCase extends OTFFileTestCase {
int csLen;
int fdLen;
- public OTFSubSetFileEntryOrder(int csLen, int fdLen) throws IOException {
+ OTFSubSetFileEntryOrder(int csLen, int fdLen) throws IOException {
super();
this.csLen = csLen;
this.fdLen = fdLen;
@@ -610,7 +610,7 @@ public class OTFSubSetFileTestCase extends OTFFileTestCase {
cffReader = makeCFFDataReader();
LinkedHashMap<String, DICTEntry> topDict = new LinkedHashMap<String, DICTEntry>();
DICTEntry entry = new DICTEntry();
- entry.setOperands(Arrays.<Number>asList(0));
+ entry.setOperands(Collections.<Number>singletonList(0));
topDict.put("charset", entry);
entry.setOperandLength(csLen);
topDict.put("CharStrings", entry);
@@ -640,7 +640,7 @@ public class OTFSubSetFileTestCase extends OTFFileTestCase {
when(cffReader.getFDSelect()).thenReturn(fdSelect);
CFFDataReader.FontDict fd = mock(CFFDataReader.FontDict.class);
when(fd.getPrivateDictData()).thenReturn(new byte[0]);
- when(cffReader.getFDFonts()).thenReturn(Arrays.asList(fd));
+ when(cffReader.getFDFonts()).thenReturn(Collections.singletonList(fd));
LinkedHashMap<String, DICTEntry> map = new LinkedHashMap<String, DICTEntry>();
DICTEntry e = new DICTEntry();
@@ -662,7 +662,7 @@ public class OTFSubSetFileTestCase extends OTFFileTestCase {
cffReader = makeCFFDataReader();
fdSubrs = new ArrayList<List<byte[]>>();
fdSubrs.add(new ArrayList<byte[]>());
- writeCIDDictsAndSubrs(Arrays.asList(0));
+ writeCIDDictsAndSubrs(Collections.singletonList(0));
}
};
subSetFile.readFont(null, null, (MultiByteFont) null);
@@ -676,4 +676,28 @@ public class OTFSubSetFileTestCase extends OTFFileTestCase {
is.skip(2); //start index
Assert.assertEquals(is.read(), 1);
}
+
+ @Test
+ public void testResizeOfOperand2() throws IOException {
+ OTFSubSetFile otfSubSetFile = new OTFSubSetFile() {
+ void readFont(FontFileReader in, String embeddedName, MultiByteFont mbFont,
+ Map<Integer, Integer> usedGlyphs) throws IOException {
+ output = new byte[7];
+ cffReader = makeCFFDataReader();
+ LinkedHashMap<String, DICTEntry> topDict = new LinkedHashMap<String, DICTEntry>();
+ DICTEntry entry = new DICTEntry();
+ entry.setOperandLength(1);
+ entry.setOperator(new int[0]);
+ entry.setOperands(Collections.<Number>singletonList(0));
+ topDict.put("version", entry);
+ when(cffReader.getTopDictEntries()).thenReturn(topDict);
+ writeTopDICT();
+ }
+ };
+ otfSubSetFile.readFont(sourceSansReader, "StandardOpenType", null, glyphs);
+ ByteArrayInputStream fontSubset = new ByteArrayInputStream(otfSubSetFile.getFontSubset());
+ fontSubset.skip(5);
+ Assert.assertEquals(fontSubset.read(), 248);
+ Assert.assertEquals(fontSubset.read(), (byte)(390 - 108));
+ }
}