diff options
author | Simon Steiner <ssteiner@apache.org> | 2017-03-09 11:58:08 +0000 |
---|---|---|
committer | Simon Steiner <ssteiner@apache.org> | 2017-03-09 11:58:08 +0000 |
commit | be8fcffac2745206394e0b23c454c1cbea2dddb5 (patch) | |
tree | 3ffe262fbce238f8782294b90e4e347343ab1fa5 | |
parent | acde10f62da3cc991244f8b38743d6a3bceea240 (diff) | |
download | xmlgraphics-fop-be8fcffac2745206394e0b23c454c1cbea2dddb5.tar.gz xmlgraphics-fop-be8fcffac2745206394e0b23c454c1cbea2dddb5.zip |
FOP-2697: Adobe Reader error with Adobe Kozuka Mincho font
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1786148 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | fop-core/src/main/java/org/apache/fop/fonts/truetype/OTFSubSetFile.java | 19 | ||||
-rw-r--r-- | fop-core/src/test/java/org/apache/fop/fonts/truetype/OTFSubSetFileTestCase.java | 75 |
2 files changed, 62 insertions, 32 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 bb5c48910..0cf05a618 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 @@ -1055,12 +1055,21 @@ public class OTFSubSetFile extends OTFFile { } private void writeCharsetTable(boolean cidFont) throws IOException { - writeByte(0); - for (Entry<Integer, Integer> entry : gidToSID.entrySet()) { - if (cidFont && entry.getKey() == 0) { - continue; + if (cidFont) { + writeByte(2); + for (int entry : gidToSID.keySet()) { + if (entry == 0) { + continue; + } + writeCard16(entry); + writeCard16(gidToSID.size() - 1); + break; + } + } else { + writeByte(0); + for (int entry : gidToSID.values()) { + writeCard16(entry); } - writeCard16((cidFont) ? entry.getKey() : entry.getValue()); } } 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 e653f7f9c..73fd6028a 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 @@ -19,6 +19,7 @@ package org.apache.fop.fonts.truetype; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; @@ -48,6 +49,7 @@ public class OTFSubSetFileTestCase extends OTFFileTestCase { private CFFDataReader cffReaderSourceSans; private OTFSubSetFile sourceSansSubset; + private Map<Integer, Integer> glyphs = new HashMap<Integer, Integer>(); /** * Initialises the test by creating the font subset. A CFFDataReader is @@ -57,8 +59,6 @@ public class OTFSubSetFileTestCase extends OTFFileTestCase { @Before public void setUp() throws Exception { super.setUp(); - - Map<Integer, Integer> glyphs = new HashMap<Integer, Integer>(); for (int i = 0; i < 256; i++) { glyphs.put(i, i); } @@ -444,27 +444,7 @@ public class OTFSubSetFileTestCase extends OTFFileTestCase { FontFileReader reader = sourceSansReader; String header = OFFontLoader.readHeader(reader); - OTFSubSetFile otfSubSetFile = new OTFSubSetFile() { - protected void createCFF() throws IOException { - cffReader = mock(CFFDataReader.class); - when(cffReader.getHeader()).thenReturn(new byte[0]); - when(cffReader.getTopDictIndex()).thenReturn(new CFFDataReader().new CFFIndexData() { - public byte[] getByteData() throws IOException { - return new byte[3]; - } - }); - - LinkedHashMap<String, DICTEntry> map = new LinkedHashMap<String, DICTEntry>(); - DICTEntry dict = new DICTEntry(); - dict.setOperands(Collections.<Number>singletonList(1)); - map.put("charset", dict); - map.put("CharStrings", dict); - when((cffReader.getTopDictEntries())).thenReturn(map); - when(cffReader.getFDSelect()).thenReturn(new CFFDataReader().new Format3FDSelect()); - cffReader.getTopDictEntries().get("CharStrings").setOperandLength(opLen); - super.createCFF(); - } - }; + OTFSubSetFile otfSubSetFile = new MyOTFSubSetFile(opLen); otfSubSetFile.readFont(reader, "StandardOpenType", header, new HashMap<Integer, Integer>()); return otfSubSetFile.getFontSubset(); @@ -472,10 +452,6 @@ public class OTFSubSetFileTestCase extends OTFFileTestCase { @Test public void testOffsets() throws IOException { - Map<Integer, Integer> glyphs = new HashMap<Integer, Integer>(); - for (int i = 0; i < 256; i++) { - glyphs.put(i, i); - } StringBuilder sb = new StringBuilder(); for (int i = 0; i < 2048; i++) { sb.append("SourceSansProBold"); @@ -484,4 +460,49 @@ public class OTFSubSetFileTestCase extends OTFFileTestCase { otfSubSetFile.readFont(sourceSansReader, sb.toString(), null, glyphs); new CFFParser().parse(otfSubSetFile.getFontSubset()); } + + @Test + public void testCharset() throws IOException { + FontFileReader reader = sourceSansReader; + MyOTFSubSetFile otfSubSetFile = new MyOTFSubSetFile(1); + otfSubSetFile.readFont(reader, "StandardOpenType", null, new HashMap<Integer, Integer>()); + ByteArrayInputStream is = new ByteArrayInputStream(otfSubSetFile.getFontSubset()); + is.skip(otfSubSetFile.charsetOffset); + Assert.assertEquals(is.read(), 2); + } + + class MyOTFSubSetFile extends OTFSubSetFile { + int charsetOffset; + int opLen; + MyOTFSubSetFile(int opLen) throws IOException { + super(); + this.opLen = opLen; + } + + protected void createCFF() throws IOException { + cffReader = mock(CFFDataReader.class); + when(cffReader.getHeader()).thenReturn(new byte[0]); + when(cffReader.getTopDictIndex()).thenReturn(new CFFDataReader().new CFFIndexData() { + public byte[] getByteData() throws IOException { + return new byte[3]; + } + }); + + LinkedHashMap<String, DICTEntry> map = new LinkedHashMap<String, DICTEntry>(); + DICTEntry dict = new DICTEntry(); + dict.setOperands(Collections.<Number>singletonList(1)); + map.put("charset", dict); + map.put("CharStrings", dict); + when((cffReader.getTopDictEntries())).thenReturn(map); + when(cffReader.getFDSelect()).thenReturn(new CFFDataReader().new Format3FDSelect()); + cffReader.getTopDictEntries().get("CharStrings").setOperandLength(opLen); + super.createCFF(); + } + + protected void updateFixedOffsets(Map<String, DICTEntry> topDICT, int dataTopDictOffset, + int charsetOffset, int charStringOffset, int encodingOffset) { + this.charsetOffset = charsetOffset; + super.updateFixedOffsets(topDICT, dataTopDictOffset, charsetOffset, charStringOffset, encodingOffset); + } + } } |