Hi,

Am 28.01.13 23:06, schrieb Leleu Eric:
Hi,


I'm currently working on the PDFBOX-1398 [1] issue.
An ArrayOutOfBound Exception is thrown on TrueType font file parsing. (A
embedded fontfile in the CIDType2Font dictionary)

The problem comes from the "glyphIdToCharacterCode" array that haven't the
right size in the "processSubtype4" method.
(This array is initialized with "new int[numGlyphs]" where numGlyphs
contains the number of glyph present in the MaxProfile table of the Font)

At the beginning, I thought that the font was damaged, but in the TrueType
Font specification [2] there is this comment for the glyphIdArray
description in the SubType4 for the CMap table : Glyph index array
(arbitrary length)

Does that mean the GlyphIdArray doesn't have a size based on the number of
declared glyphs in the MaxProfile table and can have some glyph identifiers
that will be mapped on the ".notdef" glyph if this index is used ?
AFAIU the spec that assumption is correct.

In other words, can we extend the "glyphIdToCharacterCode" if the computed
glyph index is bigger than the length of array (see example here after) ? I
didn't see any error on variables initialization in this method that could
explain a wrong size of array and the extracted font stream seems to be a
valid font when I open it with FontForge.

                         int glyphid = (j+delta)%65536;
                         if (glyphid >= glyphIdToCharacterCode.length) {
                             glyphIdToCharacterCode =
Arrays.copyOf(glyphIdToCharacterCode, glyphid+1);
                         }
                         glyphIdToCharacterCode[ glyphid ]=j;
                         characterCodeToGlyphId.put(j, glyphid);


An other possibility is throwing an explicit  RuntimeException specifying
that the number of glyph inside the FontFile is inconsistent.

What is your opinion?
How about using HashMap to temporarily store the glyph mapping? At the
end you are able to determine the correct size of the array (max glyph
id). It can be initialized using the ".nodef" character and be filled
with the mappings calculated before. The result should be an array with
several ranges of glyph mappings divided by one or more ".notdef"
characters.

BR,
Eric

[1] https://issues.apache.org/jira/browse/PDFBOX-1398
[2] http://www.microsoft.com/typography/otspec/cmap.htm


BR
Andreas Lehmkühler

Reply via email to