Author: ssteiner
Date: Tue Jan 12 11:33:57 2016
New Revision: 1724209

URL: http://svn.apache.org/viewvc?rev=1724209&view=rev
Log:
FOP-2562: Update to PDFBox 2

Added:
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/FontContainer.java
   (with props)
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MaximumProfileTable.java
   (with props)
Modified:
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/lib/fontbox-2.0.0-SNAPSHOT.jar
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/lib/pdfbox-2.0.0-SNAPSHOT.jar
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/AbstractPDFBoxHandler.java
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFMultiByteFont.java
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFSingleByteFont.java
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MergeCFFFonts.java
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MergeFontsPDFWriter.java
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MergeTTFonts.java
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MergeType1Fonts.java
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapter.java
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/PDFUtil.java
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/PDFWriter.java
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/PSPDFGraphics2D.java
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/PageParentTreeFinder.java
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/PreloaderPDF.java
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/StructureTreeMerger.java
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/test/java/org/apache/fop/render/pdf/DocumentRootModifierTestCase.java
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/test/java/org/apache/fop/render/pdf/PDFRotateTestCase.java
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/test/java/org/apache/fop/render/pdf/PageParentTreeFinderTestCase.java
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/test/java/org/apache/fop/render/pdf/StructureTreeMergerTestCase.java
    
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/test/java/org/apache/fop/render/pdf/TaggedPDFConductorTestCase.java

Modified: 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/lib/fontbox-2.0.0-SNAPSHOT.jar
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/lib/fontbox-2.0.0-SNAPSHOT.jar?rev=1724209&r1=1724208&r2=1724209&view=diff
==============================================================================
Binary files - no diff available.

Modified: 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/lib/pdfbox-2.0.0-SNAPSHOT.jar
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/lib/pdfbox-2.0.0-SNAPSHOT.jar?rev=1724209&r1=1724208&r2=1724209&view=diff
==============================================================================
Binary files - no diff available.

Modified: 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/AbstractPDFBoxHandler.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/AbstractPDFBoxHandler.java?rev=1724209&r1=1724208&r2=1724209&view=diff
==============================================================================
--- 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/AbstractPDFBoxHandler.java
 (original)
+++ 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/AbstractPDFBoxHandler.java
 Tue Jan 12 11:33:57 2016
@@ -93,7 +93,7 @@ public abstract class AbstractPDFBoxHand
 
         Map<Object, Object> objectCache = getObjectCache(originalImageUri, 
userAgent);
 
