in pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java [607:710]
public int codeToGID(int code) throws IOException
{
extractCmapTable();
int gid = 0;
if (!isSymbolic()) // non-symbolic
{
String name = encoding.getName(code);
if (".notdef".equals(name))
{
return 0;
}
else
{
// (3, 1) - (Windows, Unicode)
if (cmapWinUnicode != null)
{
String unicode = GlyphList.getAdobeGlyphList().toUnicode(name);
if (unicode != null)
{
int uni = unicode.codePointAt(0);
gid = cmapWinUnicode.getGlyphId(uni);
}
}
// (1, 0) - (Macintosh, Roman)
if (gid == 0 && cmapMacRoman != null)
{
Integer macCode = INVERTED_MACOS_ROMAN.get(name);
if (macCode != null)
{
gid = cmapMacRoman.getGlyphId(macCode);
}
}
// 'post' table
if (gid == 0)
{
gid = ttf.nameToGID(name);
}
}
}
else // symbolic
{
// PDFBOX-4755 / PDF.js #5501
// PDFBOX-3965: fallback for font has that the symbol flag but isn't
if (cmapWinUnicode != null)
{
if (encoding instanceof WinAnsiEncoding || encoding instanceof MacRomanEncoding)
{
String name = encoding.getName(code);
if (".notdef".equals(name))
{
return 0;
}
String unicode = GlyphList.getAdobeGlyphList().toUnicode(name);
if (unicode != null)
{
int uni = unicode.codePointAt(0);
gid = cmapWinUnicode.getGlyphId(uni);
}
}
else
{
gid = cmapWinUnicode.getGlyphId(code);
}
}
// (3, 0) - (Windows, Symbol)
if (gid == 0 && cmapWinSymbol != null)
{
gid = cmapWinSymbol.getGlyphId(code);
if (code >= 0 && code <= 0xFF)
{
// the CMap may use one of the following code ranges,
// so that we have to add the high byte to get the
// mapped value
if (gid == 0)
{
// F000 - F0FF
gid = cmapWinSymbol.getGlyphId(code + START_RANGE_F000);
}
if (gid == 0)
{
// F100 - F1FF
gid = cmapWinSymbol.getGlyphId(code + START_RANGE_F100);
}
if (gid == 0)
{
// F200 - F2FF
gid = cmapWinSymbol.getGlyphId(code + START_RANGE_F200);
}
}
}
// (1, 0) - (Mac, Roman)
if (gid == 0 && cmapMacRoman != null)
{
gid = cmapMacRoman.getGlyphId(code);
}
}
return gid;
}