You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ja...@apache.org on 2014/08/26 01:58:43 UTC

svn commit: r1620487 - /pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java

Author: jahewson
Date: Mon Aug 25 23:58:43 2014
New Revision: 1620487

URL: http://svn.apache.org/r1620487
Log:
PDFBOX-2262: Override embedded font widths

Modified:
    pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java

Modified: pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java?rev=1620487&r1=1620486&r2=1620487&view=diff
==============================================================================
--- pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java (original)
+++ pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java Mon Aug 25 23:58:43 2014
@@ -162,38 +162,32 @@ public abstract class PDFont implements 
      */
     public float getWidth(int code) throws IOException
     {
-        if (!isEmbedded())
+        // Acrobat overrides the widths in the font program on the conforming reader's system with
+        // the widths specified in the font dictionary." (Adobe Supplement to the ISO 32000)
+        //
+        // Note: The Adobe Supplement says that the override happens "If the font program is not
+        // embedded", however PDFBOX-427 shows that it also applies to embedded fonts.
+
+        // Type1, Type1C, Type3
+        int firstChar = dict.getInt(COSName.FIRST_CHAR, -1);
+        int lastChar = dict.getInt(COSName.LAST_CHAR, -1);
+        if (getWidths().size() > 0 && code >= firstChar && code <= lastChar)
         {
-            // "If the font program is not embedded, Acrobat overrides the widths in the font
-            // program on the conforming reader?s system with the widths specified in the font
-            // dictionary." (Adobe Supplement to the ISO 32000)
-
-            // Type1, Type1C, Type3
-            int firstChar = dict.getInt(COSName.FIRST_CHAR, -1);
-            int lastChar = dict.getInt(COSName.LAST_CHAR, -1);
-            if (getWidths().size() > 0 && code >= firstChar && code <= lastChar)
+            return getWidths().get(code - firstChar).floatValue();
+        }
+        else
+        {
+            PDFontDescriptor fd = getFontDescriptor();
+            if (fd instanceof PDFontDescriptorDictionary)
             {
-                return getWidths().get(code - firstChar).floatValue();
+                return fd.getMissingWidth();
             }
             else
             {
-                PDFontDescriptor fd = getFontDescriptor();
-                if (fd instanceof PDFontDescriptorDictionary)
-                {
-                    return fd.getMissingWidth();
-                }
-                else
-                {
-                    // if there's nothing to override with, then obviously we fall back to the font
-                    return getWidthFromFont(code);
-                }
+                // if there's nothing to override with, then obviously we fall back to the font
+                return getWidthFromFont(code);
             }
         }
-        else
-        {
-            // otherwise the fonts widths should exactly match the widths in the font dictionary
-            return getWidthFromFont(code);
-        }
     }
 
     /**