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

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

Introduction

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

Prototype

COSName DIFFERENCES

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

Click Source Link

Usage

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;/*from w  ww .  j  a va 2  s  .  co 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;
}