Author: ssteiner Date: Thu Oct 5 10:50:48 2017 New Revision: 1811185 URL: http://svn.apache.org/viewvc?rev=1811185&view=rev Log: FOP-2747: OTF subsetting: Resize entry to fit value
Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/truetype/OTFSubSetFile.java xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/fonts/truetype/OTFSubSetFileTestCase.java Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/truetype/OTFSubSetFile.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/truetype/OTFSubSetFile.java?rev=1811185&r1=1811184&r2=1811185&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/truetype/OTFSubSetFile.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/truetype/OTFSubSetFile.java Thu Oct 5 10:50:48 2017 @@ -296,6 +296,10 @@ public class OTFSubSetFile extends OTFSu } 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 OTFSu 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 OTFSu 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 OTFSu } 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 OTFSu 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(); } Modified: xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/fonts/truetype/OTFSubSetFileTestCase.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/fonts/truetype/OTFSubSetFileTestCase.java?rev=1811185&r1=1811184&r2=1811185&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/fonts/truetype/OTFSubSetFileTestCase.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/fonts/truetype/OTFSubSetFileTestCase.java Thu Oct 5 10:50:48 2017 @@ -312,7 +312,7 @@ public class OTFSubSetFileTestCase exten 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 exten int offset; int fdFontCount = 128; - public OTFSubSetFileFDArraySize() throws IOException { + OTFSubSetFileFDArraySize() throws IOException { super(); } @@ -600,7 +600,7 @@ public class OTFSubSetFileTestCase exten 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 exten 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 exten 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 exten 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 exten 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)); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: fop-commits-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-commits-h...@xmlgraphics.apache.org