Example usage for org.apache.pdfbox.pdmodel.font.encoding Encoding getCOSObject

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

Introduction

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

Prototype

COSBase getCOSObject();

Source Link

Document

Convert this standard java object to a COS object.

Usage

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

License:Apache License

String getBaseEncodingName() {
    Encoding encoding = getEncoding();
    if (encoding != null && !(encoding instanceof BuiltInEncoding)) {
        COSBase cosObject = encoding.getCOSObject();
        if (cosObject != null) {
            if (cosObject instanceof COSDictionary) {
                COSBase item = ((COSDictionary) cosObject).getItem(COSName.BASE_ENCODING);
                if (item != null) {
                    return ((COSName) item).getName();
                }//  w  w  w .  java 2s. c  om
            } else if (cosObject instanceof COSName) {
                return ((COSName) cosObject).getName();
            } else {
                throw new RuntimeException(cosObject.toString() + " not supported");
            }
        }
    }
    return null;
}

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

License:Apache License

private Map<Integer, String> getCodeToName(Encoding encoding) {
    Map<Integer, String> codeToName = new HashMap<Integer, String>();
    if (encoding != null) {
        COSBase cos = null;/*  w w w.j a v  a  2 s.  c  o  m*/
        if (!(encoding instanceof BuiltInEncoding)) {
            cos = encoding.getCOSObject();
        }
        if (cos instanceof COSDictionary) {
            COSDictionary enc = (COSDictionary) cos;
            COSName baseEncodingName = (COSName) enc.getDictionaryObject(COSName.BASE_ENCODING);
            if (baseEncodingName != null) {
                Encoding baseEncoding = Encoding.getInstance(baseEncodingName);
                codeToName.putAll(baseEncoding.getCodeToNameMap());
            }
            COSArray differences = (COSArray) enc.getDictionaryObject(COSName.DIFFERENCES);
            int currentIndex = -1;
            for (int i = 0; differences != null && i < differences.size(); i++) {
                COSBase next = differences.getObject(i);
                if (next instanceof COSNumber) {
                    currentIndex = ((COSNumber) next).intValue();
                } else if (next instanceof COSName) {
                    COSName name = (COSName) next;
                    codeToName.put(currentIndex++, name.getName());
                }
            }
        } else {
            return encoding.getCodeToNameMap();
        }
    }
    return codeToName;
}