Example usage for org.apache.pdfbox.pdmodel.font PDFont getType

List of usage examples for org.apache.pdfbox.pdmodel.font PDFont getType

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel.font PDFont getType.

Prototype

public String getType() 

Source Link

Document

This will always return "Font" for fonts.

Usage

From source file:org.mabb.fontverter.pdf.PdfFontExtractor.java

License:Open Source License

public static FVFont convertFont(PDFont font, FontFormat format) throws IOException {
    FVFont readFont = null;/*from   w w w  .java2 s . co  m*/

    if (font instanceof PDTrueTypeFont) {
        byte[] data = font.getFontDescriptor().getFontFile2().toByteArray();
        readFont = FontVerter.readFont(data);

    } else if (font instanceof PDType0Font) {
        readFont = convertType0FontToOpenType((PDType0Font) font);
        readFont.normalize();

    } else if (font instanceof PDType1CFont) {
        byte[] data = font.getFontDescriptor().getFontFile3().toByteArray();
        readFont = FontVerter.readFont(data);

    } else
        log.warn("Skipped font: '{}'. FontVerter does not support font type: '{}'", font.getName(),
                font.getType());

    if (readFont == null)
        return null;

    if (!readFont.isValid())
        readFont.normalize();

    return FontVerter.convertFont(readFont, format);
}

From source file:org.xmlcml.pdf2svg.AMIFont.java

License:Apache License

public AMIFont(PDFont pdFont) {
    fontDescriptor = getFontDescriptorOrDescendantFontDescriptor(pdFont);
    this.firstDescendantFont = getFirstDescendantFont(pdFont);
    this.baseFont = pdFont.getBaseFont();
    this.fontType = pdFont.getType();
    this.encoding = pdFont.getFontEncoding();
    if (encoding == null && pdFont instanceof PDType0Font) {
        pdFont = firstDescendantFont;//from   ww w  .jav a 2s.  c  o  m
        encoding = pdFont.getFontEncoding();
    }
    fontEncoding = (encoding == null) ? null : encoding.getClass().getSimpleName();
    this.pdFont = pdFont;
    fontFamilyName = null;
    if (fontDescriptor != null) {
        fontName = fontDescriptor.getFontName();

        stripFontNameComponents();
        if (fontFamilyName == null) {
            fontFamilyName = createFontFamilyFromFontName(fontName);
        }
        LOG.trace("FFFFF " + fontFamilyName);

        fontName = fontDescriptor.getFontName();
        LOG.trace("name=" + fontName + " fam=" + fontFamilyName + " type=" + pdFont.getSubType() + " bold="
                + forceBold + " it=" + isItalic() + " face=" + finalSuffix + " sym=" + isSymbolic() + " enc="
                + (encoding == null ? "null" : encoding.getClass().getSimpleName()));
    } else {
        fontName = baseFont;
        stripFontNameComponents();
        if (fontFamilyName == null) {
            fontFamilyName = fontName;
        }
        LOG.trace(this.toString());
        LOG.warn("font had no descriptor: " + baseFont + " / " + fontFamilyName);
    }
}