svn commit: r1814217 - in /xmlgraphics/fop-pdf-images/trunk: src/java/org/apache/fop/render/pdf/pdfbox/MergeFontsPDFWriter.java test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java test/resources/type0cff.pdf test/resources/type0tt.pdf

[email protected]
Newsgroups gmane.text.xml.fop.cvs
Message-ID <[email protected]>
Author: ssteiner
Date: Fri Nov  3 15:33:27 2017
New Revision: 1814217

URL: http://svn.apache.org/viewvc?rev=1814217&view=rev
Log:
FOP-2754: Error when merging True Type font with CFF PDF font

Added:
    xmlgraphics/fop-pdf-images/trunk/test/resources/type0cff.pdf   (with props)
    xmlgraphics/fop-pdf-images/trunk/test/resources/type0tt.pdf   (with props)
Modified:
    xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/MergeFontsPDFWriter.java
    xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java

Modified: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/MergeFontsPDFWriter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/MergeFontsPDFWriter.java?rev=1814217&r1=1814216&r2=1814217&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/MergeFontsPDFWriter.java (original)
+++ xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/MergeFontsPDFWriter.java Fri Nov  3 15:33:27 2017
@@ -44,6 +44,7 @@ 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.PDCIDFont;
 import org.apache.pdfbox.pdmodel.font.PDCIDFontType0;
 import org.apache.pdfbox.pdmodel.font.PDCIDFontType2;
 import org.apache.pdfbox.pdmodel.font.PDFont;
@@ -164,22 +165,22 @@ public class MergeFontsPDFWriter extends
         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";
+            if (font instanceof PDType0Font) {
+                PDCIDFont descendantFont = ((PDType0Font) font).getDescendantFont();
+                if (descendantFont instanceof PDCIDFontType0) {
+                    CFFFont cffFont = ((PDCIDFontType0) descendantFont).getCFFFont();
+                    if (cffFont instanceof CFFCIDFont
+                            && ((CFFCIDFont) cffFont).getFdSelect().getClass().getName()
+                            .equals("org.apache.fontbox.cff.CFFParser$Format0FDSelect")) {
+                        extra += "format0";
+                    }
+                    return name + extra + "cff";
+                } else if (descendantFont instanceof PDCIDFontType2 && fontContainer.getToUnicode() != null) {
+                    if (!isSubsetFont(font.getName())) {
+                        extra = "f3";
+                    }
+                    return name + extra;
                 }
-                return name + extra;
             } else if (font instanceof PDTrueTypeFont && isSubsetFont(font.getName())) {
                 TrueTypeFont tt = ((PDTrueTypeFont) font).getTrueTypeFont();
                 for (CmapSubtable c : tt.getCmap().getCmaps()) {

Modified: xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java?rev=1814217&r1=1814216&r2=1814217&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java (original)
+++ xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java Fri Nov  3 15:33:27 2017
@@ -113,6 +113,8 @@ public class PDFBoxAdapterTestCase {
     private static final String ERROR = "test/resources/error.pdf";
     private static final String LIBREOFFICE = "test/resources/libreoffice.pdf";
     private static final String SMASK = "test/resources/smask.pdf";
+    private static final String TYPE0TT = "test/resources/type0tt.pdf";
+    private static final String TYPE0CFF = "test/resources/type0cff.pdf";
 
     private static PDFPage getPDFPage(PDFDocument doc) {
         final Rectangle2D r = new Rectangle2D.Double();
@@ -158,7 +160,18 @@ public class PDFBoxAdapterTestCase {
         Assert.assertTrue(msg, msg.contains("/URWChanceryL-MediItal_Type1 20 Tf"));
         msg = writeText(fi, Type1Subset4);
         Assert.assertTrue(msg, msg.contains("/F15-1521012718 40 Tf"));
+        parseFonts(fi);
+    }
+
+    @Test
+    public void testMergeTTCFF() throws IOException {
+        FontInfo fi = new FontInfo();
+        writeText(fi, TYPE0TT);
+        writeText(fi, TYPE0CFF);
+        parseFonts(fi);
+    }
 
+    private void parseFonts(FontInfo fi) throws IOException {
         for (Typeface font : fi.getUsedFonts().values()) {
             InputStream is = ((CustomFont) font).getInputStream();
             if (font.getFontType() == FontType.TYPE1C || font.getFontType() == FontType.CIDTYPE0) {

Added: xmlgraphics/fop-pdf-images/trunk/test/resources/type0cff.pdf
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/test/resources/type0cff.pdf?rev=1814217&view=auto
==============================================================================
Binary file - no diff available.

Propchange: xmlgraphics/fop-pdf-images/trunk/test/resources/type0cff.pdf
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: xmlgraphics/fop-pdf-images/trunk/test/resources/type0tt.pdf
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/test/resources/type0tt.pdf?rev=1814217&view=auto
==============================================================================
Binary file - no diff available.

Propchange: xmlgraphics/fop-pdf-images/trunk/test/resources/type0tt.pdf
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream
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.