You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2014/07/20 11:28:51 UTC

svn commit: r1612067 - /pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeDescript.java

Author: tilman
Date: Sun Jul 20 09:28:51 2014
New Revision: 1612067

URL: http://svn.apache.org/r1612067
Log:
PDFBOX-2229: make getPointCount() return 0 instead of throwing NPE

Modified:
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeDescript.java

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeDescript.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeDescript.java?rev=1612067&r1=1612066&r2=1612067&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeDescript.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeDescript.java Sun Jul 20 09:28:51 2014
@@ -22,16 +22,23 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
- * Glyph description for composite glyphs. Composite glyphs are made up of one or more simple glyphs, usually with some
- * sort of transformation applied to each.
- * 
- * This class is based on code from Apache Batik a subproject of Apache XMLGraphics. see
- * http://xmlgraphics.apache.org/batik/ for further details.
+ * Glyph description for composite glyphs. Composite glyphs are made up of one
+ * or more simple glyphs, usually with some sort of transformation applied to
+ * each.
+ *
+ * This class is based on code from Apache Batik a subproject of Apache
+ * XMLGraphics. see http://xmlgraphics.apache.org/batik/ for further details.
  */
 public class GlyfCompositeDescript extends GlyfDescript
 {
+    /**
+     * Log instance.
+     */
+    private static final Log LOG = LogFactory.getLog(GlyfCompositeDescript.class);
 
     private final List<GlyfCompositeComp> components = new ArrayList<GlyfCompositeComp>();
     private GlyphData[] glyphs = null;
@@ -57,7 +64,8 @@ public class GlyfCompositeDescript exten
         {
             comp = new GlyfCompositeComp(bais);
             components.add(comp);
-        } while ((comp.getFlags() & GlyfCompositeComp.MORE_COMPONENTS) != 0);
+        } 
+        while ((comp.getFlags() & GlyfCompositeComp.MORE_COMPONENTS) != 0);
 
         // Are there hinting instructions to read?
         if ((comp.getFlags() & GlyfCompositeComp.WE_HAVE_INSTRUCTIONS) != 0)
@@ -78,7 +86,7 @@ public class GlyfCompositeDescript exten
         }
         if (beingResolved)
         {
-            System.err.println("Circular reference in GlyfCompositeDesc");
+            LOG.error("Circular reference in GlyfCompositeDesc");
             return;
         }
         beingResolved = true;
@@ -193,10 +201,16 @@ public class GlyfCompositeDescript exten
     {
         if (!resolved)
         {
-            System.err.println("getPointCount called on unresolved GlyfCompositeDescript");
+            LOG.error("getPointCount called on unresolved GlyfCompositeDescript");
         }
         GlyfCompositeComp c = (GlyfCompositeComp) components.get(components.size() - 1);
-        return c.getFirstIndex() + getGlypDescription(c.getGlyphIndex()).getPointCount();
+        GlyphDescription gd = getGlypDescription(c.getGlyphIndex());
+        if (gd == null)
+        {
+            LOG.error("getGlypDescription(" + c.getGlyphIndex() + ") is null, returning 0");
+            return 0;
+        }
+        return c.getFirstIndex() + gd.getPointCount();
     }
 
     /**
@@ -207,7 +221,7 @@ public class GlyfCompositeDescript exten
     {
         if (!resolved)
         {
-            System.err.println("getContourCount called on unresolved GlyfCompositeDescript");
+            LOG.error("getContourCount called on unresolved GlyfCompositeDescript");
         }
         GlyfCompositeComp c = (GlyfCompositeComp) components.get(components.size() - 1);
         return c.getFirstContour() + getGlypDescription(c.getGlyphIndex()).getContourCount();