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/18 23:09:03 UTC

svn commit: r1618738 - in /pdfbox/branches/no-awt: fontbox/src/main/java/org/apache/fontbox/ttf/ pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/ pdfbox/src/main/java/org/apache/pdfbox/rendering/font/ preflight/src/main/java/org/apache/pdfbox/prefl...

Author: jahewson
Date: Mon Aug 18 21:09:03 2014
New Revision: 1618738

URL: http://svn.apache.org/r1618738
Log:
PDFBOX-2262: Fix font loading NPEs

Modified:
    pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/ttf/HorizontalMetricsTable.java
    pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/ttf/TTFSubsetter.java
    pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/ttf/TrueTypeFont.java
    pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/ttf/Type1Equivalent.java
    pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java
    pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java
    pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0.java
    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/PDTrueTypeFont.java
    pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFontEmbedder.java
    pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java
    pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java
    pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Equivalent.java
    pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
    pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java
    pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/font/Glyph2D.java
    pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/font/TTFGlyph2D.java
    pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/CIDType2Container.java
    pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/FontContainer.java
    pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/TrueTypeContainer.java

Modified: pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/ttf/HorizontalMetricsTable.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/ttf/HorizontalMetricsTable.java?rev=1618738&r1=1618737&r2=1618738&view=diff
==============================================================================
--- pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/ttf/HorizontalMetricsTable.java (original)
+++ pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/ttf/HorizontalMetricsTable.java Mon Aug 18 21:09:03 2014
@@ -46,21 +46,27 @@ public class HorizontalMetricsTable exte
         HorizontalHeaderTable hHeader = ttf.getHorizontalHeader();
         int numHMetrics = hHeader.getNumberOfHMetrics();
         int numGlyphs = ttf.getNumberOfGlyphs();
-        
+
+        int bytesRead = 0;
         advanceWidth = new int[ numHMetrics ];
         leftSideBearing = new short[ numHMetrics ];
         for( int i=0; i<numHMetrics; i++ )
         {
             advanceWidth[i] = data.readUnsignedShort();
             leftSideBearing[i] = data.readSignedShort();
+            bytesRead += 4;
         }
-        
-        int numberNonHorizontal = numGlyphs - numHMetrics;
-        nonHorizontalLeftSideBearing = new short[ numberNonHorizontal ];
-        for( int i=0; i<numberNonHorizontal; i++ )
+
+        if (bytesRead < getLength())
         {
-            nonHorizontalLeftSideBearing[i] = data.readSignedShort();
+            int numberNonHorizontal = numGlyphs - numHMetrics;
+            nonHorizontalLeftSideBearing = new short[ numberNonHorizontal ];
+            for( int i=0; i<numberNonHorizontal; i++ )
+            {
+                nonHorizontalLeftSideBearing[i] = data.readSignedShort();
+            }
         }
+
         initialized = true;
     }
     /**

Modified: pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/ttf/TTFSubsetter.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/ttf/TTFSubsetter.java?rev=1618738&r1=1618737&r2=1618738&view=diff
==============================================================================
--- pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/ttf/TTFSubsetter.java (original)
+++ pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/ttf/TTFSubsetter.java Mon Aug 18 21:09:03 2014
@@ -70,7 +70,7 @@ public class TTFSubsetter
      * @param suffix suffix used for the naming
      * 
      */
