You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2013/10/26 11:26:33 UTC

svn commit: r1535953 - in /pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf: GlyfCompositeComp.java GlyfCompositeDescript.java GlyfSimpleDescript.java OS2WindowsMetricsTable.java PostScriptTable.java TTFDataStream.java

Author: lehmi
Date: Sat Oct 26 09:26:32 2013
New Revision: 1535953

URL: http://svn.apache.org/r1535953
Log:
PDFBOX-1749: detect premature end of file to avoid OOM-exception

Modified:
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeComp.java
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeDescript.java
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfSimpleDescript.java
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/OS2WindowsMetricsTable.java
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/PostScriptTable.java
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFDataStream.java

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeComp.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeComp.java?rev=1535953&r1=1535952&r2=1535953&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeComp.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeComp.java Sat Oct 26 09:26:32 2013
@@ -21,14 +21,14 @@ package org.apache.fontbox.ttf;
 import java.io.IOException;
 
 /**
- * This class is based on code from Apache Batik a subproject of Apache XMLGraphics.
- * see http://xmlgraphics.apache.org/batik/ for further details.
+ * 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 GlyfCompositeComp 
+public class GlyfCompositeComp
 {
 
     // Flags for composite glyphs.
-    
+
     /**
      * If set, the arguments are words; otherwise, they are bytes.
      */
@@ -62,8 +62,7 @@ public class GlyfCompositeComp 
      */
     protected static final short WE_HAVE_INSTRUCTIONS = 0x0100;
     /**
-     * If set, this forces the aw and lsb (and rsb) for the composite to be equal to
-     * those from this original glyph.
+     * If set, this forces the aw and lsb (and rsb) for the composite to be equal to those from this original glyph.
      */
     protected static final short USE_MY_METRICS = 0x0200;
 
@@ -72,7 +71,7 @@ public class GlyfCompositeComp 
     private short argument1;
     private short argument2;
     private short flags;
-    private int    glyphIndex;
+    private int glyphIndex;
     private double xscale = 1.0;
     private double yscale = 1.0;
     private double scale01 = 0.0;
@@ -88,49 +87,50 @@ public class GlyfCompositeComp 
      * @param bais the stream to be read
      * @throws IOException is thrown if something went wrong
      */
-    protected GlyfCompositeComp(TTFDataStream bais) throws IOException 
+    protected GlyfCompositeComp(TTFDataStream bais) throws IOException
     {
         flags = bais.readSignedShort();
         glyphIndex = bais.readUnsignedShort();// number of glyph in a font is uint16
 
         // Get the arguments as just their raw values
-        if ((flags & ARG_1_AND_2_ARE_WORDS) != 0) 
+        if ((flags & ARG_1_AND_2_ARE_WORDS) != 0)
         {
             argument1 = bais.readSignedShort();
             argument2 = bais.readSignedShort();
-        } 
-        else 
+        }
+        else
         {
-            argument1 = (short) bais.read();
-            argument2 = (short) bais.read();
+            argument1 = (short) bais.readUnsignedByte();
+            argument2 = (short) bais.readUnsignedByte();
         }
 
         // Assign the arguments according to the flags
-        if ((flags & ARGS_ARE_XY_VALUES) != 0) 
+        if ((flags & ARGS_ARE_XY_VALUES) != 0)
         {
             xtranslate = argument1;
             ytranslate = argument2;
-        } 
-        else 
+        }
+        else
         {
+            // TODO unused?
             point1 = argument1;
             point2 = argument2;
         }
 
         // Get the scale values (if any)
