Search in sources :

Example 76 with COSName

use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.

the class PDType0Font method readEncoding.

/**
 * Reads the font's Encoding entry, which should be a CMap name/stream.
 */
private void readEncoding() throws IOException {
    COSBase encoding = dict.getDictionaryObject(COSName.ENCODING);
    if (encoding instanceof COSName) {
        // predefined CMap
        COSName encodingName = (COSName) encoding;
        cMap = CMapManager.getPredefinedCMap(encodingName.getName());
        if (cMap != null) {
            isCMapPredefined = true;
        } else {
            throw new IOException("Missing required CMap");
        }
    } else if (encoding != null) {
        cMap = readCMap(encoding);
        if (cMap == null) {
            throw new IOException("Missing required CMap");
        } else if (!cMap.hasCIDMappings()) {
            Log.w("PdfBox-Android", "Invalid Encoding CMap in font " + getName());
        }
    }
    // check if the descendant font is CJK
    PDCIDSystemInfo ros = descendantFont.getCIDSystemInfo();
    if (ros != null) {
        isDescendantCJK = "Adobe".equals(ros.getRegistry()) && ("GB1".equals(ros.getOrdering()) || "CNS1".equals(ros.getOrdering()) || "Japan1".equals(ros.getOrdering()) || "Korea1".equals(ros.getOrdering()));
    }
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) COSBase(com.tom_roush.pdfbox.cos.COSBase) IOException(java.io.IOException)

Example 77 with COSName

use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.

the class PDType3Font method readEncoding.

@Override
protected final void readEncoding() throws IOException {
    COSBase encodingBase = dict.getDictionaryObject(COSName.ENCODING);
    if (encodingBase instanceof COSName) {
        COSName encodingName = (COSName) encodingBase;
        encoding = Encoding.getInstance(encodingName);
        if (encoding == null) {
            Log.w("PdfBox-Android", "Unknown encoding: " + encodingName.getName());
        }
    } else if (encodingBase instanceof COSDictionary) {
        encoding = new DictionaryEncoding((COSDictionary) encodingBase);
    }
    glyphList = GlyphList.getAdobeGlyphList();
}
Also used : DictionaryEncoding(com.tom_roush.pdfbox.pdmodel.font.encoding.DictionaryEncoding) COSName(com.tom_roush.pdfbox.cos.COSName) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 78 with COSName

use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.

the class PDType3Font method generateBoundingBox.

private BoundingBox generateBoundingBox() {
    PDRectangle rect = getFontBBox();
    if (rect.getLowerLeftX() == 0 && rect.getLowerLeftY() == 0 && rect.getUpperRightX() == 0 && rect.getUpperRightY() == 0) {
        // Plan B: get the max bounding box of the glyphs
        COSDictionary cp = getCharProcs();
        for (COSName name : cp.keySet()) {
            COSBase base = cp.getDictionaryObject(name);
            if (base instanceof COSStream) {
                PDType3CharProc charProc = new PDType3CharProc(this, (COSStream) base);
                try {
                    PDRectangle glyphBBox = charProc.getGlyphBBox();
                    if (glyphBBox == null) {
                        continue;
                    }
                    rect.setLowerLeftX(Math.min(rect.getLowerLeftX(), glyphBBox.getLowerLeftX()));
                    rect.setLowerLeftY(Math.min(rect.getLowerLeftY(), glyphBBox.getLowerLeftY()));
                    rect.setUpperRightX(Math.max(rect.getUpperRightX(), glyphBBox.getUpperRightX()));
                    rect.setUpperRightY(Math.max(rect.getUpperRightY(), glyphBBox.getUpperRightY()));
                } catch (IOException ex) {
                // ignore
                }
            }
        }
    }
    return new BoundingBox(rect.getLowerLeftX(), rect.getLowerLeftY(), rect.getUpperRightX(), rect.getUpperRightY());
}
Also used : COSStream(com.tom_roush.pdfbox.cos.COSStream) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSName(com.tom_roush.pdfbox.cos.COSName) BoundingBox(com.tom_roush.fontbox.util.BoundingBox) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle) IOException(java.io.IOException)

Example 79 with COSName

use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.

the class DictionaryEncoding method applyDifferences.

private void applyDifferences() {
    // now replace with the differences
    COSBase base = encoding.getDictionaryObject(COSName.DIFFERENCES);
    if (!(base instanceof COSArray)) {
        return;
    }
    COSArray diffArray = (COSArray) base;
    int currentIndex = -1;
    for (int i = 0; i < diffArray.size(); i++) {
        COSBase next = diffArray.getObject(i);
        if (next instanceof COSNumber) {
            currentIndex = ((COSNumber) next).intValue();
        } else if (next instanceof COSName) {
            COSName name = (COSName) next;
            overwrite(currentIndex, name.getName());
            this.differences.put(currentIndex, name.getName());
            currentIndex++;
        }
    }
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSName(com.tom_roush.pdfbox.cos.COSName) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 80 with COSName

use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.

the class PDFontDescriptor method getFontName.

/**
 * Get the font name.
 *
 * @return The name of the font.
 */
public String getFontName() {
    String retval = null;
    COSBase base = dic.getDictionaryObject(COSName.FONT_NAME);
    if (base instanceof COSName) {
        retval = ((COSName) base).getName();
    }
    return retval;
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) COSBase(com.tom_roush.pdfbox.cos.COSBase) COSString(com.tom_roush.pdfbox.cos.COSString)

Aggregations

COSName (com.tom_roush.pdfbox.cos.COSName)83 COSBase (com.tom_roush.pdfbox.cos.COSBase)50 COSArray (com.tom_roush.pdfbox.cos.COSArray)27 IOException (java.io.IOException)24 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)23 COSObject (com.tom_roush.pdfbox.cos.COSObject)11 COSString (com.tom_roush.pdfbox.cos.COSString)11 HashMap (java.util.HashMap)10 Map (java.util.Map)10 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)9 COSStream (com.tom_roush.pdfbox.cos.COSStream)7 PDFormXObject (com.tom_roush.pdfbox.pdmodel.graphics.form.PDFormXObject)7 MissingOperandException (com.tom_roush.pdfbox.contentstream.operator.MissingOperandException)5 COSInteger (com.tom_roush.pdfbox.cos.COSInteger)5 COSNumber (com.tom_roush.pdfbox.cos.COSNumber)5 PDXObject (com.tom_roush.pdfbox.pdmodel.graphics.PDXObject)5 PDRectangle (com.tom_roush.pdfbox.pdmodel.common.PDRectangle)4 PDTransparencyGroup (com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup)4 OutputStream (java.io.OutputStream)4 Operator (com.tom_roush.pdfbox.contentstream.operator.Operator)3