Example usage for org.apache.pdfbox.pdmodel.font PDCIDFont getCOSObject

List of usage examples for org.apache.pdfbox.pdmodel.font PDCIDFont getCOSObject

Introduction

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

Prototype

@Override
    public COSDictionary getCOSObject() 

Source Link

Usage

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

License:Apache License

CMap getToUnicodeCMap() throws IOException {
    COSBase base = dict.getDictionaryObject(COSName.TO_UNICODE);
    if (font instanceof PDType0Font && base == null) {
        PDCIDFont cidFont = ((PDType0Font) font).getDescendantFont();
        base = cidFont.getCOSObject().getDictionaryObject(COSName.TO_UNICODE);
    }//from   w  w  w . ja v a2  s. com
    if (base instanceof COSName) {
        // predefined CMap
        String name = ((COSName) base).getName();
        CMapParser parser = new CMapParser();
        return parser.parsePredefined(name);
    } else if (base instanceof COSStream) {
        // embedded CMap
        InputStream input = null;
        try {
            input = ((COSStream) base).getUnfilteredStream();
            CMapParser parser = new CMapParser();
            return parser.parse(input);
        } finally {
            IOUtils.closeQuietly(input);
        }
    } else {
        //            throw new IOException("Expected Name or Stream");
    }
    return null;
}

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 w  w w.j  a va  2  s . 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();
}