-        if ((flags & WE_HAVE_A_SCALE) != 0) 
+        if ((flags & WE_HAVE_A_SCALE) != 0)
         {
             int i = bais.readSignedShort();
             xscale = yscale = (double) i / (double) 0x4000;
-        } 
-        else if ((flags & WE_HAVE_AN_X_AND_Y_SCALE) != 0) 
+        }
+        else if ((flags & WE_HAVE_AN_X_AND_Y_SCALE) != 0)
         {
             short i = bais.readSignedShort();
             xscale = (double) i / (double) 0x4000;
             i = bais.readSignedShort();
             yscale = (double) i / (double) 0x4000;
-        } 
-        else if ((flags & WE_HAVE_A_TWO_BY_TWO) != 0) 
+        }
+        else if ((flags & WE_HAVE_A_TWO_BY_TWO) != 0)
         {
             int i = bais.readSignedShort();
             xscale = (double) i / (double) 0x4000;
@@ -145,149 +145,165 @@ public class GlyfCompositeComp 
 
     /**
      * Sets the first index.
+     * 
      * @param idx the first index
      */
-    public void setFirstIndex(int idx) 
+    public void setFirstIndex(int idx)
     {
         firstIndex = idx;
     }
 
     /**
      * Returns the first index.
+     * 
      * @return the first index.
      */
-    public int getFirstIndex() 
+    public int getFirstIndex()
     {
         return firstIndex;
     }
 
     /**
      * Sets the index for the first contour.
+     * 
      * @param idx the index of the first contour
      */
-    public void setFirstContour(int idx) 
+    public void setFirstContour(int idx)
     {
         firstContour = idx;
     }
 
     /**
      * Returns the index of the first contour.
+     * 
      * @return the index of the first contour.
      */
-    public int getFirstContour() 
+    public int getFirstContour()
     {
         return firstContour;
     }
 
     /**
      * Returns argument 1.
+     * 
      * @return argument 1.
      */
-    public short getArgument1() 
+    public short getArgument1()
     {
         return argument1;
     }
 
     /**
      * Returns argument 2.
+     * 
      * @return argument 2.
      */
-    public short getArgument2() 
+    public short getArgument2()
     {
         return argument2;
     }
 
     /**
      * Returns the flags of the glyph.
+     * 
      * @return the flags.
      */
-    public short getFlags() 
+    public short getFlags()
     {
         return flags;
     }
 
     /**
      * Returns the index of the first contour.
+     * 
      * @return index of the first contour.
      */
-    public int getGlyphIndex() 
+    public int getGlyphIndex()
     {
         return glyphIndex;
     }
 
     /**
      * Returns the scale-01 value.
+     * 
      * @return the scale-01 value.
      */
-    public double getScale01() 
+    public double getScale01()
     {
         return scale01;
     }
 
     /**
      * Returns the scale-10 value.
+     * 
      * @return the scale-10 value.
      */
-    public double getScale10() 
+    public double getScale10()
     {
         return scale10;
     }
 
     /**
      * Returns the x-scaling value.
+     * 
      * @return the x-scaling value.
      */
-    public double getXScale() 
+    public double getXScale()
     {
         return xscale;
     }
 
     /**
      * Returns the y-scaling value.
+     * 
      * @return the y-scaling value.
      */
-    public double getYScale() 
+    public double getYScale()
     {
         return yscale;
     }
 
     /**
      * Returns the x-translation value.
+     * 
      * @return the x-translation value.
      */
-    public int getXTranslate() 
+    public int getXTranslate()
     {
         return xtranslate;
     }
 
     /**
      * Returns the y-translation value.
+     * 
      * @return the y-translation value.
      */
-    public int getYTranslate() 
+    public int getYTranslate()
     {
         return ytranslate;
     }
 
     /**
      * Transforms an x-coordinate of a point for this component.
+     * 
      * @param x The x-coordinate of the point to transform
      * @param y The y-coordinate of the point to transform
      * @return The transformed x-coordinate
      */
-    public int scaleX(int x, int y) 
+    public int scaleX(int x, int y)
     {
-        return Math.round((float)(x * xscale + y * scale10));
+        return Math.round((float) (x * xscale + y * scale10));
     }
 
     /**
      * Transforms a y-coordinate of a point for this component.
+     * 
      * @param x The x-coordinate of the point to transform
      * @param y The y-coordinate of the point to transform
      * @return The transformed y-coordinate
      */
-    public int scaleY(int x, int y) 
+    public int scaleY(int x, int y)
     {
-        return Math.round((float)(x * scale01 + y * yscale));
+        return Math.round((float) (x * scale01 + y * yscale));
     }
 }

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=1535953&r1=1535952&r2=1535953&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 Sat Oct 26 09:26:32 2013
@@ -23,236 +23,236 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
-
 /**
- * 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 
+public class GlyfCompositeDescript extends GlyfDescript
 {
 
-	private List<GlyfCompositeComp> components = new ArrayList<GlyfCompositeComp>();
-	private GlyphData[] glyphs = null;
-	private boolean beingResolved = false;
-	private boolean resolved = false;
-
-	/**
-	 * Constructor.
-	 * 
-	 * @param bais the stream to be read
-	 * @param glyphTable the Glyphtable containing all glyphs
-	 * @throws IOException is thrown if something went wrong
-	 */
-	public GlyfCompositeDescript(TTFDataStream bais, GlyphTable glyphTable) throws IOException 
-	{
-		super((short) -1, bais);
-
-		glyphs = glyphTable.getGlyphs();
-
-		// Get all of the composite components
-		GlyfCompositeComp comp;
-		do 
-		{
-			comp = new GlyfCompositeComp(bais);
-			components.add(comp);
-		} 
-		while ((comp.getFlags() & GlyfCompositeComp.MORE_COMPONENTS) != 0);
-
-		// Are there hinting instructions to read?
-		if ((comp.getFlags() & GlyfCompositeComp.WE_HAVE_INSTRUCTIONS) != 0) 
-		{
-			readInstructions(bais, (bais.read()<<8 | bais.read()));
-		}
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public void resolve() 
-	{
-		if (resolved) 
-		{
-			return;
-		}
-		if (beingResolved) 
-		{
-			System.err.println("Circular reference in GlyfCompositeDesc");
-			return;
-		}
-		beingResolved = true;
-
-		int firstIndex = 0;
-		int firstContour = 0;
-
-		Iterator<GlyfCompositeComp> i = components.iterator();
-		while (i.hasNext()) 
-		{
-			GlyfCompositeComp comp = (GlyfCompositeComp)i.next();
-			comp.setFirstIndex(firstIndex);
-			comp.setFirstContour(firstContour);
-
-			GlyphDescription desc;
-			desc = getGlypDescription(comp.getGlyphIndex());
-			if (desc != null) 
-			{
-				desc.resolve();
-				firstIndex   += desc.getPointCount();
-				firstContour += desc.getContourCount();
-			}
-		}
-		resolved = true;
-		beingResolved = false;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public int getEndPtOfContours(int i) 
-	{
-		GlyfCompositeComp c = getCompositeCompEndPt(i);
-		if (c != null) 
-		{
-			GlyphDescription gd = getGlypDescription(c.getGlyphIndex());
-			return gd.getEndPtOfContours(i - c.getFirstContour()) + c.getFirstIndex();
-		}
-		return 0;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public byte getFlags(int i) 
-	{
-		GlyfCompositeComp c = getCompositeComp(i);
-		if (c != null) 
-		{
-			GlyphDescription gd = getGlypDescription(c.getGlyphIndex());
-			return gd.getFlags(i - c.getFirstIndex());
-		}
-		return 0;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public short getXCoordinate(int i) 
-	{
-		GlyfCompositeComp c = getCompositeComp(i);
-		if (c != null) 
-		{
-			GlyphDescription gd = getGlypDescription(c.getGlyphIndex());
-			int n = i - c.getFirstIndex();
-			int x = gd.getXCoordinate(n);
-			int y = gd.getYCoordinate(n);
-			short x1 = (short) c.scaleX(x, y);
-			x1 += c.getXTranslate();
-			return x1;
-		}
-		return 0;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public short getYCoordinate(int i) 
-	{
-		GlyfCompositeComp c = getCompositeComp(i);
-		if (c != null) 
-		{
-			GlyphDescription gd = getGlypDescription(c.getGlyphIndex());
-			int n = i - c.getFirstIndex();
-			int x = gd.getXCoordinate(n);
-			int y = gd.getYCoordinate(n);
-			short y1 = (short) c.scaleY(x, y);
-			y1 += c.getYTranslate();
-			return y1;
-		}
-		return 0;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public boolean isComposite() 
-	{
-		return true;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public int getPointCount() 
-	{
-		if (!resolved)
-		{
-			System.err.println("getPointCount called on unresolved GlyfCompositeDescript");
-		}
-		GlyfCompositeComp c = (GlyfCompositeComp) components.get(components.size()-1);
-		return c.getFirstIndex() + getGlypDescription(c.getGlyphIndex()).getPointCount();
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public int getContourCount() 
-	{
-		if (!resolved)
-		{
-			System.err.println("getContourCount called on unresolved GlyfCompositeDescript");
-		}
-		GlyfCompositeComp c = (GlyfCompositeComp) components.get(components.size()-1);
-		return c.getFirstContour() + getGlypDescription(c.getGlyphIndex()).getContourCount();
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public int getComponentCount() 
-	{
-		return components.size();
-	}
-
-	private GlyfCompositeComp getCompositeComp(int i) 
-	{
-		GlyfCompositeComp c;
-		for (int n = 0; n < components.size(); n++) 
-		{
-			c = (GlyfCompositeComp) components.get(n);
-			GlyphDescription gd = getGlypDescription(c.getGlyphIndex());
-			if (c.getFirstIndex() <= i && i < (c.getFirstIndex() + gd.getPointCount())) 
-			{
-				return c;
-			}
-		}
-		return null;
-	}
-
-	private GlyfCompositeComp getCompositeCompEndPt(int i) 
-	{
-		GlyfCompositeComp c;
-		for (int j = 0; j < components.size(); j++) 
-		{
-			c = (GlyfCompositeComp) components.get(j);
-			GlyphDescription gd = getGlypDescription(c.getGlyphIndex());
-			if (c.getFirstContour() <= i && i < (c.getFirstContour() + gd.getContourCount())) 
-			{
-				return c;
-			}
-		}
-		return null;
-	}
-
-	private GlyphDescription getGlypDescription(int index)
-	{
-		if (glyphs != null && index < glyphs.length) 
-		{
-			GlyphData glyph = glyphs[index];
-			if (glyph != null)
-				return glyph.getDescription();
-		}
-		return null;
-	}
+    private List<GlyfCompositeComp> components = new ArrayList<GlyfCompositeComp>();
+    private GlyphData[] glyphs = null;
+    private boolean beingResolved = false;
+    private boolean resolved = false;
+
+    /**
+     * Constructor.
+     * 
+     * @param bais the stream to be read
+     * @param glyphTable the Glyphtable containing all glyphs
+     * @throws IOException is thrown if something went wrong
+     */
+    public GlyfCompositeDescript(TTFDataStream bais, GlyphTable glyphTable) throws IOException
+    {
+        super((short) -1, bais);
+
+        glyphs = glyphTable.getGlyphs();
+
+        // Get all of the composite components
+        GlyfCompositeComp comp;
+        do
+        {
+            comp = new GlyfCompositeComp(bais);
+            components.add(comp);
+        } while ((comp.getFlags() & GlyfCompositeComp.MORE_COMPONENTS) != 0);
+
+        // Are there hinting instructions to read?
+        if ((comp.getFlags() & GlyfCompositeComp.WE_HAVE_INSTRUCTIONS) != 0)
+        {
+            readInstructions(bais, (bais.readUnsignedShort()));
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void resolve()
+    {
+        if (resolved)
+        {
+            return;
+        }
+        if (beingResolved)
+        {
+            System.err.println("Circular reference in GlyfCompositeDesc");
+            return;
+        }
+        beingResolved = true;
+
+        int firstIndex = 0;
+        int firstContour = 0;
+
+        Iterator<GlyfCompositeComp> i = components.iterator();
+        while (i.hasNext())
+        {
+            GlyfCompositeComp comp = (GlyfCompositeComp) i.next();
+            comp.setFirstIndex(firstIndex);
+            comp.setFirstContour(firstContour);
+
+            GlyphDescription desc;
+            desc = getGlypDescription(comp.getGlyphIndex());
+            if (desc != null)
+            {
+                desc.resolve();
+                firstIndex += desc.getPointCount();
+                firstContour += desc.getContourCount();
+            }
+        }
+        resolved = true;
+        beingResolved = false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getEndPtOfContours(int i)
+    {
+        GlyfCompositeComp c = getCompositeCompEndPt(i);
+        if (c != null)
+        {
+            GlyphDescription gd = getGlypDescription(c.getGlyphIndex());
+            return gd.getEndPtOfContours(i - c.getFirstContour()) + c.getFirstIndex();
+        }
+        return 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public byte getFlags(int i)
+    {
+        GlyfCompositeComp c = getCompositeComp(i);
+        if (c != null)
+        {
+            GlyphDescription gd = getGlypDescription(c.getGlyphIndex());
+            return gd.getFlags(i - c.getFirstIndex());
+        }
+        return 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public short getXCoordinate(int i)
+    {
+        GlyfCompositeComp c = getCompositeComp(i);
+        if (c != null)
+        {
+            GlyphDescription gd = getGlypDescription(c.getGlyphIndex());
+            int n = i - c.getFirstIndex();
+            int x = gd.getXCoordinate(n);
+            int y = gd.getYCoordinate(n);
+            short x1 = (short) c.scaleX(x, y);
+            x1 += c.getXTranslate();
+            return x1;
+        }
+        return 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public short getYCoordinate(int i)
+    {
+        GlyfCompositeComp c = getCompositeComp(i);
+        if (c != null)
+        {
+            GlyphDescription gd = getGlypDescription(c.getGlyphIndex());
+            int n = i - c.getFirstIndex();
+            int x = gd.getXCoordinate(n);
+            int y = gd.getYCoordinate(n);
+            short y1 = (short) c.scaleY(x, y);
+            y1 += c.getYTranslate();
+            return y1;
+        }
+        return 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isComposite()
+    {
+        return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getPointCount()
+    {
+        if (!resolved)
+        {
+            System.err.println("getPointCount called on unresolved GlyfCompositeDescript");
+        }
+        GlyfCompositeComp c = (GlyfCompositeComp) components.get(components.size() - 1);
+        return c.getFirstIndex() + getGlypDescription(c.getGlyphIndex()).getPointCount();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getContourCount()
+    {
+        if (!resolved)
+        {
+            System.err.println("getContourCount called on unresolved GlyfCompositeDescript");
+        }
+        GlyfCompositeComp c = (GlyfCompositeComp) components.get(components.size() - 1);
+        return c.getFirstContour() + getGlypDescription(c.getGlyphIndex()).getContourCount();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getComponentCount()
+    {
+        return components.size();
+    }
+
+    private GlyfCompositeComp getCompositeComp(int i)
+    {
+        GlyfCompositeComp c;
+        for (int n = 0; n < components.size(); n++)
+        {
+            c = (GlyfCompositeComp) components.get(n);
+            GlyphDescription gd = getGlypDescription(c.getGlyphIndex());
+            if (c.getFirstIndex() <= i && i < (c.getFirstIndex() + gd.getPointCount()))
+            {
+                return c;
+            }
+        }
+        return null;
+    }
+
+    private GlyfCompositeComp getCompositeCompEndPt(int i)
+    {
+        GlyfCompositeComp c;
+        for (int j = 0; j < components.size(); j++)
+        {
+            c = (GlyfCompositeComp) components.get(j);
+            GlyphDescription gd = getGlypDescription(c.getGlyphIndex());
+            if (c.getFirstContour() <= i && i < (c.getFirstContour() + gd.getContourCount()))
+            {
+                return c;
+            }
+        }
+        return null;
+    }
+
+    private GlyphDescription getGlypDescription(int index)
+    {
+        if (glyphs != null && index < glyphs.length)
+        {
+            GlyphData glyph = glyphs[index];
+            if (glyph != null)
+            {
+                return glyph.getDescription();
+            }
+        }
+        return null;
+    }
 }

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfSimpleDescript.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfSimpleDescript.java?rev=1535953&r1=1535952&r2=1535953&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfSimpleDescript.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfSimpleDescript.java Sat Oct 26 09:26:32 2013
@@ -21,10 +21,10 @@ package org.apache.fontbox.ttf;
 import java.io.IOException;
 
 /**
- * This class is based on code from Apache Batik a subproject of Apache XMLGraphics.
- * see http://xmlgraphics.apache.org/batik/ for further details.
+ * 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 GlyfSimpleDescript extends GlyfDescript 
+public class GlyfSimpleDescript extends GlyfDescript
 {
 
     private int[] endPtsOfContours;
@@ -38,18 +38,18 @@ public class GlyfSimpleDescript extends 
      * 
      * @param numberOfContours number of contours
      * @param bais the stream to be read
-     * @throws IOException is thrown if something went wrong 
+     * @throws IOException is thrown if something went wrong
      */
     public GlyfSimpleDescript(short numberOfContours, TTFDataStream bais) throws IOException
     {
         super(numberOfContours, bais);
-        
-        /* https://developer.apple.com/fonts/TTRefMan/RM06/Chap6glyf.html
-         * "If a glyph has zero contours, it need not have any glyph data."
-         * set the pointCount to zero to initialize attributes and avoid nullpointer but 
-         * maybe there shouldn't have GlyphDescript in the GlyphData?
+
+        /*
+         * https://developer.apple.com/fonts/TTRefMan/RM06/Chap6glyf.html
+         * "If a glyph has zero contours, it need not have any glyph data." set the pointCount to zero to initialize
+         * attributes and avoid nullpointer but maybe there shouldn't have GlyphDescript in the GlyphData?
          */
-        if (numberOfContours == 0) 
+        if (numberOfContours == 0)
         {
             pointCount = 0;
             return;
@@ -60,8 +60,8 @@ public class GlyfSimpleDescript extends 
         endPtsOfContours = bais.readUnsignedShortArray(numberOfContours);
 
         // The last end point index reveals the total number of points
-        pointCount = endPtsOfContours[numberOfContours -1] + 1;   
-        
+        pointCount = endPtsOfContours[numberOfContours - 1] + 1;
+
         flags = new byte[pointCount];
         xCoordinates = new short[pointCount];
         yCoordinates = new short[pointCount];
@@ -75,7 +75,7 @@ public class GlyfSimpleDescript extends 
     /**
      * {@inheritDoc}
      */
-    public int getEndPtOfContours(int i) 
+    public int getEndPtOfContours(int i)
     {
         return endPtsOfContours[i];
     }
@@ -83,7 +83,7 @@ public class GlyfSimpleDescript extends 
     /**
      * {@inheritDoc}
      */
-    public byte getFlags(int i) 
+    public byte getFlags(int i)
     {
         return flags[i];
     }
@@ -91,7 +91,7 @@ public class GlyfSimpleDescript extends 
     /**
      * {@inheritDoc}
      */
-    public short getXCoordinate(int i) 
+    public short getXCoordinate(int i)
     {
         return xCoordinates[i];
     }
@@ -99,7 +99,7 @@ public class GlyfSimpleDescript extends 
     /**
      * {@inheritDoc}
      */
-    public short getYCoordinate(int i) 
+    public short getYCoordinate(int i)
     {
         return yCoordinates[i];
     }
@@ -107,7 +107,7 @@ public class GlyfSimpleDescript extends 
     /**
      * {@inheritDoc}
      */
-    public boolean isComposite() 
+    public boolean isComposite()
     {
         return false;
     }
@@ -115,7 +115,7 @@ public class GlyfSimpleDescript extends 
     /**
      * {@inheritDoc}
      */
-    public int getPointCount() 
+    public int getPointCount()
     {
         return pointCount;
     }
@@ -127,22 +127,22 @@ public class GlyfSimpleDescript extends 
     {
         short x = 0;
         short y = 0;
-        for (int i = 0; i < count; i++) 
+        for (int i = 0; i < count; i++)
         {
-            if ((flags[i] & X_DUAL) != 0) 
+            if ((flags[i] & X_DUAL) != 0)
             {
-                if ((flags[i] & X_SHORT_VECTOR) != 0) 
+                if ((flags[i] & X_SHORT_VECTOR) != 0)
                 {
-                    x += (short) bais.read();
+                    x += (short) bais.readUnsignedByte();
                 }
-            } 
-            else 
+            }
+            else
             {
-                if ((flags[i] & X_SHORT_VECTOR) != 0) 
+                if ((flags[i] & X_SHORT_VECTOR) != 0)
                 {
-                    x += (short) -((short) bais.read());
-                } 
-                else 
+                    x += (short) -((short) bais.readUnsignedByte());
+                }
+                else
                 {
                     x += bais.readSignedShort();
                 }
@@ -150,22 +150,22 @@ public class GlyfSimpleDescript extends 
             xCoordinates[i] = x;
         }
 
-        for (int i = 0; i < count; i++) 
+        for (int i = 0; i < count; i++)
         {
-            if ((flags[i] & Y_DUAL) != 0) 
+            if ((flags[i] & Y_DUAL) != 0)
             {
-                if ((flags[i] & Y_SHORT_VECTOR) != 0) 
+                if ((flags[i] & Y_SHORT_VECTOR) != 0)
                 {
-                    y += (short) bais.read();
+                    y += (short) bais.readUnsignedByte();
                 }
-            } 
-            else 
+            }
+            else
             {
-                if ((flags[i] & Y_SHORT_VECTOR) != 0) 
+                if ((flags[i] & Y_SHORT_VECTOR) != 0)
                 {
-                    y += (short) -((short) bais.read());
-                } 
-                else 
+                    y += (short) -((short) bais.readUnsignedByte());
+                }
+                else
                 {
                     y += bais.readSignedShort();
                 }
@@ -179,25 +179,26 @@ public class GlyfSimpleDescript extends 
      */
     private void readFlags(int flagCount, TTFDataStream bais) throws IOException
     {
-        try 
+        try
         {
-            for (int index = 0; index < flagCount; index++) 
+            for (int index = 0; index < flagCount; index++)
             {
-                flags[index] = (byte) bais.read();
-                if ((flags[index] & REPEAT) != 0) 
+                flags[index] = (byte) bais.readUnsignedByte();
+                if ((flags[index] & REPEAT) != 0)
                 {
-                    int repeats = bais.read();
-                    for (int i = 1; i <= repeats; i++) 
+                    int repeats = bais.readUnsignedByte();
+                    for (int i = 1; i <= repeats; i++)
                     {
                         flags[index + i] = flags[index];
                     }
                     index += repeats;
                 }
             }
-        } 
-        catch (ArrayIndexOutOfBoundsException e) 
+        }
+        catch (ArrayIndexOutOfBoundsException e)
         {
             System.out.println("error: array index out of bounds");
         }
     }
+
 }

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/OS2WindowsMetricsTable.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/OS2WindowsMetricsTable.java?rev=1535953&r1=1535952&r2=1535953&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/OS2WindowsMetricsTable.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/OS2WindowsMetricsTable.java Sat Oct 26 09:26:32 2013
@@ -22,11 +22,11 @@ import java.io.IOException;
  * A table in a true type font.
  * 
  * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.1 $
+ * 
  */
 public class OS2WindowsMetricsTable extends TTFTable
 {
-    
+
     /**
      * Weight class constant.
      */
@@ -63,7 +63,7 @@ public class OS2WindowsMetricsTable exte
      * Weight class constant.
      */
     public static final int WEIGHT_CLASS_BLACK = 900;
-    
+
     /**
      * Width class constant.
      */
@@ -100,7 +100,7 @@ public class OS2WindowsMetricsTable exte
      * Width class constant.
      */
     public static final int WIDTH_CLASS_ULTRA_EXPANDED = 9;
-    
+
     /**
      * Family class constant.
      */
@@ -145,7 +145,7 @@ public class OS2WindowsMetricsTable exte
      * Family class constant.
      */
     public static final int FAMILY_CLASS_SYMBOLIC = 12;
-    
+
     /**
      * @return Returns the achVendId.
      */
@@ -153,6 +153,7 @@ public class OS2WindowsMetricsTable exte
     {
         return achVendId;
     }
+
     /**
      * @param achVendIdValue The achVendId to set.
      */
@@ -160,6 +161,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.achVendId = achVendIdValue;
     }
+
     /**
      * @return Returns the averageCharWidth.
      */
@@ -167,6 +169,7 @@ public class OS2WindowsMetricsTable exte
     {
         return averageCharWidth;
     }
+
     /**
      * @param averageCharWidthValue The averageCharWidth to set.
      */
@@ -174,6 +177,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.averageCharWidth = averageCharWidthValue;
     }
+
     /**
      * @return Returns the codePageRange1.
      */
@@ -181,6 +185,7 @@ public class OS2WindowsMetricsTable exte
     {
         return codePageRange1;
     }
+
     /**
      * @param codePageRange1Value The codePageRange1 to set.
      */
@@ -188,6 +193,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.codePageRange1 = codePageRange1Value;
     }
+
     /**
      * @return Returns the codePageRange2.
      */
@@ -195,6 +201,7 @@ public class OS2WindowsMetricsTable exte
     {
         return codePageRange2;
     }
+
     /**
      * @param codePageRange2Value The codePageRange2 to set.
      */
@@ -202,6 +209,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.codePageRange2 = codePageRange2Value;
     }
+
     /**
      * @return Returns the familyClass.
      */
@@ -209,6 +217,7 @@ public class OS2WindowsMetricsTable exte
     {
         return familyClass;
     }
+
     /**
      * @param familyClassValue The familyClass to set.
      */
@@ -216,6 +225,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.familyClass = familyClassValue;
     }
+
     /**
      * @return Returns the familySubClass.
      */
@@ -223,6 +233,7 @@ public class OS2WindowsMetricsTable exte
     {
         return familySubClass;
     }
+
     /**
      * @param familySubClassValue The familySubClass to set.
      */
@@ -230,6 +241,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.familySubClass = familySubClassValue;
     }
+
     /**
      * @return Returns the firstCharIndex.
      */
@@ -237,6 +249,7 @@ public class OS2WindowsMetricsTable exte
     {
         return firstCharIndex;
     }
+
     /**
      * @param firstCharIndexValue The firstCharIndex to set.
      */
@@ -244,6 +257,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.firstCharIndex = firstCharIndexValue;
     }
+
     /**
      * @return Returns the fsSelection.
      */
@@ -251,6 +265,7 @@ public class OS2WindowsMetricsTable exte
     {
         return fsSelection;
     }
+
     /**
      * @param fsSelectionValue The fsSelection to set.
      */
@@ -258,6 +273,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.fsSelection = fsSelectionValue;
     }
+
     /**
      * @return Returns the fsType.
      */
@@ -265,6 +281,7 @@ public class OS2WindowsMetricsTable exte
     {
         return fsType;
     }
+
     /**
      * @param fsTypeValue The fsType to set.
      */
@@ -272,6 +289,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.fsType = fsTypeValue;
     }
+
     /**
      * @return Returns the lastCharIndex.
      */
@@ -279,6 +297,7 @@ public class OS2WindowsMetricsTable exte
     {
         return lastCharIndex;
     }
+
     /**
      * @param lastCharIndexValue The lastCharIndex to set.
      */
@@ -286,6 +305,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.lastCharIndex = lastCharIndexValue;
     }
+
     /**
      * @return Returns the panose.
      */
@@ -293,6 +313,7 @@ public class OS2WindowsMetricsTable exte
     {
         return panose;
     }
+
     /**
      * @param panoseValue The panose to set.
      */
@@ -300,6 +321,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.panose = panoseValue;
     }
+
     /**
      * @return Returns the strikeoutPosition.
      */
@@ -307,6 +329,7 @@ public class OS2WindowsMetricsTable exte
     {
         return strikeoutPosition;
     }
+
     /**
      * @param strikeoutPositionValue The strikeoutPosition to set.
      */
@@ -314,6 +337,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.strikeoutPosition = strikeoutPositionValue;
     }
+
     /**
      * @return Returns the strikeoutSize.
      */
@@ -321,6 +345,7 @@ public class OS2WindowsMetricsTable exte
     {
         return strikeoutSize;
     }
+
     /**
      * @param strikeoutSizeValue The strikeoutSize to set.
      */
@@ -328,6 +353,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.strikeoutSize = strikeoutSizeValue;
     }
+
     /**
      * @return Returns the subscriptXOffset.
      */
@@ -335,6 +361,7 @@ public class OS2WindowsMetricsTable exte
     {
         return subscriptXOffset;
     }
+
     /**
      * @param subscriptXOffsetValue The subscriptXOffset to set.
      */
@@ -342,6 +369,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.subscriptXOffset = subscriptXOffsetValue;
     }
+
     /**
      * @return Returns the subscriptXSize.
      */
@@ -349,6 +377,7 @@ public class OS2WindowsMetricsTable exte
     {
         return subscriptXSize;
     }
+
     /**
      * @param subscriptXSizeValue The subscriptXSize to set.
      */
@@ -356,6 +385,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.subscriptXSize = subscriptXSizeValue;
     }
+
     /**
      * @return Returns the subscriptYOffset.
      */
@@ -363,6 +393,7 @@ public class OS2WindowsMetricsTable exte
     {
         return subscriptYOffset;
     }
+
     /**
      * @param subscriptYOffsetValue The subscriptYOffset to set.
      */
@@ -370,6 +401,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.subscriptYOffset = subscriptYOffsetValue;
     }
+
     /**
      * @return Returns the subscriptYSize.
      */
@@ -377,6 +409,7 @@ public class OS2WindowsMetricsTable exte
     {
         return subscriptYSize;
     }
+
     /**
      * @param subscriptYSizeValue The subscriptYSize to set.
      */
@@ -384,6 +417,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.subscriptYSize = subscriptYSizeValue;
     }
+
     /**
      * @return Returns the superscriptXOffset.
      */
@@ -391,6 +425,7 @@ public class OS2WindowsMetricsTable exte
     {
         return superscriptXOffset;
     }
+
     /**
      * @param superscriptXOffsetValue The superscriptXOffset to set.
      */
@@ -398,6 +433,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.superscriptXOffset = superscriptXOffsetValue;
     }
+
     /**
      * @return Returns the superscriptXSize.
      */
@@ -405,6 +441,7 @@ public class OS2WindowsMetricsTable exte
     {
         return superscriptXSize;
     }
+
     /**
      * @param superscriptXSizeValue The superscriptXSize to set.
      */
@@ -412,6 +449,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.superscriptXSize = superscriptXSizeValue;
     }
