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/24 22:36:17 UTC

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

Author: jahewson
Date: Sun Aug 24 20:36:16 2014
New Revision: 1620186

URL: http://svn.apache.org/r1620186
Log:
PDFBOX-2262: Fix handling of Type 3 widths

Modified:
    pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java
    pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.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=1620186&r1=1620185&r2=1620186&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 Sun Aug 24 20:36:16 2014
@@ -392,11 +392,19 @@ public abstract class PDFont implements 
     }
 
     /**
+     * Returns the name of this font, either the PostScript "BaseName" or the Type 3 "Name".
+     */
+    public String getName()
+    {
+        return getBaseFont();
+    }
+
+    /**
      * The widths of the characters. This will be null for the standard 14 fonts.
      *
      * @return The widths of the characters.
      */
-    private List<Integer> getWidths()
+    protected final List<Integer> getWidths()
     {
         if (widths == null)
         {
@@ -482,6 +490,6 @@ public abstract class PDFont implements 
     @Override
     public String toString()
     {
-        return getClass().getSimpleName() + " " + getBaseFont();
+        return getClass().getSimpleName() + " " + getName();
     }
 }

Modified: pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java?rev=1620186&r1=1620185&r2=1620186&view=diff
==============================================================================
--- pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java (original)
+++ pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java Sun Aug 24 20:36:16 2014
@@ -19,6 +19,8 @@ package org.apache.pdfbox.pdmodel.font;
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSFloat;
@@ -37,6 +39,8 @@ import org.apache.pdfbox.pdmodel.common.
  */
 public class PDType3Font extends PDSimpleFont
 {
+    private static final Log LOG = LogFactory.getLog(PDFont.class);
+
 	private PDResources type3Resources = null;
     private COSDictionary charProcs = null;
     private PDMatrix fontMatrix;
@@ -53,16 +57,47 @@ public class PDType3Font extends PDSimpl
     }
 
     @Override
+    public String getName()
+    {
+        return dict.getNameAsString(COSName.NAME);
+    }
+
+    @Override
     protected Encoding readEncodingFromFont() throws IOException
     {
         return null;
     }
 
     @Override
+    public float getWidth(int code) throws IOException
+    {
+        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 fd.getMissingWidth();
+            }
+            else
+            {
+                // todo: call getWidthFromFont?
+                LOG.error("No width for glyph " + code + " in font " + getName());
+                return 0;
+            }
+        }
+    }
+
+    @Override
     protected float getWidthFromFont(int code)
     {
-        // todo: implement me (need to peek into stream)
-        return 0;
+       // todo: could these be extracted from the font's stream?
+       throw new UnsupportedOperationException("not suppported");
     }
 
     @Override