pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1577725 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: cos/COSDictionary.java pdmodel/font/PDFontFactory.java pdmodel/font/PDTrueTypeFont.java util/PDFStreamEngine.java
Date Fri, 14 Mar 2014 21:26:31 GMT
Author: jahewson
Date: Fri Mar 14 21:26:30 2014
New Revision: 1577725

URL: http://svn.apache.org/r1577725
Log:
PDFBOX-1988: assume Font with missing SubType is Type1

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.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/PDTrueTypeFont.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java?rev=1577725&r1=1577724&r2=1577725&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java Fri Mar 14
21:26:30 2014
@@ -592,7 +592,7 @@ public class COSDictionary extends COSBa
      * @param key The key to the item in the dictionary.
      * @return The COS name.
      */
-    public COSName getName( COSName key )
+    public COSName getCOSName(COSName key)
     {
         COSBase name = getDictionaryObject( key );
         if( name != null )
@@ -613,7 +613,7 @@ public class COSDictionary extends COSBa
      * @param defaultValue The value to return if the dictionary item is null.
      * @return The COS name.
      */
-    public COSName getName( COSName key, COSName defaultValue )
+    public COSName getCOSName(COSName key, COSName defaultValue)
     {
         COSBase name = getDictionaryObject( key );
         if( name != null )

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=1577725&r1=1577724&r2=1577725&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 Fri
Mar 14 21:26:30 2014
@@ -17,7 +17,6 @@
 package org.apache.pdfbox.pdmodel.font;
 
 import java.io.IOException;
-import java.util.Map;
 
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
@@ -25,101 +24,67 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 /**
- * This will create the correct type of font based on information in the dictionary.
- *
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.6 $
+ * Creates the appropriate font subtype based on information in the dictionary.
+ * @author Ben Litchfield
  */
 public class PDFontFactory
 {
-    /**
-     * private constructor, should only use static methods in this class.
-     */
-    private PDFontFactory()
-    {
-    }
-
-    /**
-     * Logger instance.
-     */
     private static final Log LOG = LogFactory.getLog(PDFontFactory.class);
-    
-    /**
-     * This will create the correct font based on information in the dictionary.
-     *
-     * @param dic The populated dictionary.
-     *
-     * @param fontCache A Map to cache already created fonts
-     *
-     * @return The corrent implementation for the font.
-     *
-     * @throws IOException If the dictionary is not valid.
-     * 
-     * @deprecated due to some side effects font caching is no longer supported, 
-     * use {@link #createFont(COSDictionary)} instead
-     */
-    public static PDFont createFont(COSDictionary dic, Map fontCache) throws IOException
+
+    private PDFontFactory()
     {
-        return createFont(dic);
     }
 
     /**
-     * This will create the correct font based on information in the dictionary.
+     * Creates a new PDFont instance with the appropriate subclass.
      *
-     * @param dic The populated dictionary.
-     *
-     * @return The corrent implementation for the font.
-     *
-     * @throws IOException If the dictionary is not valid.
+     * @param dictionary a font dictionary
+     * @return a PDFont instance, based on the SubType entry of the dictionary
+     * @throws IOException
      */
-    public static PDFont createFont( COSDictionary dic ) throws IOException
+    public static PDFont createFont(COSDictionary dictionary) throws IOException
     {
-        PDFont retval = null;
-
-        COSName type = (COSName)dic.getDictionaryObject( COSName.TYPE );
-        if( type != null && !COSName.FONT.equals( type ) )
+        COSName type = dictionary.getCOSName(COSName.TYPE, COSName.FONT);
+        if (!COSName.FONT.equals(type))
         {
-            throw new IOException( "Cannot create font if /Type is not /Font.  Actual=" +type
);
+            throw new IOException("Expected 'Font' dictionary but found '" + type.getName()
+ "'");
         }
 
-        COSName subType = (COSName)dic.getDictionaryObject( COSName.SUBTYPE );
-        if (subType == null) 
-        {
-            throw new IOException( "Cannot create font as /SubType is not set." );
-        }
-        if( subType.equals( COSName.TYPE1) )
+        COSName subType = dictionary.getCOSName(COSName.SUBTYPE);
+        if (COSName.TYPE1.equals(subType))
         {
-            retval = new PDType1Font( dic );
+            return new PDType1Font(dictionary);
         }
-        else if( subType.equals( COSName.MM_TYPE1 ) )
+        else if (COSName.MM_TYPE1.equals(subType))
         {
-            retval = new PDMMType1Font( dic );
+            return new PDMMType1Font(dictionary);
         }
-        else if( subType.equals( COSName.TRUE_TYPE ) )
+        else if (COSName.TRUE_TYPE.equals(subType))
         {
-            retval = new PDTrueTypeFont( dic );
+            return new PDTrueTypeFont(dictionary);
         }
-        else if( subType.equals( COSName.TYPE3 ) )
+        else if (COSName.TYPE3.equals(subType))
         {
-            retval = new PDType3Font( dic );
+            return new PDType3Font(dictionary);
         }
-        else if( subType.equals( COSName.TYPE0 ) )
+        else if (COSName.TYPE0.equals(subType))
         {
-            retval = new PDType0Font( dic );
+            return new PDType0Font(dictionary);
         }
-        else if( subType.equals( COSName.CID_FONT_TYPE0 ) )
+        else if (COSName.CID_FONT_TYPE0.equals(subType))
         {
-            retval = new PDCIDFontType0Font( dic );
+            return new PDCIDFontType0Font(dictionary);
         }
-        else if( subType.equals( COSName.CID_FONT_TYPE2 ) )
+        else if (COSName.CID_FONT_TYPE2.equals(subType))
         {
-            retval = new PDCIDFontType2Font( dic );
+            return new PDCIDFontType2Font(dictionary);
         }
         else
         {
-            LOG.warn("Substituting TrueType for unknown font subtype=" + subType.getName());
-            retval = new PDTrueTypeFont( dic );
+            // assuming Type 1 font (see PDFBOX-1988) because it seems that Adobe Reader
does this
+            // however, we may need more sophisticated logic perhaps looking at the FontFile
+            LOG.warn("Invalid font subtype '" + subType.getName() + "'");
+            return new PDType1Font(dictionary);
         }
-        return retval;
     }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java?rev=1577725&r1=1577724&r2=1577725&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java Fri
Mar 14 21:26:30 2014
@@ -94,10 +94,8 @@ public class PDTrueTypeFont extends PDSi
      * Constructor.
      * 
      * @param fontDictionary The font dictionary according to the PDF specification.
-     * 
-     * @throws IOException exception if something went wrong when loading the font.
      */
-    public PDTrueTypeFont(COSDictionary fontDictionary) throws IOException
+    public PDTrueTypeFont(COSDictionary fontDictionary)
     {
         super(fontDictionary);
     }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java?rev=1577725&r1=1577724&r2=1577725&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java Fri Mar
14 21:26:30 2014
@@ -334,18 +334,15 @@ public class PDFStreamEngine
             glyphSpaceToTextSpaceFactor = 1f / fontMatrix.getValue(0, 0);
         }
         float spaceWidthText = 0;
-        if (font != null) // PDFBOX-1946 font might still be null if in applet
+        try
         {
-            try
-            {
-                // to avoid crash as described in PDFBOX-614
-                // lets see what the space displacement should be
-                spaceWidthText = (font.getSpaceWidth() * glyphSpaceToTextSpaceFactor);
-            }
-            catch (Throwable exception)
-            {
-                LOG.warn(exception, exception);
-            }
+            // to avoid crash as described in PDFBOX-614
+            // lets see what the space displacement should be
+            spaceWidthText = (font.getSpaceWidth() * glyphSpaceToTextSpaceFactor);
+        }
+        catch (Throwable exception)
+        {
+            LOG.warn(exception, exception);
         }
 
         if (spaceWidthText == 0)



Mime
View raw message