-    public TTFSubsetter(TrueTypeFont baseFont, String suffix)
+    public TTFSubsetter(TrueTypeFont baseFont, String suffix) throws IOException
     {
         baseTTF = baseFont;
         nameSuffix = suffix;

Modified: pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/ttf/TrueTypeFont.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/ttf/TrueTypeFont.java?rev=1618738&r1=1618737&r2=1618738&view=diff
==============================================================================
--- pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/ttf/TrueTypeFont.java (original)
+++ pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/ttf/TrueTypeFont.java Mon Aug 18 21:09:03 2014
@@ -118,7 +118,7 @@ public class TrueTypeFont implements Typ
      * 
      * @return The naming table.
      */
-    public NamingTable getNaming()
+    public NamingTable getNaming() throws IOException
     {
         NamingTable naming = (NamingTable)tables.get( NamingTable.TAG );
         if (naming != null && !naming.getInitialized())
@@ -133,7 +133,7 @@ public class TrueTypeFont implements Typ
      * 
      * @return The postscript table.
      */
-    public PostScriptTable getPostScript()
+    public PostScriptTable getPostScript() throws IOException
     {
         PostScriptTable postscript = (PostScriptTable)tables.get( PostScriptTable.TAG );
         if (postscript != null && !postscript.getInitialized())
@@ -148,7 +148,7 @@ public class TrueTypeFont implements Typ
      * 
      * @return The OS/2 table.
      */
-    public OS2WindowsMetricsTable getOS2Windows()
+    public OS2WindowsMetricsTable getOS2Windows() throws IOException
     {
         OS2WindowsMetricsTable os2WindowsMetrics = (OS2WindowsMetricsTable)tables.get( OS2WindowsMetricsTable.TAG );
         if (os2WindowsMetrics != null && !os2WindowsMetrics.getInitialized())
@@ -163,7 +163,7 @@ public class TrueTypeFont implements Typ
      * 
      * @return The maxp table.
      */
-    public MaximumProfileTable getMaximumProfile()
+    public MaximumProfileTable getMaximumProfile() throws IOException
     {
         MaximumProfileTable maximumProfile = (MaximumProfileTable)tables.get( MaximumProfileTable.TAG );
         if (maximumProfile != null && !maximumProfile.getInitialized())
@@ -178,7 +178,7 @@ public class TrueTypeFont implements Typ
      * 
      * @return The head table.
      */
-    public HeaderTable getHeader()
+    public HeaderTable getHeader() throws IOException
     {
         HeaderTable header = (HeaderTable)tables.get( HeaderTable.TAG );
         if (header != null && !header.getInitialized())
@@ -193,7 +193,7 @@ public class TrueTypeFont implements Typ
      * 
      * @return The hhea table.
      */
-    public HorizontalHeaderTable getHorizontalHeader()
+    public HorizontalHeaderTable getHorizontalHeader() throws IOException
     {
         HorizontalHeaderTable horizontalHeader = (HorizontalHeaderTable)tables.get( HorizontalHeaderTable.TAG );
         if (horizontalHeader != null && !horizontalHeader.getInitialized())
@@ -208,7 +208,7 @@ public class TrueTypeFont implements Typ
      * 
      * @return The hmtx table.
      */
-    public HorizontalMetricsTable getHorizontalMetrics()
+    public HorizontalMetricsTable getHorizontalMetrics() throws IOException
     {
         HorizontalMetricsTable horizontalMetrics = (HorizontalMetricsTable)tables.get( HorizontalMetricsTable.TAG );
         if (horizontalMetrics != null && !horizontalMetrics.getInitialized())
@@ -223,7 +223,7 @@ public class TrueTypeFont implements Typ
      * 
      * @return The loca table.
      */
-    public IndexToLocationTable getIndexToLocation()
+    public IndexToLocationTable getIndexToLocation() throws IOException
     {
         IndexToLocationTable indexToLocation = (IndexToLocationTable)tables.get( IndexToLocationTable.TAG );
         if (indexToLocation != null && !indexToLocation.getInitialized())
@@ -238,7 +238,7 @@ public class TrueTypeFont implements Typ
      * 
      * @return The glyf table.
      */
-    public GlyphTable getGlyph()
+    public GlyphTable getGlyph() throws IOException
     {
         GlyphTable glyph = (GlyphTable)tables.get( GlyphTable.TAG );
         if (glyph != null && !glyph.getInitialized())
@@ -253,7 +253,7 @@ public class TrueTypeFont implements Typ
      * 
      * @return The cmap table.
      */
-    public CMAPTable getCMAP()
+    public CMAPTable getCMAP() throws IOException
     {
         CMAPTable cmap = (CMAPTable)tables.get( CMAPTable.TAG );
         if (cmap != null && !cmap.getInitialized())
@@ -282,21 +282,14 @@ public class TrueTypeFont implements Typ
      * 
      * @param table the table to be initialized
      */
-    void readTable(TTFTable table)
+    void readTable(TTFTable table) throws IOException
     {
-        try
-        {
-            // save current position
-            long currentPosition = data.getCurrentPosition();
-            data.seek(table.getOffset());
-            table.read(this, data);
-            // restore current position
-            data.seek(currentPosition);
-        }
-        catch (IOException exception)
-        {
-            log.error("An error occured when reading table " + table.getTag(), exception);
-        }
+        // save current position
+        long currentPosition = data.getCurrentPosition();
+        data.seek(table.getOffset());
+        table.read(this, data);
+        // restore current position
+        data.seek(currentPosition);
     }
 
     /**
@@ -304,7 +297,7 @@ public class TrueTypeFont implements Typ
      * 
      * @return the number of glyphs
      */
-    public int getNumberOfGlyphs()
+    public int getNumberOfGlyphs() throws IOException
     {
         if (numberOfGlyphs == -1)
         {
@@ -327,7 +320,7 @@ public class TrueTypeFont implements Typ
      * 
      * @return units per EM
      */
-    public int getUnitsPerEm()
+    public int getUnitsPerEm() throws IOException
     {
         if (unitsPerEm == -1)
         {
@@ -351,7 +344,7 @@ public class TrueTypeFont implements Typ
      * @param code the glyph code
      * @return the width
      */
-    public int getAdvanceWidth(int code)
+    public int getAdvanceWidth(int code) throws IOException
     {
         if (advanceWidths == null)
         {
@@ -379,12 +372,12 @@ public class TrueTypeFont implements Typ
     }
 
     @Override
-    public String getFullName()
+    public String getFullName() throws IOException
     {
         return getNaming().getPostScriptName();
     }
 
-    private void readPostScriptNames()
+    private void readPostScriptNames() throws IOException
     {
         if (postScriptNames == null)
         {
@@ -435,7 +428,7 @@ public class TrueTypeFont implements Typ
     }
 
     @Override
-    public boolean hasGlyph(String name)
+    public boolean hasGlyph(String name) throws IOException
     {
         readPostScriptNames();
 
@@ -455,6 +448,13 @@ public class TrueTypeFont implements Typ
     @Override
     public String toString()
     {
-        return getNaming().getPostScriptName();
+        try
+        {
+            return getNaming().getPostScriptName();
+        }
+        catch (IOException e)
+        {
+            return "(null)";
+        }
     }
 }

Modified: pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/ttf/Type1Equivalent.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/ttf/Type1Equivalent.java?rev=1618738&r1=1618737&r2=1618738&view=diff
==============================================================================
--- pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/ttf/Type1Equivalent.java (original)
+++ pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/ttf/Type1Equivalent.java Mon Aug 18 21:09:03 2014
@@ -16,7 +16,7 @@ public interface Type1Equivalent
     /**
      * The PostScript name of the font.
      */
-    public String getFullName();
+    public String getFullName() throws IOException;
 
     /**
      * Returns the Type 1 CharString for the character with the given name.
@@ -30,7 +30,7 @@ public interface Type1Equivalent
      * Returns true if the font contains the given glyph.
      * @param name PostScript glyph name
      */
-    public boolean hasGlyph(String name);
+    public boolean hasGlyph(String name) throws IOException;
 
     /**
      * Returns the PostScript Encoding vector for the font.

Modified: pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java?rev=1618738&r1=1618737&r2=1618738&view=diff
==============================================================================
--- pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java (original)
+++ pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java Mon Aug 18 21:09:03 2014
@@ -109,36 +109,38 @@ final class FileSystemFontProvider imple
             NamingTable nameTable = ttf.getNaming();
             if (nameTable == null)
             {
-                throw new IOException("Missing 'name' table");
+                LOG.warn("Missing 'name' table in font " + otfFile);
             }
-
-            // read PostScript name, if any
-            if (nameTable.getPostScriptName() != null)
+            else
             {
-                String psName = nameTable.getPostScriptName();
-
-                String format;
-                if (ttf.getTableMap().get("CFF ") != null)
+                // read PostScript name, if any
+                if (nameTable.getPostScriptName() != null)
                 {
-                    format = "OTF";
-                    cffFontFiles.put(psName, otfFile);
+                    String psName = nameTable.getPostScriptName();
+
+                    String format;
+                    if (ttf.getTableMap().get("CFF ") != null)
+                    {
+                        format = "OTF";
+                        cffFontFiles.put(psName, otfFile);
+                    }
+                    else
+                    {
+                        format = "TTF";
+                        ttfFontFiles.put(psName, otfFile);
+                    }
+
+                    if (LOG.isTraceEnabled())
+                    {
+                        LOG.trace(format +": '" + psName + "' / '" + nameTable.getFontFamily() +
+                                "' / '" + nameTable.getFontSubFamily() + "'");
+                    }
                 }
                 else
                 {
-                    format = "TTF";
-                    ttfFontFiles.put(psName, otfFile);
-                }
-
-                if (LOG.isTraceEnabled())
-                {
-                    LOG.trace(format +": '" + psName + "' / '" + nameTable.getFontFamily() +
-                            "' / '" + nameTable.getFontSubFamily() + "'");
+                    LOG.warn("Missing 'name' entry for PostScript name in font " + otfFile);
                 }
             }
-            else
-            {
-                throw new IOException("Missing 'name' entry for PostScript name");
-            }
         }
         finally
         {

Modified: pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java?rev=1618738&r1=1618737&r2=1618738&view=diff
==============================================================================
--- pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java (original)
+++ pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java Mon Aug 18 21:09:03 2014
@@ -69,18 +69,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
-    public PDRectangle getFontBoundingBox() throws IOException
-    {
-        throw new RuntimeException("getFontBoundingBox(): Not yet implemented");
-    }
-
-    /**
      * This will get the default width.  The default value for the default width is 1000.
      *
      * @return The default width for the glyphs in this font.

Modified: pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0.java?rev=1618738&r1=1618737&r2=1618738&view=diff
==============================================================================
--- pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0.java (original)
+++ pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0.java Mon Aug 18 21:09:03 2014
@@ -50,7 +50,6 @@ public class PDCIDFontType0 extends PDCI
     private final Map<Integer, Float> glyphWidths = new HashMap<Integer, Float>();
     private final Map<Integer, Float> glyphHeights = new HashMap<Integer, Float>();
     private Float avgWidth = null;
-    private PDRectangle fontBBox = null;
 
     /**
      * Constructor.
@@ -219,16 +218,6 @@ public class PDCIDFontType0 extends PDCI
     }
 
     @Override
-    public PDRectangle getFontBoundingBox() throws IOException
-    {
-        if (fontBBox == null)
-        {
-            fontBBox = new PDRectangle(cffFont.getFontBBox());
-        }
-        return fontBBox;
-    }
-
-    @Override
     public PDMatrix getFontMatrix()
     {
         if (fontMatrix == null)

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=1618738&r1=1618737&r2=1618738&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 18 21:09:03 2014
@@ -38,6 +38,8 @@ import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.encoding.DictionaryEncoding;
 import org.apache.pdfbox.encoding.Encoding;
+import org.apache.pdfbox.encoding.MacRomanEncoding;
+import org.apache.pdfbox.encoding.WinAnsiEncoding;
 import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.pdmodel.common.COSArrayList;
 import org.apache.pdfbox.pdmodel.common.COSObjectable;
@@ -293,7 +295,7 @@ public abstract class PDFont implements 
      * @param length The length of the data.
      * @return The width is in 1000 unit of text space, ie 333 or 777
      */
-    public float getFontWidth(byte[] c, int offset, int length)
+    public float getFontWidth(byte[] c, int offset, int length) throws IOException
     {
         int code = getCodeFromArray(c, offset, length);
         Float fontWidth = fontSizes.get(code);
@@ -615,7 +617,22 @@ public abstract class PDFont implements 
      */
     public boolean isSymbolicFont()
     {
-        return getFontDescriptor().isSymbolic();
+        if (getFontDescriptor() != null)
+        {
+            // fixme: isSymbolic() defaults to false if the flag is missing, which isn't useful!
+            // todo: what about isNonSymbolic()?
+            if (getFontDescriptor().isSymbolic()) // we can trust "true", but not "false"
+            {
+                return true;
+            }
+        }
+
+        // fixme: this heuristic is a starting point only
+        if (fontEncoding instanceof MacRomanEncoding || fontEncoding instanceof WinAnsiEncoding)
+        {
+            return false;
+        }
+        return true;
     }
 
     /**
@@ -700,23 +717,12 @@ 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 PDRectangle getFontBoundingBox() throws IOException
-    {
-        return getFontDescriptor().getFontBoundingBox();
-    }
-
-    /**
      * Determines the width of the given character.
      * 
      * @param charCode the code of the given character
      * @return the width of the character
      */
-    public float getFontWidth(int charCode)
+    public float getFontWidth(int charCode) throws IOException
     {
         float width = -1;
         int firstChar = getFirstChar();

Modified: pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java?rev=1618738&r1=1618737&r2=1618738&view=diff
==============================================================================
--- pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java (original)
+++ pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java Mon Aug 18 21:09:03 2014
@@ -129,7 +129,7 @@ public class PDTrueTypeFont extends PDFo
     }
 
     @Override
-    public float getFontWidth(int charCode)
+    public float getFontWidth(int charCode) throws IOException
     {
         float width = super.getFontWidth(charCode);
         if (width <= 0)
@@ -160,7 +160,7 @@ public class PDTrueTypeFont extends PDFo
      * @param code character code
      * @return GID (glyph index)
      */
-    public int getGIDForCharacterCode(int code)
+    public int getGIDForCharacterCode(int code) throws IOException
     {
         extractCmapTable();
         int result = 0;
@@ -254,7 +254,7 @@ public class PDTrueTypeFont extends PDFo
     /**
      * extract all useful "cmap" subtables.
      */
-    private void extractCmapTable()
+    private void extractCmapTable() throws IOException
     {
         if (cmapInitialized)
         {

Modified: pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFontEmbedder.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFontEmbedder.java?rev=1618738&r1=1618737&r2=1618738&view=diff
==============================================================================
--- pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFontEmbedder.java (original)
+++ pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFontEmbedder.java Mon Aug 18 21:09:03 2014
@@ -97,6 +97,7 @@ class PDTrueTypeFontEmbedder
 
     // creates a new font descriptor dictionary for the given TTF
     private PDFontDescriptorDictionary createFontDescriptor(COSDictionary dict, TrueTypeFont ttf)
+            throws IOException
     {
         PDFontDescriptorDictionary fd = new PDFontDescriptorDictionary();
 

Modified: pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java?rev=1618738&r1=1618737&r2=1618738&view=diff
==============================================================================
--- pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java (original)
+++ pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java Mon Aug 18 21:09:03 2014
@@ -78,12 +78,6 @@ public class PDType0Font extends PDFont
     }
 
     @Override
-    public PDRectangle getFontBoundingBox() throws IOException
-    {
-        throw new RuntimeException("Not yet implemented");
-    }
-
-    @Override
     public float getFontWidth(byte[] c, int offset, int length)
     {
         return descendantFont.getFontWidth(c, offset, length);

Modified: pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java?rev=1618738&r1=1618737&r2=1618738&view=diff
==============================================================================
--- pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java (original)
+++ pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1CFont.java Mon Aug 18 21:09:03 2014
@@ -131,7 +131,7 @@ public class PDType1CFont extends PDFont
     }
 
     @Override
-    public boolean hasGlyph(String name)
+    public boolean hasGlyph(String name) throws IOException
     {
         return type1Equivalent.hasGlyph(name);
     }
@@ -174,7 +174,8 @@ public class PDType1CFont extends PDFont
         String character = getUnicode(bytes, offset, length);
         if (character == null)
         {
-            LOG.error("No character for code " + (bytes[offset] & 0xff) + " in " + fontName);
+            // todo: message is for debugging, remove in long term
+            LOG.warn("No character for code " + (bytes[offset] & 0xff) + " in " + fontName);
             return null;
         }
         return character;
@@ -202,7 +203,8 @@ public class PDType1CFont extends PDFont
         String character = getFontEncoding().getCharacter(code);
         if (character == null)
         {
-            LOG.error("Could not get character " + code);
+            // todo: message is for debugging, remove in long term
+            LOG.warn("Could not get character " + code);
         }
         return character;
     }
@@ -215,7 +217,8 @@ public class PDType1CFont extends PDFont
 
         if (isNotDef(name) && !Arrays.equals(SPACE_BYTES, bytes))
         {
-            LOG.error("No name for code " + (bytes[offset] & 0xff) + " in " + fontName);
+            // todo: message is for debugging, remove in long term
+            LOG.warn("No name for code " + (bytes[offset] & 0xff) + " in " + fontName);
             return 0;
         }
 
@@ -237,7 +240,8 @@ public class PDType1CFont extends PDFont
 
         if (isNotDef(name))
         {
-            LOG.error("No name for code " + (bytes[offset] & 0xff) + " in " + fontName);
+            // todo: message is for debugging, remove in long term
+            LOG.warn("No name for code " + (bytes[offset] & 0xff) + " in " + fontName);
             return 0;
         }
 
@@ -260,7 +264,8 @@ public class PDType1CFont extends PDFont
             String name = getFontEncoding().getNameForCharacter(character.charAt(0));
             if (isNotDef(name))
             {
-                LOG.error("No code for character " + character);
+                // todo: message is for debugging, remove in long term
+                LOG.warn("No code for character " + character);
                 return 0;
             }
             width += getCharacterWidth(name);
@@ -279,16 +284,6 @@ public class PDType1CFont extends PDFont
     }
 
     @Override
-    public PDRectangle getFontBoundingBox() throws IOException
-    {
-        if (fontBBox == null)
-        {
-            fontBBox = new PDRectangle(cffFont.getFontBBox()); // todo: cffFont could be null
-        }
-        return fontBBox;
-    }
-
-    @Override
     public PDMatrix getFontMatrix()
     {
         if (fontMatrix == null)
@@ -332,6 +327,7 @@ public class PDType1CFont extends PDFont
             Type1CharString charstring = cffFont.getType1CharString(name);
             if (charstring == notdef)
             {
+                // todo: message is for debugging, remove in long term
                 LOG.warn("No width for character " + name + ", using .notdef");
             }
             return charstring.getWidth();

Modified: pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Equivalent.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Equivalent.java?rev=1618738&r1=1618737&r2=1618738&view=diff
==============================================================================
--- pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Equivalent.java (original)
+++ pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Equivalent.java Mon Aug 18 21:09:03 2014
@@ -19,7 +19,7 @@ public interface PDType1Equivalent
     /**
      * Returns true if the font contains a glyph with the given name.
      */
-    public boolean hasGlyph(String name);
+    public boolean hasGlyph(String name) throws IOException;
 
     /**
      * Returns the glyph name for the given character code.

Modified: pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java?rev=1618738&r1=1618737&r2=1618738&view=diff
==============================================================================
--- pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java (original)
+++ pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java Mon Aug 18 21:09:03 2014
@@ -41,6 +41,7 @@ import org.apache.pdfbox.encoding.Type1E
 import org.apache.pdfbox.encoding.WinAnsiEncoding;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.common.PDMatrix;
+import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.common.PDStream;
 import org.apache.pdfbox.util.ResourceLoader;
 
@@ -348,7 +349,7 @@ public class PDType1Font extends PDFont 
     }
 
     @Override
-    public float getFontWidth(int charCode)
+    public float getFontWidth(int charCode) throws IOException
     {
         float width = super.getFontWidth(charCode);
         if (width <= 0)
@@ -422,7 +423,7 @@ public class PDType1Font extends PDFont 
     }
 
     @Override
-    public boolean hasGlyph(String name)
+    public boolean hasGlyph(String name) throws IOException
     {
         return type1Equivalent.hasGlyph(name);
     }

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=1618738&r1=1618737&r2=1618738&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 Mon Aug 18 21:09:03 2014
@@ -70,8 +70,7 @@ public class PDType3Font extends PDFont
      * @return The fonts bounding box.
      * @throws IOException If there is an error getting the bounding box.
      */
-    @Override
-    public PDRectangle getFontBoundingBox() throws IOException
+    public PDRectangle getBoundingBox() throws IOException
     {
         COSArray rect = (COSArray) dict.getDictionaryObject(COSName.FONT_BBOX);
         PDRectangle retval = null;

Modified: pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/font/Glyph2D.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/font/Glyph2D.java?rev=1618738&r1=1618737&r2=1618738&view=diff
==============================================================================
--- pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/font/Glyph2D.java (original)
+++ pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/font/Glyph2D.java Mon Aug 18 21:09:03 2014
@@ -20,6 +20,7 @@
 package org.apache.pdfbox.rendering.font;
 
 import java.awt.geom.GeneralPath;
+import java.io.IOException;
 
 /**
  * This interface is implemented by several font specific classes which is called to get the
@@ -34,7 +35,7 @@ public interface Glyph2D
      * 
      * @return the GeneralPath for the given character code
      */
-    public GeneralPath getPathForCharacterCode(int code);
+    public GeneralPath getPathForCharacterCode(int code) throws IOException;
 
     /**
      * Remove all cached resources.

Modified: pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/font/TTFGlyph2D.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/font/TTFGlyph2D.java?rev=1618738&r1=1618737&r2=1618738&view=diff
==============================================================================
--- pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/font/TTFGlyph2D.java (original)
+++ pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/font/TTFGlyph2D.java Mon Aug 18 21:09:03 2014
@@ -145,7 +145,7 @@ public class TTFGlyph2D implements Glyph
     }
 
     @Override
-    public GeneralPath getPathForCharacterCode(int code)
+    public GeneralPath getPathForCharacterCode(int code) throws IOException
     {
         int glyphId = getGIDForCharacterCode(code);
 
@@ -167,7 +167,7 @@ public class TTFGlyph2D implements Glyph
     }
 
     // Try to map the given code to the corresponding glyph-ID
-    private int getGIDForCharacterCode(int code)
+    private int getGIDForCharacterCode(int code) throws IOException
     {
         if (isCIDFont)
         {
@@ -186,17 +186,40 @@ public class TTFGlyph2D implements Glyph
      *
      * @return the GeneralPath for the given glyphId
      */
-    public GeneralPath getPathForGlyphId(int glyphId)
+    public GeneralPath getPathForGlyphId(int glyphId) throws IOException
     {
-        GeneralPath glyphPath = null;
+        GeneralPath glyphPath;
         if (glyphs.containsKey(glyphId))
         {
             glyphPath = glyphs.get(glyphId);
         }
         else
         {
-            GlyphData[] glyphData = ttf.getGlyph().getGlyphs();
-            if (glyphId < glyphData.length && glyphData[glyphId] != null)
+            // fixme: TrueTypeFont is buggy so we have to catch RuntimeException for debugging
+            GlyphData[] glyphData;
+            try
+            {
+                glyphData = ttf.getGlyph().getGlyphs();
+            }
+            catch (RuntimeException e)
+            {
+                throw new RuntimeException("Error in TTF:" + pdFont.getBaseFont() + " -> " +
+                        ttf.getNaming().getPostScriptName(), e);
+            }
+
+            if (glyphId >= glyphData.length)
+            {
+                LOG.warn(name + ": Glyph not found: " + glyphId);
+                glyphPath = new GeneralPath();
+                glyphs.put(glyphId, glyphPath);
+            }
+            else if (glyphData[glyphId] == null)
+            {
+                // empty glyph (e.g. space, newline)
+                glyphPath = new GeneralPath();
+                glyphs.put(glyphId, glyphPath);
+            }
+            else
             {
                 GlyphData glyph = glyphData[glyphId];
                 glyphPath = glyph.getPath();
@@ -207,12 +230,8 @@ public class TTFGlyph2D implements Glyph
                 }
                 glyphs.put(glyphId, glyphPath);
             }
-            else
-            {
-                LOG.error(name + ": Glyph not found:" + glyphId);
-            }
         }
-        return glyphPath != null ? (GeneralPath) glyphPath.clone() : null;
+        return glyphPath != null ? (GeneralPath) glyphPath.clone() : null; // todo: expensive
     }
 
     @Override

Modified: pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/CIDType2Container.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/CIDType2Container.java?rev=1618738&r1=1618737&r2=1618738&view=diff
==============================================================================
--- pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/CIDType2Container.java (original)
+++ pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/CIDType2Container.java Mon Aug 18 21:09:03 2014
@@ -23,7 +23,11 @@ package org.apache.pdfbox.preflight.font
 
 import org.apache.fontbox.ttf.TrueTypeFont;
 import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.font.util.CIDToGIDMap;
+import org.apache.pdfbox.preflight.font.util.GlyphException;
+
+import java.io.IOException;
 
 public class CIDType2Container extends FontContainer
 {
@@ -38,30 +42,37 @@ public class CIDType2Container extends F
     }
 
     @Override
-    protected float getFontProgramWidth(int cid)
+    protected float getFontProgramWidth(int cid) throws GlyphException
     {
         float foundWidth = -1;
         final int glyphIndex = getGlyphIndex(cid);
 
-        // if glyph exists we can check the width
-        if (this.ttf != null && this.ttf.getGlyph().getGlyphs().length > glyphIndex)
+        try
         {
+            // if glyph exists we can check the width
+            if (this.ttf != null && this.ttf.getGlyph().getGlyphs().length > glyphIndex)
+            {
             /*
              * In a Mono space font program, the length of the AdvanceWidth array must be one. According to the TrueType
              * font specification, the Last Value of the AdvanceWidth array is apply to the subsequent glyphs. So if the
              * GlyphId is greater than the length of the array the last entry is used.
              */
-            int numberOfLongHorMetrics = ttf.getHorizontalHeader().getNumberOfHMetrics();
-            int unitsPerEm = ttf.getHeader().getUnitsPerEm();
-            int[] advanceGlyphWidths = ttf.getHorizontalMetrics().getAdvanceWidth();
-            float glypdWidth = advanceGlyphWidths[numberOfLongHorMetrics - 1];
-            if (glyphIndex < numberOfLongHorMetrics)
-            {
-                glypdWidth = advanceGlyphWidths[glyphIndex];
+                int numberOfLongHorMetrics = ttf.getHorizontalHeader().getNumberOfHMetrics();
+                int unitsPerEm = ttf.getHeader().getUnitsPerEm();
+                int[] advanceGlyphWidths = ttf.getHorizontalMetrics().getAdvanceWidth();
+                float glypdWidth = advanceGlyphWidths[numberOfLongHorMetrics - 1];
+                if (glyphIndex < numberOfLongHorMetrics)
+                {
+                    glypdWidth = advanceGlyphWidths[glyphIndex];
+                }
+                foundWidth = ((glypdWidth * 1000) / unitsPerEm);
             }
-            foundWidth = ((glypdWidth * 1000) / unitsPerEm);
+            return foundWidth;
+        }
+        catch (IOException e)
+        {
+            throw new GlyphException(PreflightConstants.ERROR_FONTS_GLYPH, cid, "Unexpected error during the width validtion for the character CID(" + cid+") : " + e.getMessage());
         }
-        return foundWidth;
     }
 
     /**

Modified: pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/FontContainer.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/FontContainer.java?rev=1618738&r1=1618737&r2=1618738&view=diff
==============================================================================
--- pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/FontContainer.java (original)
+++ pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/FontContainer.java Mon Aug 18 21:09:03 2014
@@ -21,6 +21,7 @@
 
 package org.apache.pdfbox.preflight.font.container;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -110,10 +111,16 @@ public abstract class FontContainer
         {
             return;
         }
-
-        final float expectedWidth = this.font.getFontWidth(cid);
-        final float foundWidth = getFontProgramWidth(cid);
-        checkWidthsConsistency(cid, expectedWidth, foundWidth);
+        try
+        {
+            final float expectedWidth = this.font.getFontWidth(cid);
+            final float foundWidth = getFontProgramWidth(cid);
+            checkWidthsConsistency(cid, expectedWidth, foundWidth);
+        }
+        catch (IOException e)
+        {
+            throw new GlyphException(PreflightConstants.ERROR_FONTS_GLYPH, cid, "Unexpected error during the width validtion for the character CID(" + cid+") : " + e.getMessage());
+        }
     }
 
     /**

Modified: pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/TrueTypeContainer.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/TrueTypeContainer.java?rev=1618738&r1=1618737&r2=1618738&view=diff
==============================================================================
--- pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/TrueTypeContainer.java (original)
+++ pdfbox/branches/no-awt/preflight/src/main/java/org/apache/pdfbox/preflight/font/container/TrueTypeContainer.java Mon Aug 18 21:09:03 2014
@@ -30,6 +30,8 @@ import org.apache.fontbox.ttf.CMAPTable;
 import org.apache.fontbox.ttf.TrueTypeFont;
 import org.apache.pdfbox.encoding.Encoding;
 import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.preflight.PreflightConstants;
+import org.apache.pdfbox.preflight.font.util.GlyphException;
 
 public class TrueTypeContainer extends FontContainer
 {
@@ -65,14 +67,21 @@ public class TrueTypeContainer extends F
         if (this.cmapEncodingEntries != null)
             return;
 
-        CMAPTable cmap = this.ttFont.getCMAP();
-        if (this.font.getFontDescriptor().isSymbolic())
+        try
         {
-            this.cmapEncodingEntries = cmap.getCmaps();
+            CMAPTable cmap = this.ttFont.getCMAP();
+            if (this.font.getFontDescriptor().isSymbolic())
+            {
+                this.cmapEncodingEntries = cmap.getCmaps();
+            }
+            else
+            {
+                this.cmapEncodingEntries = orderCMapEntries(cmap);
+            }
         }
-        else
+        catch (IOException e)
         {
-            this.cmapEncodingEntries = orderCMapEntries(cmap);
+            return;
         }
     }
 
@@ -111,22 +120,29 @@ public class TrueTypeContainer extends F
     }
 
     @Override
-    protected float getFontProgramWidth(int cid)
+    protected float getFontProgramWidth(int cid) throws GlyphException
     {
-        float result = -1f;
-        if (cmapEncodingEntries != null)
+        try
         {
-            for (CMAPEncodingEntry entry : cmapEncodingEntries)
+            float result = -1f;
+            if (cmapEncodingEntries != null)
             {
-                int glyphID = extractGlyphID(cid, entry);
-                if (glyphID > 0)
+                for (CMAPEncodingEntry entry : cmapEncodingEntries)
                 {
-                    result = extractGlyphWidth(glyphID);
-                    break;
+                    int glyphID = extractGlyphID(cid, entry);
+                    if (glyphID > 0)
+                    {
+                        result = extractGlyphWidth(glyphID);
+                        break;
+                    }
                 }
             }
+            return result;
+        }
+        catch (IOException e)
+        {
+            throw new GlyphException(PreflightConstants.ERROR_FONTS_GLYPH, cid, "Unexpected error during the width validtion for the character CID(" + cid+") : " + e.getMessage());
         }
-        return result;
     }
 
     /**
@@ -182,7 +198,7 @@ public class TrueTypeContainer extends F
         return cmap.getGlyphId(innerFontCid);
     }
 
-    private float extractGlyphWidth(int glyphID)
+    private float extractGlyphWidth(int glyphID) throws IOException
     {
         int unitsPerEm = this.ttFont.getHeader().getUnitsPerEm();
         int[] glyphWidths = this.ttFont.getHorizontalMetrics().getAdvanceWidth();