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/06/18 02:15:39 UTC

svn commit: r1603335 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/

Author: jahewson
Date: Wed Jun 18 00:15:38 2014
New Revision: 1603335

URL: http://svn.apache.org/r1603335
Log:
PDFBOX-2145: Clean up PDFont and subclasses

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0Font.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Font.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDMMType1Font.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1AfmPfbFont.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java?rev=1603335&r1=1603334&r2=1603335&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java Wed Jun 18 00:15:38 2014
@@ -33,16 +33,12 @@ import org.apache.pdfbox.pdmodel.common.
 import org.apache.pdfbox.util.ResourceLoader;
 
 /**
- * This is implementation for the CIDFontType0/CIDFontType2 Fonts.
+ * A CIDFont.
  *
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * 
+ * @author Ben Litchfield
  */
 public abstract class PDCIDFont extends PDSimpleFont
 {
-    /**
-     * Log instance.
-     */
     private static final Log LOG = LogFactory.getLog(PDCIDFont.class);
 
     private Map<Integer, Float> widthCache = null;
@@ -71,7 +67,6 @@ public abstract class PDCIDFont extends 
      * This will get the fonts bounding box.
      *
      * @return The fonts bounding box.
-     *
      * @throws IOException If there is an error getting the font bounding box.
      */
     @Override
@@ -119,22 +114,19 @@ public abstract class PDCIDFont extends 
      * @param c The character code to get the width for.
      * @param offset The offset into the array.
      * @param length The length of the data.
-     *
      * @return The width is in 1000 unit of text space, ie 333 or 777
-     *
      * @throws IOException If an error occurs while parsing.
      */
     @Override
     public float getFontWidth(byte[] c, int offset, int length) throws IOException
     {
-
         float retval = getDefaultWidth();
         int code = getCodeFromArray(c, offset, length);
 
         Float widthFloat = widthCache.get(code);
         if (widthFloat != null)
         {
-            retval = widthFloat.floatValue();
+            retval = widthFloat;
         }
         return retval;
     }
@@ -273,9 +265,6 @@ public abstract class PDCIDFont extends 
         return average;
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public float getFontWidth(int charCode)
     {
@@ -294,12 +283,12 @@ public abstract class PDCIDFont extends 
     private String getCIDSystemInfo()
     {
         String cidSystemInfo = null;
-        COSDictionary cidsysteminfo = (COSDictionary) font.getDictionaryObject(COSName.CIDSYSTEMINFO);
-        if (cidsysteminfo != null)
+        COSDictionary dict = (COSDictionary)font.getDictionaryObject(COSName.CIDSYSTEMINFO);
+        if (dict != null)
         {
-            String ordering = cidsysteminfo.getString(COSName.ORDERING);
-            String registry = cidsysteminfo.getString(COSName.REGISTRY);
-            int supplement = cidsysteminfo.getInt(COSName.SUPPLEMENT);
+            String ordering = dict.getString(COSName.ORDERING);
+            String registry = dict.getString(COSName.REGISTRY);
+            int supplement = dict.getInt(COSName.SUPPLEMENT);
             cidSystemInfo = registry + "-" + ordering + "-" + supplement;
         }
         return cidSystemInfo;
@@ -321,7 +310,8 @@ public abstract class PDCIDFont extends 
             }
             else
             {
-                cidSystemInfo = cidSystemInfo.substring(0, cidSystemInfo.lastIndexOf("-")) + "-UCS2";
+                cidSystemInfo = cidSystemInfo.substring(0, cidSystemInfo.lastIndexOf("-")) +
+                        "-UCS2";
             }
             cmap = cmapObjects.get(cidSystemInfo);
             if (cmap == null)
@@ -336,17 +326,20 @@ public abstract class PDCIDFont extends 
                     	cmap = parseCmap(resourceRootCMAP, cmapStream);
                     	if (cmap == null)
                     	{
-                    		LOG.error("Error: Could not parse predefined CMAP file for '" + cidSystemInfo + "'");
+                    		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.");
+                		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 + "'");
+                    LOG.error("Error: Could not find predefined CMAP file for '" + cidSystemInfo +
+                              "'");
                 }
                 finally
                 {
@@ -363,7 +356,7 @@ public abstract class PDCIDFont extends 
     @Override
     public String encode(byte[] c, int offset, int length) throws IOException
     {
-        String result = null;
+        String result;
         if (cmap != null)
         {
             result = cmapEncoding(getCodeFromArray(c, offset, length), length, true, cmap);

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0Font.java?rev=1603335&r1=1603334&r2=1603335&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0Font.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0Font.java Wed Jun 18 00:15:38 2014
@@ -24,10 +24,9 @@ import org.apache.pdfbox.cos.COSDictiona
 import org.apache.pdfbox.cos.COSName;
 
 /**
- * This is implementation of the CIDFontType0 Font.
- * 
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
+ * A Type0 CIDFont (CFF).
  * 
+ * @author Ben Litchfield
  */
 public class PDCIDFontType0Font extends PDCIDFont
 {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Font.java?rev=1603335&r1=1603334&r2=1603335&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Font.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Font.java Wed Jun 18 00:15:38 2014
@@ -31,17 +31,12 @@ import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.pdmodel.common.PDStream;
 
 /**
- * This is implementation of the CIDFontType2 Font.
- * 
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
+ * A Type2 CIDFont (TrueType).
  * 
+ * @author Ben Litchfield
  */
 public class PDCIDFontType2Font extends PDCIDFont
 {
-
-    /**
-     * Log instance.
-     */
     private static final Log LOG = LogFactory.getLog(PDCIDFontType2Font.class);
 
     private Boolean hasCIDToGIDMap = null;
@@ -68,36 +63,6 @@ public class PDCIDFontType2Font extends 
     }
 
     /**
-     * read the CIDToGID map.
-     */
-    private void readCIDToGIDMapping()
-    {
-        COSBase map = font.getDictionaryObject(COSName.CID_TO_GID_MAP);
-        if (map instanceof COSStream)
-        {
-            COSStream stream = (COSStream) map;
-            try
-            {
-                InputStream is = stream.getUnfilteredStream();
-                byte[] mapAsBytes = IOUtils.toByteArray(is);
-                IOUtils.closeQuietly(is);
-                int numberOfInts = mapAsBytes.length / 2;
-                cid2gid = new int[numberOfInts];
-                int offset = 0;
-                for (int index = 0; index < numberOfInts; index++)
-                {
-                    cid2gid[index] = getCodeFromArray(mapAsBytes, offset, 2);
-                    offset += 2;
-                }
-            }
-            catch (IOException exception)
-            {
-                LOG.error("Can't read the CIDToGIDMap", exception);
-            }
-        }
-    }
-
-    /**
      * Indicates if this font has a CIDToGIDMap.
      * 
      * @return returns true if the font has a CIDToGIDMap.
@@ -116,7 +81,7 @@ public class PDCIDFontType2Font extends 
                 hasCIDToGIDMap = Boolean.FALSE;
             }
         }
-        return hasCIDToGIDMap.booleanValue();
+        return hasCIDToGIDMap;
     }
 
     /**
@@ -138,7 +103,7 @@ public class PDCIDFontType2Font extends 
                 hasIdentityCIDToGIDMap = Boolean.FALSE;
             }
         }
-        return hasIdentityCIDToGIDMap.booleanValue();
+        return hasIdentityCIDToGIDMap;
     }
 
     /**
@@ -185,6 +150,33 @@ public class PDCIDFontType2Font extends 
         return cid2gid;
     }
 
+    private void readCIDToGIDMapping()
+    {
+        COSBase map = font.getDictionaryObject(COSName.CID_TO_GID_MAP);
+        if (map instanceof COSStream)
+        {
+            COSStream stream = (COSStream) map;
+            try
+            {
+                InputStream is = stream.getUnfilteredStream();
+                byte[] mapAsBytes = IOUtils.toByteArray(is);
+                IOUtils.closeQuietly(is);
+                int numberOfInts = mapAsBytes.length / 2;
+                cid2gid = new int[numberOfInts];
+                int offset = 0;
+                for (int index = 0; index < numberOfInts; index++)
+                {
+                    cid2gid[index] = getCodeFromArray(mapAsBytes, offset, 2);
+                    offset += 2;
+                }
+            }
+            catch (IOException exception)
+            {
+                LOG.error("Can't read the CIDToGIDMap", exception);
+            }
+        }
+    }
+
     /**
      * Returns the embedded true type font.
      * 
@@ -203,5 +195,4 @@ public class PDCIDFontType2Font extends 
         }
         return trueTypeFont;
     }
-
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java?rev=1603335&r1=1603334&r2=1603335&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java Wed Jun 18 00:15:38 2014
@@ -44,31 +44,21 @@ import org.apache.pdfbox.pdmodel.common.
 /**
  * This is the base class for all PDF fonts.
  * 
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * 
+ * @author Ben Litchfield
  */
 public abstract class PDFont implements COSObjectable
 {
-
-    /**
-     * Log instance.
-     */
     private static final Log LOG = LogFactory.getLog(PDFont.class);
 
-    /**
-     * The cos dictionary for this font.
-     */
-    protected COSDictionary font;
+    protected static final String resourceRootCMAP = "org/apache/pdfbox/resources/cmap/";
 
-    /**
-     * This is only used if this is a font object and it has an encoding.
-     */
-    private Encoding fontEncoding = null;
+    protected static Map<String, CMap> cmapObjects =
+            Collections.synchronizedMap(new HashMap<String, CMap>()); // todo: why synchronized?
 
     /**
-     * The descriptor of the font.
+     * The cos dictionary for this font.
      */
-    private PDFontDescriptor fontDescriptor = null;
+    protected COSDictionary font;
 
     /**
      * The font matrix.
@@ -76,7 +66,7 @@ public abstract class PDFont implements 
     protected PDMatrix fontMatrix = null;
 
     /**
-     * This is only used if this is a font object and it has an encoding and it is a type0 font with a cmap.
+     * Used only if this is a font object and it has an encoding and it is a Type0 font with a CMap.
      */
     protected CMap cmap = null;
 
@@ -85,27 +75,20 @@ public abstract class PDFont implements 
      */
     protected CMap toUnicodeCmap = null;
 
+    private List<Integer> widths = null;
+    private Encoding fontEncoding = null; // only used when this font has an encoding
+    private PDFontDescriptor fontDescriptor = null;
     private boolean hasToUnicode = false;
-
     private boolean widthsAreMissing = false;
 
-    protected static Map<String, CMap> cmapObjects = Collections.synchronizedMap(new HashMap<String, CMap>());
-
-    /**
-     * A list a floats representing the widths.
-     */
-    private List<Integer> widths = null;
-
-    protected static final String resourceRootCMAP = "org/apache/pdfbox/resources/cmap/";
-
     /**
-     * This will clear AFM resources that are stored statically. This is usually not a problem unless you want to
-     * reclaim resources for a long running process.
+     * This will clear AFM resources that are stored statically. This is usually not a problem
+     * unless you want to reclaim resources for a long running process.
      * 
-     * SPECIAL NOTE: The font calculations are currently in COSObject, which is where they will reside until PDFont is
-     * mature enough to take them over. PDFont is the appropriate place for them and not in COSObject but we need font
-     * calculations for text extraction. THIS METHOD WILL BE MOVED OR REMOVED TO ANOTHER LOCATION IN A FUTURE VERSION OF
-     * PDFBOX.
+     * SPECIAL NOTE: The font calculations are currently in COSObject, which is where they will
+     * reside until PDFont is mature enough to take them over. PDFont is the appropriate place for
+     * them and not in COSObject but we need font calculations for text extraction. THIS METHOD WILL
+     * BE MOVED OR REMOVED TO ANOTHER LOCATION IN A FUTURE VERSION OF PDFBOX.
      */
     public static void clearResources()
     {
@@ -136,7 +119,6 @@ public abstract class PDFont implements 
      * This will get the font descriptor for this font.
      * 
      * @return The font descriptor for this font.
-     * 
      */
     public PDFontDescriptor getFontDescriptor()
     {
@@ -176,14 +158,12 @@ public abstract class PDFont implements 
     }
 
     /**
-     * Determines the encoding for the font. This method as to be overwritten, as there are different possibilities to
-     * define a mapping.
+     * Determines the encoding for the font. This method as to be overwritten, as there are
+     * different possibilities to define a mapping.
      */
     protected abstract void determineEncoding();
 
-    /**
-     * {@inheritDoc}
-     */
+    @Override
     public COSBase getCOSObject()
     {
         return font;
@@ -195,9 +175,7 @@ public abstract class PDFont implements 
      * @param c The character code to get the width for.
      * @param offset The offset into the array.
      * @param length The length of the data.
-     * 
      * @return The width is in 1000 unit of text space, ie 333 or 777
-     * 
      * @throws IOException If an error occurs while parsing.
      */
     public abstract float getFontWidth(byte[] c, int offset, int length) throws IOException;
@@ -208,9 +186,7 @@ public abstract class PDFont implements 
      * @param c The character code to get the height for.
      * @param offset The offset into the array.
      * @param length The length of the data.
-     * 
      * @return The height is in 1000 unit of text space, ie 333 or 777
-     * 
      * @throws IOException If an error occurs while parsing.
      */
     public abstract float getFontHeight(byte[] c, int offset, int length) throws IOException;
@@ -219,9 +195,7 @@ public abstract class PDFont implements 
      * This will get the width of this string for this font.
      * 
      * @param string The string to get the width of.
-     * 
      * @return The width of the string in 1000 units of text space, ie 333 567...
-     * 
      * @throws IOException If there is an error getting the width information.
      */
     public float getStringWidth(String string) throws IOException
@@ -239,7 +213,6 @@ public abstract class PDFont implements 
      * This will get the average font width for all characters.
      * 
      * @return The width is in 1000 unit of text space, ie 333 or 777
-     * 
      * @throws IOException If an error occurs while parsing.
      */
     public abstract float getAverageFontWidth() throws IOException;
@@ -250,7 +223,6 @@ public abstract class PDFont implements 
      * @param data The array of data.
      * @param offset The offset into the array.
      * @param length The number of bytes to use.
-     * 
      * @return The int value of data from the array.
      */
     public int getCodeFromArray(byte[] data, int offset, int length)
@@ -268,9 +240,7 @@ public abstract class PDFont implements 
      * This will attempt to get the font width from an AFM file.
      * 
      * @param code The character code we are trying to get.
-     * 
      * @return The font width from the AFM file.
-     * 
      * @throws IOException if we cannot find the width.
      */
     protected float getFontWidthFromAFMFile(int code) throws IOException
@@ -289,7 +259,6 @@ public abstract class PDFont implements 
      * This will attempt to get the average font width from an AFM file.
      * 
      * @return The average font width from the AFM file.
-     * 
      * @throws IOException if we cannot find the width.
      */
     protected float getAverageFontWidthFromAFMFile() throws IOException
@@ -307,7 +276,6 @@ public abstract class PDFont implements 
      * This will get an AFM object if one exists.
      * 
      * @return The afm object from the name.
-     * 
      */
     protected FontMetric getAFM()
     {
@@ -317,7 +285,7 @@ public abstract class PDFont implements 
     private COSBase encoding = null;
 
     /**
-     * cache the {@link COSName#ENCODING} object from the font's dictionary since it is called so often.
+     * Cache the {@link COSName#ENCODING} object from the font's dictionary as it is called often.
      * <p>
      * Use this method instead of
      * 
@@ -357,7 +325,8 @@ public abstract class PDFont implements 
      * @return The value of the encoded character.
      * @throws IOException if something went wrong
      */
-    protected String cmapEncoding(int code, int length, boolean isCIDFont, CMap sourceCmap) throws IOException
+    protected String cmapEncoding(int code, int length, boolean isCIDFont, CMap sourceCmap)
+            throws IOException
     {
         String retval = null;
         // there is not sourceCmap if this is a descendant font
@@ -382,9 +351,7 @@ public abstract class PDFont implements 
      * @param c The character to encode.
      * @param offset The offset into the array to get the data
      * @param length The number of bytes to read.
-     * 
      * @return The value of the encoded character.
-     * 
      * @throws IOException If there is an error during the encoding.
      */
     public String encode(byte[] c, int offset, int length) throws IOException
@@ -444,7 +411,8 @@ public abstract class PDFont implements 
             {
                 try
                 {
-                    DOUBLE_CHAR_STRING[i][j] = new String(new byte[] { (byte) i, (byte) j }, "UTF-16BE");
+                    DOUBLE_CHAR_STRING[i][j] = new String(new byte[] { (byte) i, (byte) j },
+                            "UTF-16BE");
                 }
                 catch (UnsupportedEncodingException e)
                 {
@@ -457,7 +425,7 @@ public abstract class PDFont implements 
 
     private static String getStringFromArray(byte[] c, int offset, int length) throws IOException
     {
-        String retval = null;
+        String retval;
         if (length == 1)
         {
             retval = SINGLE_CHAR_STRING[(c[offset] + 256) % 256];
@@ -710,11 +678,11 @@ public abstract class PDFont implements 
     }
 
     /**
-     * This will get the matrix that is used to transform glyph space to text space. By default there are 1000 glyph
-     * units to 1 text space unit, but type3 fonts can use any value.
+     * This will get the matrix that is used to transform glyph space to text space. By default
+     * there are 1000 glyph units to 1 text space unit, but type3 fonts can use any value.
      * 
-     * Note:If this is a type3 font then it can be modified via the PDType3Font.setFontMatrix, otherwise this is a
-     * read-only property.
+     * Note: If this is a type3 font then it can be modified via the PDType3Font.setFontMatrix,
+     * otherwise this is a read-only property.
      * 
      * @return The matrix to transform from glyph space to text space.
      */
@@ -742,28 +710,11 @@ public abstract class PDFont implements 
      * This will get the fonts bounding box.
      * 
      * @return The fonts bounding box.
-     * 
      * @throws IOException If there is an error getting the bounding box.
      */
     public abstract PDRectangle getFontBoundingBox() throws IOException;
 
     /**
-     * {@inheritDoc}
-     */
-    public boolean equals(Object other)
-    {
-        return other instanceof PDFont && ((PDFont) other).getCOSObject() == this.getCOSObject();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public int hashCode()
-    {
-        return this.getCOSObject().hashCode();
-    }
-
-    /**
      * Determines the width of the given character.
      * 
      * @param charCode the code of the given character
@@ -851,4 +802,15 @@ public abstract class PDFont implements 
     {
     }
 
+    @Override
+    public boolean equals(Object other)
+    {
+        return other instanceof PDFont && ((PDFont) other).getCOSObject() == this.getCOSObject();
+    }
+
+    @Override
+    public int hashCode()
+    {
+        return this.getCOSObject().hashCode();
+    }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDMMType1Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDMMType1Font.java?rev=1603335&r1=1603334&r2=1603335&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDMMType1Font.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDMMType1Font.java Wed Jun 18 00:15:38 2014
@@ -20,10 +20,9 @@ import org.apache.pdfbox.cos.COSDictiona
 import org.apache.pdfbox.cos.COSName;
 
 /**
- * This is implementation of the Multiple Master Type1 Font.
+ * Type 1 Multiple Master Font.
  *
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.4 $
+ * @author Ben Litchfield
  */
 public class PDMMType1Font extends PDType1Font
 {
@@ -33,7 +32,7 @@ public class PDMMType1Font extends PDTyp
     public PDMMType1Font()
     {
         super();
-        font.setItem( COSName.SUBTYPE, COSName.MM_TYPE1 );
+        font.setItem(COSName.SUBTYPE, COSName.MM_TYPE1);
     }
 
     /**
@@ -41,8 +40,8 @@ public class PDMMType1Font extends PDTyp
      *
      * @param fontDictionary The font dictionary according to the PDF specification.
      */
-    public PDMMType1Font( COSDictionary fontDictionary )
+    public PDMMType1Font(COSDictionary fontDictionary)
     {
-        super( fontDictionary );
+        super(fontDictionary);
     }
 }

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=1603335&r1=1603334&r2=1603335&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 Jun 18 00:15:38 2014
@@ -39,23 +39,18 @@ import org.apache.pdfbox.util.ResourceLo
 /**
  * This class contains implementation details of the simple pdf fonts.
  * 
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * 
+ * @author Ben Litchfield
  */
 public abstract class PDSimpleFont extends PDFont
 {
-    private final HashMap<Integer, Float> mFontSizes = new HashMap<Integer, Float>(128);
+    private static final Log LOG = LogFactory.getLog(PDSimpleFont.class);
+    private static final byte[] SPACE_BYTES = { (byte) 32 };
 
+    private final HashMap<Integer, Float> fontSizes = new HashMap<Integer, Float>(128);
     private float avgFontWidth = 0.0f;
     private float avgFontHeight = 0.0f;
     private float fontWidthOfSpace = -1f;
-
-    private static final byte[] SPACE_BYTES = { (byte) 32 };
-
-    /**
-     * Log instance.
-     */
-    private static final Log LOG = LogFactory.getLog(PDSimpleFont.class);
+    private boolean isFontSubstituted = false;
 
     /**
      * Constructor.
@@ -81,11 +76,10 @@ public abstract class PDSimpleFont exten
      * @param c The character code to get the width for.
      * @param offset The offset into the array.
      * @param length The length of the data.
-     * 
      * @return The width is in 1000 unit of text space, ie 333 or 777
-     * 
      * @throws IOException If an error occurs while parsing.
      */
+    @Override
     public float getFontHeight(byte[] c, int offset, int length) throws IOException
     {
         // maybe there is already a precalculated value
@@ -107,9 +101,8 @@ public abstract class PDSimpleFont exten
             PDFontDescriptor desc = getFontDescriptor();
             if (desc != null)
             {
-                // the following values are all more or less accurate
-                // at least all are average values. Maybe we'll find
-                // another way to get those value for every single glyph
+                // the following values are all more or less accurate at least all are average
+                // values. Maybe we'll find another way to get those value for every single glyph
                 // in the future if needed
                 PDRectangle fontBBox = desc.getFontBoundingBox();
                 if (fontBBox != null)
@@ -144,15 +137,14 @@ public abstract class PDSimpleFont exten
      * @param c The character code to get the width for.
      * @param offset The offset into the array.
      * @param length The length of the data.
-     * 
      * @return The width is in 1000 unit of text space, ie 333 or 777
-     * 
      * @throws IOException If an error occurs while parsing.
      */
+    @Override
     public float getFontWidth(byte[] c, int offset, int length) throws IOException
     {
         int code = getCodeFromArray(c, offset, length);
-        Float fontWidth = mFontSizes.get(code);
+        Float fontWidth = fontSizes.get(code);
         if (fontWidth == null)
         {
             fontWidth = getFontWidth(code);
@@ -161,7 +153,7 @@ public abstract class PDSimpleFont exten
                 // TODO should this be in PDType1Font??
                 fontWidth = getFontWidthFromAFMFile(code);
             }
-            mFontSizes.put(code, fontWidth);
+            fontSizes.put(code, fontWidth);
         }
         return fontWidth;
     }
@@ -170,13 +162,12 @@ public abstract class PDSimpleFont exten
      * This will get the average font width for all characters.
      * 
      * @return The width is in 1000 unit of text space, ie 333 or 777
-     * 
      * @throws IOException If an error occurs while parsing.
      */
+    @Override
     public float getAverageFontWidth() throws IOException
     {
-        float average = 0.0f;
-
+        float average;
         if (avgFontWidth != 0.0f)
         {
             average = avgFontWidth;
@@ -236,17 +227,15 @@ public abstract class PDSimpleFont exten
      * This will get the fonts bounding box.
      * 
      * @return The fonts bouding box.
-     * 
      * @throws IOException If there is an error getting the bounding box.
      */
+    @Override
     public PDRectangle getFontBoundingBox() throws IOException
     {
         return getFontDescriptor().getFontBoundingBox();
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    @Override
     protected void determineEncoding()
     {
         String cmapName = null;
@@ -322,12 +311,14 @@ public abstract class PDSimpleFont exten
                 	cmap = parseCmap(resourceRootCMAP, cmapStream);
                 	if (cmap == null && encodingName == null)
                 	{
-                		LOG.error("Error: Could not parse predefined CMAP file for '" + cmapName + "'");
+                		LOG.error("Error: Could not parse predefined CMAP file for '" +
+                                  cmapName + "'");
                 	}
                 }
                 else
                 {
-            		LOG.debug("Debug: '" + cmapName + "' isn't a predefined map, most likely it's embedded in the pdf itself.");
+            		LOG.debug("Debug: '" + cmapName + "' isn't a predefined map, most likely it's" +
+                              "embedded in the pdf itself.");
                 }
             }
             catch (IOException exception)
@@ -343,8 +334,8 @@ public abstract class PDSimpleFont exten
 
     private void extractToUnicodeEncoding()
     {
-        COSName encodingName = null;
-        String cmapName = null;
+        COSName encodingName;
+        String cmapName;
         COSBase toUnicode = getToUnicode();
         if (toUnicode != null)
         {
@@ -372,26 +363,27 @@ public abstract class PDSimpleFont exten
                     String resourceName = resourceRootCMAP + cmapName;
                     try
                     {
-                        toUnicodeCmap = parseCmap(resourceRootCMAP, ResourceLoader.loadResource(resourceName));
+                        toUnicodeCmap = parseCmap(resourceRootCMAP,
+                                ResourceLoader.loadResource(resourceName));
                     }
                     catch (IOException exception)
                     {
-                        LOG.error("Error: Could not find predefined ToUnicode CMap file for '" + cmapName + "'");
+                        LOG.error("Error: Could not find predefined ToUnicode CMap file for '" +
+                                cmapName + "'");
                     }
                     if (toUnicodeCmap == null)
                     {
-                        LOG.error("Error: Could not parse predefined ToUnicode CMap file for '" + cmapName + "'");
+                        LOG.error("Error: Could not parse predefined ToUnicode CMap file for '" +
+                                cmapName + "'");
                     }
                 }
             }
         }
     }
 
-    private boolean isFontSubstituted = false;
-
     /**
-     * This will get the value for isFontSubstituted, which indicates if the font was substituted due to a problem with
-     * the embedded one.
+     * This will get the value for isFontSubstituted, which indicates if the font was substituted
+     * due to a problem with the embedded one.
      * 
      * @return true if the font was substituted
      */
@@ -410,9 +402,7 @@ public abstract class PDSimpleFont exten
         isFontSubstituted = isSubstituted;
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    @Override
     public float getSpaceWidth()
     {
         if (fontWidthOfSpace == -1f)
@@ -440,11 +430,10 @@ public abstract class PDSimpleFont exten
             }
             catch (Exception e)
             {
-                LOG.error("Can't determine the width of the space character using 250 as default", e);
+                LOG.error("Can't determine the width of the space character, assuming 250", e);
                 fontWidthOfSpace = 250f;
             }
         }
         return fontWidthOfSpace;
     }
-
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java?rev=1603335&r1=1603334&r2=1603335&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java Wed Jun 18 00:15:38 2014
@@ -53,22 +53,14 @@ import org.apache.pdfbox.pdmodel.common.
 import org.apache.pdfbox.pdmodel.common.PDStream;
 
 /**
- * This is the TrueType implementation of fonts.
- * 
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
+ * TrueType font.
  * 
+ * @author Ben Litchfield
  */
 public class PDTrueTypeFont extends PDSimpleFont
 {
-
-    /**
-     * Log instance.
-     */
     private static final Log LOG = LogFactory.getLog(PDTrueTypeFont.class);
 
-    /**
-     * Start of coderanges.
-     */
     private static final int START_RANGE_F000 = 0xF000;
     private static final int START_RANGE_F100 = 0xF100;
     private static final int START_RANGE_F200 = 0xF200;
@@ -77,9 +69,8 @@ public class PDTrueTypeFont extends PDSi
     private CMAPEncodingEntry cmapWinSymbol = null;
     private CMAPEncodingEntry cmapMacintoshSymbol = null;
     private boolean cmapInitialized = false;
-    
-    private TrueTypeFont trueTypeFont = null;
 
+    private TrueTypeFont trueTypeFont = null;
     private HashMap<Integer, Float> advanceWidths = new HashMap<Integer, Float> (); 
     
     /**
@@ -149,7 +140,8 @@ public class PDTrueTypeFont extends PDSi
      * @return a PDTrueTypeFont instance.
      * @throws IOException If there is an error loading the data.
      */
-    public static PDTrueTypeFont loadTTF(PDDocument doc, InputStream stream, Encoding enc) throws IOException
+    public static PDTrueTypeFont loadTTF(PDDocument doc, InputStream stream, Encoding enc)
+            throws IOException
     {
         PDStream fontStream = new PDStream(doc, stream, false);
         fontStream.getStream().setInt(COSName.LENGTH1, fontStream.getByteArray().length);
@@ -189,7 +181,8 @@ public class PDTrueTypeFont extends PDSi
         return retval;
     }
 
-    private void loadDescriptorDictionary(PDFontDescriptorDictionary fd, InputStream ttfData) throws IOException
+    private void loadDescriptorDictionary(PDFontDescriptorDictionary fd, InputStream ttfData)
+            throws IOException
     {
         TrueTypeFont ttf = null;
         try
@@ -198,15 +191,13 @@ public class PDTrueTypeFont extends PDSi
             ttf = parser.parseTTF(ttfData);
             NamingTable naming = ttf.getNaming();
             List<NameRecord> records = naming.getNameRecords();
-            for (int i = 0; i < records.size(); i++)
+            for (NameRecord nr : records)
             {
-                NameRecord nr = records.get(i);
                 if (nr.getNameId() == NameRecord.NAME_POSTSCRIPT_NAME)
                 {
                     setBaseFont(nr.getString());
                     fd.setFontName(nr.getString());
-                }
-                else if (nr.getNameId() == NameRecord.NAME_FONT_FAMILY_NAME)
+                } else if (nr.getNameId() == NameRecord.NAME_FONT_FAMILY_NAME)
                 {
                     fd.setFontFamily(nr.getString());
                 }
@@ -299,8 +290,7 @@ public class PDTrueTypeFont extends PDSi
             {
                 for (int i = 0; i < names.length; i++)
                 {
-                    // if we have a capital H then use that, otherwise use the
-                    // tallest letter
+                    // if we have a capital H then use that, otherwise use the tallest letter
                     if (names[i].equals("H"))
                     {
                         fd.setCapHeight(glyphs[i].getBoundingBox().getUpperRightY() / scaling);
@@ -314,7 +304,7 @@ public class PDTrueTypeFont extends PDSi
 
             // hmm there does not seem to be a clear definition for StemV,
             // this is close enough and I am told it doesn't usually get used.
-            fd.setStemV((fd.getFontBoundingBox().getWidth() * .13f));
+            fd.setStemV(fd.getFontBoundingBox().getWidth() * .13f);
 
             CMAPTable cmapTable = ttf.getCMAP();
             CMAPEncodingEntry[] cmaps = cmapTable.getCmaps();
@@ -357,9 +347,8 @@ public class PDTrueTypeFont extends PDSi
             // unicode cpoint point mapping of Adobe's glyphlist.txt
             Encoding glyphlist = WinAnsiEncoding.INSTANCE;
 
-            // A character code is mapped to a glyph name via the provided
-            // font encoding. Afterwards, the glyph name is translated to a
-            // glyph ID.
+            // A character code is mapped to a glyph name via the provided font encoding
+            // Afterwards, the glyph name is translated to a glyph ID.
             // For details, see PDFReference16.pdf, Section 5.5.5, p.401
             //
             for (Entry<Integer, String> e : codeToName.entrySet())
@@ -377,7 +366,8 @@ public class PDTrueTypeFont extends PDSi
                     }
                     else
                     {
-                        widths.set(e.getKey().intValue() - firstChar, Math.round(widthValues[gid] * scaling));
+                        widths.set(e.getKey().intValue() - firstChar,
+                                   Math.round(widthValues[gid] * scaling));
                     }
                 }
             }
@@ -422,7 +412,6 @@ public class PDTrueTypeFont extends PDSi
         }
         return trueTypeFont;
     }
-    
 
     @Override
     public void clear()
@@ -450,7 +439,7 @@ public class PDTrueTypeFont extends PDSi
             }
             else
             {
-                TrueTypeFont ttf = null;
+                TrueTypeFont ttf;
                 try
                 {
                     ttf = getTTFFont();
@@ -462,7 +451,7 @@ public class PDTrueTypeFont extends PDSi
                         // do we have to scale the width
                         if (unitsPerEM != 1000)
                         {
-                            width *= 1000f/unitsPerEM;
+                            width *= 1000f / unitsPerEM;
                         }
                     }
                 }
@@ -486,21 +475,22 @@ public class PDTrueTypeFont extends PDSi
         {
             try
             {
-                String charactername = getFontEncoding().getName(code);
-                if (charactername != null)
+                String characterName = getFontEncoding().getName(code);
+                if (characterName != null)
                 {
                     if (cmapWinUnicode != null)
                     {
-                        String unicode = Encoding.getCharacterForName(charactername);
+                        String unicode = Encoding.getCharacterForName(characterName);
                         if (unicode != null)
                         {
                             result = unicode.codePointAt(0);
                         }
                         result = cmapWinUnicode.getGlyphId(result);
                     }
-                    else if (cmapMacintoshSymbol != null && MacOSRomanEncoding.INSTANCE.hasCodeForName(charactername))
+                    else if (cmapMacintoshSymbol != null &&
+                             MacOSRomanEncoding.INSTANCE.hasCodeForName(characterName))
                     {
-                        result = MacOSRomanEncoding.INSTANCE.getCode(charactername);
+                        result = MacOSRomanEncoding.INSTANCE.getCode(characterName);
                         result = cmapMacintoshSymbol.getGlyphId(result);
                     }
                     else if (cmapWinSymbol != null)
@@ -572,24 +562,22 @@ public class PDTrueTypeFont extends PDSi
             {
                 // get all relevant CMaps
                 CMAPEncodingEntry[] cmaps = cmapTable.getCmaps();
-                for (int i = 0; i < cmaps.length; i++)
+                for (CMAPEncodingEntry cmap1 : cmaps)
                 {
-                    if (CMAPTable.PLATFORM_WINDOWS == cmaps[i].getPlatformId())
+                    if (CMAPTable.PLATFORM_WINDOWS == cmap1.getPlatformId())
                     {
-                        if (CMAPTable.ENCODING_UNICODE == cmaps[i].getPlatformEncodingId())
+                        if (CMAPTable.ENCODING_UNICODE == cmap1.getPlatformEncodingId())
                         {
-                            cmapWinUnicode = cmaps[i];
-                        }
-                        else if (CMAPTable.ENCODING_SYMBOL == cmaps[i].getPlatformEncodingId())
+                            cmapWinUnicode = cmap1;
+                        } else if (CMAPTable.ENCODING_SYMBOL == cmap1.getPlatformEncodingId())
                         {
-                            cmapWinSymbol = cmaps[i];
+                            cmapWinSymbol = cmap1;
                         }
-                    }
-                    else if (CMAPTable.PLATFORM_MACINTOSH == cmaps[i].getPlatformId())
+                    } else if (CMAPTable.PLATFORM_MACINTOSH == cmap1.getPlatformId())
                     {
-                        if (CMAPTable.ENCODING_SYMBOL == cmaps[i].getPlatformEncodingId())
+                        if (CMAPTable.ENCODING_SYMBOL == cmap1.getPlatformEncodingId())
                         {
-                            cmapMacintoshSymbol = cmaps[i];
+                            cmapMacintoshSymbol = cmap1;
                         }
                     }
                 }
@@ -598,4 +586,3 @@ public class PDTrueTypeFont extends PDSi
         }
     }
 }
-

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java?rev=1603335&r1=1603334&r2=1603335&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java Wed Jun 18 00:15:38 2014
@@ -26,17 +26,12 @@ import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 
 /**
- * This is implementation of the Type0 Font. See <a
- * href="https://issues.apache.org/jira/browse/PDFBOX-605">PDFBOX-605</a> for the related improvement issue.
+ * Type 0 (composite) Font.
  * 
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
+ * @author <Ben Litchfield
  */
 public class PDType0Font extends PDSimpleFont
 {
-
-    /**
-     * Log instance.
-     */
     private static final Log LOG = LogFactory.getLog(PDType0Font.class);
 
     private COSArray descendantFontArray;
@@ -48,7 +43,6 @@ public class PDType0Font extends PDSimpl
      */
     public PDType0Font()
     {
-        super();
         font.setItem(COSName.SUBTYPE, COSName.TYPE0);
     }
 
@@ -74,18 +68,21 @@ public class PDType0Font extends PDSimpl
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    private COSArray getDescendantFonts()
+    {
+        if (descendantFontArray == null)
+        {
+            descendantFontArray = (COSArray) font.getDictionaryObject(COSName.DESCENDANT_FONTS);
+        }
+        return descendantFontArray;
+    }
+
     @Override
     public PDRectangle getFontBoundingBox() throws IOException
     {
         throw new RuntimeException("Not yet implemented");
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public float getFontWidth(byte[] c, int offset, int length) throws IOException
     {
@@ -110,45 +107,24 @@ public class PDType0Font extends PDSimpl
         return descendantFont.getFontWidth(c, offset, length);
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public float getFontHeight(byte[] c, int offset, int length) throws IOException
     {
         return descendantFont.getFontHeight(c, offset, length);
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public float getAverageFontWidth() throws IOException
     {
         return descendantFont.getAverageFontWidth();
     }
 
-    private COSArray getDescendantFonts()
-    {
-        if (descendantFontArray == null)
-        {
-            descendantFontArray = (COSArray) font.getDictionaryObject(COSName.DESCENDANT_FONTS);
-        }
-        return descendantFontArray;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public float getFontWidth(int charCode)
     {
         return descendantFont.getFontWidth(charCode);
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public String encode(byte[] c, int offset, int length) throws IOException
     {
@@ -170,11 +146,9 @@ public class PDType0Font extends PDSimpl
     }
 
     /**
-     * 
-     * Provides the descendant font.
-     * 
+     * Returns the descendant font.
+     *
      * @return the descendant font.
-     * 
      */
     public PDFont getDescendantFont()
     {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1AfmPfbFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1AfmPfbFont.java?rev=1603335&r1=1603334&r2=1603335&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1AfmPfbFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1AfmPfbFont.java Wed Jun 18 00:15:38 2014
@@ -40,21 +40,14 @@ import org.apache.pdfbox.pdmodel.common.
 import org.apache.pdfbox.pdmodel.common.PDStream;
 
 /**
- * This is implementation of the Type1 Font with a afm and a pfb file.
- * 
- * @author <a href="mailto:m.g.n@gmx.de">Michael Niedermair</a>
+ * Adobe Type 1 Font with an .afm and .pfb file.
  * 
+ * @author Michael Niedermair
  */
 public class PDType1AfmPfbFont extends PDType1Font
 {
-    /**
-     * the buffersize.
-     */
-    private static final int BUFFERSIZE = 0xffff;
+    private static final int BUFFER_SIZE = 0xffff;
 
-    /**
-     * The font metric.
-     */
     private FontMetric metric;
 
     /**
@@ -66,12 +59,10 @@ public class PDType1AfmPfbFont extends P
      */
     public PDType1AfmPfbFont(final PDDocument doc, final String afmname) throws IOException
     {
-
-        super();
-        InputStream afmin = new BufferedInputStream(new FileInputStream(afmname), BUFFERSIZE);
-        String pfbname = afmname.replaceAll(".AFM", "").replaceAll(".afm", "") + ".pfb";
-        InputStream pfbin = new BufferedInputStream(new FileInputStream(pfbname), BUFFERSIZE);
-        load(doc, afmin, pfbin);
+        InputStream afmIn = new BufferedInputStream(new FileInputStream(afmname), BUFFER_SIZE);
+        String pfbName = afmname.replaceAll(".AFM", "").replaceAll(".afm", "") + ".pfb";
+        InputStream pfbIn = new BufferedInputStream(new FileInputStream(pfbName), BUFFER_SIZE);
+        load(doc, afmIn, pfbIn);
     }
 
     /**
@@ -82,9 +73,9 @@ public class PDType1AfmPfbFont extends P
      * @param pfb The pfb input.
      * @throws IOException If there is an error loading the data.
      */
-    public PDType1AfmPfbFont(final PDDocument doc, final InputStream afm, final InputStream pfb) throws IOException
+    public PDType1AfmPfbFont(final PDDocument doc, final InputStream afm, final InputStream pfb)
+            throws IOException
     {
-        super();
         load(doc, afm, pfb);
     }
 
@@ -96,9 +87,9 @@ public class PDType1AfmPfbFont extends P
      * @param pfb The pfb input.
      * @throws IOException If there is an error loading the data.
      */
-    private void load(final PDDocument doc, final InputStream afm, final InputStream pfb) throws IOException
+    private void load(final PDDocument doc, final InputStream afm, final InputStream pfb)
+            throws IOException
     {
-
         PDFontDescriptorDictionary fd = new PDFontDescriptorDictionary();
         setFontDescriptor(fd);
 
@@ -161,7 +152,7 @@ public class PDType1AfmPfbFont extends P
                 {
                     int width = Math.round(m.getWx());
                     widths.set(n, width);
-                    // germandbls has 2 character codes !! Don't ask me why .....
+                    // germandbls has 2 character codes !! Don't ask me why
                     // StandardEncoding = 0373 = 251
                     // WinANSIEncoding = 0337 = 223
                     if (m.getName().equals("germandbls") && n != 223)
@@ -205,12 +196,10 @@ public class PDType1AfmPfbFont extends P
         setWidths(widths);
     }
 
-    /*
-     * This will generate a Encoding from the AFM-Encoding, because the AFM-Enconding isn't exported to the pdf and
-     * consequently the StandardEncoding is used so that any special character is missing I've copied the code from the
-     * pdfbox-forum posted by V0JT4 and made some additions concerning german umlauts see also
-     * https://sourceforge.net/forum/message.php?msg_id=4705274
-     */
+    // This will generate a Encoding from the AFM-Encoding, because the AFM-Enconding isn't exported
+    // to the pdf and consequently the StandardEncoding is used so that any special character is
+    // missing I've copied the code from the pdfbox-forum posted by V0JT4 and made some additions
+    // concerning german umlauts see also https://sourceforge.net/forum/message.php?msg_id=4705274
     private DictionaryEncoding afmToDictionary(AFMEncoding encoding) throws java.io.IOException
     {
         COSArray array = new COSArray();

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java?rev=1603335&r1=1603334&r2=1603335&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java Wed Jun 18 00:15:38 2014
@@ -45,39 +45,27 @@ import org.apache.pdfbox.pdmodel.common.
 import org.apache.pdfbox.pdmodel.common.PDStream;
 
 /**
- * This class represents a CFF/Type2 Font (aka Type1C Font).
+ * Adobe CFF Font, also known as a "Type1C" font.
  * 
  * @author Villu Ruusmann
- * 
  */
 public class PDType1CFont extends PDSimpleFont
 {
-    private CFFFont cffFont = null;
+    private static final Log LOG = LogFactory.getLog(PDType1CFont.class);
+    private static final byte[] SPACE_BYTES = { (byte) 32 };
 
+    private CFFFont cffFont = null;
     private String fontname = null;
-
     private Map<Integer, String> sidToName = new HashMap<Integer, String>();
-
     private Map<Integer, Integer> codeToSID = new HashMap<Integer, Integer>();
-
     private Map<Integer, String> sidToCharacter = new HashMap<Integer, String>();
-
     private Map<String, Integer> characterToSID = new HashMap<String, Integer>();
-
     private FontMetric fontMetric = null;
-
     private Map<String, Float> glyphWidths = new HashMap<String, Float>();
-
     private Map<String, Float> glyphHeights = new HashMap<String, Float>();
-
     private Float avgWidth = null;
-
     private PDRectangle fontBBox = null;
 
-    private static final Log LOG = LogFactory.getLog(PDType1CFont.class);
-
-    private static final byte[] SPACE_BYTES = { (byte) 32 };
-
     /**
      * Constructor.
      * 
@@ -90,9 +78,7 @@ public class PDType1CFont extends PDSimp
         load();
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    @Override
     public String encode(byte[] bytes, int offset, int length) throws IOException
     {
         String character = getCharacter(bytes, offset, length);
@@ -104,9 +90,6 @@ public class PDType1CFont extends PDSimp
         return character;
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public int encodeToCID(byte[] bytes, int offset, int length)
     {
@@ -137,9 +120,7 @@ public class PDType1CFont extends PDSimp
         return character;
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    @Override
     public float getFontWidth(byte[] bytes, int offset, int length) throws IOException
     {
         String name = getName(bytes, offset, length);
@@ -149,19 +130,17 @@ public class PDType1CFont extends PDSimp
             return 0;
         }
 
-        Float width = (Float) glyphWidths.get(name);
+        Float width = glyphWidths.get(name);
         if (width == null)
         {
-            width = Float.valueOf(getFontMetric().getCharacterWidth(name));
+            width = getFontMetric().getCharacterWidth(name);
             glyphWidths.put(name, width);
         }
 
-        return width.floatValue();
+        return width;
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    @Override
     public float getFontHeight(byte[] bytes, int offset, int length) throws IOException
     {
         String name = getName(bytes, offset, length);
@@ -197,9 +176,7 @@ public class PDType1CFont extends PDSimp
         return sidToName.get(code);
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    @Override
     public float getStringWidth(String string) throws IOException
     {
         float width = 0;
@@ -227,21 +204,17 @@ public class PDType1CFont extends PDSimp
         return characterToSID.get(character);
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    @Override
     public float getAverageFontWidth() throws IOException
     {
         if (avgWidth == null)
         {
             avgWidth = getFontMetric().getAverageCharacterWidth();
         }
-        return avgWidth.floatValue();
+        return avgWidth;
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    @Override
     public PDRectangle getFontBoundingBox() throws IOException
     {
         if (fontBBox == null)
@@ -251,9 +224,7 @@ public class PDType1CFont extends PDSimp
         return fontBBox;
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    @Override
     public PDMatrix getFontMatrix()
     {
         if (fontMatrix == null)
@@ -313,14 +284,14 @@ public class PDType1CFont extends PDSimp
         }
         if (cffFont == null)
         {
-            cffFont = (CFFFont) fonts.get(0);
+            cffFont = fonts.get(0);
         }
-        // chache the font name
+        // cache the font name
         fontname = cffFont.getName();
 
         // TODO is this really needed?
         Number defaultWidthX = (Number) this.cffFont.getProperty("defaultWidthX");
-        glyphWidths.put(null, Float.valueOf(defaultWidthX.floatValue()));
+        glyphWidths.put(null, defaultWidthX.floatValue());
 
         // calculate some mappings to be used for rendering and text extraction
         Encoding encoding = getFontEncoding();
@@ -402,10 +373,9 @@ public class PDType1CFont extends PDSimp
 
             // Replace default FontBBox value with a newly computed one
             BoundingBox bounds = result.getFontBBox();
-            List<Integer> numbers = Arrays.asList(Integer.valueOf((int) bounds.getLowerLeftX()),
-                    Integer.valueOf((int) bounds.getLowerLeftY()),
-                    Integer.valueOf((int) bounds.getUpperRightX()),
-                    Integer.valueOf((int) bounds.getUpperRightY()));
+            List<Integer> numbers = Arrays.asList((int) bounds.getLowerLeftX(),
+                    (int) bounds.getLowerLeftY(), (int) bounds.getUpperRightX(),
+                    (int) bounds.getUpperRightY());
             font.addValueToTopDict("FontBBox", numbers);
 
             return result;

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java?rev=1603335&r1=1603334&r2=1603335&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java Wed Jun 18 00:15:38 2014
@@ -46,77 +46,27 @@ import org.apache.pdfbox.pdmodel.common.
 import org.apache.pdfbox.util.ResourceLoader;
 
 /**
- * This is implementation of the Type1 Font.
- * 
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
+ * PostScript Type 1 Font.
  * 
+ * @author Ben Litchfield
  */
 public class PDType1Font extends PDSimpleFont
 {
-
-    /**
-     * Log instance.
-     */
     private static final Log LOG = LogFactory.getLog(PDType1Font.class);
 
-    private PDType1CFont type1CFont = null;
-    private Type1Font type1font = null;
-
-    /**
-     * Standard Base 14 Font.
-     */
     public static final PDType1Font TIMES_ROMAN = new PDType1Font("Times-Roman");
-    /**
-     * Standard Base 14 Font.
-     */
     public static final PDType1Font TIMES_BOLD = new PDType1Font("Times-Bold");
-    /**
-     * Standard Base 14 Font.
-     */
     public static final PDType1Font TIMES_ITALIC = new PDType1Font("Times-Italic");
-    /**
-     * Standard Base 14 Font.
-     */
     public static final PDType1Font TIMES_BOLD_ITALIC = new PDType1Font("Times-BoldItalic");
-    /**
-     * Standard Base 14 Font.
-     */
     public static final PDType1Font HELVETICA = new PDType1Font("Helvetica");
-    /**
-     * Standard Base 14 Font.
-     */
     public static final PDType1Font HELVETICA_BOLD = new PDType1Font("Helvetica-Bold");
-    /**
-     * Standard Base 14 Font.
-     */
     public static final PDType1Font HELVETICA_OBLIQUE = new PDType1Font("Helvetica-Oblique");
-    /**
-     * Standard Base 14 Font.
-     */
     public static final PDType1Font HELVETICA_BOLD_OBLIQUE = new PDType1Font("Helvetica-BoldOblique");
-    /**
-     * Standard Base 14 Font.
-     */
     public static final PDType1Font COURIER = new PDType1Font("Courier");
-    /**
-     * Standard Base 14 Font.
-     */
     public static final PDType1Font COURIER_BOLD = new PDType1Font("Courier-Bold");
-    /**
-     * Standard Base 14 Font.
-     */
     public static final PDType1Font COURIER_OBLIQUE = new PDType1Font("Courier-Oblique");
-    /**
-     * Standard Base 14 Font.
-     */
     public static final PDType1Font COURIER_BOLD_OBLIQUE = new PDType1Font("Courier-BoldOblique");
-    /**
-     * Standard Base 14 Font.
-     */
     public static final PDType1Font SYMBOL = new PDType1Font("Symbol");
-    /**
-     * Standard Base 14 Font.
-     */
     public static final PDType1Font ZAPF_DINGBATS = new PDType1Font("ZapfDingbats");
 
     private static final Map<String, PDType1Font> STANDARD_14 = new HashMap<String, PDType1Font>();
@@ -141,57 +91,53 @@ public class PDType1Font extends PDSimpl
     /**
      * The static map of the default Adobe font metrics.
      */
-    private static final Map<String, FontMetric> afmObjects = Collections.unmodifiableMap(getAdobeFontMetrics());
-
-    private FontMetric afm = null;
+    private static final Map<String, FontMetric> AFM_MAP = getAdobeFontMetrics();
 
     private static Map<String, FontMetric> getAdobeFontMetrics()
     {
         Map<String, FontMetric> metrics = new HashMap<String, FontMetric>();
-        addAdobeFontMetric(metrics, "Courier-Bold");
-        addAdobeFontMetric(metrics, "Courier-BoldOblique");
-        addAdobeFontMetric(metrics, "Courier");
-        addAdobeFontMetric(metrics, "Courier-Oblique");
-        addAdobeFontMetric(metrics, "Helvetica");
-        addAdobeFontMetric(metrics, "Helvetica-Bold");
-        addAdobeFontMetric(metrics, "Helvetica-BoldOblique");
-        addAdobeFontMetric(metrics, "Helvetica-Oblique");
-        addAdobeFontMetric(metrics, "Symbol");
-        addAdobeFontMetric(metrics, "Times-Bold");
-        addAdobeFontMetric(metrics, "Times-BoldItalic");
-        addAdobeFontMetric(metrics, "Times-Italic");
-        addAdobeFontMetric(metrics, "Times-Roman");
-        addAdobeFontMetric(metrics, "ZapfDingbats");
+        addMetric("Courier-Bold");
+        addMetric("Courier-BoldOblique");
+        addMetric("Courier");
+        addMetric("Courier-Oblique");
+        addMetric("Helvetica");
+        addMetric("Helvetica-Bold");
+        addMetric("Helvetica-BoldOblique");
+        addMetric("Helvetica-Oblique");
+        addMetric("Symbol");
+        addMetric("Times-Bold");
+        addMetric("Times-BoldItalic");
+        addMetric("Times-Italic");
+        addMetric("Times-Roman");
+        addMetric("ZapfDingbats");
         
         // PDFBOX-239
-        addAdobeFontMetric(metrics, "Arial", "Helvetica");
-        addAdobeFontMetric(metrics, "Arial,Bold", "Helvetica-Bold");
-        addAdobeFontMetric(metrics, "Arial,Italic", "Helvetica-Oblique");
-        addAdobeFontMetric(metrics, "Arial,BoldItalic", "Helvetica-BoldOblique");
+        addMetric("Arial", "Helvetica");
+        addMetric("Arial,Bold", "Helvetica-Bold");
+        addMetric("Arial,Italic", "Helvetica-Oblique");
+        addMetric("Arial,BoldItalic", "Helvetica-BoldOblique");
 
-        return metrics;
+        return Collections.unmodifiableMap(metrics);
     }
 
-    private static final String resourceRootAFM = "org/apache/pdfbox/resources/afm/";
-
-    private static void addAdobeFontMetric(Map<String, FontMetric> metrics, String name)
+    private static void addMetric(String name)
     {
-        addAdobeFontMetric(metrics, name, name);
+        addMetric(name, name);
     }
     
-    private static void addAdobeFontMetric(Map<String, FontMetric> metrics, String name, String filePrefix)
+    private static void addMetric(String name, String prefix)
     {
         try
         {
-            String resource = resourceRootAFM + filePrefix + ".afm";
+            String resource = "org/apache/pdfbox/resources/afm/" + prefix + ".afm";
             InputStream afmStream = ResourceLoader.loadResource(resource);
             if (afmStream != null)
             {
                 try
                 {
                     AFMParser parser = new AFMParser(afmStream);
-                    FontMetric metric = parser.parse(); 
-                    metrics.put(name, metric);
+                    FontMetric metric = parser.parse();
+                    AFM_MAP.put(name, metric);
                 }
                 finally
                 {
@@ -205,12 +151,15 @@ public class PDType1Font extends PDSimpl
         }
     }
 
+    private PDType1CFont type1CFont = null;
+    private Type1Font type1font = null;
+    private FontMetric afm = null;
+
     /**
      * Constructor.
      */
     public PDType1Font()
     {
-        super();
         font.setItem(COSName.SUBTYPE, COSName.TYPE1);
     }
 
@@ -264,6 +213,7 @@ public class PDType1Font extends PDSimpl
         }
         getEncodingFromFont(getFontEncoding() == null);
     }
+
     /**
      * Constructor.
      * 
@@ -286,7 +236,7 @@ public class PDType1Font extends PDSimpl
             if (baseFont instanceof COSName)
             {
                 name = ((COSName) baseFont).getName();
-                if (name.indexOf("+") > -1)
+                if (name.contains("+"))
                 {
                     name = name.substring(name.indexOf("+") + 1);
                 }
@@ -299,7 +249,7 @@ public class PDType1Font extends PDSimpl
             }
             if (name != null)
             {
-                afm = afmObjects.get(name);
+                afm = AFM_MAP.get(name);
             }
         }
         return afm;
@@ -314,7 +264,7 @@ public class PDType1Font extends PDSimpl
      */
     public static PDType1Font getStandardFont(String name)
     {
-        return (PDType1Font) STANDARD_14.get(name);
+        return STANDARD_14.get(name);
     }
 
     /**
@@ -324,12 +274,9 @@ public class PDType1Font extends PDSimpl
      */
     public static String[] getStandard14Names()
     {
-        return (String[]) STANDARD_14.keySet().toArray(new String[14]);
+        return STANDARD_14.keySet().toArray(new String[14]);
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     protected void determineEncoding()
     {
@@ -348,13 +295,12 @@ public class PDType1Font extends PDSimpl
 
     /**
      * Tries to get the encoding for the type1 font.
-     *
      */
     private void getEncodingFromFont(boolean extractEncoding)
     {
         if (type1font != null)
         {
-            // Fontmatrix
+            // FontMatrix
             List<Number> matrixValues = type1font.getFontMatrix();
             if (!matrixValues.isEmpty() && matrixValues.size() == 6)
             {
@@ -387,9 +333,6 @@ public class PDType1Font extends PDSimpl
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public String encode(byte[] c, int offset, int length) throws IOException
     {
@@ -404,9 +347,6 @@ public class PDType1Font extends PDSimpl
         return super.encode(c, offset, length);
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public int encodeToCID(byte[] c, int offset, int length) throws IOException
     {
@@ -420,9 +360,6 @@ public class PDType1Font extends PDSimpl
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public PDMatrix getFontMatrix()
     {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java?rev=1603335&r1=1603334&r2=1603335&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java Wed Jun 18 00:15:38 2014
@@ -27,16 +27,13 @@ import org.apache.pdfbox.pdmodel.common.
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 
 /**
- * This is implementation of the Type3 Font.
+ * A PostScript Type 3 Font.
  *
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * 
+ * @author Ben Litchfield
  */
 public class PDType3Font extends PDSimpleFont
 {
-
 	private PDResources type3Resources = null;
-    
     private COSDictionary charProcs = null;
     
     /**
@@ -45,7 +42,7 @@ public class PDType3Font extends PDSimpl
     public PDType3Font()
     {
         super();
-        font.setItem( COSName.SUBTYPE, COSName.TYPE3 );
+        font.setItem(COSName.SUBTYPE, COSName.TYPE3);
     }
 
     /**
@@ -53,9 +50,9 @@ public class PDType3Font extends PDSimpl
      *
      * @param fontDictionary The font dictionary according to the PDF specification.
      */
-    public PDType3Font( COSDictionary fontDictionary )
+    public PDType3Font(COSDictionary fontDictionary)
     {
-        super( fontDictionary );
+        super(fontDictionary);
     }
 
     /**
@@ -63,25 +60,24 @@ public class PDType3Font extends PDSimpl
      *
      * @param matrix The font matrix for this type3 font.
      */
-    public void setFontMatrix( PDMatrix matrix )
+    public void setFontMatrix(PDMatrix matrix)
     {
-        font.setItem( COSName.FONT_MATRIX, matrix );
+        font.setItem(COSName.FONT_MATRIX, matrix);
     }
 
-
     /**
      * Returns the optional resources of the type3 stream.
      * 
      * @return the resources bound to be used when parsing the type3 stream 
      */
-    public PDResources getType3Resources( )
+    public PDResources getType3Resources()
     {
         if (type3Resources == null)
         {
-            COSDictionary resources = (COSDictionary)font.getDictionaryObject( COSName.RESOURCES );
+            COSDictionary resources = (COSDictionary)font.getDictionaryObject(COSName.RESOURCES);
             if (resources != null)
             {
-            	type3Resources = new PDResources( resources );
+            	type3Resources = new PDResources(resources);
             }
         }
         return type3Resources;
@@ -91,16 +87,16 @@ public class PDType3Font extends PDSimpl
      * This will get the fonts bounding box.
      *
      * @return The fonts bounding box.
-     *
      * @throws IOException If there is an error getting the bounding box.
      */
+    @Override
     public PDRectangle getFontBoundingBox() throws IOException
     {
-        COSArray rect = (COSArray)font.getDictionaryObject( COSName.FONT_BBOX );
+        COSArray rect = (COSArray)font.getDictionaryObject(COSName.FONT_BBOX);
         PDRectangle retval = null;
-        if( rect != null )
+        if(rect != null)
         {
-            retval = new PDRectangle( rect );
+            retval = new PDRectangle(rect);
         }
         return retval;
     }
@@ -114,7 +110,7 @@ public class PDType3Font extends PDSimpl
     {
         if (charProcs == null)
         {
-        	charProcs = (COSDictionary)font.getDictionaryObject( COSName.CHAR_PROCS );
+        	charProcs = (COSDictionary)font.getDictionaryObject(COSName.CHAR_PROCS);
         }
         return charProcs;
     }
@@ -132,7 +128,7 @@ public class PDType3Font extends PDSimpl
         String cMapsTo = getFontEncoding().getName(character);
         if (cMapsTo != null)
         {
-        	stream = (COSStream)getCharProcs().getDictionaryObject( COSName.getPDFName( cMapsTo ) );
+        	stream = (COSStream)getCharProcs().getDictionaryObject(COSName.getPDFName(cMapsTo));
         }
         return stream;
     }