+
     /**
      * @return Returns the superscriptYOffset.
      */
@@ -419,6 +457,7 @@ public class OS2WindowsMetricsTable exte
     {
         return superscriptYOffset;
     }
+
     /**
      * @param superscriptYOffsetValue The superscriptYOffset to set.
      */
@@ -426,6 +465,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.superscriptYOffset = superscriptYOffsetValue;
     }
+
     /**
      * @return Returns the superscriptYSize.
      */
@@ -433,6 +473,7 @@ public class OS2WindowsMetricsTable exte
     {
         return superscriptYSize;
     }
+
     /**
      * @param superscriptYSizeValue The superscriptYSize to set.
      */
@@ -440,6 +481,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.superscriptYSize = superscriptYSizeValue;
     }
+
     /**
      * @return Returns the typeLineGap.
      */
@@ -447,6 +489,7 @@ public class OS2WindowsMetricsTable exte
     {
         return typeLineGap;
     }
+
     /**
      * @param typeLineGapValue The typeLineGap to set.
      */
@@ -454,6 +497,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.typeLineGap = typeLineGapValue;
     }
+
     /**
      * @return Returns the typoAscender.
      */
@@ -461,6 +505,7 @@ public class OS2WindowsMetricsTable exte
     {
         return typoAscender;
     }
