org.apache.pdfbox.pdmodel.font.PDCIDFontType2 Java Examples

The following examples show how to use org.apache.pdfbox.pdmodel.font.PDCIDFontType2. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PdfFont.java    From cat-boot with Apache License 2.0 6 votes vote down vote up
public static PdfFont registerFont(PDType0Font font) {
    String fontBaseName = font.getName();
    String fontStyle = "regular";

    if (font.getDescendantFont() instanceof PDCIDFontType2) {
        PDCIDFontType2 tmpFont = (PDCIDFontType2) font.getDescendantFont();
        NamingTable ttfNamingTable = (NamingTable) tmpFont.getTrueTypeFont().getTableMap().get("name");

        fontBaseName = ttfNamingTable.getFontFamily();
        fontStyle = ttfNamingTable.getFontSubFamily().toLowerCase();
    }

    PdfFont f;
    if (fonts.containsKey(fontBaseName)) {
        f = fonts.get(fontBaseName);
        f.addStyle(fontStyle, font);
    } else {
        f = new PdfFont(fontBaseName);
        f.addStyle(fontStyle, font);
        fonts.put(fontBaseName, f);
    }

    return f;
}
 
Example #2
Source File: TTFGlyph2D.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Constructor.
 *
 * @param type0Font Type0 font, with CIDFontType2 descendant
 */
TTFGlyph2D(PDType0Font type0Font) throws IOException
{
    this(((PDCIDFontType2)type0Font.getDescendantFont()).getTrueTypeFont(), type0Font, true);
    vectorFont = type0Font;
}
 
Example #3
Source File: PageDrawer.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * 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;
        glyph2D = new TTFGlyph2D(ttfFont);  // TTF is never null
    }
    else if (font instanceof PDType1Font)
    {
        PDType1Font pdType1Font = (PDType1Font)font;
        glyph2D = new Type1Glyph2D(pdType1Font); // T1 is never null
    }
    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)
        {
            glyph2D = new TTFGlyph2D(type0Font); // TTF is never null
        }
        else if (type0Font.getDescendantFont() instanceof PDCIDFontType0)
        {
            // a Type0 CIDFont contains CFF font
            PDCIDFontType0 cidType0Font = (PDCIDFontType0)type0Font.getDescendantFont();
            glyph2D = new CIDType0Glyph2D(cidType0Font); // todo: could be null (need incorporate fallback)
        }
    }
    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;
}