PDFontDescriptor fd = getFontDescriptor();
PDStream ff2Stream = fd.getFontFile2();
PDStream ff3Stream = fd.getFontFile3();
TrueTypeFont ttfFont = null;
boolean fontIsDamaged = false;
if (ff2Stream != null)
{
try
{
// embedded
TTFParser ttfParser = new TTFParser(true);
ttfFont = ttfParser.parse(ff2Stream.createInputStream());
}
catch (NullPointerException e) // TTF parser is buggy
{
LOG.warn("Could not read embedded TTF for font " + getBaseFont(), e);
fontIsDamaged = true;
}
catch (IOException e)
{
LOG.warn("Could not read embedded TTF for font " + getBaseFont(), e);
fontIsDamaged = true;
}
}
else if (ff3Stream != null)
{
try
{
// embedded
OTFParser otfParser = new OTFParser(true);
OpenTypeFont otf = otfParser.parse(ff3Stream.createInputStream());
ttfFont = otf;
if (otf.isPostScript())
{
// todo: we need more abstraction to support CFF fonts here
throw new IOException("Not implemented: OpenType font with CFF table " +
getBaseFont());
}
if (otf.hasLayoutTables())
{
LOG.error("OpenType Layout tables used in font " + getBaseFont() +
" are not implemented in PDFBox and will be ignored");
}
}
catch (NullPointerException e) // TTF parser is buggy
{
fontIsDamaged = true;
LOG.warn("Could not read embedded OTF for font " + getBaseFont(), e);
}
catch (IOException e)
{
fontIsDamaged = true;
LOG.warn("Could not read embedded OTF for font " + getBaseFont(), e);
}
}
isEmbedded = ttfFont != null;
isDamaged = fontIsDamaged;
if (ttfFont == null)
{
// substitute
TrueTypeFont ttfSubstitute = ExternalFonts.getTrueTypeFont(getBaseFont());
if (ttfSubstitute != null)
{
ttfFont = ttfSubstitute;
}
else