+
     /**
      * @param typoAscenderValue The typoAscender to set.
      */
@@ -468,6 +513,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.typoAscender = typoAscenderValue;
     }
+
     /**
      * @return Returns the typoDescender.
      */
@@ -475,6 +521,7 @@ public class OS2WindowsMetricsTable exte
     {
         return typoDescender;
     }
+
     /**
      * @param typoDescenderValue The typoDescender to set.
      */
@@ -482,6 +529,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.typoDescender = typoDescenderValue;
     }
+
     /**
      * @return Returns the unicodeRange1.
      */
@@ -489,6 +537,7 @@ public class OS2WindowsMetricsTable exte
     {
         return unicodeRange1;
     }
+
     /**
      * @param unicodeRange1Value The unicodeRange1 to set.
      */
@@ -496,6 +545,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.unicodeRange1 = unicodeRange1Value;
     }
+
     /**
      * @return Returns the unicodeRange2.
      */
@@ -503,6 +553,7 @@ public class OS2WindowsMetricsTable exte
     {
         return unicodeRange2;
     }
+
     /**
      * @param unicodeRange2Value The unicodeRange2 to set.
      */
@@ -510,6 +561,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.unicodeRange2 = unicodeRange2Value;
     }
+
     /**
      * @return Returns the unicodeRange3.
      */
