use of org.apache.fontbox.ttf.TrueTypeCollection in project pdfbox by apache.
the class FileSystemFontProvider method readTrueTypeFont.
private TrueTypeFont readTrueTypeFont(String postScriptName, File file) throws IOException {
if (file.getName().toLowerCase().endsWith(".ttc")) {
TrueTypeCollection ttc = new TrueTypeCollection(file);
TrueTypeFont ttf = ttc.getFontByName(postScriptName);
if (ttf == null) {
ttc.close();
throw new IOException("Font " + postScriptName + " not found in " + file);
}
return ttf;
} else {
TTFParser ttfParser = new TTFParser(false, true);
return ttfParser.parse(file);
}
}
use of org.apache.fontbox.ttf.TrueTypeCollection in project pdfbox-graphics2d by rototor.
the class PdfBoxGraphics2DFontTextDrawer method mapFont.
/**
* Try to map the java.awt.Font to a PDFont.
*
* @param font
* the java.awt.Font for which a mapping should be found
* @param env
* environment of the font mapper
* @return the PDFont or null if none can be found.
*/
@SuppressWarnings("WeakerAccess")
protected PDFont mapFont(final Font font, final IFontTextDrawerEnv env) throws IOException, FontFormatException {
/*
* If we have any font registering's, we must perform them now
*/
for (final FontEntry fontEntry : fontFiles) {
if (fontEntry.overrideName == null) {
Font javaFont = Font.createFont(Font.TRUETYPE_FONT, fontEntry.file);
fontEntry.overrideName = javaFont.getFontName();
}
if (fontEntry.file.getName().toLowerCase(Locale.US).endsWith(".ttc")) {
TrueTypeCollection collection = new TrueTypeCollection(fontEntry.file);
collection.processAllFonts(new TrueTypeCollection.TrueTypeFontProcessor() {
@Override
public void process(TrueTypeFont ttf) throws IOException {
PDFont pdFont = PDType0Font.load(env.getDocument(), ttf, true);
fontMap.put(fontEntry.overrideName, pdFont);
fontMap.put(pdFont.getName(), pdFont);
}
});
} else {
/*
* We load the font using the file.
*/
PDFont pdFont = PDType0Font.load(env.getDocument(), fontEntry.file);
fontMap.put(fontEntry.overrideName, pdFont);
}
}
fontFiles.clear();
return fontMap.get(font.getFontName());
}
Aggregations