Search in sources :

Example 1 with OTFParser

use of org.apache.fontbox.ttf.OTFParser in project pdfbox by apache.

the class FileSystemFontProvider method getOTFFont.

private OpenTypeFont getOTFFont(String postScriptName, File file) {
    try {
        // todo JH: we don't yet support loading CFF fonts from OTC collections
        OTFParser parser = new OTFParser(false, true);
        OpenTypeFont otf = parser.parse(file);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Loaded " + postScriptName + " from " + file);
        }
        return otf;
    } catch (IOException e) {
        LOG.error("Could not load font file: " + file, e);
    }
    return null;
}
Also used : OTFParser(org.apache.fontbox.ttf.OTFParser) OpenTypeFont(org.apache.fontbox.ttf.OpenTypeFont) IOException(java.io.IOException)

Example 2 with OTFParser

use of org.apache.fontbox.ttf.OTFParser in project pdfbox by apache.

the class FileSystemFontProvider method addTrueTypeFont.

/**
 * Adds an OTF or TTF font to the file cache. To reduce memory, the parsed font is not cached.
 */
private void addTrueTypeFont(File ttfFile) throws IOException {
    try {
        if (ttfFile.getPath().toLowerCase().endsWith(".otf")) {
            OTFParser parser = new OTFParser(false, true);
            OpenTypeFont otf = parser.parse(ttfFile);
            addTrueTypeFontImpl(otf, ttfFile);
        } else {
            TTFParser parser = new TTFParser(false, true);
            TrueTypeFont ttf = parser.parse(ttfFile);
            addTrueTypeFontImpl(ttf, ttfFile);
        }
    } catch (IOException e) {
        LOG.warn("Could not load font file: " + ttfFile, e);
    }
}
Also used : TrueTypeFont(org.apache.fontbox.ttf.TrueTypeFont) OTFParser(org.apache.fontbox.ttf.OTFParser) OpenTypeFont(org.apache.fontbox.ttf.OpenTypeFont) IOException(java.io.IOException) TTFParser(org.apache.fontbox.ttf.TTFParser)

Aggregations

IOException (java.io.IOException)2 OTFParser (org.apache.fontbox.ttf.OTFParser)2 OpenTypeFont (org.apache.fontbox.ttf.OpenTypeFont)2 TTFParser (org.apache.fontbox.ttf.TTFParser)1 TrueTypeFont (org.apache.fontbox.ttf.TrueTypeFont)1