@@ -517,6 +569,7 @@ public class OS2WindowsMetricsTable exte
     {
         return unicodeRange3;
     }
+
     /**
      * @param unicodeRange3Value The unicodeRange3 to set.
      */
@@ -524,6 +577,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.unicodeRange3 = unicodeRange3Value;
     }
+
     /**
      * @return Returns the unicodeRange4.
      */
@@ -531,6 +585,7 @@ public class OS2WindowsMetricsTable exte
     {
         return unicodeRange4;
     }
+
     /**
      * @param unicodeRange4Value The unicodeRange4 to set.
      */
@@ -538,6 +593,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.unicodeRange4 = unicodeRange4Value;
     }
+
     /**
      * @return Returns the version.
      */
@@ -545,6 +601,7 @@ public class OS2WindowsMetricsTable exte
     {
         return version;
     }
+
     /**
      * @param versionValue The version to set.
      */
@@ -552,6 +609,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.version = versionValue;
     }
+
     /**
      * @return Returns the weightClass.
      */
@@ -559,6 +617,7 @@ public class OS2WindowsMetricsTable exte
     {
         return weightClass;
     }
+
     /**
      * @param weightClassValue The weightClass to set.
      */
@@ -566,6 +625,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.weightClass = weightClassValue;
     }
+
     /**
      * @return Returns the widthClass.
      */