-        PDPage page = (PDPage) 
pddoc.getDocumentCatalog().getAllPages().get(selectedPage);
+        PDPage page = (PDPage) 
pddoc.getDocumentCatalog().getPages().get(selectedPage);
 
         if (targetPage.getPDFResources().getParentResources() == null) {
             PDFResources res = pdfDoc.getFactory().makeResources();

Modified: 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFMultiByteFont.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFMultiByteFont.java?rev=1724209&r1=1724208&r2=1724209&view=diff
==============================================================================
--- 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFMultiByteFont.java
 (original)
+++ 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFMultiByteFont.java
 Tue Jan 12 11:33:57 2016
@@ -19,18 +19,19 @@ package org.apache.fop.render.pdf.pdfbox
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.TreeMap;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.fontbox.cff.CFFCharset;
 import org.apache.fontbox.cff.CFFFont;
+import org.apache.fontbox.cff.CFFStandardString;
 import org.apache.fontbox.cmap.CMap;
-import org.apache.fontbox.ttf.CMAPEncodingEntry;
+
+import org.apache.fontbox.ttf.CmapSubtable;
 import org.apache.fontbox.ttf.GlyphData;
-import org.apache.fontbox.ttf.MaximumProfileTable;
 import org.apache.fontbox.ttf.TrueTypeFont;
 
 import org.apache.pdfbox.cos.COSArray;
@@ -38,16 +39,15 @@ import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSObject;
-import org.apache.pdfbox.encoding.Encoding;
 import org.apache.pdfbox.pdmodel.common.PDStream;
 import org.apache.pdfbox.pdmodel.font.PDCIDFont;
-import org.apache.pdfbox.pdmodel.font.PDCIDFontType0Font;
-import org.apache.pdfbox.pdmodel.font.PDCIDFontType2Font;
+import org.apache.pdfbox.pdmodel.font.PDCIDFontType0;
+import org.apache.pdfbox.pdmodel.font.PDCIDFontType2;
 import org.apache.pdfbox.pdmodel.font.PDFont;
-import org.apache.pdfbox.pdmodel.font.PDFontDescriptorDictionary;
-import org.apache.pdfbox.pdmodel.font.PDFontFactory;
+import org.apache.pdfbox.pdmodel.font.PDFontDescriptor;
 import org.apache.pdfbox.pdmodel.font.PDTrueTypeFont;
 import org.apache.pdfbox.pdmodel.font.PDType0Font;
+import org.apache.pdfbox.pdmodel.font.encoding.GlyphList;
 
 import org.apache.fop.fonts.CIDFontType;
 import org.apache.fop.fonts.CustomFont;
@@ -65,7 +65,7 @@ public class FOPPDFMultiByteFont extends
     private MergeTTFonts mergeTTFonts = new MergeTTFonts();
     private MergeCFFFonts mergeCFFFonts = new MergeCFFFonts();
     //private Map<String, GlyphData> glyphs = new HashMap<String, GlyphData>();
-    private final Map<COSDictionary, PDFont> fontMap = new 
HashMap<COSDictionary, PDFont>();
+    private final Map<COSDictionary, FontContainer> fontMap = new 
HashMap<COSDictionary, FontContainer>();
 
     public FOPPDFMultiByteFont(COSDictionary fontData, String name) throws 
IOException {
         super(null, EmbeddingMode.SUBSET);
@@ -77,22 +77,23 @@ public class FOPPDFMultiByteFont extends
     }
 
     public String addFont(COSDictionary fontData) throws IOException {
-        PDFont font = getFont(fontData);
-        setProperties(this, font);
-        PDFont mainFont = font;
+        FontContainer font = getFont(fontData);
+        setProperties(this, font.font);
+        PDCIDFont mainFont = null;
         TrueTypeFont ttf = null;
-        if (font instanceof PDType0Font) {
-            PDCIDFont cidFont = (PDCIDFont) ((PDType0Font) 
font).getDescendantFont();
-            setDefaultWidth((int) cidFont.getDefaultWidth());
+        if (font.font instanceof PDType0Font) {
+            PDCIDFont cidFont = ((PDType0Font) font.font).getDescendantFont();
+            int dw = cidFont.getCOSObject().getInt(COSName.DW);
+            setDefaultWidth(dw);
             mainFont = cidFont;
-            if (cidFont instanceof PDCIDFontType0Font) {
+            if (cidFont instanceof PDCIDFontType0) {
                 setCIDType(CIDFontType.CIDTYPE0);
                 setFontType(FontType.CIDTYPE0);
             } else {
-                ttf = ((PDCIDFontType2Font) cidFont).getTTFFont();
+                ttf = ((PDCIDFontType2) cidFont).getTrueTypeFont();
             }
         } else {
-            ttf = ((PDTrueTypeFont) font).getTTFFont();
+            ttf = ((PDTrueTypeFont) font.font).getTrueTypeFont();
             setDefaultWidth(1000);
         }
         GlyphData[] glyphData = new GlyphData[0];
@@ -103,26 +104,22 @@ public class FOPPDFMultiByteFont extends
         if (charMapGlobal.isEmpty()) {
             oldToNewGIMap.put(0, 0); // .notdef glyph
         }
-        CMap c = mainFont.getToUnicodeCMap();
-        if (c == null) {
-            c = font.getToUnicodeCMap();
-        }
-        Map<Integer, String> mapping = getMapping(mainFont, c, 
glyphData.length);
+        CMap c = font.getToUnicodeCMap();
+        Map<Integer, String> mapping = getMapping(font, c, glyphData.length);
         //if (glyphData.length > 0 && differentGlyphData(glyphData, mapping)) {
         //    return null;
         //}
         Map<Integer, String> gidToGlyph = new TreeMap<Integer, 
String>(mapping);
-        if (mainFont instanceof PDTrueTypeFont) {
-            CMAPEncodingEntry cmap = ttf.getCMAP().getCmaps()[0];
+        if (font.font instanceof PDTrueTypeFont) {
+            CmapSubtable cmap = ttf.getCmap().getCmaps()[0];
             gidToGlyph.clear();
-            int[] gidToCode = cmap.getGlyphIdToCharacterCode();
-            for (int i = 1; i < glyphData.length && i < gidToCode.length; i++) 
{
-                String mappedChar = mapping.get(gidToCode[i]);
+            for (int i = 1; i < glyphData.length; i++) {
+                String mappedChar = mapping.get(cmap.getCharacterCode(i));
                 gidToGlyph.put(i, mappedChar);
             }
         }
         readCharMap(font, gidToGlyph, glyphData, mainFont, oldToNewGIMap);
-        FontFileReader ffr = readFontFile(mainFont);
+        FontFileReader ffr = readFontFile(font.font);
         if (ttf != null) {
             mergeMaxp(ttf, mergeTTFonts.maxp);
             int sizeNoCompGlyphs = oldToNewGIMap.size();
@@ -136,8 +133,8 @@ public class FOPPDFMultiByteFont extends
         return getFontName();
     }
 
-    private void readCharMap(PDFont font, Map<Integer, String> gidToGlyph, 
GlyphData[] glyphData,
-                             PDFont mainFont, Map<Integer, Integer> 
oldToNewGIMap) {
+    private void readCharMap(FontContainer font, Map<Integer, String> 
gidToGlyph, GlyphData[] glyphData,
+                             PDCIDFont mainFont, Map<Integer, Integer> 
oldToNewGIMap) throws IOException {
         int widthPos = font.getFirstChar() + 1;
         for (Map.Entry<Integer, String> i : gidToGlyph.entrySet()) {
             String mappedChar = i.getValue();
@@ -168,12 +165,12 @@ public class FOPPDFMultiByteFont extends
                 }
                 oldToNewGIMap.put(key, glyph);
                 if (!skipWidth) {
-                    if (!(mainFont instanceof PDTrueTypeFont)) {
+                    if (!(font.font instanceof PDTrueTypeFont)) {
                         widthPos = key;
                     }
-                    float w = font.getFontWidth(widthPos);
+                    float w = font.font.getWidth(widthPos);
                     if (w >= 0) {
-                        if (mainFont instanceof PDCIDFontType0Font) {
+                        if (mainFont instanceof PDCIDFontType0) {
                             newWidth.put(key, (int)w);
                         } else {
                             newWidth.put(glyph, (int)w);
@@ -187,14 +184,12 @@ public class FOPPDFMultiByteFont extends
         }
     }
 
-    private Map<Integer, String> getMapping(PDFont font, CMap c, int len) 
throws IOException {
+    private Map<Integer, String> getMapping(FontContainer font, CMap c, int 
len) throws IOException {
         Map<Integer, String> mapping = new HashMap<Integer, String>();
-        if (font instanceof PDCIDFontType0Font) {
-            Collection<CFFFont.Mapping> mappings =
-                    ((PDCIDFontType0Font) 
font).getType1CFont().getCFFFont().getMappings();
-            for (CFFFont.Mapping m : mappings) {
-                String character = Encoding.getCharacterForName(m.getName());
-                mapping.put(m.getSID(), character);
+        if (font.font instanceof PDType0Font) {
+            PDCIDFont cidFont = ((PDType0Font) font.font).getDescendantFont();
+            if (cidFont instanceof PDCIDFontType0) {
+                mapping = getStrings(((PDCIDFontType0) cidFont).getCFFFont());
             }
         }
         if (c != null) {
@@ -202,12 +197,8 @@ public class FOPPDFMultiByteFont extends
             if (last == -1) {
                 last = len;
             }
-            int size = 1;
-            if (c.hasTwoByteMappings()) {
-                size = 2;
-            }
             for (int i = font.getFirstChar(); i <= last; i++) {
-                String l = c.lookup(i, size);
+                String l = c.toUnicode(i);
                 if (l != null) {
                     mapping.put(i, l);
                 }
@@ -216,6 +207,26 @@ public class FOPPDFMultiByteFont extends
         return mapping;
     }
 
+    private Map<Integer, String> getStrings(CFFFont ff) throws IOException {
+        CFFCharset cs = ff.getCharset();
+        Map<Integer, String> strings = new LinkedHashMap<Integer, String>();
+        for (int gid = 0; gid < 256; gid++) {
+            int sid = cs.getCIDForGID(gid);
+            if (sid != 0) {
+                strings.put(sid, 
GlyphList.getAdobeGlyphList().toUnicode(readString(sid)));
+            }
+        }
+        return strings;
+    }
+
+    private String readString(int index) throws IOException {
+        if (index >= 0 && index <= 390) {
+            return CFFStandardString.getName(index);
+        }
+        // technically this maps to .notdef, but we need a unique glyph name
+        return "SID" + index;
+    }
+
 //        private boolean differentGlyphData(GlyphData[] data, Map<Integer, 
String> mapping) throws IOException {
 //            Map<String, Integer> tmpMap = new HashMap<String, Integer>();
 //            for (Map.Entry<Integer, String> entry : mapping.entrySet()) {
@@ -240,7 +251,11 @@ public class FOPPDFMultiByteFont extends
 //        }
 
     private FontFileReader readFontFile(PDFont font) throws IOException {
-        PDFontDescriptorDictionary fd = (PDFontDescriptorDictionary) 
font.getFontDescriptor();
+        PDFontDescriptor fd = font.getFontDescriptor();
+        if (font instanceof PDType0Font) {
+            PDCIDFont cidFont = ((PDType0Font) font).getDescendantFont();
+            fd = cidFont.getFontDescriptor();
+        }
         PDStream ff = fd.getFontFile3();
         if (ff == null) {
             ff = fd.getFontFile2();
@@ -248,6 +263,9 @@ public class FOPPDFMultiByteFont extends
                 ff = fd.getFontFile();
             }
         }
+        if (ff == null) {
+            throw new IOException(font.getName() + " no fontfile");
+        }
         InputStream is = ff.createInputStream();
         return new FontFileReader(new 
ByteArrayInputStream(IOUtils.toByteArray(is)));
     }
@@ -310,12 +328,12 @@ public class FOPPDFMultiByteFont extends
         return new ByteArrayInputStream(mergeTTFonts.getFontSubset());
     }
 
-    protected PDFont getFont(COSDictionary fontData) throws IOException {
+    protected FontContainer getFont(COSDictionary fontData) throws IOException 
{
         if (!fontMap.containsKey(fontData)) {
             if (fontMap.size() > 10) {
                 fontMap.clear();
             }
-            fontMap.put(fontData, PDFontFactory.createFont(fontData));
+            fontMap.put(fontData, new FontContainer(fontData));
         }
         return fontMap.get(fontData);
     }
@@ -330,8 +348,8 @@ public class FOPPDFMultiByteFont extends
         }
     }
 
-    protected static void mergeMaxp(TrueTypeFont ttf, MaximumProfileTable 
outMaxp) {
-        MaximumProfileTable mp = ttf.getMaximumProfile();
+    protected static void mergeMaxp(TrueTypeFont ttf, MaximumProfileTable 
outMaxp) throws IOException {
+        org.apache.fontbox.ttf.MaximumProfileTable mp = 
ttf.getMaximumProfile();
         outMaxp.setVersion(mp.getVersion());
         outMaxp.setNumGlyphs(outMaxp.getNumGlyphs() + mp.getNumGlyphs());
         outMaxp.setMaxPoints(outMaxp.getMaxPoints() + mp.getMaxPoints());

Modified: 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFSingleByteFont.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFSingleByteFont.java?rev=1724209&r1=1724208&r2=1724209&view=diff
==============================================================================
--- 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFSingleByteFont.java
 (original)
+++ 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFSingleByteFont.java
 Tue Jan 12 11:33:57 2016
@@ -28,8 +28,10 @@ import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
 
+import org.apache.fontbox.cff.CFFType1Font;
 import org.apache.fontbox.cmap.CMap;
-import org.apache.fontbox.ttf.CMAPEncodingEntry;
+
+import org.apache.fontbox.ttf.CmapSubtable;
 import org.apache.fontbox.ttf.TrueTypeFont;
 
 import org.apache.pdfbox.cos.COSArray;
@@ -37,13 +39,15 @@ import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSNumber;
-import org.apache.pdfbox.encoding.Encoding;
+
 import org.apache.pdfbox.pdmodel.common.PDStream;
 import org.apache.pdfbox.pdmodel.font.PDFont;
-import org.apache.pdfbox.pdmodel.font.PDFontDescriptorDictionary;
-import org.apache.pdfbox.pdmodel.font.PDFontFactory;
+import org.apache.pdfbox.pdmodel.font.PDFontDescriptor;
 import org.apache.pdfbox.pdmodel.font.PDTrueTypeFont;
+import org.apache.pdfbox.pdmodel.font.PDType1CFont;
 import org.apache.pdfbox.pdmodel.font.PDType1Font;
+import org.apache.pdfbox.pdmodel.font.encoding.BuiltInEncoding;
+import org.apache.pdfbox.pdmodel.font.encoding.Encoding;
 
 import org.apache.fop.fonts.EmbeddingMode;
 import org.apache.fop.fonts.FontType;
@@ -54,7 +58,7 @@ import org.apache.fop.pdf.PDFDictionary;
 
 public class FOPPDFSingleByteFont extends SingleByteFont implements FOPPDFFont 
{
     private int fontCount;
-    private PDFont font;
+    private FontContainer font;
     protected PDFDictionary ref;
     protected Map<String, Integer> charMapGlobal = new LinkedHashMap<String, 
Integer>();
     private Map<Integer, Integer> newWidth = new HashMap<Integer, Integer>();
@@ -66,7 +70,7 @@ public class FOPPDFSingleByteFont extend
     private MergeCFFFonts mergeCFFFonts = new MergeCFFFonts();
     private MergeType1Fonts mergeType1Fonts = new MergeType1Fonts();
     private String shortFontName;
-    private final Map<COSDictionary, PDFont> fontMap = new 
HashMap<COSDictionary, PDFont>();
+    private final Map<COSDictionary, FontContainer> fontMap = new 
HashMap<COSDictionary, FontContainer>();
 
     public FOPPDFSingleByteFont(COSDictionary fontData, String name) throws 
IOException {
         super(null, EmbeddingMode.FULL);
@@ -77,9 +81,9 @@ public class FOPPDFSingleByteFont extend
         font = getFont(fontData);
         setFirstChar(font.getFirstChar());
         setLastChar(font.getLastChar());
-        shortFontName = MergeFontsPDFWriter.getName(font.getBaseFont());
+        shortFontName = MergeFontsPDFWriter.getName(font.font.getName());
         loadFontFile(font);
-        float[] bBoxF = font.getFontBoundingBox().getCOSArray().toFloatArray();
+        float[] bBoxF = font.getBoundingBox();
         int[] bBox = new int[bBoxF.length];
         for (int i = 0; i < bBox.length; i++) {
             bBox[i] = (int)bBoxF[i];
@@ -96,11 +100,11 @@ public class FOPPDFSingleByteFont extend
         }
         //mark font as used
         notifyMapOperation();
-        FOPPDFMultiByteFont.setProperties(this, font);
+        FOPPDFMultiByteFont.setProperties(this, font.font);
         if (font.getWidths() != null) {
             //if width contains 0 we cant rely on codeToNameMap
             boolean usesZero = font.getWidths().contains(0);
-            Set<Integer> codeToName = 
getCodeToName(font.getFontEncoding()).keySet();
+            Set<Integer> codeToName = 
getCodeToName(font.getEncoding()).keySet();
             for (int i = getFirstChar();
                  i <= Math.min(getLastChar(), getFirstChar() + 
font.getWidths().size()); i++) {
                 if (usesZero || codeToName.contains(i)) {
@@ -116,10 +120,13 @@ public class FOPPDFSingleByteFont extend
         addEncoding(font);
     }
 
-    private Map<Integer, String> getCodeToName(Encoding encoding) throws 
IOException {
+    private Map<Integer, String> getCodeToName(Encoding encoding) {
         Map<Integer, String> codeToName = new HashMap<Integer, String>();
         if (encoding != null) {
-            COSBase cos = encoding.getCOSObject();
+            COSBase cos = null;
+            if (!(encoding instanceof BuiltInEncoding)) {
+                cos = encoding.getCOSObject();
+            }
             if (cos instanceof COSDictionary) {
                 COSDictionary enc = (COSDictionary) cos;
                 COSName baseEncodingName = (COSName) 
enc.getDictionaryObject(COSName.BASE_ENCODING);
@@ -145,15 +152,18 @@ public class FOPPDFSingleByteFont extend
         return codeToName;
     }
 
-    private Object getCmap(PDFont font) throws IOException {
-        if (font.getFontEncoding() != null) {
-            return font.getFontEncoding();
+    private Object getCmap(FontContainer font) throws IOException {
+        if (font.getEncoding() != null) {
+            return font.getEncoding();
+        }
+        if (font.getToUnicodeCMap() == null) {
+            throw new IOException("No cmap found in " + font.font.getName());
         }
         return font.getToUnicodeCMap();
     }
 
     private PDStream readFontFile(PDFont font) throws IOException {
-        PDFontDescriptorDictionary fd = (PDFontDescriptorDictionary) 
font.getFontDescriptor();
+        PDFontDescriptor fd = font.getFontDescriptor();
         setFlags(fd.getFlags());
         PDStream ff = fd.getFontFile3();
         if (ff == null) {
@@ -165,18 +175,18 @@ public class FOPPDFSingleByteFont extend
             setFontType(FontType.TYPE1C);
         }
         if (ff == null) {
-            throw new IOException(font.getBaseFont() + " no font file");
+            throw new IOException(font.getName() + " no font file");
         }
         return ff;
     }
 
-    private void loadFontFile(PDFont font) throws IOException {
-        PDStream ff = readFontFile(font);
+    private void loadFontFile(FontContainer font) throws IOException {
+        PDStream ff = readFontFile(font.font);
         mergeFontFile(ff.createInputStream(), font);
-        if (font instanceof PDTrueTypeFont) {
-            TrueTypeFont ttfont = ((PDTrueTypeFont) font).getTTFFont();
-            CMAPEncodingEntry[] cmapList = ttfont.getCMAP().getCmaps();
-            for (CMAPEncodingEntry c : cmapList) {
+        if (font.font instanceof PDTrueTypeFont) {
+            TrueTypeFont ttfont = ((PDTrueTypeFont) 
font.font).getTrueTypeFont();
+            CmapSubtable[] cmapList = ttfont.getCmap().getCmaps();
+            for (CmapSubtable c : cmapList) {
                 MergeTTFonts.Cmap tempCmap = getNewCmap(c.getPlatformId(), 
c.getPlatformEncodingId());
                 for (int i = 0; i < 256 * 256; i++) {
                     if (c.getGlyphId(i) != 0) {
@@ -225,8 +235,8 @@ public class FOPPDFSingleByteFont extend
     }
 
     public String addFont(COSDictionary fontData) throws IOException {
-        PDFont font = getFont(fontData);
-        if (font instanceof PDType1Font && differentGlyphData((PDType1Font) 
font)) {
+        FontContainer font = getFont(fontData);
+        if ((font.font instanceof PDType1Font || font.font instanceof 
PDType1CFont) && differentGlyphData(font.font)) {
             return null;
         }
         mergeWidths(font);
@@ -247,18 +257,25 @@ public class FOPPDFSingleByteFont extend
         return fontCount;
     }
 
-    private Map<String, byte[]> getCharStringsDict(PDType1Font font) throws 
IOException {
-        if (getFontType() == FontType.TYPE1) {
-            return font.getType1Font().getCharStringsDict();
+    private Map<String, byte[]> getCharStringsDict(PDFont font) throws 
IOException {
+        if (font instanceof PDType1Font) {
+            return ((PDType1Font)font).getType1Font().getCharStringsDict();
         }
-        return font.getType1CFont().getCFFFont().getCharStringsDict();
+        CFFType1Font cffFont = ((PDType1CFont) font).getCFFType1Font();
+        List<byte[]> bytes = cffFont.getCharStringBytes();
+        Map<String, byte[]> map = new HashMap<String, byte[]>();
+        for (int i = 0; i < bytes.size(); i++) {
+            map.put(cffFont.getCharset().getNameForGID(i), bytes.get(i));
+        }
+        return map;
     }
 
-    private boolean differentGlyphData(PDType1Font otherFont) throws 
IOException {
+    private boolean differentGlyphData(PDFont otherFont) throws IOException {
         if (charStringsDict == null) {
-            charStringsDict = getCharStringsDict((PDType1Font) font);
+            charStringsDict = getCharStringsDict(font.font);
         }
-        for (Map.Entry<String, byte[]> s : 
getCharStringsDict(otherFont).entrySet()) {
+        Map<String, byte[]> otherFontMap = getCharStringsDict(otherFont);
+        for (Map.Entry<String, byte[]> s : otherFontMap.entrySet()) {
             if (charStringsDict.containsKey(s.getKey())) {
                 int numberDiff = 0;
                 byte[] b1 = charStringsDict.get(s.getKey());
@@ -284,15 +301,15 @@ public class FOPPDFSingleByteFont extend
         return false;
     }
 
-    private void mergeWidths(PDFont font) throws IOException {
+    private void mergeWidths(FontContainer font) throws IOException {
         int w = 0;
         int skipGlyphIndex = getLastChar() + 1;
         Object cmap = getCmap(font);
-        Set<Integer> codeToName = 
getCodeToName(font.getFontEncoding()).keySet();
+        Set<Integer> codeToName = getCodeToName(font.getEncoding()).keySet();
         for (int i = font.getFirstChar(); i <= font.getLastChar(); i++) {
             boolean addedWidth = false;
             int glyphIndexPos = skipGlyphIndex;
-            if (font instanceof PDTrueTypeFont) {
+            if (font.font instanceof PDTrueTypeFont) {
                 glyphIndexPos = i;
             }
             int neww = 0;
@@ -300,7 +317,7 @@ public class FOPPDFSingleByteFont extend
                 neww = font.getWidths().get(i - font.getFirstChar());
                 if (!newWidth.containsKey(i) || newWidth.get(i) == 0) {
                     if (getFontType() == FontType.TYPE1
-                            || font instanceof PDTrueTypeFont
+                            || font.font instanceof PDTrueTypeFont
                             || codeToName.contains(i)) {
                         newWidth.put(i, neww);
                         glyphIndexPos = i;
@@ -325,19 +342,19 @@ public class FOPPDFSingleByteFont extend
     private String getChar(Object cmap, int i) throws IOException {
         if (cmap instanceof CMap) {
             CMap c = (CMap)cmap;
-            int size = 1;
-            if (c.hasTwoByteMappings()) {
-                size = 2;
-            }
-            return c.lookup(i, size);
+            return c.toUnicode(i);
         }
         Encoding enc = (Encoding)cmap;
         return enc.getName(i);
     }
 
     public String getEncodingName() {
-        if (font.getFontEncoding() != null) {
-            COSBase cosObject = font.getFontEncoding().getCOSObject();
+        Encoding encoding = font.getEncoding();
+        if (encoding != null) {
+            COSBase cosObject = null;
+            if (!(encoding instanceof BuiltInEncoding)) {
+                cosObject = encoding.getCOSObject();
+            }
             if (cosObject != null) {
                 if (cosObject instanceof COSDictionary) {
                     COSBase item = ((COSDictionary) 
cosObject).getItem(COSName.BASE_ENCODING);
@@ -354,9 +371,9 @@ public class FOPPDFSingleByteFont extend
         return null;
     }
 
-    private void addEncoding(PDFont fontForEnc) throws IOException {
+    private void addEncoding(FontContainer fontForEnc) {
         List<String> added = new ArrayList<String>(encodingMap.values());
-        Map<Integer, String> codeToName = 
getCodeToName(fontForEnc.getFontEncoding());
+        Map<Integer, String> codeToName = 
getCodeToName(fontForEnc.getEncoding());
         for (int i = fontForEnc.getFirstChar(); i <= fontForEnc.getLastChar(); 
i++) {
             if (codeToName.keySet().contains(i)) {
                 String s = codeToName.get(i);
@@ -393,7 +410,7 @@ public class FOPPDFSingleByteFont extend
 
         public char[] getUnicodeCharMap() {
             if (cmap) {
-                if (MergeFontsPDFWriter.getToUnicode(font) == null) {
+                if (font.getToUnicode() == null) {
                     return new char[0];
                 }
                 List<String> cmapStrings = new ArrayList<String>();
@@ -451,13 +468,13 @@ public class FOPPDFSingleByteFont extend
         return false;
     }
 
-    private void mergeFontFile(InputStream ff, PDFont pdFont) throws 
IOException {
+    private void mergeFontFile(InputStream ff, FontContainer pdFont) throws 
IOException {
         if (getFontType() == FontType.TRUETYPE) {
             Map<Integer, Integer> chars = new HashMap<Integer, Integer>();
             chars.put(0, 0);
             mergeTTFonts.readFont(new FontFileReader(ff), chars, false);
         } else if (getFontType() == FontType.TYPE1) {
-            mergeType1Fonts.readFont(ff, (PDType1Font) pdFont);
+            mergeType1Fonts.readFont(ff, pdFont);
         } else {
             mergeCFFFonts.readType1CFont(ff, shortFontName);
         }
@@ -479,12 +496,12 @@ public class FOPPDFSingleByteFont extend
         return null;
     }
 
-    protected PDFont getFont(COSDictionary fontData) throws IOException {
+    protected FontContainer getFont(COSDictionary fontData) throws IOException 
{
         if (!fontMap.containsKey(fontData)) {
             if (fontMap.size() > 10) {
                 fontMap.clear();
             }
-            fontMap.put(fontData, PDFontFactory.createFont(fontData));
+            fontMap.put(fontData, new FontContainer(fontData));
         }
         return fontMap.get(fontData);
     }

Added: 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/FontContainer.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/FontContainer.java?rev=1724209&view=auto
==============================================================================
--- 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/FontContainer.java
 (added)
+++ 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/FontContainer.java
 Tue Jan 12 11:33:57 2016
@@ -0,0 +1,119 @@
+/*
+ * 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.pdf.pdfbox;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.fontbox.cmap.CMap;
+import org.apache.fontbox.cmap.CMapParser;
+import org.apache.fontbox.util.BoundingBox;
+import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.cos.COSStream;
+import org.apache.pdfbox.pdmodel.common.COSArrayList;
+import org.apache.pdfbox.pdmodel.font.PDCIDFont;
+import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.pdmodel.font.PDFontFactory;
+import org.apache.pdfbox.pdmodel.font.PDSimpleFont;
+import org.apache.pdfbox.pdmodel.font.PDType0Font;
+import org.apache.pdfbox.pdmodel.font.encoding.DictionaryEncoding;
+import org.apache.pdfbox.pdmodel.font.encoding.Encoding;
+
+public class FontContainer {
+    private COSDictionary dict;
+    private List<Integer> widths;
+    PDFont font;
+
+    FontContainer(COSDictionary fontData) throws IOException {
+        dict = fontData;
+        font = PDFontFactory.createFont(fontData);
+    }
+
+    int getFirstChar() {
+        return dict.getInt(COSName.FIRST_CHAR);
+    }
+
+    int getLastChar() {
+        return dict.getInt(COSName.LAST_CHAR);
+    }
+
+    CMap getToUnicodeCMap() throws IOException {
+        COSBase base = dict.getDictionaryObject(COSName.TO_UNICODE);
+        if (font instanceof PDType0Font && base == null) {
+            PDCIDFont cidFont = ((PDType0Font) font).getDescendantFont();
+            base = 
cidFont.getCOSObject().getDictionaryObject(COSName.TO_UNICODE);
+        }
+        if (base instanceof COSName) {
+            // predefined CMap
+            String name = ((COSName)base).getName();
+            CMapParser parser = new CMapParser();
+            return parser.parsePredefined(name);
+        } else if (base instanceof COSStream) {
+            // embedded CMap
+            InputStream input = null;
+            try {
+                input = ((COSStream)base).getUnfilteredStream();
+                CMapParser parser = new CMapParser();
+                return parser.parse(input);
+            } finally {
+                IOUtils.closeQuietly(input);
+            }
+        } else {
+//            throw new IOException("Expected Name or Stream");
+        }
+        return null;
+    }
+
+    COSBase getToUnicode() {
+        return dict.getDictionaryObject(COSName.TO_UNICODE);
+    }
+
+    List<Integer> getWidths() {
+        if (widths == null) {
+            COSArray array = (COSArray) 
dict.getDictionaryObject(COSName.WIDTHS);
+            if (array != null) {
+                widths = COSArrayList.convertIntegerCOSArrayToList(array);
+            } else {
+                widths = Collections.emptyList();
+            }
+        }
+        return widths;
+    }
+
+    Encoding getEncoding() {
+        if (font instanceof PDSimpleFont) {
+            if (((PDSimpleFont) font).getEncoding() instanceof 
DictionaryEncoding) {
+                return new DictionaryEncoding(
+                        
(COSDictionary)((PDSimpleFont)font).getEncoding().getCOSObject(), true, null);
+            }
+            return ((PDSimpleFont) font).getEncoding();
+        }
+        return null;
+    }
+
+    float[] getBoundingBox() throws IOException {
+        BoundingBox bb = font.getBoundingBox();
+        return new float[] {bb.getLowerLeftX(), bb.getLowerLeftY(), 
bb.getUpperRightX(), bb.getUpperRightY()};
+    }
+}

Propchange: 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/FontContainer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java?rev=1724209&r1=1724208&r2=1724209&view=diff
==============================================================================
--- 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java
 (original)
+++ 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java
 Tue Jan 12 11:33:57 2016
@@ -29,7 +29,7 @@ import java.util.Map;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
-import org.apache.pdfbox.rendering.PageDrawer;
+import org.apache.pdfbox.rendering.PDFRenderer;
 
 import org.apache.xmlgraphics.image.loader.Image;
 import org.apache.xmlgraphics.image.loader.ImageException;
@@ -57,10 +57,8 @@ public class ImageConverterPDF2G2D exten
                 src.getInfo().getOriginalURI());
 
         PDDocument pddoc = imgPDF.getPDDocument();
-        PDPage page = 
(PDPage)pddoc.getDocumentCatalog().getAllPages().get(selectedPage);
 
-        Graphics2DImagePainter painter = new Graphics2DImagePainterPDF(
-                page);
+        Graphics2DImagePainter painter = new Graphics2DImagePainterPDF(pddoc, 
selectedPage);
 
         ImageGraphics2D g2dImage = new ImageGraphics2D(src.getInfo(), painter);
         return g2dImage;
@@ -85,14 +83,18 @@ public class ImageConverterPDF2G2D exten
     private static class Graphics2DImagePainterPDF implements 
GeneralGraphics2DImagePainter {
 
         private final PDPage page;
+        private final PDDocument pdDocument;
+        private int selectedPage;
 
-        public Graphics2DImagePainterPDF(PDPage page) {
-            this.page = page;
+        public Graphics2DImagePainterPDF(PDDocument pddoc, int selectedPage) {
+            pdDocument = pddoc;
+            this.selectedPage = selectedPage;
+            page = pdDocument.getPage(selectedPage);
         }
 
         /** {@inheritDoc} */
         public Dimension getImageSize() {
-            PDRectangle mediaBox = page.findMediaBox();
+            PDRectangle mediaBox = page.getMediaBox();
             int wmpt = (int)Math.ceil(mediaBox.getWidth() * 1000);
             int hmpt = (int)Math.ceil(mediaBox.getHeight() * 1000);
             return new Dimension(wmpt, hmpt);
@@ -101,8 +103,7 @@ public class ImageConverterPDF2G2D exten
         /** {@inheritDoc} */
         public void paint(Graphics2D g2d, Rectangle2D area) {
             try {
-                PDRectangle mediaBox = page.findCropBox();
-                Dimension pageDimension = mediaBox.createDimension();
+                PDRectangle mediaBox = page.getCropBox();
 
                 AffineTransform at = new AffineTransform();
 
@@ -130,12 +131,11 @@ public class ImageConverterPDF2G2D exten
                 }
 
                 at.translate(area.getX(), area.getY());
-                at.scale(area.getWidth() / pageDimension.width,
-                        area.getHeight() / pageDimension.height);
+                at.scale(area.getWidth() / mediaBox.getWidth(),
+                        area.getHeight() / mediaBox.getHeight());
                 g2d.transform(at);
 
-                PageDrawer drawer = new PageDrawer(null, page);
-                drawer.drawPage(g2d, mediaBox);
+                new PDFRenderer(pdDocument).renderPageToGraphics(selectedPage, 
g2d);
             } catch (IOException ioe) {
                 //TODO Better exception handling
                 throw new RuntimeException("I/O error while painting PDF 
page", ioe);

Added: 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MaximumProfileTable.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MaximumProfileTable.java?rev=1724209&view=auto
==============================================================================
--- 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MaximumProfileTable.java
 (added)
+++ 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MaximumProfileTable.java
 Tue Jan 12 11:33:57 2016
@@ -0,0 +1,224 @@
+/*
+ * 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.pdf.pdfbox;
+
+/**
+ * A table in a true type font.
+ */
+public class MaximumProfileTable {
+    /**
+     * A tag that identifies this table type.
+     */
+    public static final String TAG = "maxp";
+
+    private float version;
+    private int numGlyphs;
+    private int maxPoints;
+    private int maxContours;
+    private int maxCompositePoints;
+    private int maxCompositeContours;
+    private int maxZones;
+    private int maxTwilightPoints;
+    private int maxStorage;
+    private int maxFunctionDefs;
+    private int maxInstructionDefs;
+    private int maxStackElements;
+    private int maxSizeOfInstructions;
+    private int maxComponentElements;
+    private int maxComponentDepth;
+
+    /**
+     * @return Returns the maxComponentDepth.
+     */
+    public int getMaxComponentDepth() {
+        return maxComponentDepth;
+    }
+    /**
+     * @param maxComponentDepthValue The maxComponentDepth to set.
+     */
+    public void setMaxComponentDepth(int maxComponentDepthValue) {
+        this.maxComponentDepth = maxComponentDepthValue;
+    }
+    /**
+     * @return Returns the maxComponentElements.
+     */
+    public int getMaxComponentElements() {
+        return maxComponentElements;
+    }
+    /**
+     * @param maxComponentElementsValue The maxComponentElements to set.
+     */
+    public void setMaxComponentElements(int maxComponentElementsValue) {
+        this.maxComponentElements = maxComponentElementsValue;
+    }
+    /**
+     * @return Returns the maxCompositeContours.
+     */
+    public int getMaxCompositeContours() {
+        return maxCompositeContours;
+    }
+    /**
+     * @param maxCompositeContoursValue The maxCompositeContours to set.
+     */
+    public void setMaxCompositeContours(int maxCompositeContoursValue) {
+        this.maxCompositeContours = maxCompositeContoursValue;
+    }
+    /**
+     * @return Returns the maxCompositePoints.
+     */
+    public int getMaxCompositePoints() {
+        return maxCompositePoints;
+    }
+    /**
+     * @param maxCompositePointsValue The maxCompositePoints to set.
+     */
+    public void setMaxCompositePoints(int maxCompositePointsValue) {
+        this.maxCompositePoints = maxCompositePointsValue;
+    }
+    /**
+     * @return Returns the maxContours.
+     */
+    public int getMaxContours() {
+        return maxContours;
+    }
+    /**
+     * @param maxContoursValue The maxContours to set.
+     */
+    public void setMaxContours(int maxContoursValue) {
+        this.maxContours = maxContoursValue;
+    }
+    /**
+     * @return Returns the maxFunctionDefs.
+     */
+    public int getMaxFunctionDefs() {
+        return maxFunctionDefs;
+    }
+    /**
+     * @param maxFunctionDefsValue The maxFunctionDefs to set.
+     */
+    public void setMaxFunctionDefs(int maxFunctionDefsValue) {
+        this.maxFunctionDefs = maxFunctionDefsValue;
+    }
+    /**
+     * @return Returns the maxInstructionDefs.
+     */
+    public int getMaxInstructionDefs() {
+        return maxInstructionDefs;
+    }
+    /**
+     * @param maxInstructionDefsValue The maxInstructionDefs to set.
+     */
+    public void setMaxInstructionDefs(int maxInstructionDefsValue) {
+        this.maxInstructionDefs = maxInstructionDefsValue;
+    }
+    /**
+     * @return Returns the maxPoints.
+     */
+    public int getMaxPoints() {
+        return maxPoints;
+    }
+    /**
+     * @param maxPointsValue The maxPoints to set.
+     */
+    public void setMaxPoints(int maxPointsValue) {
+        this.maxPoints = maxPointsValue;
+    }
+    /**
+     * @return Returns the maxSizeOfInstructions.
+     */
+    public int getMaxSizeOfInstructions() {
+        return maxSizeOfInstructions;
+    }
+    /**
+     * @param maxSizeOfInstructionsValue The maxSizeOfInstructions to set.
+     */
+    public void setMaxSizeOfInstructions(int maxSizeOfInstructionsValue) {
+        this.maxSizeOfInstructions = maxSizeOfInstructionsValue;
+    }
+    /**
+     * @return Returns the maxStackElements.
+     */
+    public int getMaxStackElements() {
+        return maxStackElements;
+    }
+    /**
+     * @param maxStackElementsValue The maxStackElements to set.
+     */
+    public void setMaxStackElements(int maxStackElementsValue) {
+        this.maxStackElements = maxStackElementsValue;
+    }
+    /**
+     * @return Returns the maxStorage.
+     */
+    public int getMaxStorage() {
+        return maxStorage;
+    }
+    /**
+     * @param maxStorageValue The maxStorage to set.
+     */
+    public void setMaxStorage(int maxStorageValue) {
+        this.maxStorage = maxStorageValue;
+    }
+    /**
+     * @return Returns the maxTwilightPoints.
+     */
+    public int getMaxTwilightPoints() {
+        return maxTwilightPoints;
+    }
+    /**
+     * @param maxTwilightPointsValue The maxTwilightPoints to set.
+     */
+    public void setMaxTwilightPoints(int maxTwilightPointsValue) {
+        this.maxTwilightPoints = maxTwilightPointsValue;
+    }
+    /**
+     * @return Returns the maxZones.
+     */
+    public int getMaxZones() {
+        return maxZones;
+    }
+    /**
+     * @param maxZonesValue The maxZones to set.
+     */
+    public void setMaxZones(int maxZonesValue) {
+        this.maxZones = maxZonesValue;
+    }
+    /**
+     * @return Returns the numGlyphs.
+     */
+    public int getNumGlyphs() {
+        return numGlyphs;
+    }
+    /**
+     * @param numGlyphsValue The numGlyphs to set.
+     */
+    public void setNumGlyphs(int numGlyphsValue) {
+        this.numGlyphs = numGlyphsValue;
+    }
+    /**
+     * @return Returns the version.
+     */
+    public float getVersion() {
+        return version;
+    }
+    /**
+     * @param versionValue The version to set.
+     */
+    public void setVersion(float versionValue) {
+        this.version = versionValue;
+    }
+}

Propchange: 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MaximumProfileTable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MergeCFFFonts.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MergeCFFFonts.java?rev=1724209&r1=1724208&r2=1724209&view=diff
==============================================================================
--- 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MergeCFFFonts.java
 (original)
+++ 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MergeCFFFonts.java
 Tue Jan 12 11:33:57 2016
@@ -18,6 +18,9 @@ package org.apache.fop.render.pdf.pdfbox
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashSet;
@@ -27,13 +30,15 @@ import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
 
+import org.apache.fontbox.cff.CFFCIDFont;
+import org.apache.fontbox.cff.CFFCharset;
+import org.apache.fontbox.cff.CFFEncoding;
 import org.apache.fontbox.cff.CFFFont;
-import org.apache.fontbox.cff.CFFFontROS;
+import org.apache.fontbox.cff.CFFISOAdobeCharset;
 import org.apache.fontbox.cff.CFFParser;
-import org.apache.fontbox.cff.charset.CFFCharset;
-import org.apache.fontbox.cff.charset.CFFISOAdobeCharset;
-import org.apache.fontbox.cff.encoding.CFFEncoding;
-import org.apache.fontbox.cff.encoding.CFFStandardEncoding;
+import org.apache.fontbox.cff.CFFStandardEncoding;
+import org.apache.fontbox.cff.CFFStandardString;
+import org.apache.fontbox.cff.CFFType1Font;
 
 import org.apache.fop.fonts.cff.CFFDataReader;
 import org.apache.fop.fonts.truetype.FontFileReader;
@@ -50,6 +55,7 @@ public class MergeCFFFonts extends OTFSu
     private List<String> added = new ArrayList<String>();
     private Map<Integer, Integer> range = new LinkedHashMap<Integer, 
Integer>();
     private int noOfFonts;
+    private CFFEncoding encoding = null;
 
     public MergeCFFFonts() throws IOException {
         gidToSID = new LinkedHashMap<Integer, Integer>();
@@ -72,7 +78,7 @@ public class MergeCFFFonts extends OTFSu
             fileFont = ff;
         }
         LinkedHashMap<Integer, Integer> sg = new LinkedHashMap<Integer, 
Integer>();
-        for (int i = 0; i < ff.getCharStringsDict().size() + 1; i++) {
+        for (int i = 0; i < ff.getNumCharStrings() + 1; i++) {
             sg.put(i, i);
         }
         subsetGlyphsList.add(sg);
@@ -90,12 +96,13 @@ public class MergeCFFFonts extends OTFSu
             }
         }
 
-        CFFEncoding encoding = ff.getEncoding();
-        if (!(encoding instanceof CFFStandardEncoding)) {
-            for (CFFEncoding.Entry e : encoding.getEntries()) {
-                int c = e.getCode();
-                if (!chars.contains(c) && c != 0) {
-                    chars.add(c);
+        if (ff instanceof CFFType1Font) {
+            encoding = ((CFFType1Font)ff).getEncoding();
+            if (!(encoding instanceof CFFStandardEncoding)) {
+                for (int c : encoding.getCodeToNameMap().keySet()) {
+                    if (!chars.contains(c) && c != 0) {
+                        chars.add(c);
+                    }
                 }
             }
         }
@@ -143,16 +150,66 @@ public class MergeCFFFonts extends OTFSu
 
     public static List<Integer> getSids(CFFCharset cSet) {
         List<Integer> sids = new ArrayList<Integer>();
-        for (CFFCharset.Entry x : cSet.getEntries()) {
-            if (x.getSID() != 0) {
-                sids.add(x.getSID());
+        try {
+            for (int gid = 0; gid < 1024; gid++) {
+                int sid = cSet.getCIDForGID(gid);
+                if (sid != 0) {
+                    sids.add(sid);
+                }
+            }
+        } catch (IllegalStateException e) {
+            try {
+                final Method getSIDForGID = 
CFFCharset.class.getDeclaredMethod("getSIDForGID", int.class);
+                AccessController.doPrivileged(new PrivilegedAction() {
+                    public Object run() {
+                        getSIDForGID.setAccessible(true);
+                        return null;
+                    }
+                });
+                for (int gid = 0; gid < 1024; gid++) {
+                    int sid = (Integer)getSIDForGID.invoke(cSet, gid);
+                    if (sid != 0) {
+                        sids.add(sid);
+                    }
+                }
+            } catch (ReflectiveOperationException e1) {
+                throw new RuntimeException(e1);
             }
         }
         return sids;
     }
 
     public static Map<String, byte[]> getStrings(CFFFont ff) throws 
IOException {
-        return ff.getCharStringsDict();
+        CFFCharset cs = ff.getCharset();
+        List<byte[]> csbytes = ff.getCharStringBytes();
+        Map<String, byte[]> strings = new LinkedHashMap<String, byte[]>();
+        int i = 0;
+        try {
+            for (int gid = 0; gid < 256; gid++) {
+                String name = cs.getNameForGID(gid);
+                if (name != null && i < csbytes.size()) {
+                    strings.put(name, csbytes.get(i));
+                    i++;
+                }
+            }
+        } catch (IllegalStateException e) {
+            strings.put(".notdef", csbytes.get(0));
+            for (int sid : getSids(ff.getCharset())) {
+                if (i < csbytes.size()) {
+                    i++;
+                    strings.put(readString(sid), csbytes.get(i));
+                }
+            }
+        }
+        return strings;
+    }
+
+    private static String readString(int index) throws IOException {
+        if (index >= 0 && index <= 390) {
+            return CFFStandardString.getName(index);
+        }
+        // technically this maps to .notdef, but we need a unique glyph name
+        return "SID" + index;
     }
 
     public void writeFont() throws IOException {
@@ -296,15 +353,15 @@ public class MergeCFFFonts extends OTFSu
                     stringIndexData.add(stringIndexData.remove(0));
                 }
             } else {
-                String notice = (String)fileFont.getProperty("Notice");
-                if (notice != null && !(fileFont instanceof CFFFontROS)) {
+                String notice = (String)fileFont.getTopDict().get("Notice");
+                if (notice != null && !(fileFont instanceof CFFCIDFont)) {
                     stringIndexData.add(notice.getBytes("ISO-8859-1"));
                 }
             }
             stringIndexData.add(embeddedName.getBytes("UTF-8"));
             writeIndex(stringIndexData);
         } else {
-            String notice = (String)fileFont.getProperty("Notice");
+            String notice = (String)fileFont.getTopDict().get("Notice");
             if (notice != null) {
                 
writeIndex(Arrays.<byte[]>asList(notice.getBytes("ISO-8859-1"), 
embeddedName.getBytes("UTF-8")));
             } else {

Modified: 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MergeFontsPDFWriter.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MergeFontsPDFWriter.java?rev=1724209&r1=1724208&r2=1724209&view=diff
==============================================================================
--- 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MergeFontsPDFWriter.java
 (original)
+++ 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MergeFontsPDFWriter.java
 Tue Jan 12 11:33:57 2016
@@ -16,7 +16,9 @@
  */
 package org.apache.fop.render.pdf.pdfbox;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -28,49 +30,53 @@ import java.util.regex.Pattern;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
+import org.apache.fontbox.cff.CFFCIDFont;
+import org.apache.fontbox.cff.CFFCharset;
+import org.apache.fontbox.cff.CFFEncoding;
 import org.apache.fontbox.cff.CFFFont;
-import org.apache.fontbox.cff.CFFFontROS;
-import org.apache.fontbox.cff.charset.CFFCharset;
-import org.apache.fontbox.cff.encoding.CFFEncoding;
-import org.apache.fontbox.ttf.CMAPEncodingEntry;
+import org.apache.fontbox.ttf.CmapSubtable;
 import org.apache.fontbox.ttf.TrueTypeFont;
-
+import org.apache.pdfbox.contentstream.operator.Operator;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSString;
+
 import org.apache.pdfbox.pdmodel.common.PDStream;
-import org.apache.pdfbox.pdmodel.font.PDCIDFontType0Font;
-import org.apache.pdfbox.pdmodel.font.PDCIDFontType2Font;
+import org.apache.pdfbox.pdmodel.font.PDCIDFontType0;
+import org.apache.pdfbox.pdmodel.font.PDCIDFontType2;
 import org.apache.pdfbox.pdmodel.font.PDFont;
-import org.apache.pdfbox.pdmodel.font.PDFontDescriptorDictionary;
-import org.apache.pdfbox.pdmodel.font.PDFontFactory;
 import org.apache.pdfbox.pdmodel.font.PDTrueTypeFont;
 import org.apache.pdfbox.pdmodel.font.PDType0Font;
+import org.apache.pdfbox.pdmodel.font.PDType1CFont;
 import org.apache.pdfbox.pdmodel.font.PDType1Font;
-import org.apache.pdfbox.util.operator.Operator;
 
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.SingleByteFont;
 import org.apache.fop.fonts.Typeface;
 import org.apache.fop.fonts.truetype.OTFSubSetFile;
+
 import org.apache.fop.pdf.PDFText;
 
+
 public class MergeFontsPDFWriter extends PDFWriter {
     protected static final Log log = 
LogFactory.getLog(MergeFontsPDFWriter.class);
     private COSDictionary fonts;
     private FontInfo fontInfo;
     private Typeface font;
-    private PDFont oldFont = null;
+    private FontContainer oldFont = null;
     protected Map<COSName, String> fontsToRemove = new HashMap<COSName, 
String>();
-    private final Map<COSDictionary, PDFont> fontMap = new 
HashMap<COSDictionary, PDFont>();
+    private final Map<COSDictionary, FontContainer> fontMap = new 
HashMap<COSDictionary, FontContainer>();
     private static final Pattern SUBSET_PATTERN = 
Pattern.compile("[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]\\+.+");
     private Collection<String> parentFonts;
 
-    public MergeFontsPDFWriter(COSDictionary fonts, FontInfo fontInfo, String 
key, List<COSName> resourceNames) {
-        super(key, resourceNames, 0);
+    public MergeFontsPDFWriter(COSDictionary fonts, FontInfo fontInfo, String 
key, List<COSName> resourceNames,
+                               Collection<String> parentFonts, int mcid) {
+        super(key, resourceNames, mcid);
         this.fonts = fonts;
         this.fontInfo = fontInfo;
+        this.parentFonts = parentFonts;
     }
 
     public String writeText(PDStream pdStream) throws IOException {
@@ -81,7 +87,8 @@ public class MergeFontsPDFWriter extends
         for (COSName cn : fontsToRemove.keySet()) {
             fonts.removeItem(cn);
         }
-        parentFonts = fontsToRemove.values();
+        parentFonts.clear();
+        parentFonts.addAll(fontsToRemove.values());
         return txt;
     }
 
@@ -97,7 +104,7 @@ public class MergeFontsPDFWriter extends
                 if (fontData == null || internalName == null) {
                     s.append("/" + cn.getName());
                     addKey(cn);
-                    if (op.getOperation().equals("Tf")) {
+                    if (op.getName().equals("Tf")) {
                         font = null;
                         oldFont = null;
                     }
@@ -153,59 +160,56 @@ public class MergeFontsPDFWriter extends
     }
 
     private String getUniqueFontName(COSDictionary fontData) throws 
IOException {
-        PDFont font = getFont(fontData);
-        String extra = "";
-        String name = getName(font.getBaseFont()) + "_" + 
((COSName)fontData.getItem(COSName.SUBTYPE)).getName();
-        if (font instanceof PDType0Font
-                && ((PDType0Font) font).getDescendantFont() instanceof 
PDCIDFontType0Font
-                && ((PDCIDFontType0Font) ((PDType0Font) 
font).getDescendantFont()).getType1CFont() != null) {
-            CFFFont cffFont =
-                    ((PDCIDFontType0Font) ((PDType0Font) 
font).getDescendantFont()).getType1CFont().getCFFFont();
-            if (cffFont instanceof CFFFontROS
-                    && ((CFFFontROS)cffFont).getFdSelect().getClass().getName()
-                    
.equals("org.apache.fontbox.cff.CFFParser$Format0FDSelect")) {
-                extra += "format0";
-            }
-            return name + extra;
-        } else if (font instanceof PDType0Font
-                && getToUnicode(font) != null
-                && ((PDType0Font) font).getDescendantFont() instanceof 
PDCIDFontType2Font) {
-            if (!isSubsetFont(font.getBaseFont())) {
-                extra = "f3";
-            }
-            return name + extra;
-        } else if (font instanceof PDTrueTypeFont && 
isSubsetFont(font.getBaseFont())) {
-            TrueTypeFont tt = ((PDTrueTypeFont) font).getTTFFont();
-            for (CMAPEncodingEntry c : tt.getCMAP().getCmaps()) {
-                if (c.getGlyphId(1) > 0) {
-                    extra = "cid";
+        FontContainer fontContainer = getFont(fontData);
+        PDFont font = fontContainer.font;
+        if (font.getName() != null) {
+            String extra = "";
+            String name = getName(font.getName()) + "_" + 
((COSName)fontData.getItem(COSName.SUBTYPE)).getName();
+            if (font instanceof PDType0Font
+                    && ((PDType0Font) font).getDescendantFont() instanceof 
PDCIDFontType0) {
+                CFFFont cffFont = ((PDCIDFontType0) ((PDType0Font) 
font).getDescendantFont()).getCFFFont();
+                if (cffFont instanceof CFFCIDFont
+                        && 
((CFFCIDFont)cffFont).getFdSelect().getClass().getName()
+                        
.equals("org.apache.fontbox.cff.CFFParser$Format0FDSelect")) {
+                    extra += "format0";
                 }
+                return name + extra;
+            } else if (font instanceof PDType0Font
+                    && fontContainer.getToUnicode() != null
+                    && ((PDType0Font) font).getDescendantFont() instanceof 
PDCIDFontType2) {
+                if (!isSubsetFont(font.getName())) {
+                    extra = "f3";
+                }
+                return name + extra;
+            } else if (font instanceof PDTrueTypeFont && 
isSubsetFont(font.getName())) {
+                TrueTypeFont tt = ((PDTrueTypeFont) font).getTrueTypeFont();
+                for (CmapSubtable c : tt.getCmap().getCmaps()) {
+                    if (c.getGlyphId(1) > 0) {
+                        extra = "cid";
+                    }
+                }
+                return name + extra;
+            } else if (font instanceof PDType1CFont) {
+                return getNamePDType1Font(name, (PDType1CFont) font);
+            } else if (font instanceof PDType1Font) {
+                return name;
             }
-            return name + extra;
-        } else if (font instanceof PDType1Font) {
-            return getNamePDType1Font(name, (PDType1Font) font);
         }
         return null;
     }
 
-    private String getNamePDType1Font(String name, PDType1Font font) throws 
IOException {
+    private String getNamePDType1Font(String name, PDType1CFont font) throws 
IOException {
         String extra = "";
-        if (font.getType1CFont() == null
-                || font.getType1CFont().getCFFFont() == null) {
-            if (font.getFontDescriptor() instanceof 
PDFontDescriptorDictionary) {
-                return name;
-            }
-            return null;
-        }
-        CFFEncoding encoding = font.getType1CFont().getCFFFont().getEncoding();
+        CFFEncoding encoding = font.getCFFType1Font().getEncoding();
         String eClass = encoding.getClass().getName();
         if (eClass.equals("org.apache.fontbox.cff.CFFParser$Format1Encoding")) 
{
             extra = "f1enc";
         } else if 
(eClass.equals("org.apache.fontbox.cff.CFFParser$Format0Encoding")) {
             extra = "f0enc";
         }
-        CFFCharset cs = font.getType1CFont().getCFFFont().getCharset();
-        if (cs.getEntries().get(0).getSID() < 
OTFSubSetFile.NUM_STANDARD_STRINGS) {
+        CFFCharset cs = font.getCFFType1Font().getCharset();
+        List<Integer> sids = MergeCFFFonts.getSids(cs);
+        if (!sids.isEmpty() && sids.get(0) < 
OTFSubSetFile.NUM_STANDARD_STRINGS) {
             extra += "stdcs";
         }
         if 
(cs.getClass().getName().equals("org.apache.fontbox.cff.CFFParser$Format1Charset"))
 {
@@ -258,44 +262,36 @@ public class MergeFontsPDFWriter extends
     }
 
     private Integer getMapping(byte i) throws IOException {
-        if (oldFont.getFontEncoding() != null && font instanceof 
FOPPDFSingleByteFont) {
-            String name = oldFont.getFontEncoding().getName(i);
-            if (name != null && 
((FOPPDFSingleByteFont)font).charMapGlobal.containsKey(name)) {
+        if (oldFont.getEncoding() != null && font instanceof 
FOPPDFSingleByteFont) {
+            String name = oldFont.getEncoding().getName(i);
+            if (!name.equals(".notdef") && 
((FOPPDFSingleByteFont)font).charMapGlobal.containsKey(name)) {
                 return ((FOPPDFSingleByteFont)font).charMapGlobal.get(name);
             }
         }
         return null;
     }
 
-    private List<String> readCOSString(COSString s, PDFont oldFont) throws 
IOException {
+    private List<String> readCOSString(COSString s, FontContainer oldFont) 
throws IOException {
         List<String> word = new ArrayList<String>();
         byte[] string = s.getBytes();
-        int codeLength;
-//            String t1Str = new String(string, "UTF-8");
-        for (int i = 0; i < string.length; i += codeLength) {
-            codeLength = 1;
-            String c = oldFont.encode(string, i, codeLength);
-//                if (oldFont instanceof PDType1Font && i < t1Str.length()) {
-//                    c = ((PDType1Font)oldFont).encodetype1(string, i, 
codeLength);
-//                }
-            if (c == null && i + 1 < string.length) {
-                codeLength++;
-                c = oldFont.encode(string, i, codeLength);
-            }
-            if (c == null) {
+        InputStream in = new ByteArrayInputStream(string);
+        while (in.available() > 0) {
+            int code = oldFont.font.readCode(in);
+            String unicode = oldFont.font.toUnicode(code);
+            if (unicode == null) {
                 return null;
             }
-            word.add(c);
+            word.add(unicode);
         }
         return word;
     }
 
-    protected PDFont getFont(COSDictionary fontData) throws IOException {
+    protected FontContainer getFont(COSDictionary fontData) throws IOException 
{
         if (!fontMap.containsKey(fontData)) {
             if (fontMap.size() > 10) {
                 fontMap.clear();
             }
-            fontMap.put(fontData, PDFontFactory.createFont(fontData));
+            fontMap.put(fontData, new FontContainer(fontData));
         }
         return fontMap.get(fontData);
     }
@@ -310,9 +306,4 @@ public class MergeFontsPDFWriter extends
         }
         return name.replace(" ", "");
     }
-
-    protected static COSBase getToUnicode(PDFont font) {
-        COSDictionary dict = (COSDictionary) font.getCOSObject();
-        return dict.getDictionaryObject(COSName.TO_UNICODE);
-    }
 }

Modified: 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MergeTTFonts.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MergeTTFonts.java?rev=1724209&r1=1724208&r2=1724209&view=diff
==============================================================================
--- 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MergeTTFonts.java
 (original)
+++ 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MergeTTFonts.java
 Tue Jan 12 11:33:57 2016
@@ -21,8 +21,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 
-import org.apache.fontbox.ttf.MaximumProfileTable;
-
 import org.apache.fop.fonts.truetype.FontFileReader;
 import org.apache.fop.fonts.truetype.GlyfTable;
 import org.apache.fop.fonts.truetype.OFDirTabEntry;

Modified: 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MergeType1Fonts.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MergeType1Fonts.java?rev=1724209&r1=1724208&r2=1724209&view=diff
==============================================================================
--- 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MergeType1Fonts.java
 (original)
+++ 
xmlgraphics/fop-pdf-images/branches/Temp_PDFBox2/src/java/org/apache/fop/render/pdf/pdfbox/MergeType1Fonts.java
 Tue Jan 12 11:33:57 2016
@@ -28,6 +28,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.fontbox.encoding.Encoding;
+import org.apache.fontbox.type1.Type1Font;
 import org.apache.pdfbox.pdmodel.font.PDType1Font;
 
 import org.apache.fop.fonts.type1.PFBData;
@@ -54,13 +55,14 @@ public class MergeType1Fonts extends Typ
         subsetEncodingEntries.add("dup 0 /.notdef put");
     }
 
-    public void readFont(InputStream fontFile, PDType1Font font) throws 
IOException {
+    public void readFont(InputStream fontFile, FontContainer font) throws 
IOException {
         PFBParser pfbParser = new PFBParser();
         pfbData = pfbParser.parsePFB(fontFile);
 
         PostscriptParser psParser = new PostscriptParser();
         List<Integer> glyphs = new ArrayList<Integer>();
-        Encoding enc = font.getType1Font().getEncoding();
+        Type1Font t1f = ((PDType1Font)font.font).getType1Font();
+        Encoding enc = t1f.getEncoding();
         for (int i = font.getFirstChar(); i <= font.getLastChar(); i++) {
             if (!enc.getName(i).equals(".notdef")) {
                 nameMap.put(i, enc.getName(i));
@@ -93,14 +95,14 @@ public class MergeType1Fonts extends Typ
             subrsEndStream.write(decoded, subroutines.getEndPoint(),
                     charStrings.getStartPoint() - subroutines.getEndPoint());
         }
-        List<byte[]> subArray = font.getType1Font().getSubrsArray();
+        List<byte[]> subArray = t1f.getSubrsArray();
         for (int i = 0; i < subArray.size(); i++) {
             if (subByteMap.containsKey(i) && !Arrays.equals(subByteMap.get(i), 
subArray.get(i))) {
-                throw new IOException("Can't merge font subroutines " + 
font.getBaseFont());
+                throw new IOException("Can't merge font subroutines " + 
font.font.getName());
             }
             subByteMap.put(i, subArray.get(i));
         }
-        Map<String, byte[]> cs = font.getType1Font().getCharStringsDict();
+        Map<String, byte[]> cs = t1f.getCharStringsDict();
         int lenIV = 4;
         PostscriptParser.PSElement element = getElement("/lenIV", mainSection);
         if (element != null && element instanceof PostscriptParser.PSVariable) 
{
@@ -108,12 +110,15 @@ public class MergeType1Fonts extends Typ
             lenIV = Integer.parseInt(lenIVVar.getValue());
         }
         for (String e : cs.keySet()) {
-            byte[] charStringEntry = 
getBinaryEntry(charStrings.getBinaryEntries().get("/" + e), decoded);
-            if (lenIV != 4) {
-                charStringEntry = BinaryCoder.decodeBytes(charStringEntry, 
4330, lenIV);
-                charStringEntry = BinaryCoder.encodeBytes(charStringEntry, 
4330, 4);
+            int[] be = charStrings.getBinaryEntries().get("/" + e);
+            if (be != null) {
+                byte[] charStringEntry = getBinaryEntry(be, decoded);
+                if (lenIV != 4) {
+                    charStringEntry = BinaryCoder.decodeBytes(charStringEntry, 
4330, lenIV);
+                    charStringEntry = BinaryCoder.encodeBytes(charStringEntry, 
4330, 4);
+                }
+                subsetCharStrings.put("/" + e, charStringEntry);
             }
-            subsetCharStrings.put("/" + e, charStringEntry);
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to