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

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

Introduction

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

Prototype

COSName BASE_ENCODING

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

Click Source Link

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  ww . j  av  a  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 om
        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;
}