} 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());
if (sid > 391) {
stringIndexData.add(cffReader.getStringIndex().getValue(sid - 391));
}
-
byte[] newDictEntry = createNewRef(stringIndexData.size() + 390, dictEntry.getOperator(),
dictEntry.getOperandLength(), true);
return newDictEntry;
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);
} 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);
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();
}
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;
}
int offset;
int fdFontCount = 128;
- public OTFSubSetFileFDArraySize() throws IOException {
+ OTFSubSetFileFDArraySize() throws IOException {
super();
}
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;
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);
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();
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);
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));
+ }
}