]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-3203: Upgrade to PDFBox 3 main
authorSimon Steiner <ssteiner@apache.org>
Tue, 8 Oct 2024 09:19:59 +0000 (10:19 +0100)
committerSimon Steiner <ssteiner@apache.org>
Mon, 14 Oct 2024 08:31:51 +0000 (09:31 +0100)
15 files changed:
fop-core/pom.xml
fop-core/src/main/java/org/apache/fop/fonts/CFFToType1Font.java
fop-core/src/main/java/org/apache/fop/fonts/cff/CFFDataReader.java
fop-core/src/main/java/org/apache/fop/fonts/cff/FOPCFFDataInput.java
fop-core/src/main/java/org/apache/fop/fonts/truetype/OTFFile.java
fop-core/src/main/java/org/apache/fop/fonts/truetype/OTFSubSetFile.java
fop-core/src/main/java/org/apache/fop/render/ps/DataOutput.java [new file with mode: 0644]
fop-core/src/main/java/org/apache/fop/render/ps/Type1CharStringFormatter.java
fop-core/src/main/java/org/apache/fop/render/ps/Type1FontFormatter.java
fop-core/src/test/java/org/apache/fop/fonts/cff/CFFDataReaderTestCase.java
fop-core/src/test/java/org/apache/fop/fonts/truetype/OTFSubSetFileTestCase.java
fop-core/src/test/java/org/apache/fop/render/pdf/PDFEncodingTestCase.java
fop-servlet/pom.xml
fop/build.xml
fop/releasedist.xml

index d4ba999f347813dc8a0c2f64e040db001d2eb09e..b8f4f73a71e574e12e6ddece7f968aa947573f84 100644 (file)
     <dependency>
       <groupId>org.apache.pdfbox</groupId>
       <artifactId>fontbox</artifactId>
     <dependency>
       <groupId>org.apache.pdfbox</groupId>
       <artifactId>fontbox</artifactId>
-      <version>2.0.27</version>
+      <version>3.0.3</version>
     </dependency>
     <dependency>
       <groupId>javax.media</groupId>
     </dependency>
     <dependency>
       <groupId>javax.media</groupId>
     <dependency>
       <groupId>org.apache.pdfbox</groupId>
       <artifactId>pdfbox</artifactId>
     <dependency>
       <groupId>org.apache.pdfbox</groupId>
       <artifactId>pdfbox</artifactId>
-      <version>2.0.27</version>
+      <version>3.0.3</version>
       <scope>test</scope>
     </dependency>
   </dependencies>
       <scope>test</scope>
     </dependency>
   </dependencies>
index 3ef9b6e33478eb138ba6420bce378cbc5db9cc60..22d23e0f2ad8a7953067b3e2426ce9426c1bdf66 100644 (file)
@@ -30,6 +30,7 @@ import java.util.Map;
 import org.apache.commons.io.IOUtils;
 import org.apache.fontbox.cff.CFFFont;
 import org.apache.fontbox.cff.CFFParser;
 import org.apache.commons.io.IOUtils;
 import org.apache.fontbox.cff.CFFFont;
 import org.apache.fontbox.cff.CFFParser;
+import org.apache.pdfbox.io.RandomAccessReadBuffer;
 
 import org.apache.fop.apps.io.InternalResourceResolver;
 import org.apache.fop.fonts.type1.PFBData;
 
 import org.apache.fop.apps.io.InternalResourceResolver;
 import org.apache.fop.fonts.type1.PFBData;
