pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1554645 - in /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font: PDCIDFont.java PDSimpleFont.java
Date Wed, 01 Jan 2014 17:10:13 GMT
Author: lehmi
Date: Wed Jan  1 17:10:13 2014
New Revision: 1554645

URL: http://svn.apache.org/r1554645
Log:
PDFBOX-940: avoid false error messages when reading a CMap based on a proposal by Wolfgang
Kronberg

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java?rev=1554645&r1=1554644&r2=1554645&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java
Wed Jan  1 17:10:13 2014
@@ -17,7 +17,7 @@
 package org.apache.pdfbox.pdmodel.font;
 
 import java.io.IOException;
-
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -28,7 +28,7 @@ import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSNumber;
-import org.apache.pdfbox.encoding.conversion.CMapSubstitution;
+import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.util.ResourceLoader;
 
@@ -320,18 +320,32 @@ public abstract class PDCIDFont extends 
             cmap = cmapObjects.get( cidSystemInfo );
             if (cmap == null)
             {
-                String resourceName = resourceRootCMAP + cidSystemInfo;
-                try {
-                    cmap = parseCmap( resourceRootCMAP, ResourceLoader.loadResource( resourceName
));
-                    if( cmap == null)
+            	InputStream cmapStream = null;
+                try
+                {
+                    // look for a predefined CMap with the given name
+                    cmapStream = ResourceLoader.loadResource(resourceRootCMAP + cidSystemInfo);
+                    if (cmapStream != null)
                     {
-                        log.error("Error: Could not parse predefined CMAP file for '" + cidSystemInfo
+ "'" );
+                    	cmap = parseCmap(resourceRootCMAP, cmapStream);
+                    	if (cmap == null)
+                    	{
+                    		log.error("Error: Could not parse predefined CMAP file for '" + cidSystemInfo
+ "'");
+                    	}
+                    }
+                    else
+                    {
+                		log.debug("Debug: '" + cidSystemInfo + "' isn't a predefined CMap, most
likely it's embedded in the pdf itself.");
                     }
                 }
                 catch(IOException exception) 
                 {
                     log.error("Error: Could not find predefined CMAP file for '" + cidSystemInfo
+ "'" );
                 }
+                finally
+                {
+                	IOUtils.closeQuietly(cmapStream);
+                }
             }
         }
         else

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java?rev=1554645&r1=1554644&r2=1554645&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java
Wed Jan  1 17:10:13 2014
@@ -27,6 +27,7 @@ import java.awt.geom.Point2D;
 import java.awt.geom.NoninvertibleTransformException;
 import java.io.IOException;
 
+import java.io.InputStream;
 import java.util.HashMap;
 
 import org.apache.fontbox.afm.FontMetric;
@@ -44,6 +45,7 @@ import org.apache.pdfbox.encoding.Dictio
 import org.apache.pdfbox.encoding.Encoding;
 import org.apache.pdfbox.encoding.EncodingManager;
 
+import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.util.ResourceLoader;
 
@@ -427,19 +429,32 @@ public abstract class PDSimpleFont exten
 
         if (cmap == null && cmapName != null) 
         {
-            String resourceName = resourceRootCMAP + cmapName;
+        	InputStream cmapStream = null;
             try 
             {
-                cmap = parseCmap( resourceRootCMAP, ResourceLoader.loadResource( resourceName
) );
-                if( cmap == null && encodingName == null)
+                // look for a predefined CMap with the given name
+                cmapStream = ResourceLoader.loadResource(resourceRootCMAP + cmapName);
+                if (cmapStream != null)
+                {
+                	cmap = parseCmap(resourceRootCMAP, cmapStream);
+                	if (cmap == null && encodingName == null)
+                	{
+                		LOG.error("Error: Could not parse predefined CMAP file for '" + cmapName
+ "'");
+                	}
+                }
+                else
                 {
-                    LOG.error("Error: Could not parse predefined CMAP file for '" + cmapName
+ "'" );
+            		LOG.debug("Debug: '" + cmapName + "' isn't a predefined map, most likely it's
embedded in the pdf itself.");
                 }
             }
             catch(IOException exception) 
             {
                 LOG.error("Error: Could not find predefined CMAP file for '" + cmapName +
"'" );
             }
+            finally
+            {
+            	IOUtils.closeQuietly(cmapStream);
+            }
         }
     }
 



Mime
View raw message