Search in sources :

Example 1 with PDType1CFont

use of com.tom_roush.pdfbox.pdmodel.font.PDType1CFont in project PdfBox-Android by TomRoush.

the class PageDrawer method createGlyph2D.

/**
 * Provide a Glyph2D for the given font.
 *
 * @param font the font
 * @return the implementation of the Glyph2D interface for the given font
 * @throws IOException if something went wrong
 */
private Glyph2D createGlyph2D(PDFont font) throws IOException {
    Glyph2D glyph2D = fontGlyph2D.get(font);
    // Is there already a Glyph2D for the given font?
    if (glyph2D != null) {
        return glyph2D;
    }
    if (font instanceof PDTrueTypeFont) {
        PDTrueTypeFont ttfFont = (PDTrueTypeFont) font;
        // TTF is never null
        glyph2D = new TTFGlyph2D(ttfFont);
    } else if (font instanceof PDType1Font) {
        PDType1Font pdType1Font = (PDType1Font) font;
        // T1 is never null
        glyph2D = new Type1Glyph2D(pdType1Font);
    } else if (font instanceof PDType1CFont) {
        PDType1CFont type1CFont = (PDType1CFont) font;
        glyph2D = new Type1Glyph2D(type1CFont);
    } else if (font instanceof PDType0Font) {
        PDType0Font type0Font = (PDType0Font) font;
        if (type0Font.getDescendantFont() instanceof PDCIDFontType2) {
            // TTF is never null
            glyph2D = new TTFGlyph2D(type0Font);
        } else if (type0Font.getDescendantFont() instanceof PDCIDFontType0) {
            // a Type0 CIDFont contains CFF font
            PDCIDFontType0 cidType0Font = (PDCIDFontType0) type0Font.getDescendantFont();
            // todo: could be null (need incorporate fallback)
            glyph2D = new CIDType0Glyph2D(cidType0Font);
        }
    } else {
        throw new IllegalStateException("Bad font type: " + font.getClass().getSimpleName());
    }
    // cache the Glyph2D instance
    if (glyph2D != null) {
        fontGlyph2D.put(font, glyph2D);
    }
    if (glyph2D == null) {
        // todo: make sure this never happens
        throw new UnsupportedOperationException("No font for " + font.getName());
    }
    return glyph2D;
}
Also used : PDType1Font(com.tom_roush.pdfbox.pdmodel.font.PDType1Font) PDType1CFont(com.tom_roush.pdfbox.pdmodel.font.PDType1CFont) PDType0Font(com.tom_roush.pdfbox.pdmodel.font.PDType0Font) PDTrueTypeFont(com.tom_roush.pdfbox.pdmodel.font.PDTrueTypeFont) PDCIDFontType0(com.tom_roush.pdfbox.pdmodel.font.PDCIDFontType0) PDCIDFontType2(com.tom_roush.pdfbox.pdmodel.font.PDCIDFontType2)

Aggregations

PDCIDFontType0 (com.tom_roush.pdfbox.pdmodel.font.PDCIDFontType0)1 PDCIDFontType2 (com.tom_roush.pdfbox.pdmodel.font.PDCIDFontType2)1 PDTrueTypeFont (com.tom_roush.pdfbox.pdmodel.font.PDTrueTypeFont)1 PDType0Font (com.tom_roush.pdfbox.pdmodel.font.PDType0Font)1 PDType1CFont (com.tom_roush.pdfbox.pdmodel.font.PDType1CFont)1 PDType1Font (com.tom_roush.pdfbox.pdmodel.font.PDType1Font)1