@@ -55,7 +56,7 @@ public class CFFToType1Font extends MultiByteFont {
     }
 
     private List<InputStream> convertOTFToType1(InputStream in) throws IOException {
     }
 
     private List<InputStream> convertOTFToType1(InputStream in) throws IOException {
-        CFFFont f = new CFFParser().parse(IOUtils.toByteArray(in)).get(0);
+        CFFFont f = new CFFParser().parse(new RandomAccessReadBuffer(IOUtils.toByteArray(in))).get(0);
         List<InputStream> fonts = new ArrayList<InputStream>();
         Map<Integer, Integer> glyphs = cidSet.getGlyphs();
         int i = 0;
         List<InputStream> fonts = new ArrayList<InputStream>();
         Map<Integer, Integer> glyphs = cidSet.getGlyphs();
         int i = 0;
index e9ad9cfed58bb1936ea40a4bc9ae8e743786f92d..5f68026961ee829a36f67a56e0442644b3751932 100644 (file)
@@ -25,8 +25,8 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
 import java.util.List;
 import java.util.Map;
 
-import org.apache.fontbox.cff.CFFDataInput;
 import org.apache.fontbox.cff.CFFOperator;
 import org.apache.fontbox.cff.CFFOperator;
+import org.apache.fontbox.cff.DataInputByteArray;
 
 import org.apache.fop.fonts.truetype.FontFileReader;
 import org.apache.fop.fonts.truetype.OTFFile;
 
 import org.apache.fop.fonts.truetype.FontFileReader;
 import org.apache.fop.fonts.truetype.OTFFile;
@@ -35,7 +35,7 @@ import org.apache.fop.fonts.truetype.OTFFile;
  * A class to read the CFF data from an OTF CFF font file.
  */
 public class CFFDataReader {
  * A class to read the CFF data from an OTF CFF font file.
  */
 public class CFFDataReader {
-    private CFFDataInput cffData;
+    private DataInputByteArray cffData;
 
     private byte[] header;
     private CFFIndexData nameIndex;
 
     private byte[] header;
     private CFFIndexData nameIndex;
@@ -137,14 +137,10 @@ public class CFFDataReader {
                     operator[0] = dictData[i];
                 }
                 String operatorName = "";
                     operator[0] = dictData[i];
                 }
                 String operatorName = "";
-                CFFOperator tempOp = null;
                 if (operator.length > 1) {
                 if (operator.length > 1) {
-                    tempOp = CFFOperator.getOperator(new CFFOperator.Key(operator[0], operator[1]));
+                    operatorName = CFFOperator.getOperator(operator[0], operator[1]);
                 } else {
                 } else {
-                    tempOp = CFFOperator.getOperator(new CFFOperator.Key(operator[0]));
-                }
-                if (tempOp != null) {
-                    operatorName = tempOp.getName();
+                    operatorName = CFFOperator.getOperator(operator[0]);
                 }
                 DICTEntry newEntry = new DICTEntry();
                 newEntry.setOperator(operator);
                 }
                 DICTEntry newEntry = new DICTEntry();
                 newEntry.setOperator(operator);
@@ -330,7 +326,7 @@ public class CFFDataReader {
      * @return Returns an object representing the index
      * @throws IOException Throws an IO Exception if an error occurs
      */
      * @return Returns an object representing the index
      * @throws IOException Throws an IO Exception if an error occurs
      */
-    public CFFIndexData readIndex(CFFDataInput input) throws IOException {
+    public CFFIndexData readIndex(DataInputByteArray input) throws IOException {
         CFFIndexData nameIndex = new CFFIndexData();
         if (input != null) {
             int origPos = input.getPosition();
         CFFIndexData nameIndex = new CFFIndexData();
         if (input != null) {
             int origPos = input.getPosition();
@@ -352,11 +348,11 @@ public class CFFDataReader {
             return 0;
         }
         cffData.setPosition(charsetOffset);
             return 0;
         }
         cffData.setPosition(charsetOffset);
-        int charsetFormat = cffData.readCard8();
+        int charsetFormat = cffData.readUnsignedByte();
         switch (charsetFormat) {
         case 0: //Adjust for .notdef character
                  cffData.setPosition(cffData.getPosition() + (--gid * 2));
         switch (charsetFormat) {
         case 0: //Adjust for .notdef character
                  cffData.setPosition(cffData.getPosition() + (--gid * 2));
-                 return cffData.readSID();
+                 return cffData.readUnsignedShort();
         case 1: return getSIDFromGIDFormat(gid, 1);
         case 2: return getSIDFromGIDFormat(gid, 2);
         default: return 0;
         case 1: return getSIDFromGIDFormat(gid, 1);
         case 2: return getSIDFromGIDFormat(gid, 2);
         default: return 0;
@@ -367,8 +363,8 @@ public class CFFDataReader {
         int glyphCount = 0;
         while (true) {
             int oldGlyphCount = glyphCount;
         int glyphCount = 0;
         while (true) {
             int oldGlyphCount = glyphCount;
-            int start = cffData.readSID();
-            glyphCount += ((format == 1) ? cffData.readCard8() : cffData.readCard16()) + 1;
+            int start = cffData.readUnsignedShort();
+            glyphCount += ((format == 1) ? cffData.readUnsignedByte() : cffData.readUnsignedShort()) + 1;
             if (gid <= glyphCount) {
                 return start + (gid - oldGlyphCount) - 1;
             }
             if (gid <= glyphCount) {
                 return start + (gid - oldGlyphCount) - 1;
             }
@@ -407,7 +403,7 @@ public class CFFDataReader {
         return charStringIndex;
     }
 
         return charStringIndex;
     }
 
-    public CFFDataInput getCFFData() {
+    public DataInputByteArray getCFFData() {
         return cffData;
     }
 
         return cffData;
     }
 
@@ -423,7 +419,7 @@ public class CFFDataReader {
         return fdFonts;
     }
 
         return fdFonts;
     }
 
-    public CFFDataInput getLocalSubrsForGlyph(int glyph) throws IOException {
+    public DataInputByteArray getLocalSubrsForGlyph(int glyph) throws IOException {
         //Subsets are currently written using a Format0 FDSelect
         FDSelect fontDictionary = getFDSelect();
         if (fontDictionary instanceof Format0FDSelect) {
         //Subsets are currently written using a Format0 FDSelect
         FDSelect fontDictionary = getFDSelect();
         if (fontDictionary instanceof Format0FDSelect) {
@@ -432,7 +428,7 @@ public class CFFDataReader {
             FontDict font = getFDFonts().get(found);
             byte[] localSubrData = font.getLocalSubrData().getByteData();
             if (localSubrData != null) {
             FontDict font = getFDFonts().get(found);
             byte[] localSubrData = font.getLocalSubrData().getByteData();
             if (localSubrData != null) {
-                return new CFFDataInput(localSubrData);
+                return new DataInputByteArray(localSubrData);
             } else {
                 return null;
             }
             } else {
                 return null;
             }
@@ -448,7 +444,7 @@ public class CFFDataReader {
             FontDict font = getFDFonts().get(index);
             byte[] localSubrsData = font.getLocalSubrData().getByteData();
             if (localSubrsData != null) {
             FontDict font = getFDFonts().get(index);
             byte[] localSubrsData = font.getLocalSubrData().getByteData();
             if (localSubrsData != null) {
-                return new CFFDataInput(localSubrsData);
+                return new DataInputByteArray(localSubrsData);
             } else {
                 return null;
             }
             } else {
                 return null;
             }
@@ -473,8 +469,8 @@ public class CFFDataReader {
             int offset = topDict.get("Encoding").getOperands().get(0).intValue();
             if (offset != 0 && offset != 1) {
                 //No need to set the offset as we are reading the data sequentially.
             int offset = topDict.get("Encoding").getOperands().get(0).intValue();
             if (offset != 0 && offset != 1) {
                 //No need to set the offset as we are reading the data sequentially.
-                int format = cffData.readCard8();
-                int numEntries = cffData.readCard8();
+                int format = cffData.readUnsignedByte();
+                int numEntries = cffData.readUnsignedByte();
                 switch (format) {
                 case 0:
                     foundEncoding = readFormat0Encoding(format, numEntries);
                 switch (format) {
                 case 0:
                     foundEncoding = readFormat0Encoding(format, numEntries);
@@ -496,7 +492,7 @@ public class CFFDataReader {
         newEncoding.setNumEntries(numEntries);
         int[] codes = new int[numEntries];
         for (int i = 0; i < numEntries; i++) {
         newEncoding.setNumEntries(numEntries);
         int[] codes = new int[numEntries];
         for (int i = 0; i < numEntries; i++) {
-            codes[i] = cffData.readCard8();
+            codes[i] = cffData.readUnsignedByte();
         }
         newEncoding.setCodes(codes);
         return newEncoding;
         }
         newEncoding.setCodes(codes);
         return newEncoding;
@@ -509,8 +505,8 @@ public class CFFDataReader {
         newEncoding.setNumEntries(numEntries);
         Map<Integer, Integer> ranges = new LinkedHashMap<Integer, Integer>();
         for (int i = 0; i < numEntries; i++) {
         newEncoding.setNumEntries(numEntries);
         Map<Integer, Integer> ranges = new LinkedHashMap<Integer, Integer>();
         for (int i = 0; i < numEntries; i++) {
-            int first = cffData.readCard8();
-            int left = cffData.readCard8();
+            int first = cffData.readUnsignedByte();
+            int left = cffData.readUnsignedByte();
             ranges.put(first, left);
         }
         newEncoding.setRanges(ranges);
             ranges.put(first, left);
         }
         newEncoding.setRanges(ranges);
@@ -523,7 +519,7 @@ public class CFFDataReader {
         if (fdSelectEntry != null) {
             int fdOffset = fdSelectEntry.getOperands().get(0).intValue();
             cffData.setPosition(fdOffset);
         if (fdSelectEntry != null) {
             int fdOffset = fdSelectEntry.getOperands().get(0).intValue();
             cffData.setPosition(fdOffset);
-            int format = cffData.readCard8();
+            int format = cffData.readUnsignedByte();
             switch (format) {
             case 0:
                 fdSelect = readFormat0FDSelect();
             switch (format) {
             case 0:
                 fdSelect = readFormat0FDSelect();
@@ -543,7 +539,7 @@ public class CFFDataReader {
         int glyphCount = charStringIndex.getNumObjects();
         int[] fds = new int[glyphCount];
         for (int i = 0; i < glyphCount; i++) {
         int glyphCount = charStringIndex.getNumObjects();
         int[] fds = new int[glyphCount];
         for (int i = 0; i < glyphCount; i++) {
-            fds[i] = cffData.readCard8();
+            fds[i] = cffData.readUnsignedByte();
         }
         newFDs.setFDIndexes(fds);
         return newFDs;
         }
         newFDs.setFDIndexes(fds);
         return newFDs;
@@ -552,16 +548,16 @@ public class CFFDataReader {
     private Format3FDSelect readFormat3FDSelect() throws IOException {
         Format3FDSelect newFDs = new Format3FDSelect();
         newFDs.setFormat(3);
     private Format3FDSelect readFormat3FDSelect() throws IOException {
         Format3FDSelect newFDs = new Format3FDSelect();
         newFDs.setFormat(3);
-        int rangeCount = cffData.readCard16();
+        int rangeCount = cffData.readUnsignedShort();
         newFDs.setRangeCount(rangeCount);
         Map<Integer, Integer> ranges = new LinkedHashMap<Integer, Integer>();
         for (int i = 0; i < rangeCount; i++) {
         newFDs.setRangeCount(rangeCount);
         Map<Integer, Integer> ranges = new LinkedHashMap<Integer, Integer>();
         for (int i = 0; i < rangeCount; i++) {
-            int first = cffData.readCard16();
-            int fd = cffData.readCard8();
+            int first = cffData.readUnsignedShort();
+            int fd = cffData.readUnsignedByte();
             ranges.put(first, fd);
         }
         newFDs.setRanges(ranges);
             ranges.put(first, fd);
         }
         newFDs.setRanges(ranges);
-        newFDs.setSentinelGID(cffData.readCard16());
+        newFDs.setSentinelGID(cffData.readUnsignedShort());
         return newFDs;
     }
 
         return newFDs;
     }
 
@@ -709,19 +705,19 @@ public class CFFDataReader {
          * @param cffData A byte array containing the CFF data
          * @throws IOException Throws an IO Exception if an error occurs
          */
          * @param cffData A byte array containing the CFF data
          * @throws IOException Throws an IO Exception if an error occurs
          */
-        public void parseIndexHeader(CFFDataInput cffData) throws IOException {
-            setNumObjects(cffData.readCard16());
-            setOffSize(cffData.readOffSize());
+        public void parseIndexHeader(DataInputByteArray cffData) throws IOException {
+            setNumObjects(cffData.readUnsignedShort());
+            setOffSize(cffData.readUnsignedByte());
             int[] offsets = new int[getNumObjects() + 1];
             byte[] bytes;
             //Fills the offsets array
             for (int i = 0; i <= getNumObjects(); i++) {
                 switch (getOffSize()) {
                 case 1:
             int[] offsets = new int[getNumObjects() + 1];
             byte[] bytes;
             //Fills the offsets array
             for (int i = 0; i <= getNumObjects(); i++) {
                 switch (getOffSize()) {
                 case 1:
-                    offsets[i] = cffData.readCard8();
+                    offsets[i] = cffData.readUnsignedByte();
                     break;
                 case 2:
                     break;
                 case 2:
-                    offsets[i] = cffData.readCard16();
+                    offsets[i] = cffData.readUnsignedShort();
                     break;
                 case 3:
                     bytes = cffData.readBytes(3);
                     break;
                 case 3:
                     bytes = cffData.readBytes(3);
index 43fc6b291e8d3f948d482766b8d5c21d55a078aa..52028516cb51c68c5c056ac7b9a5736e17a89845 100644 (file)
@@ -20,14 +20,76 @@ package org.apache.fop.fonts.cff;
 
 import java.io.IOException;
 
 
 import java.io.IOException;
 
-import org.apache.fontbox.cff.CFFDataInput;
+import org.apache.fontbox.cff.DataInputByteArray;
+
+public class FOPCFFDataInput extends DataInputByteArray {
+    private final byte[] inputBuffer;
+    private int bufferPosition;
 
 
-public class FOPCFFDataInput extends CFFDataInput {
     public FOPCFFDataInput(byte[] buffer) {
         super(buffer);
     public FOPCFFDataInput(byte[] buffer) {
         super(buffer);
+        this.inputBuffer = buffer;
+    }
+
+    public boolean hasRemaining() throws IOException {
+        return this.bufferPosition < this.inputBuffer.length;
+    }
+
+    public int getPosition() {
+        return this.bufferPosition;
+    }
+
+    public void setPosition(int position) throws IOException {
+        if (position < 0) {
+            throw new IOException("position is negative");
+//        } else if (position >= this.inputBuffer.length) {
+//            throw new IOException("New position is out of range " + position + " >= " + this.inputBuffer.length);
+        } else {
+            this.bufferPosition = position;
+        }
+    }
+
+    public byte readByte() throws IOException {
+        if (!this.hasRemaining()) {
+            throw new IOException("End off buffer reached");
+        } else {
+            return this.inputBuffer[this.bufferPosition++];
+        }
+    }
+
+    public int readUnsignedByte() throws IOException {
+        if (!this.hasRemaining()) {
+            throw new IOException("End off buffer reached");
+        } else {
+            return this.inputBuffer[this.bufferPosition++] & 255;
+        }
+    }
+
+    public int peekUnsignedByte(int offset) throws IOException {
+        if (offset < 0) {
+            throw new IOException("offset is negative");
+        } else if (this.bufferPosition + offset >= this.inputBuffer.length) {
+            throw new IOException("Offset position is out of range " + (this.bufferPosition + offset)
+                    + " >= " + this.inputBuffer.length);
+        } else {
+            return this.inputBuffer[this.bufferPosition + offset] & 255;
+        }
+    }
+
+    public byte[] readBytes(int length) throws IOException {
+        if (length < 0) {
+            throw new IOException("length is negative");
+        } else if (this.inputBuffer.length - this.bufferPosition < length) {
+            throw new IOException("Premature end of buffer reached");
+        } else {
+            byte[] bytes = new byte[length];
+            System.arraycopy(this.inputBuffer, this.bufferPosition, bytes, 0, length);
+            this.bufferPosition += length;
+            return bytes;
+        }
     }
 
     }
 
-    public int readOffSize() throws IOException {
-        return readUnsignedByte();
+    public int length() throws IOException {
+        return this.inputBuffer.length;
     }
 }
     }
 }
index 683fd51b15392cde42742ffed3f704575f2962a8..befbb9453a0cd1811148498c8f36e16471147ba3 100644 (file)
@@ -22,10 +22,11 @@ package org.apache.fop.fonts.truetype;
 import java.io.IOException;
 import java.util.List;
 
 import java.io.IOException;
 import java.util.List;
 
-import org.apache.fontbox.cff.CFFDataInput;
 import org.apache.fontbox.cff.CFFFont;
 import org.apache.fontbox.cff.CFFParser;
 import org.apache.fontbox.cff.CFFType1Font;
 import org.apache.fontbox.cff.CFFFont;
 import org.apache.fontbox.cff.CFFParser;
 import org.apache.fontbox.cff.CFFType1Font;
+import org.apache.fontbox.cff.DataInputByteArray;
+import org.apache.pdfbox.io.RandomAccessReadBuffer;
 
 public class OTFFile extends OpenFont {
 
 
 public class OTFFile extends OpenFont {
 
@@ -100,7 +101,7 @@ public class OTFFile extends OpenFont {
         fontFile = in;
         fontFile.seekSet(0);
         CFFParser parser = new CFFParser();
         fontFile = in;
         fontFile.seekSet(0);
         CFFParser parser = new CFFParser();
-        fileFont = parser.parse(in.getAllBytes()).get(0);
+        fileFont = parser.parse(new RandomAccessReadBuffer(in.getAllBytes())).get(0);
         embedFontName = fileFont.getName();
     }
 
         embedFontName = fileFont.getName();
     }
 
@@ -122,7 +123,7 @@ public class OTFFile extends OpenFont {
      */
     public static byte[] getCFFData(FontFileReader fontFile) throws IOException {
         byte[] cff = fontFile.getAllBytes();
      */
     public static byte[] getCFFData(FontFileReader fontFile) throws IOException {
         byte[] cff = fontFile.getAllBytes();
-        CFFDataInput input = new CFFDataInput(fontFile.getAllBytes());
+        DataInputByteArray input = new DataInputByteArray(fontFile.getAllBytes());
         input.readBytes(4); //OTTO
         short numTables = input.readShort();
         input.readShort(); //searchRange
         input.readBytes(4); //OTTO
         short numTables = input.readShort();
         input.readShort(); //searchRange
@@ -143,8 +144,8 @@ public class OTFFile extends OpenFont {
         return cff;
     }
 
         return cff;
     }
 
-    private static long readLong(CFFDataInput input) throws IOException {
-        return (input.readCard16() << 16) | input.readCard16();
+    private static long readLong(DataInputByteArray input) throws IOException {
+        return (input.readUnsignedShort() << 16) | input.readUnsignedShort();
     }
 
     public boolean isType1() {
     }
 
     public boolean isType1() {
index 6f8e948ddcf98c346d6199787b58f36c84b64ce3..2ea2ed8238d2e1d50e479b3606a4c3f20428bdb8 100644 (file)
@@ -23,6 +23,7 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -39,6 +40,7 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.fontbox.cff.CFFStandardString;
 import org.apache.fontbox.cff.CFFType1Font;
 import org.apache.fontbox.cff.CharStringCommand;
 import org.apache.fontbox.cff.CFFStandardString;
 import org.apache.fontbox.cff.CFFType1Font;
 import org.apache.fontbox.cff.CharStringCommand;
+import org.apache.fontbox.cff.Type1CharString;
 import org.apache.fontbox.cff.Type2CharString;
 
 import org.apache.fop.fonts.MultiByteFont;
 import org.apache.fontbox.cff.Type2CharString;
 
 import org.apache.fop.fonts.MultiByteFont;
@@ -110,7 +112,7 @@ public class OTFSubSetFile extends OTFSubSetWriter {
     /** The operator used to identify a global subroutine reference */
     private static final int GLOBAL_SUBROUTINE = 29;
 
     /** The operator used to identify a global subroutine reference */
     private static final int GLOBAL_SUBROUTINE = 29;
 
-    private static final String ACCENT_CMD = "seac";
+    private static final String ACCENT_CMD = "SEAC|";
 
     /** The parser used to parse type2 charstring */
     private Type2Parser type2Parser;
 
     /** The parser used to parse type2 charstring */
     private Type2Parser type2Parser;
@@ -153,10 +155,10 @@ public class OTFSubSetFile extends OTFSubSetWriter {
             for (int gid : subsetGlyphs.keySet()) {
                 Type2CharString type2CharString = cffType1Font.getType2CharString(gid);
                 List<Number> stack = new ArrayList<Number>();
             for (int gid : subsetGlyphs.keySet()) {
                 Type2CharString type2CharString = cffType1Font.getType2CharString(gid);
                 List<Number> stack = new ArrayList<Number>();
-                for (Object obj : type2CharString.getType1Sequence()) {
+                List type1Sequence = getType1Sequence(type2CharString);
+                for (Object obj : type1Sequence) {
                     if (obj instanceof CharStringCommand) {
                     if (obj instanceof CharStringCommand) {
-                        String name = CharStringCommand.TYPE1_VOCABULARY.get(((CharStringCommand) obj).getKey());
-                        if (ACCENT_CMD.equals(name)) {
+                        if (ACCENT_CMD.equals(obj.toString())) {
                             int first = stack.get(3).intValue();
                             int second = stack.get(4).intValue();
                             mbFont.mapChar(AdobeStandardEncoding.getUnicodeFromCodePoint(first));
                             int first = stack.get(3).intValue();
                             int second = stack.get(4).intValue();
                             mbFont.mapChar(AdobeStandardEncoding.getUnicodeFromCodePoint(first));
@@ -171,6 +173,16 @@ public class OTFSubSetFile extends OTFSubSetWriter {
         }
     }
 
         }
     }
 
+    private List<Object> getType1Sequence(Type1CharString type1CharString) {
+        try {
+            Field f = Type1CharString.class.getDeclaredField("type1Sequence");
+            f.setAccessible(true);
+            return (List<Object>) f.get(type1CharString);
+        } catch (IllegalAccessException | NoSuchFieldException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
     private Map<Integer, Integer> sortByValue(Map<Integer, Integer> map) {
         List<Entry<Integer, Integer>> list = new ArrayList<Entry<Integer, Integer>>(map.entrySet());
         Collections.sort(list, new Comparator<Entry<Integer, Integer>>() {
     private Map<Integer, Integer> sortByValue(Map<Integer, Integer> map) {
         List<Entry<Integer, Integer>> list = new ArrayList<Entry<Integer, Integer>>(map.entrySet());
         Collections.sort(list, new Comparator<Entry<Integer, Integer>>() {
diff --git a/fop-core/src/main/java/org/apache/fop/render/ps/DataOutput.java b/fop-core/src/main/java/org/apache/fop/render/ps/DataOutput.java
new file mode 100644 (file)
index 0000000..f1a168a
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.fop.render.ps;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+public class DataOutput {
+
+    private ByteArrayOutputStream outputBuffer = new ByteArrayOutputStream();
+
+    private String outputEncoding;
+
+    /**
+     * Constructor.
+     */
+    public DataOutput() {
+        this("ISO-8859-1");
+    }
+
+    /**
+     * Constructor with a given encoding.
+     * @param encoding the encoding to be used for writing
+     */
+    public DataOutput(String encoding) {
+        this.outputEncoding = encoding;
+    }
+
+    /**
+     * Returns the written data buffer as byte array.
+     * @return the data buffer as byte array
+     */
+    public byte[] getBytes() {
+        return outputBuffer.toByteArray();
+    }
+
+    /**
+     * Write an int value to the buffer.
+     * @param value the given value
+     */
+    public void write(int value) {
+        outputBuffer.write(value);
+    }
+
+    /**
+     * Write a byte array to the buffer.
+     * @param buffer the given byte array
+     */
+    public void write(byte[] buffer) {
+        outputBuffer.write(buffer, 0, buffer.length);
+    }
+
+    /**
+     * Write a part of a byte array to the buffer.
+     * @param buffer the given byte buffer
+     * @param offset the offset where to start
+     * @param length the amount of bytes to be written from the array
+     */
+    public void write(byte[] buffer, int offset, int length) {
+        outputBuffer.write(buffer, offset, length);
+    }
+
+    /**
+     * Write the given string to the buffer using the given encoding.
+     * @param string the given string
+     * @throws IOException If an error occurs during writing the data to the buffer
+     */
+    public void print(String string) throws IOException {
+        write(string.getBytes(outputEncoding));
+    }
+
+    /**
+     * Write the given string to the buffer using the given encoding.
+     * A newline is added after the given string
+     * @param string the given string
+     * @throws IOException If an error occurs during writing the data to the buffer
+     */
+    public void println(String string) throws IOException {
+        write(string.getBytes(outputEncoding));
+        write('\n');
+    }
+
+    /**
+     * Add a newline to the given string.
+     */
+    public void println() {
+        write('\n');
+    }
+}
index 8d068c988cd3ea35c07cc394ea3178936c949e62..beaf913e1b700e74cda2b8ab58e3dfc587965ff7 100644 (file)
@@ -17,6 +17,7 @@
 package org.apache.fop.render.ps;
 
 import java.io.ByteArrayOutputStream;
 package org.apache.fop.render.ps;
 
 import java.io.ByteArrayOutputStream;
+import java.lang.reflect.Field;
 import java.util.List;
 
 import org.apache.fontbox.cff.CharStringCommand;
 import java.util.List;
 
 import org.apache.fontbox.cff.CharStringCommand;
@@ -51,12 +52,28 @@ public class Type1CharStringFormatter {
     }
 
     private void writeCommand(CharStringCommand command) {
     }
 
     private void writeCommand(CharStringCommand command) {
-        int[] value = command.getKey().getValue();
+        int[] value = getValue(command);
         for (int aValue : value) {
             output.write(aValue);
         }
     }
 
         for (int aValue : value) {
             output.write(aValue);
         }
     }
 
+    private int[] getValue(CharStringCommand command) {
+        CharStringCommand.Type1KeyWord keyWord = command.getType1KeyWord();
+        if (keyWord == null) {
+            return new int[0];
+        }
+        CharStringCommand.Key key = CharStringCommand.Key.valueOf(keyWord.name());
+        try {
+            Field f = key.getClass().getDeclaredField("hashValue");
+            f.setAccessible(true);
+            int value = (int) f.get(key);
+            return new int[] {value};
+        } catch (IllegalAccessException | NoSuchFieldException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
     private void writeNumber(Integer number) {
         int value = number;
         if (value >= -107 && value <= 107) {
     private void writeNumber(Integer number) {
         int value = number;
         if (value >= -107 && value <= 107) {
index 776d410f93f02506dc235fad22fef64e5bc99979..e9ca96091d50d2ef25f0e56363e00590a85994a2 100644 (file)
 package org.apache.fop.render.ps;
 
 import java.io.IOException;
 package org.apache.fop.render.ps;
 
 import java.io.IOException;
+import java.lang.reflect.Field;
 import java.text.DecimalFormat;
 import java.text.DecimalFormatSymbols;
 import java.text.NumberFormat;
 import java.util.Collection;
 import java.text.DecimalFormat;
 import java.text.DecimalFormatSymbols;
 import java.text.NumberFormat;
 import java.util.Collection;
+import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
 import org.apache.fontbox.cff.CFFCIDFont;
 import org.apache.fontbox.cff.CFFFont;
 import org.apache.fontbox.cff.CFFType1Font;
 import java.util.Locale;
 import java.util.Map;
 
 import org.apache.fontbox.cff.CFFCIDFont;
 import org.apache.fontbox.cff.CFFFont;
 import org.apache.fontbox.cff.CFFType1Font;
-import org.apache.fontbox.cff.DataOutput;
+import org.apache.fontbox.cff.Type1CharString;
 import org.apache.fontbox.cff.Type1FontUtil;
 
 /**
 import org.apache.fontbox.cff.Type1FontUtil;
 
 /**
@@ -178,10 +180,10 @@ public final class Type1FontFormatter {
             byte[] type1Bytes;
             if (font instanceof CFFCIDFont) {
                 int cid = font.getCharset().getCIDForGID(gid);
             byte[] type1Bytes;
             if (font instanceof CFFCIDFont) {
                 int cid = font.getCharset().getCIDForGID(gid);
-                type1Bytes = formatter.format(((CFFCIDFont)font).getType2CharString(cid).getType1Sequence());
+                type1Bytes = formatter.format(getType1Sequence(((CFFCIDFont)font).getType2CharString(cid)));
             } else {
                 mapping = font.getCharset().getNameForGID(gid);
             } else {
                 mapping = font.getCharset().getNameForGID(gid);
-                type1Bytes = formatter.format(((CFFType1Font)font).getType1CharString(mapping).getType1Sequence());
+                type1Bytes = formatter.format(getType1Sequence(((CFFType1Font)font).getType1CharString(mapping)));
             }
             byte[] charstringBytes = Type1FontUtil.charstringEncrypt(type1Bytes, 4);
             output.print("/" + mapping + " " + charstringBytes.length + " RD ");
             }
             byte[] charstringBytes = Type1FontUtil.charstringEncrypt(type1Bytes, 4);
             output.print("/" + mapping + " " + charstringBytes.length + " RD ");
@@ -199,6 +201,16 @@ public final class Type1FontFormatter {
         output.println("mark currentfile closefile");
     }
 
         output.println("mark currentfile closefile");
     }
 
+    private List<Object> getType1Sequence(Type1CharString type1CharString) {
+        try {
+            Field f = Type1CharString.class.getDeclaredField("type1Sequence");
+            f.setAccessible(true);
+            return (List<Object>) f.get(type1CharString);
+        } catch (IllegalAccessException | NoSuchFieldException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
     private static String formatArray(Object object, boolean executable) {
         return formatArray(object, null, executable);
     }
     private static String formatArray(Object object, boolean executable) {
         return formatArray(object, null, executable);
     }
index 2e112de7bda9c3ba8824c8161a7e668d6d3e48f5..cb905e9ab7a139b9ae6c34bf8a0a5f98da6d162f 100644 (file)
@@ -28,8 +28,6 @@ import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
 
 
 import static org.junit.Assert.assertEquals;
 
-import org.apache.fontbox.cff.CFFDataInput;
-
 import org.apache.fop.fonts.cff.CFFDataReader.CFFIndexData;
 import org.apache.fop.fonts.cff.CFFDataReader.DICTEntry;
 import org.apache.fop.fonts.truetype.OTFSubSetFile;
 import org.apache.fop.fonts.cff.CFFDataReader.CFFIndexData;
 import org.apache.fop.fonts.cff.CFFDataReader.DICTEntry;
 import org.apache.fop.fonts.truetype.OTFSubSetFile;
@@ -145,7 +143,7 @@ public class CFFDataReaderTestCase {
             data[i] = (byte)randGen.nextInt(255);
         }
         testIndex = OTFSubSetFile.concatArray(testIndex, data);
             data[i] = (byte)randGen.nextInt(255);
         }
         testIndex = OTFSubSetFile.concatArray(testIndex, data);
-        CFFIndexData indexData = cffReader.readIndex(new CFFDataInput(testIndex));
+        CFFIndexData indexData = cffReader.readIndex(new FOPCFFDataInput(testIndex));
         assertEquals(indexData.getNumObjects(), 5);
         assertEquals(indexData.getOffSize(), 1);
         assertEquals(indexData.getOffsets().length, 6);
         assertEquals(indexData.getNumObjects(), 5);
         assertEquals(indexData.getOffSize(), 1);
         assertEquals(indexData.getOffsets().length, 6);
index e9a610d9699e83c02df435c6153d3d5c92500155..d0fba4cd8ad4a97ccdb64b2448bd35a550ea7c95 100644 (file)
@@ -46,6 +46,7 @@ import org.apache.fontbox.cff.CFFParser;
 import org.apache.fontbox.cff.CFFType1Font;
 import org.apache.fontbox.cff.CharStringCommand;
 import org.apache.fontbox.cff.Type2CharString;
 import org.apache.fontbox.cff.CFFType1Font;
 import org.apache.fontbox.cff.CharStringCommand;
 import org.apache.fontbox.cff.Type2CharString;
+import org.apache.pdfbox.io.RandomAccessReadBuffer;
 
 import org.apache.fop.fonts.MultiByteFont;
 import org.apache.fop.fonts.cff.CFFDataReader;
 
 import org.apache.fop.fonts.MultiByteFont;
 import org.apache.fop.fonts.cff.CFFDataReader;
@@ -469,7 +470,7 @@ public class OTFSubSetFileTestCase extends OTFFileTestCase {
         }
         OTFSubSetFile otfSubSetFile = new OTFSubSetFile();
         otfSubSetFile.readFont(sourceSansReader, sb.toString(), null, glyphs);
         }
         OTFSubSetFile otfSubSetFile = new OTFSubSetFile();
         otfSubSetFile.readFont(sourceSansReader, sb.toString(), null, glyphs);
-        new CFFParser().parse(otfSubSetFile.getFontSubset());
+        new CFFParser().parse(new RandomAccessReadBuffer(otfSubSetFile.getFontSubset()));
     }
 
     @Test
     }
 
     @Test
@@ -711,7 +712,8 @@ public class OTFSubSetFileTestCase extends OTFFileTestCase {
         OTFSubSetFile sourceSansSubset = new OTFSubSetFile() {
             protected void initializeFont(FontFileReader in) {
                 fileFont = new CFFType1Font() {
         OTFSubSetFile sourceSansSubset = new OTFSubSetFile() {
             protected void initializeFont(FontFileReader in) {
                 fileFont = new CFFType1Font() {
-                    List<Object> sequence = Arrays.asList(0, 0, 0, (int)'a', (int)'b', new CharStringCommand(12, 6));
+                    List<Object> sequence = Arrays.asList(0, 0, 0, (int)'a', (int)'b',
+                            CharStringCommand.getInstance(12, 6));
                     public Type2CharString getType2CharString(int gid) {
                         return new Type2CharString(null, null, null, 0, sequence, 0, 0);
                     }
                     public Type2CharString getType2CharString(int gid) {
                         return new Type2CharString(null, null, null, 0, sequence, 0, 0);
                     }
index d6c614aa05b02cd99027e175cd9a92c07343763c..02e4e702b98ca7c030ac6b36c9566d1f0ec638fb 100644 (file)
@@ -19,8 +19,6 @@
 
 package org.apache.fop.render.pdf;
 
 
 package org.apache.fop.render.pdf;
 
-
-
 import java.io.File;
 import java.io.IOException;
 
 import java.io.File;
 import java.io.IOException;
 
@@ -30,6 +28,7 @@ import org.xml.sax.SAXException;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
+import org.apache.pdfbox.Loader;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.text.PDFTextStripper;
 
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.text.PDFTextStripper;
 
@@ -167,7 +166,7 @@ public class PDFEncodingTestCase extends BasePDFTest {
 
     private static String extractTextFromPDF(byte[] pdfContent) throws IOException {
         PDFTextStripper pdfStripper = new PDFTextStripper();
 
     private static String extractTextFromPDF(byte[] pdfContent) throws IOException {
         PDFTextStripper pdfStripper = new PDFTextStripper();
-        PDDocument pdDoc =  PDDocument.load(pdfContent);
+        PDDocument pdDoc = Loader.loadPDF(pdfContent);
         return pdfStripper.getText(pdDoc);
     }
 }
         return pdfStripper.getText(pdDoc);
     }
 }
index ae2c747090793ce06039f32d6f0d33332669957f..512d01fc5f1f9fd01ee54eafcaa448de194679ac 100644 (file)
@@ -59,6 +59,7 @@
             WEB-INF/lib/fop-*${project.version}.jar,
             WEB-INF/lib/xmlgraphics-commons-*.jar,
             WEB-INF/lib/fontbox-*.jar,
             WEB-INF/lib/fop-*${project.version}.jar,
             WEB-INF/lib/xmlgraphics-commons-*.jar,
             WEB-INF/lib/fontbox-*.jar,
+            WEB-INF/lib/pdfbox-io-*.jar,
           </packagingIncludes>
           <archive>
             <addMavenDescriptor>false</addMavenDescriptor>
           </packagingIncludes>
           <archive>
             <addMavenDescriptor>false</addMavenDescriptor>
index d456a885db5be17e46b40c3500bd70537c1da6dd..c514c95939eb8063fb9640141a3e0b4b4d897d09 100644 (file)
@@ -578,6 +578,7 @@ list of possible build targets.
         <include name="commons-io*.jar"/>
         <include name="xmlgraphics*.jar"/>
         <include name="fontbox*.jar"/>
         <include name="commons-io*.jar"/>
         <include name="xmlgraphics*.jar"/>
         <include name="fontbox*.jar"/>
+        <include name="pdfbox-io*.jar"/>
       </lib>
       <lib dir="${build.dir}">
         <include name="fop.jar"/>
       </lib>
       <lib dir="${build.dir}">
         <include name="fop.jar"/>
index 751c1b6614c234ffe766bce6a80fa0b259024f81..61f89cecf01d5b1475ef3b5a3b7372b0d19a6be6 100644 (file)
@@ -56,6 +56,7 @@
     <include name="fop/target/dependency/commons-io*"/>
     <include name="fop/target/dependency/commons-logging*"/>
     <include name="fop/target/dependency/fontbox*"/>
     <include name="fop/target/dependency/commons-io*"/>
     <include name="fop/target/dependency/commons-logging*"/>
     <include name="fop/target/dependency/fontbox*"/>
+    <include name="fop/target/dependency/pdfbox-io*"/>
     <include name="fop/target/dependency/serializer*"/>
     <include name="fop/target/dependency/xalan*"/>
     <include name="fop/target/dependency/xerces*"/>
     <include name="fop/target/dependency/serializer*"/>
     <include name="fop/target/dependency/xalan*"/>
     <include name="fop/target/dependency/xerces*"/>