pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1676677 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java
Date Wed, 29 Apr 2015 06:36:51 GMT
Author: jahewson
Date: Wed Apr 29 06:36:51 2015
New Revision: 1676677

URL: http://svn.apache.org/r1676677
Log:
PDFBOX-1900: Fix glyph stretch bug for AFM fonts (again)

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.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=1676677&r1=1676676&r2=1676677&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 Wed
Apr 29 06:36:51 2015
@@ -90,7 +90,7 @@ public abstract class PDSimpleFont exten
      * Reads the Encoding from the Font dictionary or the embedded or substituted font file.
      * Must be called at the end of any subclass constructors.
      *
-     * @throws IOException if the font file could not be read.
+     * @throws IOException if the font file could not be read
      */
     protected final void readEncoding() throws IOException
     {
@@ -99,11 +99,39 @@ public abstract class PDSimpleFont exten
         {
             if (encoding instanceof COSName)
             {
-                readEncodingFromName((COSName) encoding);
+                COSName encodingName = (COSName)encoding;
+                this.encoding = Encoding.getInstance(encodingName);
+                if (this.encoding == null)
+                {
+                    LOG.warn("Unknown encoding: " + encodingName.getName());
+                    this.encoding = readEncodingFromFont(); // fallback
+                }
             }
             else if (encoding instanceof COSDictionary)
             {
-                readEncodingFromDictionary((COSDictionary) encoding);
+                COSDictionary encodingDict = (COSDictionary)encoding;
+                Encoding builtIn = null;
+                Boolean symbolic = getSymbolicFlag();
+                boolean isFlaggedAsSymbolic = symbolic != null && symbolic;
+                if (!encodingDict.containsKey(COSName.BASE_ENCODING) && isFlaggedAsSymbolic)
+                {
+                    builtIn = readEncodingFromFont();
+                }
+
+                if (symbolic == null)
+                {
+                    symbolic = false;
+                }
+
+                if (builtIn == null && !encodingDict.containsKey(COSName.BASE_ENCODING)
&& symbolic)
+                {
+                    // TTF built-in encoding is handled by PDTrueTypeFont#codeToGID
+                    this.encoding = null;
+                }
+                else
+                {
+                    this.encoding = new DictionaryEncoding(encodingDict, !symbolic, builtIn);
+                }
             }
         }
         else
@@ -137,41 +165,6 @@ public abstract class PDSimpleFont exten
         }
     }
 
-    private void readEncodingFromDictionary(COSDictionary encodingDict) throws IOException
-    {
-        Encoding builtIn = null;
-        Boolean symbolic = getSymbolicFlag();
-        boolean isFlaggedAsSymbolic = symbolic != null && symbolic;
-        if (!encodingDict.containsKey(COSName.BASE_ENCODING) && isFlaggedAsSymbolic)
-        {
-            builtIn = readEncodingFromFont();
-        }
-        if (symbolic == null)
-        {
-            symbolic = false;
-        }
-        if (builtIn == null && !encodingDict.containsKey(COSName.BASE_ENCODING) &&
symbolic)
-        {
-            // TTF built-in encoding is handled by PDTrueTypeFont#codeToGID
-            this.encoding = null;
-        }
-        else
-        {
-            this.encoding = new DictionaryEncoding(encodingDict, !symbolic, builtIn);
-        }
-    }
-    
-    private void readEncodingFromName(COSName encodingName) throws IOException
-    {
-        this.encoding = Encoding.getInstance(encodingName);
-        if (this.encoding == null)
-        {
-            LOG.warn("Unknown encoding: " + encodingName.getName());
-            // fallback
-            this.encoding = readEncodingFromFont();
-        }
-    }
-
     /**
      * Called by readEncoding() if the encoding needs to be extracted from the font file.
      *
@@ -206,7 +199,6 @@ public abstract class PDSimpleFont exten
         }
 
         invertedEncoding = new HashMap<String, Integer>();
-        //Map<Integer, String> codeToName = MacOSRomanEncoding.INSTANCE.getCodeToNameMap();
         Map<Integer, String> codeToName = encoding.getCodeToNameMap();
         for (Map.Entry<Integer, String> entry : codeToName.entrySet())
         {
@@ -391,7 +383,6 @@ public abstract class PDSimpleFont exten
      * @param code character code
      * @return width in 1/1000 text space
      */
-    @Override
     protected final float getStandard14Width(int code)
     {
         if (getStandard14AFM() != null)
@@ -419,8 +410,16 @@ public abstract class PDSimpleFont exten
             DictionaryEncoding dictionary = (DictionaryEncoding)getEncoding();
             if (dictionary.getDifferences().size() > 0)
             {
-                // todo: do we need to check if entries actually differ from the base encoding?
-                return false;
+                // we also require that the differences are actually different, see PDFBOX-1900
with
+                // the file from PDFBOX-2192 on Windows
+                Encoding baseEncoding = dictionary.getBaseEncoding();
+                for (Map.Entry<Integer, String> entry : dictionary.getDifferences().entrySet())
+                {
+                    if (!entry.getValue().equals(baseEncoding.getName(entry.getKey())))
+                    {
+                        return false;
+                    }
+                }
             }
         }
         return super.isStandard14();



Mime
View raw message