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 2012/04/15 13:31:14 UTC
svn commit: r1326311 - in
/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf:
GlyfCompositeDescript.java GlyfDescript.java GlyfSimpleDescript.java
GlyphTable.java
Author: lehmi
Date: Sun Apr 15 11:31:14 2012
New Revision: 1326311
URL: http://svn.apache.org/viewvc?rev=1326311&view=rev
Log:
PDFBOX-490, PDFBOX-1265: fixed the TTF parser to avoid an OOM exception including a patch proposed by Eric Leleu
Modified:
pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeDescript.java
pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfDescript.java
pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfSimpleDescript.java
pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.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=1326311&r1=1326310&r2=1326311&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 Apr 15 11:31:14 2012
@@ -247,6 +247,10 @@ public class GlyfCompositeDescript exten
private GlyphDescription getGlypDescription(int index)
{
- return glyphs[index].getDescription();
+ if (glyphs != null && index < glyphs.length)
+ {
+ return glyphs[index].getDescription();
+ }
+ return null;
}
}
Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfDescript.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfDescript.java?rev=1326311&r1=1326310&r2=1326311&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfDescript.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfDescript.java Sun Apr 15 11:31:14 2012
@@ -65,7 +65,7 @@ public abstract class GlyfDescript imple
*/
public static final byte Y_DUAL = 0x20;
- private short[] instructions;
+ private int[] instructions;
private int contourCount;
/**
@@ -99,7 +99,7 @@ public abstract class GlyfDescript imple
* Returns the hinting instructions.
* @return an array containing the hinting instructions.
*/
- public short[] getInstructions()
+ public int[] getInstructions()
{
return instructions;
}
@@ -112,11 +112,8 @@ public abstract class GlyfDescript imple
*/
protected void readInstructions(TTFDataStream bais, int count) throws IOException
{
- instructions = new short[count];
- for (int i = 0; i < count; i++)
- {
- instructions[i] = (short) bais.read();
- }
+ instructions = new int[count];
+ instructions = bais.readUnsignedByteArray(count);
}
}
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=1326311&r1=1326310&r2=1326311&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 Sun Apr 15 11:31:14 2012
@@ -44,20 +44,29 @@ public class GlyfSimpleDescript extends
{
super(numberOfContours, bais);
- // Simple glyph description
- endPtsOfContours = new int[numberOfContours];
- for (int i = 0; i < numberOfContours; i++)
+ /* 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)
{
- endPtsOfContours[i] = bais.readSignedShort();
+ pointCount = 0;
+ return;
}
+ // Simple glyph description
+ endPtsOfContours = new int[numberOfContours];
+ 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];
- int instructionCount = bais.readSignedShort();
+ int instructionCount = bais.readUnsignedShort();
readInstructions(bais, instructionCount);
readFlags(pointCount, bais);
readCoords(pointCount, bais);
Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java?rev=1326311&r1=1326310&r2=1326311&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java Sun Apr 15 11:31:14 2012
@@ -44,15 +44,31 @@ public class GlyphTable extends TTFTable
{
MaximumProfileTable maxp = ttf.getMaximumProfile();
IndexToLocationTable loc = ttf.getIndexToLocation();
+ // the glyph offsets
long[] offsets = loc.getOffsets();
+ // number of glyphs
int numGlyphs = maxp.getNumGlyphs();
+ // the end of the glyph table
+ long endOfGlyphs = offsets[numGlyphs];
+ long currentOffset = -1;
+ long offset = getOffset();
glyphs = new GlyphData[numGlyphs];
for( int i=0; i<numGlyphs; i++ )
{
- GlyphData glyph = new GlyphData();
- data.seek( getOffset() + offsets[i] );
- glyph.initData( ttf, data );
- glyphs[i] = glyph;
+ // end of glyphs reached?
+ if (endOfGlyphs == offsets[i])
+ {
+ break;
+ }
+ // don't repeat glyphs
+ if (currentOffset == offsets[i])
+ {
+ continue;
+ }
+ currentOffset = offsets[i];
+ glyphs[i] = new GlyphData();
+ data.seek( offset + offsets[i] );
+ glyphs[i].initData( ttf, data );
}
for( int i=0; i<numGlyphs; i++ )
{