in fontbox/src/main/java/org/apache/fontbox/ttf/PostScriptTable.java [61:176]
void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
{
formatType = data.read32Fixed();
italicAngle = data.read32Fixed();
underlinePosition = data.readSignedShort();
underlineThickness = data.readSignedShort();
isFixedPitch = data.readUnsignedInt();
minMemType42 = data.readUnsignedInt();
maxMemType42 = data.readUnsignedInt();
mimMemType1 = data.readUnsignedInt();
maxMemType1 = data.readUnsignedInt();
if (data.getCurrentPosition() == data.getOriginalDataSize())
{
LOG.warn("No PostScript name data is provided for the font {}", ttf.getName());
}
else if (Float.compare(formatType, 1.0f) == 0)
{
// This TrueType font file contains exactly the 258 glyphs in the standard Macintosh TrueType.
glyphNames = WGL4Names.getAllNames();
}
else if (Float.compare(formatType, 2.0f) == 0)
{
int numGlyphs = data.readUnsignedShort();
int[] glyphNameIndex = new int[numGlyphs];
glyphNames = new String[numGlyphs];
int maxIndex = Integer.MIN_VALUE;
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)
{
maxIndex = Math.max(maxIndex, index);
}
}
String[] nameArray = null;
if (maxIndex >= WGL4Names.NUMBER_OF_MAC_GLYPHS)
{
nameArray = new String[maxIndex - WGL4Names.NUMBER_OF_MAC_GLYPHS + 1];
for (int i = 0; i < nameArray.length; i++)
{
int numberOfChars = data.readUnsignedByte();
try
{
nameArray[i] = data.readString(numberOfChars);
}
catch (IOException ex)
{
// PDFBOX-4851: EOF
LOG.warn(
"Error reading names in PostScript table at entry {} of {}, setting remaining entries to .notdef",
i, nameArray.length, ex);
for (int j = i; j < nameArray.length; ++j)
{
nameArray[j] = ".notdef";
}
break;
}
}
}
for (int i = 0; i < numGlyphs; i++)
{
int index = glyphNameIndex[i];
if (index >= 0 && index < WGL4Names.NUMBER_OF_MAC_GLYPHS)
{
glyphNames[i] = WGL4Names.getGlyphName(index);
}
else if (index >= WGL4Names.NUMBER_OF_MAC_GLYPHS && index <= 32767 && nameArray != null)
{
glyphNames[i] = nameArray[index - WGL4Names.NUMBER_OF_MAC_GLYPHS];
}
else
{
// PDFBOX-808: Index numbers between 32768 and 65535 are
// reserved for future use, so we should just ignore them
glyphNames[i] = ".undefined";
}
}
}
else if (Float.compare(formatType, 2.5f) == 0)
{
int[] glyphNameIndex = new int[ttf.getNumberOfGlyphs()];
for (int i = 0; i < glyphNameIndex.length; i++)
{
int offset = data.readSignedByte();
glyphNameIndex[i] = i + 1 + offset;
}
glyphNames = new String[glyphNameIndex.length];
for (int i = 0; i < glyphNames.length; i++)
{
int index = glyphNameIndex[i];
if (index >= 0 && index < WGL4Names.NUMBER_OF_MAC_GLYPHS)
{
String name = WGL4Names.getGlyphName(index);
if (name != null)
{
glyphNames[i] = name;
}
}
else
{
LOG.debug("incorrect glyph name index {}, valid numbers 0..{}",
index, WGL4Names.NUMBER_OF_MAC_GLYPHS);
}
}
}
else if (Float.compare(formatType, 3.0f) == 0)
{
// no postscript information is provided.
LOG.debug("No PostScript name information is provided for the font {}", ttf.getName());
}
initialized = true;
}