@@ -573,6 +633,7 @@ public class OS2WindowsMetricsTable exte
     {
         return widthClass;
     }
+
     /**
      * @param widthClassValue The widthClass to set.
      */
@@ -580,6 +641,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.widthClass = widthClassValue;
     }
+
     /**
      * @return Returns the winAscent.
      */
@@ -587,6 +649,7 @@ public class OS2WindowsMetricsTable exte
     {
         return winAscent;
     }
+
     /**
      * @param winAscentValue The winAscent to set.
      */
@@ -594,6 +657,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.winAscent = winAscentValue;
     }
+
     /**
      * @return Returns the winDescent.
      */
@@ -601,6 +665,7 @@ public class OS2WindowsMetricsTable exte
     {
         return winDescent;
     }
+
     /**
      * @param winDescentValue The winDescent to set.
      */
@@ -608,6 +673,7 @@ public class OS2WindowsMetricsTable exte
     {
         this.winDescent = winDescentValue;
     }
+
     private int version;
     private short averageCharWidth;
     private int weightClass;
@@ -641,12 +707,12 @@ public class OS2WindowsMetricsTable exte
     private int winDescent;
     private long codePageRange1 = -1;
     private long codePageRange2 = -1;
-    
+
     /**
      * A tag that identifies this table type.
      */
     public static final String TAG = "OS/2";
-    
+
     /**
      * This will read the required data from the stream.
      * 
@@ -654,7 +720,7 @@ public class OS2WindowsMetricsTable exte
      * @param data The stream to read the data from.
      * @throws IOException If there is an error reading the data.
      */
