svn commit: r1781906 - in /xmlgraphics/fop-pdf-images/trunk: src/java/org/apache/fop/render/pdf/pdfbox/ test/java/org/apache/fop/render/pdf/

[email protected]
Newsgroups gmane.text.xml.fop.cvs
Message-ID <[email protected]>
Author: ssteiner
Date: Mon Feb  6 14:18:02 2017
New Revision: 1781906

URL: http://svn.apache.org/viewvc?rev=1781906&view=rev
Log:
FOP-2687: NPE for merge fonts in pdf with accessibility

Modified:
    xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFMultiByteFont.java
    xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/FontContainer.java
    xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/FOPPDFSingleMultiByteFontTestCase.java

Modified: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFMultiByteFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFMultiByteFont.java?rev=1781906&r1=1781905&r2=1781906&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFMultiByteFont.java (original)
+++ xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFMultiByteFont.java Mon Feb  6 14:18:02 2017
@@ -105,9 +105,9 @@ public class FOPPDFMultiByteFont extends
         }
         CMap c = font.getToUnicodeCMap();
         Map<Integer, String> mapping = getMapping(font, c, glyphData.length);
-        //if (glyphData.length > 0 && differentGlyphData(glyphData, mapping)) {
-        //    return null;
-        //}
+        if (glyphData.length > 0) {
+            differentGlyphData(glyphData, mapping);
+        }
         Map<Integer, String> gidToGlyph = new TreeMap<Integer, String>(mapping);
         if (font.font instanceof PDTrueTypeFont) {
             CmapSubtable cmap = ttf.getCmap().getCmaps()[0];
@@ -233,28 +233,31 @@ public class FOPPDFMultiByteFont extends
         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()) {
-//                if (!tmpMap.containsKey(entry.getValue())) {
-//                    tmpMap.put(entry.getValue(), entry.getKey());
-//                }
-//            }
-//            mapping.clear();
-//            for (Map.Entry<String, Integer> entry : tmpMap.entrySet()) {
-//                mapping.put(entry.getValue(), entry.getKey());
-//            }
-//
-//            for (Map.Entry<Integer, String> n : mapping.entrySet()) {
+        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()) {
+                if (!tmpMap.containsKey(entry.getValue())) {
+                    tmpMap.put(entry.getValue(), entry.getKey());
+                }
+            }
+            mapping.clear();
+            for (Map.Entry<String, Integer> entry : tmpMap.entrySet()) {
+                mapping.put(entry.getValue(), entry.getKey());
+            }
+
+            for (Map.Entry<Integer, String> n : mapping.entrySet()) {
+                if (n.getKey() >= data.length) {
+                    throw new IOException("Mapping not found in glyphData");
+                }
 //                if (data[n.getKey()] != null) {
 //                    if (glyphs.containsKey(n.getValue()) && !glyphs.get(n.getValue()).equals(data[n.getKey()])) {
 //                        return true;
 //                    }
 //                    glyphs.put(n.getValue(), data[n.getKey()]);
 //                }
-//            }
-//            return false;
-//        }
+            }
+            return false;
+        }
 
     private InputStream readFontFile(PDFont font) throws IOException {
         PDFontDescriptor fd = font.getFontDescriptor();

Modified: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/FontContainer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/FontContainer.java?rev=1781906&r1=1781905&r2=1781906&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/FontContainer.java (original)
+++ xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/FontContainer.java Mon Feb  6 14:18:02 2017
@@ -137,4 +137,8 @@ public class FontContainer {
         BoundingBox bb = font.getBoundingBox();
         return new float[] {bb.getLowerLeftX(), bb.getLowerLeftY(), bb.getUpperRightX(), bb.getUpperRightY()};
     }
+
+    public PDFont getFont() {
+        return font;
+    }
 }

Modified: xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/FOPPDFSingleMultiByteFontTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/FOPPDFSingleMultiByteFontTestCase.java?rev=1781906&r1=1781905&r2=1781906&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/FOPPDFSingleMultiByteFontTestCase.java (original)
+++ xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/FOPPDFSingleMultiByteFontTestCase.java Mon Feb  6 14:18:02 2017
@@ -28,15 +28,20 @@ import org.junit.Test;
 import org.apache.commons.io.IOUtils;
 import org.apache.fontbox.cff.CFFFont;
 import org.apache.fontbox.cff.CFFParser;
+import org.apache.fontbox.ttf.GlyphData;
+import org.apache.fontbox.ttf.GlyphTable;
 import org.apache.fontbox.type1.Type1Font;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.PDResources;
+import org.apache.pdfbox.pdmodel.font.PDCIDFontType2;
+import org.apache.pdfbox.pdmodel.font.PDType0Font;
 
 import org.apache.fop.render.pdf.pdfbox.FOPPDFMultiByteFont;
 import org.apache.fop.render.pdf.pdfbox.FOPPDFSingleByteFont;
+import org.apache.fop.render.pdf.pdfbox.FontContainer;
 
 public class FOPPDFSingleMultiByteFontTestCase {
     private COSDictionary getFont(PDDocument doc, String internalname) throws IOException {
@@ -160,4 +165,33 @@ public class FOPPDFSingleMultiByteFontTe
         Assert.assertTrue(multiByteFont.hadMappingOperations());
         pdf.close();
     }
+
+    @Test
+    public void testMappingNotFound() throws IOException {
+        PDDocument pdf = PDDocument.load(new File(PDFBoxAdapterTestCase.TTCID1));
+        final COSDictionary fontDict = getFont(pdf, "C2_0");
+        MyFOPPDFMultiByteFont multiByteFont = new MyFOPPDFMultiByteFont(fontDict, null);
+        PDType0Font font = (PDType0Font) multiByteFont.getFontContainer().getFont();
+        GlyphTable glyphTable = ((PDCIDFontType2)font.getDescendantFont()).getTrueTypeFont().getGlyph();
+        glyphTable.setGlyphs(new GlyphData[glyphTable.getGlyphs().length - 1]);
+        String ex = "";
+        try {
+            multiByteFont.addFont(fontDict);
+        } catch (IOException e) {
+            ex = e.getMessage();
+        }
+        Assert.assertEquals(ex, "Mapping not found in glyphData");
+        pdf.close();
+    }
+
+    private static class MyFOPPDFMultiByteFont extends FOPPDFMultiByteFont {
+        COSDictionary fontData;
+        MyFOPPDFMultiByteFont(COSDictionary fontData, String name) throws IOException {
+            super(fontData, name);
+            this.fontData = fontData;
+        }
+        FontContainer getFontContainer() throws IOException {
+            return getFont(fontData);
+        }
+    }
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.