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

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

Introduction

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

Prototype

public String getSubType() 

Source Link

Document

This will get the subtype of font.

Usage

From source file:net.padaf.preflight.font.AbstractFontValidator.java

License:Apache License

protected AbstractFontContainer instanciateContainer(PDFont fd) {
    String subtype = fd.getSubType();
    if (FONT_DICTIONARY_VALUE_TRUETYPE.equals(subtype)) {
        return new TrueTypeFontContainer(fd);
    } else if (FONT_DICTIONARY_VALUE_MMTYPE.equals(subtype)) {
        return new Type1FontContainer(fd);
    } else if (FONT_DICTIONARY_VALUE_TYPE1.equals(subtype)) {
        return new Type1FontContainer(fd);
    } else if (FONT_DICTIONARY_VALUE_TYPE3.equals(subtype)) {
        return new Type3FontContainer(fd);
    } else if (FONT_DICTIONARY_VALUE_COMPOSITE.equals(subtype)) {
        return new CompositeFontContainer(fd);
    } else {/*from w w w  . ja  va  2  s  . c o  m*/
        return new UndefFontContainer(fd);
    }
}

From source file:no.digipost.print.validate.PdfValidator.java

License:Apache License

private List<String> describe(Iterable<PDFont> fonts) {
    List<String> fontDescriptions = new ArrayList<>();
    for (PDFont font : fonts) {
        fontDescriptions.add(font.getSubType() + " '" + font.getBaseFont() + "'");
    }/* w  w w .j  ava2 s.c  o  m*/
    return fontDescriptions;
}

From source file:org.elacin.pdfextract.datasource.pdfbox.Fonts.java

License:Apache License

private FontInfo getFontInfo(@NotNull PDFont pdFont) {

    if (fontInfoCache.containsKey(pdFont)) {
        return fontInfoCache.get(pdFont);
    }/*from w w  w.  j  av  a  2  s.  c om*/

    /* find the appropriate font name to use  - baseFont might sometimes be null */
    String font;

    if (pdFont.getBaseFont() == null) {
        font = pdFont.getSubType();
    } else {
        font = pdFont.getBaseFont();
    }

    /*
     *  a lot of embedded fonts have names like XCSFS+Times, so remove everything before and
     * including '+'
     */
    final int plusIndex = font.indexOf('+');

    if (plusIndex != -1) {
        font = font.substring(plusIndex + 1, font.length());
    }

    boolean mathFont = (font.length() > 4) && mathFonts.contains(font.substring(0, 4));
    boolean bold = font.toLowerCase().contains("bold");
    boolean italic = font.toLowerCase().contains("italic");

    /* ignore information after this */
    final int idx = font.indexOf(',');

    if (idx != -1) {
        font = font.substring(0, idx);
    }

    /* make a distinction between type3 fonts which usually have no name */
    if ((pdFont instanceof PDType3Font) && (pdFont.getBaseFont() == null)) {
        font = "Type3[" + Integer.toHexString(pdFont.hashCode()) + "]";
    }

    /**
     * Find the plain font name, without any other information
     * Three typical font names can be:
     * - LPPMinionUnicode-Italic
     * - LPPMyriadCondLightUnicode (as apposed to for example LPPMyriadCondUnicode and
     * LPPMyriadLightUnicode-Bold)
     * - Times-Bold (Type1)
     *
     * I want to separate the LPPMinion part for example from the first, so i look for the
     *  index of the first capital letter after a small one.
     *  Also stop if we reach an '-' or whitespace, as that is a normal separators
     */

    // LPPMinionUnicode-Italic
    final String[] fontParts = font.split("[-,]");
    final String subType;

    if (fontParts.length > 1) {
        subType = fontParts[1];
    } else {
        subType = "";
    }

    font = fontParts[0];

    /* this is latex specific */
    if (font.contains("CMBX")) {
        font = font.replace("CMBX", "CMR");
        bold = true;
        italic = false;
    } else if (font.contains("CMTI")) {
        font = font.replace("CMTI", "CMR");
        bold = false;
        italic = true;
    }

    final FontInfo fi = new FontInfo();

    fi.font = font;
    fi.subType = subType;
    fi.bold = bold;
    fi.italic = italic;
    fi.mathFont = mathFont;
    fontInfoCache.put(pdFont, fi);

    return fi;
}

From source file:org.xmlcml.font.NonStandardFontManager.java

License:Apache License

public AMIFont getAmiFontByFont(PDFont pdFont) {
    ensureAMIFontMaps();//from   w  w  w.ja  v  a 2  s. com
    String fontName = null;
    AMIFont amiFont = null;
    fontName = getFontName(pdFont);
    if (fontName == null) {
        throw new RuntimeException("No currentFontName");
    }
    amiFont = amiFontByFontNameMap.get(fontName);
    if (amiFont == null) {
        if (pdFont instanceof PDType1Font || pdFont instanceof PDTrueTypeFont || pdFont instanceof PDType0Font
                || pdFont instanceof PDType3Font) {
            amiFont = new AMIFont(pdFont);
            amiFontByFontNameMap.put(fontName, amiFont);
            String fontFamilyName = amiFont.getFontFamilyName();
            amiFont.setNonStandardFontFamily(this.getFontFamilyByFamilyName(fontFamilyName));
            recordExistingOrAddNewFontFamily(fontFamilyName, amiFont);
        } else {
            throw new RuntimeException("Cannot find font type: " + pdFont + " / " + pdFont.getSubType() + ", ");
        }
    }
    return amiFont;
}

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   w  w w .  j ava  2 s .  c om*/
        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);
    }
}