pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1750561 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font: PDSimpleFont.java encoding/DictionaryEncoding.java
Date Tue, 28 Jun 2016 19:24:13 GMT
Author: tilman
Date: Tue Jun 28 19:24:13 2016
New Revision: 1750561

URL: http://svn.apache.org/viewvc?rev=1750561&view=rev
Log:
PDFBOX-3403: don't throw exception if encoding is missing but use /differences table, as suggested
by Michael Klink

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/encoding/DictionaryEncoding.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java?rev=1750561&r1=1750560&r2=1750561&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java Tue
Jun 28 19:24:13 2016
@@ -369,6 +369,10 @@ public abstract class PDSimpleFont exten
                 // we also require that the differences are actually different, see PDFBOX-1900
with
                 // the file from PDFBOX-2192 on Windows
                 Encoding baseEncoding = dictionary.getBaseEncoding();
+                if (baseEncoding == null)
+                {
+                    return false;
+                }
                 for (Map.Entry<Integer, String> entry : dictionary.getDifferences().entrySet())
                 {
                     if (!entry.getValue().equals(baseEncoding.getName(entry.getKey())))

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/encoding/DictionaryEncoding.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/encoding/DictionaryEncoding.java?rev=1750561&r1=1750560&r2=1750561&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/encoding/DictionaryEncoding.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/encoding/DictionaryEncoding.java
Tue Jun 28 19:24:13 2016
@@ -19,6 +19,8 @@ package org.apache.pdfbox.pdmodel.font.e
 
 import java.util.HashMap;
 import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
@@ -32,12 +34,16 @@ import org.apache.pdfbox.cos.COSNumber;
  */
 public class DictionaryEncoding extends Encoding
 {
+    private static final Log LOG = LogFactory.getLog(DictionaryEncoding.class);
     private final COSDictionary encoding;
     private final Encoding baseEncoding;
     private final Map<Integer, String> differences = new HashMap<Integer, String>();
 
     /**
      * Creates a new DictionaryEncoding for embedding.
+     *
+     * @param baseEncoding
+     * @param differences
      */
     public DictionaryEncoding(COSName baseEncoding, COSArray differences)
     {
@@ -56,11 +62,14 @@ public class DictionaryEncoding extends
 
         if (this.baseEncoding == null)
         {
-            throw new IllegalArgumentException("Invalid encoding: " + baseEncoding);
+            LOG.error("Invalid encoding: " + baseEncoding);
         }
         
-        codeToName.putAll(this.baseEncoding.codeToName);
-        inverted.putAll(this.baseEncoding.inverted);
+        if (this.baseEncoding != null)
+        {
+            codeToName.putAll(this.baseEncoding.codeToName);
+            inverted.putAll(this.baseEncoding.inverted);
+        }
         applyDifferences();
     }
 
@@ -91,7 +100,7 @@ public class DictionaryEncoding extends
         if (encoding.containsKey(COSName.BASE_ENCODING))
         {
             COSName name = encoding.getCOSName(COSName.BASE_ENCODING);
-            base = Encoding.getInstance(name); // may be null
+            base = Encoding.getInstance(name);
         }
 
         if (base == null)
@@ -110,26 +119,33 @@ public class DictionaryEncoding extends
                 }
                 else
                 {
-                    throw new IllegalArgumentException("Symbolic fonts must have a built-in
" + 
-                                                       "encoding");
+                    LOG.error("Symbolic fonts must have a built-in encoding");
                 }
             }
         }
         baseEncoding = base;
 
-        codeToName.putAll(baseEncoding.codeToName);
-        inverted.putAll(baseEncoding.inverted);
+        if (baseEncoding != null)
+        {
+            codeToName.putAll(baseEncoding.codeToName);
+            inverted.putAll(baseEncoding.inverted);
+        }
         applyDifferences();
     }
 
     private void applyDifferences()
     {
         // now replace with the differences
-        COSArray differences = (COSArray)encoding.getDictionaryObject( COSName.DIFFERENCES
);
+        COSBase base = encoding.getDictionaryObject(COSName.DIFFERENCES);
+        if (!(base instanceof COSArray))
+        {
+            return;
+        }
+        COSArray diffArray = (COSArray) base;
         int currentIndex = -1;
-        for( int i=0; differences != null && i<differences.size(); i++ )
+        for (int i = 0; i < diffArray.size(); i++)
         {
-            COSBase next = differences.getObject( i );
+            COSBase next = diffArray.getObject(i);
             if( next instanceof COSNumber)
             {
                 currentIndex = ((COSNumber)next).intValue();
@@ -145,7 +161,7 @@ public class DictionaryEncoding extends
     }
 
     /**
-     * Returns the base encoding. Will be null for Type 3 fonts.
+     * Returns the base encoding. Will be null for Type 3 fonts or if the encoding is missing
or invalid.
      */
     public Encoding getBaseEncoding()
     {



Mime
View raw message