Search in sources :

Example 71 with COSName

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

the class BeginMarkedContentSequenceWithProperties method process.

@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
    COSName tag = null;
    COSDictionary properties = null;
    for (COSBase argument : arguments) {
        if (argument instanceof COSName) {
            tag = (COSName) argument;
        } else if (argument instanceof COSDictionary) {
            properties = (COSDictionary) argument;
        }
    }
    context.beginMarkedContentSequence(tag, properties);
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 72 with COSName

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

the class SetStrokingColorSpace method process.

@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
    COSBase base = arguments.get(0);
    if (!(base instanceof COSName)) {
        return;
    }
    PDColorSpace cs = context.getResources().getColorSpace((COSName) base);
    context.getGraphicsState().setStrokingColorSpace(cs);
    context.getGraphicsState().setStrokingColor(cs.getInitialColor());
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDColorSpace(com.tom_roush.pdfbox.pdmodel.graphics.color.PDColorSpace)

Example 73 with COSName

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

the class SetNonStrokingColorSpace method process.

@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
    COSName name = (COSName) arguments.get(0);
    PDColorSpace cs = context.getResources().getColorSpace(name);
    context.getGraphicsState().setNonStrokingColorSpace(cs);
    context.getGraphicsState().setNonStrokingColor(cs.getInitialColor());
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) PDColorSpace(com.tom_roush.pdfbox.pdmodel.graphics.color.PDColorSpace)

Example 74 with COSName

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

the class PDSimpleFont method readEncoding.

/**
 * Reads the Encoding from the Font dictionary or the embedded or substituted font file.
 * Must be called at the end of any subclass constructors.
 *
 * @throws IOException if the font file could not be read
 */
protected void readEncoding() throws IOException {
    COSBase encoding = dict.getDictionaryObject(COSName.ENCODING);
    if (encoding != null) {
        if (encoding instanceof COSName) {
            COSName encodingName = (COSName) encoding;
            this.encoding = Encoding.getInstance(encodingName);
            if (this.encoding == null) {
                Log.w("PdfBox-Android", "Unknown encoding: " + encodingName.getName());
                // fallback
                this.encoding = readEncodingFromFont();
            }
        } else if (encoding instanceof COSDictionary) {
            COSDictionary encodingDict = (COSDictionary) encoding;
            Encoding builtIn = null;
            Boolean symbolic = getSymbolicFlag();
            boolean isFlaggedAsSymbolic = symbolic != null && symbolic;
            COSName baseEncoding = encodingDict.getCOSName(COSName.BASE_ENCODING);
            boolean hasValidBaseEncoding = baseEncoding != null && Encoding.getInstance(baseEncoding) != null;
            if (!hasValidBaseEncoding && isFlaggedAsSymbolic) {
                builtIn = readEncodingFromFont();
            }
            if (symbolic == null) {
                symbolic = false;
            }
            this.encoding = new DictionaryEncoding(encodingDict, !symbolic, builtIn);
        }
    } else {
        this.encoding = readEncodingFromFont();
    }
    // normalise the standard 14 name, e.g "Symbol,Italic" -> "Symbol"
    String standard14Name = Standard14Fonts.getMappedFontName(getName());
    // assign the glyph list based on the font
    if ("ZapfDingbats".equals(standard14Name)) {
        glyphList = GlyphList.getZapfDingbats();
    } else {
        // StandardEncoding and Symbol are in the AGL
        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) MacRomanEncoding(com.tom_roush.pdfbox.pdmodel.font.encoding.MacRomanEncoding) WinAnsiEncoding(com.tom_roush.pdfbox.pdmodel.font.encoding.WinAnsiEncoding) Encoding(com.tom_roush.pdfbox.pdmodel.font.encoding.Encoding) DictionaryEncoding(com.tom_roush.pdfbox.pdmodel.font.encoding.DictionaryEncoding) StandardEncoding(com.tom_roush.pdfbox.pdmodel.font.encoding.StandardEncoding)

Example 75 with COSName

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

the class PDType0Font method fetchCMapUCS2.

/**
 * Fetches the corresponding UCS2 CMap if the font's CMap is predefined.
 */
private void fetchCMapUCS2() throws IOException {
    // if the font is composite and uses a predefined cmap (excluding Identity-H/V)
    // or whose descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
    // Adobe-Korea1 character collection:
    COSName name = dict.getCOSName(COSName.ENCODING);
    if (isCMapPredefined && !(name == COSName.IDENTITY_H || name == COSName.IDENTITY_V) || isDescendantCJK) {
        // a) Map the character code to a CID using the font's CMap
        // b) Obtain the ROS from the font's CIDSystemInfo
        // c) Construct a second CMap name by concatenating the ROS in the format "R-O-UCS2"
        // d) Obtain the CMap with the constructed name
        // e) Map the CID according to the CMap from step d), producing a Unicode value
        // todo: not sure how to interpret the PDF spec here, do we always override? or only when Identity-H/V?
        String strName = null;
        if (isDescendantCJK) {
            strName = descendantFont.getCIDSystemInfo().getRegistry() + "-" + descendantFont.getCIDSystemInfo().getOrdering() + "-" + descendantFont.getCIDSystemInfo().getSupplement();
        } else if (name != null) {
            strName = name.getName();
        }
        // try to find the corresponding Unicode (UC2) CMap
        if (strName != null) {
            CMap prdCMap = CMapManager.getPredefinedCMap(strName);
            String ucs2Name = prdCMap.getRegistry() + "-" + prdCMap.getOrdering() + "-UCS2";
            cMapUCS2 = CMapManager.getPredefinedCMap(ucs2Name);
        }
    }
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) CMap(com.tom_roush.fontbox.cmap.CMap)

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