-    public void initData( TrueTypeFont ttf, TTFDataStream data ) throws IOException
+    public void initData(TrueTypeFont ttf, TTFDataStream data) throws IOException
     {
         version = data.readUnsignedShort();
         averageCharWidth = data.readSignedShort();
@@ -671,14 +737,14 @@ public class OS2WindowsMetricsTable exte
         superscriptYOffset = data.readSignedShort();
         strikeoutSize = data.readSignedShort();
         strikeoutPosition = data.readSignedShort();
-        familyClass = data.read();
-        familySubClass = data.read();
-        panose = data.read( 10 );
+        familyClass = data.readUnsignedByte();
+        familySubClass = data.readUnsignedByte();
+        panose = data.read(10);
         unicodeRange1 = data.readUnsignedInt();
         unicodeRange2 = data.readUnsignedInt();
         unicodeRange3 = data.readUnsignedInt();
         unicodeRange4 = data.readUnsignedInt();
-        achVendId = data.readString( 4 );
+        achVendId = data.readString(4);
         fsSelection = data.readUnsignedShort();
         firstCharIndex = data.readUnsignedShort();
         lastCharIndex = data.readUnsignedShort();
@@ -687,7 +753,7 @@ public class OS2WindowsMetricsTable exte
         typeLineGap = data.readSignedShort();
         winAscent = data.readUnsignedShort();
         winDescent = data.readUnsignedShort();
-        if( version >= 1 )
+        if (version >= 1)
         {
             codePageRange1 = data.readUnsignedInt();
             codePageRange2 = data.readUnsignedInt();

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/PostScriptTable.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/PostScriptTable.java?rev=1535953&r1=1535952&r2=1535953&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/PostScriptTable.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/PostScriptTable.java Sat Oct 26 09:26:32 2013
@@ -17,13 +17,14 @@
 package org.apache.fontbox.ttf;
 
 import java.io.IOException;
+
 import org.apache.fontbox.encoding.Encoding;
 
 /**
  * A table in a true type font.
  * 
  * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.1 $
+ * 
  */
 public class PostScriptTable extends TTFTable
 {
@@ -37,13 +38,12 @@ public class PostScriptTable extends TTF
     private long mimMemType1;
     private long maxMemType1;
     private String[] glyphNames = null;
-    
 
     /**
      * A tag that identifies this table type.
      */
     public static final String TAG = "post";
-    
+
     /**
      * This will read the required data from the stream.
      * 
@@ -51,7 +51,7 @@ public class PostScriptTable extends TTF
      * @param data The stream to read the data from.
      * @throws IOException If there is an error reading the data.
      */
-    public void initData( TrueTypeFont ttf, TTFDataStream data ) throws IOException
+    public void initData(TrueTypeFont ttf, TTFDataStream data) throws IOException
     {
         MaximumProfileTable maxp = ttf.getMaximumProfile();
         formatType = data.read32Fixed();
@@ -63,53 +63,52 @@ public class PostScriptTable extends TTF
         maxMemType42 = data.readUnsignedInt();
         mimMemType1 = data.readUnsignedInt();
         maxMemType1 = data.readUnsignedInt();
-        
-        if( formatType == 1.0f )
+
+        if (formatType == 1.0f)
         {
             /*
-             * This TrueType font file contains exactly the 258 glyphs in the standard 
-             * Macintosh TrueType.
+             * This TrueType font file contains exactly the 258 glyphs in the standard Macintosh TrueType.
              */
             glyphNames = new String[Encoding.NUMBER_OF_MAC_GLYPHS];
             System.arraycopy(Encoding.MAC_GLYPH_NAMES, 0, glyphNames, 0, Encoding.NUMBER_OF_MAC_GLYPHS);
         }
-        else if( formatType == 2.0f )
+        else if (formatType == 2.0f)
         {
             int numGlyphs = data.readUnsignedShort();
             int[] glyphNameIndex = new int[numGlyphs];
-            glyphNames = new String[ numGlyphs ];
+            glyphNames = new String[numGlyphs];
             int maxIndex = Integer.MIN_VALUE;
-            for( int i=0; i<numGlyphs; i++ )
+            for (int i = 0; i < numGlyphs; i++)
             {
                 int index = data.readUnsignedShort();
                 glyphNameIndex[i] = index;
                 // PDFBOX-808: Index numbers between 32768 and 65535 are
                 // reserved for future use, so we should just ignore them
-                if (index <= 32767) 
+                if (index <= 32767)
                 {
-                    maxIndex = Math.max( maxIndex, index );
+                    maxIndex = Math.max(maxIndex, index);
                 }
             }
             String[] nameArray = null;
-            if( maxIndex >= Encoding.NUMBER_OF_MAC_GLYPHS )
+            if (maxIndex >= Encoding.NUMBER_OF_MAC_GLYPHS)
             {
-                nameArray = new String[ maxIndex-Encoding.NUMBER_OF_MAC_GLYPHS +1 ];
-                for( int i=0; i<maxIndex-Encoding.NUMBER_OF_MAC_GLYPHS+1; i++ )
+                nameArray = new String[maxIndex - Encoding.NUMBER_OF_MAC_GLYPHS + 1];
+                for (int i = 0; i < maxIndex - Encoding.NUMBER_OF_MAC_GLYPHS + 1; i++)
                 {
-                    int numberOfChars = data.read();
-                    nameArray[i]=data.readString( numberOfChars );
+                    int numberOfChars = data.readUnsignedByte();
+                    nameArray[i] = data.readString(numberOfChars);
                 }
             }
-            for( int i=0; i<numGlyphs; i++ )
+            for (int i = 0; i < numGlyphs; i++)
             {
                 int index = glyphNameIndex[i];
-                if( index < Encoding.NUMBER_OF_MAC_GLYPHS )
+                if (index < Encoding.NUMBER_OF_MAC_GLYPHS)
                 {
                     glyphNames[i] = Encoding.MAC_GLYPH_NAMES[index];
                 }
-                else if( index >= Encoding.NUMBER_OF_MAC_GLYPHS && index <= 32767 )
+                else if (index >= Encoding.NUMBER_OF_MAC_GLYPHS && index <= 32767)
                 {
-                    glyphNames[i] = nameArray[index-Encoding.NUMBER_OF_MAC_GLYPHS];
+                    glyphNames[i] = nameArray[index - Encoding.NUMBER_OF_MAC_GLYPHS];
                 }
                 else
                 {
@@ -119,30 +118,31 @@ public class PostScriptTable extends TTF
                 }
             }
         }
-        else if( formatType == 2.5f )
+        else if (formatType == 2.5f)
         {
             int[] glyphNameIndex = new int[maxp.getNumGlyphs()];
-            for( int i=0; i<glyphNameIndex.length; i++)
+            for (int i = 0; i < glyphNameIndex.length; i++)
             {
                 int offset = data.readSignedByte();
-                glyphNameIndex[i] = i+1+offset;
+                glyphNameIndex[i] = i + 1 + offset;
             }
             glyphNames = new String[glyphNameIndex.length];
-            for( int i=0; i<glyphNames.length; i++)
+            for (int i = 0; i < glyphNames.length; i++)
             {
                 String name = Encoding.MAC_GLYPH_NAMES[glyphNameIndex[i]];
-                if( name != null )
+                if (name != null)
                 {
                     glyphNames[i] = name;
                 }
             }
-            
+
         }
-        else if( formatType == 3.0f )
+        else if (formatType == 3.0f)
         {
-            //no postscript information is provided.
+            // no postscript information is provided.
         }
     }
+
     /**
      * @return Returns the formatType.
      */
@@ -150,6 +150,7 @@ public class PostScriptTable extends TTF
     {
         return formatType;
     }
+
     /**
      * @param formatTypeValue The formatType to set.
      */
@@ -157,6 +158,7 @@ public class PostScriptTable extends TTF
     {
         this.formatType = formatTypeValue;
     }
+
     /**
      * @return Returns the isFixedPitch.
      */
@@ -164,6 +166,7 @@ public class PostScriptTable extends TTF
     {
         return isFixedPitch;
     }
+
     /**
      * @param isFixedPitchValue The isFixedPitch to set.
      */
@@ -171,6 +174,7 @@ public class PostScriptTable extends TTF
     {
         this.isFixedPitch = isFixedPitchValue;
     }
+
     /**
      * @return Returns the italicAngle.
      */
@@ -178,6 +182,7 @@ public class PostScriptTable extends TTF
     {
         return italicAngle;
     }
+
     /**
      * @param italicAngleValue The italicAngle to set.
      */
@@ -185,6 +190,7 @@ public class PostScriptTable extends TTF
     {
         this.italicAngle = italicAngleValue;
     }
+
     /**
      * @return Returns the maxMemType1.
      */
@@ -192,6 +198,7 @@ public class PostScriptTable extends TTF
     {
         return maxMemType1;
     }
+
     /**
      * @param maxMemType1Value The maxMemType1 to set.
      */
@@ -199,6 +206,7 @@ public class PostScriptTable extends TTF
     {
         this.maxMemType1 = maxMemType1Value;
     }
+
     /**
      * @return Returns the maxMemType42.
      */
@@ -206,6 +214,7 @@ public class PostScriptTable extends TTF
     {
         return maxMemType42;
     }
+
     /**
      * @param maxMemType42Value The maxMemType42 to set.
      */
@@ -213,6 +222,7 @@ public class PostScriptTable extends TTF
     {
         this.maxMemType42 = maxMemType42Value;
     }
+
     /**
      * @return Returns the mimMemType1.
      */
@@ -220,6 +230,7 @@ public class PostScriptTable extends TTF
     {
         return mimMemType1;
     }
+
     /**
      * @param mimMemType1Value The mimMemType1 to set.
      */
@@ -227,6 +238,7 @@ public class PostScriptTable extends TTF
     {
         this.mimMemType1 = mimMemType1Value;
     }
+
     /**
      * @return Returns the minMemType42.
      */
@@ -234,6 +246,7 @@ public class PostScriptTable extends TTF
     {
         return minMemType42;
     }
+
     /**
      * @param minMemType42Value The minMemType42 to set.
      */
@@ -241,6 +254,7 @@ public class PostScriptTable extends TTF
     {
         this.minMemType42 = minMemType42Value;
     }
+
     /**
      * @return Returns the underlinePosition.
      */
@@ -248,6 +262,7 @@ public class PostScriptTable extends TTF
     {
         return underlinePosition;
     }
+
     /**
      * @param underlinePositionValue The underlinePosition to set.
      */
@@ -255,6 +270,7 @@ public class PostScriptTable extends TTF
     {
         this.underlinePosition = underlinePositionValue;
     }
+
     /**
      * @return Returns the underlineThickness.
      */
@@ -262,6 +278,7 @@ public class PostScriptTable extends TTF
     {
         return underlineThickness;
     }
+
     /**
      * @param underlineThicknessValue The underlineThickness to set.
      */
@@ -269,6 +286,7 @@ public class PostScriptTable extends TTF
     {
         this.underlineThickness = underlineThicknessValue;
     }
+
     /**
      * @return Returns the glyphNames.
      */
@@ -276,6 +294,7 @@ public class PostScriptTable extends TTF
     {
         return glyphNames;
     }
+
     /**
      * @param glyphNamesValue The glyphNames to set.
      */

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFDataStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFDataStream.java?rev=1535953&r1=1535952&r2=1535953&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFDataStream.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFDataStream.java Sat Oct 26 09:26:32 2013
@@ -19,7 +19,6 @@ package org.apache.fontbox.ttf;
 import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
-
 import java.util.Calendar;
 import java.util.GregorianCalendar;
 
@@ -27,14 +26,14 @@ import java.util.GregorianCalendar;
  * An interface into a data stream.
  * 
  * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.1 $
+ * 
  */
-public abstract class TTFDataStream 
+public abstract class TTFDataStream
 {
 
     /**
-     * Read a 16.16 fixed value, where the first 16 bits are the decimal and the last
-     * 16 bits are the fraction.
+     * Read a 16.16 fixed value, where the first 16 bits are the decimal and the last 16 bits are the fraction.
+     * 
      * @return A 32 bit value.
      * @throws IOException If there is an error reading the data.
      */
@@ -42,62 +41,83 @@ public abstract class TTFDataStream 
     {
         float retval = 0;
         retval = readSignedShort();
-        retval += (readUnsignedShort()/65536.0);
+        retval += (readUnsignedShort() / 65536.0);
         return retval;
     }
-    
+
     /**
      * Read a fixed length ascii string.
+     * 
      * @param length The length of the string to read.
      * @return A string of the desired length.
      * @throws IOException If there is an error reading the data.
      */
-    public String readString( int length ) throws IOException
+    public String readString(int length) throws IOException
     {
-        return readString( length, "ISO-8859-1" );
+        return readString(length, "ISO-8859-1");
     }
-    
+
     /**
      * Read a fixed length ascii string.
+     * 
      * @param length The length of the string to read in bytes.
      * @param charset The expected character set of the string.
      * @return A string of the desired length.
      * @throws IOException If there is an error reading the data.
      */
-    public String readString( int length, String charset ) throws IOException
+    public String readString(int length, String charset) throws IOException
     {
-        byte[] buffer = read( length );
+        byte[] buffer = read(length);
         return new String(buffer, charset);
     }
-    
+
     /**
      * Read an unsigned byte.
+     * 
      * @return An unsigned byte.
      * @throws IOException If there is an error reading the data.
      */
     public abstract int read() throws IOException;
-    
+
     /**
      * Read an unsigned byte.
+     * 
      * @return An unsigned byte.
      * @throws IOException If there is an error reading the data.
      */
     public abstract long readLong() throws IOException;
-    
-    
+
     /**
      * Read a signed byte.
+     * 
      * @return A signed byte.
      * @throws IOException If there is an error reading the data.
      */
     public int readSignedByte() throws IOException
     {
         int signedByte = read();
-        return signedByte < 127 ? signedByte : signedByte-256;
+        return signedByte < 127 ? signedByte : signedByte - 256;
+    }
+
+    /**
+     * Read a unsigned byte. Similar to {@link #read()}, but throws an exception if EOF is unexpectedly reached.
+     * 
+     * @return A unsigned byte.
+     * @throws IOException If there is an error reading the data.
+     */
+    public int readUnsignedByte() throws IOException
+    {
+        int unsignedByte = read();
+        if (unsignedByte == -1)
+        {
+            throw new EOFException("premature EOF");
+        }
+        return unsignedByte;
     }
-    
+
     /**
      * Read an unsigned integer.
+     * 
      * @return An unsiged integer.
      * @throws IOException If there is an error reading the data.
      */
@@ -107,13 +127,13 @@ public abstract class TTFDataStream 
         long byte2 = read();
         long byte3 = read();
         long byte4 = read();
-        if( byte4 < 0 )
+        if (byte4 < 0)
         {
             throw new EOFException();
         }
         return (byte1 << 24) + (byte2 << 16) + (byte3 << 8) + (byte4 << 0);
     }
-    
+
     /**
      * Read an unsigned short.
      * 
@@ -121,7 +141,7 @@ public abstract class TTFDataStream 
      * @throws IOException If there is an error reading the data.
      */
     public abstract int readUnsignedShort() throws IOException;
-    
+
     /**
      * Read an unsigned byte array.
      * 
@@ -129,16 +149,16 @@ public abstract class TTFDataStream 
      * @return An unsigned byte array.
      * @throws IOException If there is an error reading the data.
      */
-    public int[] readUnsignedByteArray( int length ) throws IOException
+    public int[] readUnsignedByteArray(int length) throws IOException
     {
-        int[] array = new int[ length ];
-        for( int i=0; i<length; i++ )
+        int[] array = new int[length];
+        for (int i = 0; i < length; i++)
         {
             array[i] = read();
         }
         return array;
     }
-    
+
     /**
      * Read an unsigned short array.
      * 
@@ -146,16 +166,16 @@ public abstract class TTFDataStream 
      * @return An unsigned short array.
      * @throws IOException If there is an error reading the data.
      */
-    public int[] readUnsignedShortArray( int length ) throws IOException
+    public int[] readUnsignedShortArray(int length) throws IOException
     {
-        int[] array = new int[ length ];
-        for( int i=0; i<length; i++ )
+        int[] array = new int[length];
+        for (int i = 0; i < length; i++)
         {
             array[i] = readUnsignedShort();
         }
         return array;
     }
-    
+
     /**
      * Read an signed short.
      * 
@@ -163,7 +183,7 @@ public abstract class TTFDataStream 
      * @throws IOException If there is an error reading the data.
      */
     public abstract short readSignedShort() throws IOException;
-    
+
     /**
      * Read an eight byte international date.
      * 
@@ -173,20 +193,20 @@ public abstract class TTFDataStream 
     public Calendar readInternationalDate() throws IOException
     {
         long secondsSince1904 = readLong();
-        GregorianCalendar cal = new GregorianCalendar( 1904, 0, 1 );
+        GregorianCalendar cal = new GregorianCalendar(1904, 0, 1);
         long millisFor1904 = cal.getTimeInMillis();
-        millisFor1904 += (secondsSince1904*1000);
-        cal.setTimeInMillis( millisFor1904 );
+        millisFor1904 += (secondsSince1904 * 1000);
+        cal.setTimeInMillis(millisFor1904);
         return cal;
     }
-    
+
     /**
      * Close the underlying resources.
      * 
      * @throws IOException If there is an error closing the resources.
      */
     public abstract void close() throws IOException;
-    
+
     /**
      * Seek into the datasource.
      * 
@@ -194,36 +214,37 @@ public abstract class TTFDataStream 
      * @throws IOException If there is an error seeking to that position.
      */
     public abstract void seek(long pos) throws IOException;
-    
+
     /**
      * Read a specific number of bytes from the stream.
+     * 
      * @param numberOfBytes The number of bytes to read.
      * @return The byte buffer.
      * @throws IOException If there is an error while reading.
      */
-    public byte[] read( int numberOfBytes ) throws IOException
+    public byte[] read(int numberOfBytes) throws IOException
     {
-        byte[] data = new byte[ numberOfBytes ];
+        byte[] data = new byte[numberOfBytes];
         int amountRead = 0;
         int totalAmountRead = 0;
-        //read at most numberOfBytes bytes from the stream.
+        // read at most numberOfBytes bytes from the stream.
         while (totalAmountRead < numberOfBytes
-                && (amountRead = read( data, totalAmountRead, numberOfBytes-totalAmountRead ) ) != -1) 
+                && (amountRead = read(data, totalAmountRead, numberOfBytes - totalAmountRead)) != -1)
         {
             totalAmountRead += amountRead;
         }
-        if (totalAmountRead == numberOfBytes) 
+        if (totalAmountRead == numberOfBytes)
         {
             return data;
-        } 
-        else 
+        }
+        else
         {
             throw new IOException("Unexpected end of TTF stream reached");
         }
     }
-    
+
     /**
-     * @see java.io.InputStream#read( byte[], int, int )
+     * @see java.io.InputStream#read(byte[], int, int )
      * 
      * @param b The buffer to write to.
      * @param off The offset into the buffer.
@@ -234,21 +255,21 @@ public abstract class TTFDataStream 
      * @throws IOException If there is an error reading from the stream.
      */
     public abstract int read(byte[] b, int off, int len) throws IOException;
-    
+
     /**
      * Get the current position in the stream.
+     * 
      * @return The current position in the stream.
      * @throws IOException If an error occurs while reading the stream.
      */
     public abstract long getCurrentPosition() throws IOException;
-    
+
     /**
-     * This will get the original data file that was used for this
-     * stream.
+     * This will get the original data file that was used for this stream.
      * 
      * @return The data that was read from.
      * @throws IOException If there is an issue reading the data.
      */
     public abstract InputStream getOriginalData() throws IOException;
 
-}
\ No newline at end of file
+}