Example usage for org.apache.pdfbox.cos COSName DW

List of usage examples for org.apache.pdfbox.cos COSName DW

Introduction

In this page you can find the example usage for org.apache.pdfbox.cos COSName DW.

Prototype

COSName DW

To view the source code for org.apache.pdfbox.cos COSName DW.

Click Source Link

Usage

From source file:org.apache.fop.render.pdf.pdfbox.FOPPDFMultiByteFont.java

License:Apache License

public String addFont(COSDictionary fontData) throws IOException {
    FontContainer font = getFont(fontData);
    setProperties(this, font.font);
    PDCIDFont mainFont = null;/*from ww w .  j  a  v a  2s.c  o  m*/
    TrueTypeFont ttf = null;
    if (font.font instanceof PDType0Font) {
        PDCIDFont cidFont = ((PDType0Font) font.font).getDescendantFont();
        int dw = cidFont.getCOSObject().getInt(COSName.DW);
        setDefaultWidth(dw);
        mainFont = cidFont;
        if (cidFont instanceof PDCIDFontType0) {
            setCIDType(CIDFontType.CIDTYPE0);
            setFontType(FontType.CIDTYPE0);
        } else {
            ttf = ((PDCIDFontType2) cidFont).getTrueTypeFont();
        }
    } else {
        ttf = ((PDTrueTypeFont) font.font).getTrueTypeFont();
        setDefaultWidth(1000);
    }
    GlyphData[] glyphData = new GlyphData[0];
    if (ttf != null) {
        glyphData = ttf.getGlyph().getGlyphs();
    }
    Map<Integer, Integer> oldToNewGIMap = new HashMap<Integer, Integer>();
    if (charMapGlobal.isEmpty()) {
        oldToNewGIMap.put(0, 0); // .notdef glyph
    }
    CMap c = font.getToUnicodeCMap();
    Map<Integer, String> mapping = getMapping(font, c, glyphData.length);
    //if (glyphData.length > 0 && differentGlyphData(glyphData, mapping)) {
    //    return null;
    //}
    Map<Integer, String> gidToGlyph = new TreeMap<Integer, String>(mapping);
    if (font.font instanceof PDTrueTypeFont) {
        CmapSubtable cmap = ttf.getCmap().getCmaps()[0];
        gidToGlyph.clear();
        for (int i = 1; i < glyphData.length; i++) {
            String mappedChar = mapping.get(cmap.getCharacterCode(i));
            gidToGlyph.put(i, mappedChar);
        }
    }
    readCharMap(font, gidToGlyph, glyphData, mainFont, oldToNewGIMap);
    InputStream ffr = readFontFile(font.font);
    if (mergeFonts == null) {
        if (ttf != null) {
            mergeFonts = new MergeTTFonts(null);
        } else {
            mergeFonts = new MergeCFFFonts();
        }
    }
    if (mergeFonts instanceof MergeTTFonts) {
        mergeMaxp(ttf, ((MergeTTFonts) mergeFonts).maxp);
        int sizeNoCompGlyphs = oldToNewGIMap.size();
        mergeFonts.readFont(ffr, null, null, oldToNewGIMap, true);
        if (oldToNewGIMap.size() > sizeNoCompGlyphs) {
            cidSet.mapChar(256 * 256, (char) 0);
        }
    } else {
        mergeFonts.readFont(ffr, getEmbedFontName(), null, null, true);
    }
    return getFontName();
}