pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1604497 - in /pdfbox/trunk: pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/ preflight/src/main/java/org/apache/pdfbox/preflight/font/
Date Sun, 22 Jun 2014 00:58:14 GMT
Author: jahewson
Date: Sun Jun 22 00:58:14 2014
New Revision: 1604497

URL: http://svn.apache.org/r1604497
Log:
PDFBOX-2149: Fix regression in file from PDFBOX-1283

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0Font.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Font.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontFactory.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type0FontValidator.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java?rev=1604497&r1=1604496&r2=1604497&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java Sun Jun
22 00:58:14 2014
@@ -41,21 +41,33 @@ public abstract class PDCIDFont extends 
 {
     private static final Log LOG = LogFactory.getLog(PDCIDFont.class);
 
-    private Map<Integer, Float> widthCache = null;
-    private long defaultWidth = 0;
+    private PDType0Font parent;
+    private Map<Integer, Float> widthCache;
+    private long defaultWidth;
 
     /**
      * Constructor.
      *
      * @param fontDictionary The font dictionary according to the PDF specification.
      */
-    protected PDCIDFont(COSDictionary fontDictionary)
+    protected PDCIDFont(COSDictionary fontDictionary, PDType0Font parent)
     {
         super(fontDictionary);
+        this.parent = parent;
         extractWidths();
     }
 
     /**
+     * Returns the Type 0 font which is the parent of this font.
+     *
+     * @return parent Type 0 font
+     */
+    public final PDType0Font getParent()
+    {
+        return parent;
+    }
+
+    /**
      * This will get the fonts bounding box.
      *
      * @return The fonts bounding box.

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0Font.java?rev=1604497&r1=1604496&r2=1604497&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0Font.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0Font.java
Sun Jun 22 00:58:14 2014
@@ -31,16 +31,16 @@ public class PDCIDFontType0Font extends 
 {
     private static final Log LOG = LogFactory.getLog(PDCIDFontType0Font.class);
 
-    private PDType1CFont type1CFont = null;
+    private PDType1CFont type1CFont;
 
     /**
      * Constructor.
      * 
      * @param fontDictionary The font dictionary according to the PDF specification.
      */
-    public PDCIDFontType0Font(COSDictionary fontDictionary)
+    public PDCIDFontType0Font(COSDictionary fontDictionary, PDType0Font parent)
     {
-        super(fontDictionary);
+        super(fontDictionary, parent);
         PDFontDescriptor fd = getFontDescriptor();
         if (fd instanceof PDFontDescriptorDictionary)
         {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Font.java?rev=1604497&r1=1604496&r2=1604497&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Font.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Font.java
Sun Jun 22 00:58:14 2014
@@ -48,9 +48,9 @@ public class PDCIDFontType2Font extends 
      * 
      * @param fontDictionary The font dictionary according to the PDF specification.
      */
-    public PDCIDFontType2Font(COSDictionary fontDictionary)
+    public PDCIDFontType2Font(COSDictionary fontDictionary, PDType0Font parent)
     {
-        super(fontDictionary);
+        super(fontDictionary, parent);
     }
 
     /**
@@ -196,9 +196,9 @@ public class PDCIDFontType2Font extends 
         {
             return getFontWidth(code);
         }
-        else if (getCMap() != null)
+        else if (getParent().getCMap() != null)
         {
-            String mappedString = getCMap().lookup(code, length);
+            String mappedString = getParent().getCMap().lookup(code, length);
             if (mappedString != null)
             {
                 return getFontWidth(mappedString.codePointAt(0));

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontFactory.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontFactory.java?rev=1604497&r1=1604496&r2=1604497&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontFactory.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontFactory.java Sun
Jun 22 00:58:14 2014
@@ -73,11 +73,11 @@ public class PDFontFactory
         }
         else if (COSName.CID_FONT_TYPE0.equals(subType))
         {
-            return new PDCIDFontType0Font(dictionary);
+            throw new IllegalArgumentException("Type 0 descendant font not allowed");
         }
         else if (COSName.CID_FONT_TYPE2.equals(subType))
         {
-            return new PDCIDFontType2Font(dictionary);
+            throw new IllegalArgumentException("Type 0 descendant font not allowed");
         }
         else
         {
@@ -87,4 +87,35 @@ public class PDFontFactory
             return new PDType1Font(dictionary);
         }
     }
+
+    /**
+     * Creates a new PDCIDFont instance with the appropriate subclass.
+     *
+     * @param dictionary descendant font dictionary
+     * @return a PDCIDFont instance, based on the SubType entry of the dictionary
+     * @throws IOException
+     */
+    static PDCIDFont createDescendantFont(COSDictionary dictionary, PDType0Font parent)
+            throws IOException
+    {
+        COSName type = dictionary.getCOSName(COSName.TYPE, COSName.FONT);
+        if (!COSName.FONT.equals(type))
+        {
+            throw new IOException("Expected 'Font' dictionary but found '" + type.getName()
+ "'");
+        }
+
+        COSName subType = dictionary.getCOSName(COSName.SUBTYPE);
+        if (COSName.CID_FONT_TYPE0.equals(subType))
+        {
+            return new PDCIDFontType0Font(dictionary, parent);
+        }
+        else if (COSName.CID_FONT_TYPE2.equals(subType))
+        {
+            return new PDCIDFontType2Font(dictionary, parent);
+        }
+        else
+        {
+            throw new IOException("Invalid font type: " + type);
+        }
+    }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java?rev=1604497&r1=1604496&r2=1604497&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java Sun
Jun 22 00:58:14 2014
@@ -58,7 +58,7 @@ public class PDType0Font extends PDFont
         {
             try
             {
-                descendantFont = (PDCIDFont)PDFontFactory.createFont(descendantFontDictionary);
+                descendantFont = PDFontFactory.createDescendantFont(descendantFontDictionary,
this);
             }
             catch (IOException exception)
             {

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type0FontValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type0FontValidator.java?rev=1604497&r1=1604496&r2=1604497&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type0FontValidator.java
(original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type0FontValidator.java
Sun Jun 22 00:58:14 2014
@@ -49,6 +49,7 @@ import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdmodel.font.PDCIDFontType0Font;
 import org.apache.pdfbox.pdmodel.font.PDCIDFontType2Font;
 import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.pdmodel.font.PDType0Font;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.preflight.exception.ValidationException;
@@ -161,7 +162,7 @@ public class Type0FontValidator extends 
      */
     protected FontValidator<? extends FontContainer> createCIDType0FontValidator(COSDictionary
fDict)
     {
-        return new CIDType0FontValidator(context, new PDCIDFontType0Font(fDict));
+        return new CIDType0FontValidator(context, new PDCIDFontType0Font(fDict, (PDType0Font)font));
     }
 
     /**
@@ -171,7 +172,7 @@ public class Type0FontValidator extends 
      */
     protected FontValidator<? extends FontContainer> createCIDType2FontValidator(COSDictionary
fDict)
     {
-        return new CIDType2FontValidator(context, new PDCIDFontType2Font(fDict));
+        return new CIDType2FontValidator(context, new PDCIDFontType2Font(fDict, (PDType0Font)font));
     }
 
     /**



Mime
View raw message