Search in sources :

Example 36 with COSBase

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

the class SetLineDashPattern method process.

@Override
public void process(Operator operator, List<COSBase> arguments) throws MissingOperandException {
    if (arguments.size() < 2) {
        throw new MissingOperandException(operator, arguments);
    }
    COSBase base0 = arguments.get(0);
    if (!(base0 instanceof COSArray)) {
        return;
    }
    COSBase base1 = arguments.get(1);
    if (!(base1 instanceof COSNumber)) {
        return;
    }
    COSArray dashArray = (COSArray) base0;
    int dashPhase = ((COSNumber) base1).intValue();
    boolean allZero = true;
    for (COSBase base : dashArray) {
        if (base instanceof COSNumber) {
            COSNumber num = (COSNumber) base;
            if (num.floatValue() != 0) {
                allZero = false;
                break;
            }
        } else {
            Log.w("PdfBox-Android", "dash array has non number element " + base + ", ignored");
            dashArray = new COSArray();
            break;
        }
    }
    if (dashArray.size() > 0 && allZero) {
        Log.w("PdfBox-Android", "dash lengths all zero, ignored");
        dashArray = new COSArray();
    }
    context.setLineDashPattern(dashArray, dashPhase);
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) MissingOperandException(com.tom_roush.pdfbox.contentstream.operator.MissingOperandException) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 37 with COSBase

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

the class ShowText method process.

@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
    if (arguments.isEmpty()) {
        // ignore ( )Tj
        return;
    }
    COSBase base = arguments.get(0);
    if (!(base instanceof COSString)) {
        // ignore
        return;
    }
    if (context.getTextMatrix() == null) {
        // ignore: outside of BT...ET
        return;
    }
    COSString string = (COSString) base;
    context.showTextString(string.getBytes());
}
Also used : COSBase(com.tom_roush.pdfbox.cos.COSBase) COSString(com.tom_roush.pdfbox.cos.COSString)

Example 38 with COSBase

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

the class MoveTo method process.

@Override
public void process(Operator operator, List<COSBase> operands) throws IOException {
    if (operands.size() < 2) {
        throw new MissingOperandException(operator, operands);
    }
    COSBase base0 = operands.get(0);
    if (!(base0 instanceof COSNumber)) {
        return;
    }
    COSBase base1 = operands.get(1);
    if (!(base1 instanceof COSNumber)) {
        return;
    }
    COSNumber x = (COSNumber) base0;
    COSNumber y = (COSNumber) base1;
    PointF pos = context.transformedPoint(x.floatValue(), y.floatValue());
    context.moveTo(pos.x, pos.y);
}
Also used : MissingOperandException(com.tom_roush.pdfbox.contentstream.operator.MissingOperandException) PointF(android.graphics.PointF) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 39 with COSBase

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

the class BeginMarkedContentSequence method process.

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

Example 40 with COSBase

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

the class PDStream method getFileDecodeParams.

/**
 * Get the list of decode parameters. Each entry in the list will refer to
 * an entry in the filters list.
 *
 * @return The list of decode parameters.
 * @throws IOException if there is an error retrieving the parameters.
 */
public List<Object> getFileDecodeParams() throws IOException {
    List<Object> retval = null;
    COSBase dp = stream.getDictionaryObject(COSName.F_DECODE_PARMS);
    if (dp instanceof COSDictionary) {
        Map<?, ?> map = COSDictionaryMap.convertBasicTypesToMap((COSDictionary) dp);
        retval = new COSArrayList<Object>(map, dp, stream, COSName.F_DECODE_PARMS);
    } else if (dp instanceof COSArray) {
        COSArray array = (COSArray) dp;
        List<Object> actuals = new ArrayList<Object>();
        for (int i = 0; i < array.size(); i++) {
            actuals.add(COSDictionaryMap.convertBasicTypesToMap((COSDictionary) array.getObject(i)));
        }
        retval = new COSArrayList<Object>(actuals, array);
    }
    return retval;
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSBase(com.tom_roush.pdfbox.cos.COSBase) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

COSBase (com.tom_roush.pdfbox.cos.COSBase)215 COSArray (com.tom_roush.pdfbox.cos.COSArray)108 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)68 COSName (com.tom_roush.pdfbox.cos.COSName)50 COSObject (com.tom_roush.pdfbox.cos.COSObject)42 IOException (java.io.IOException)34 COSString (com.tom_roush.pdfbox.cos.COSString)33 COSNumber (com.tom_roush.pdfbox.cos.COSNumber)29 ArrayList (java.util.ArrayList)29 COSStream (com.tom_roush.pdfbox.cos.COSStream)20 COSArrayList (com.tom_roush.pdfbox.pdmodel.common.COSArrayList)14 MissingOperandException (com.tom_roush.pdfbox.contentstream.operator.MissingOperandException)11 HashMap (java.util.HashMap)11 COSInteger (com.tom_roush.pdfbox.cos.COSInteger)10 Map (java.util.Map)10 List (java.util.List)9 Operator (com.tom_roush.pdfbox.contentstream.operator.Operator)8 COSFloat (com.tom_roush.pdfbox.cos.COSFloat)7 COSObjectKey (com.tom_roush.pdfbox.cos.COSObjectKey)7 PDFStreamParser (com.tom_roush.pdfbox.pdfparser.PDFStreamParser)6