Author: tilman Date: Fri Mar 19 19:27:19 2021 New Revision: 1887823 URL: http://svn.apache.org/viewvc?rev=1887823&view=rev Log: PDFBOX-5135: don't ignore glyphs with 0 contours because these may be used by composite glyphs
Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfSimpleDescript.java pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphData.java pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java 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=1887823&r1=1887822&r2=1887823&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 Fri Mar 19 19:27:19 2021 @@ -41,6 +41,17 @@ public class GlyfSimpleDescript extends private final int pointCount; /** + * Constructor for an empty description. + * + * @throws IOException is thrown if something went wrong + */ + GlyfSimpleDescript() throws IOException + { + super((short) 0, null); + pointCount = 0; + } + + /** * Constructor. * * @param numberOfContours number of contours Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphData.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphData.java?rev=1887823&r1=1887822&r2=1887823&view=diff ============================================================================== --- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphData.java (original) +++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphData.java Fri Mar 19 19:27:19 2021 @@ -65,7 +65,18 @@ public class GlyphData glyphDescription = new GlyfCompositeDescript(data, glyphTable); } } - + + /** + * Initialize an empty glyph record. + * + * @throws IOException + */ + void initEmptyData() throws IOException + { + glyphDescription = new GlyfSimpleDescript(); + boundingBox = new BoundingBox(); + } + /** * @return Returns the boundingBox. */ 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=1887823&r1=1887822&r2=1887823&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 Fri Mar 19 19:27:19 2021 @@ -82,7 +82,10 @@ public class GlyphTable extends TTFTable * Returns all glyphs. This method can be very slow. * * @throws IOException If there is an error reading the data. + * @deprecated use {@link #getGlyph(int)} instead. This will be removed in 3.0. If you need this + * method, please create an issue in JIRA. */ + @Deprecated public GlyphData[] getGlyphs() throws IOException { // PDFBOX-4219: synchronize on data because it is accessed by several threads @@ -161,6 +164,8 @@ public class GlyphTable extends TTFTable return glyphs[gid]; } + GlyphData glyph; + // PDFBOX-4219: synchronize on data because it is accessed by several threads // when PDFBox is accessing a standard 14 font for the first time synchronized (data) @@ -171,18 +176,23 @@ public class GlyphTable extends TTFTable if (offsets[gid] == offsets[gid + 1]) { // no outline - return null; + // PDFBOX-5135: can't return null, must return an empty glyph because + // sometimes this is used in a composite glyph. + glyph = new GlyphData(); + glyph.initEmptyData(); } - - // save - long currentPosition = data.getCurrentPosition(); + else + { + // save + long currentPosition = data.getCurrentPosition(); - data.seek(getOffset() + offsets[gid]); + data.seek(getOffset() + offsets[gid]); - GlyphData glyph = getGlyphData(gid); + glyph = getGlyphData(gid); - // restore - data.seek(currentPosition); + // restore + data.seek(currentPosition); + } if (glyphs != null && glyphs[gid] == null && cached < MAX_CACHED_GLYPHS) {