Search in sources :

Example 11 with COSNumber

use of com.tom_roush.pdfbox.cos.COSNumber 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 12 with COSNumber

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

the class COSArrayList method convertIntegerCOSArrayToList.

/**
 * This will take an array of COSNumbers and return a COSArrayList of
 * java.lang.Integer values.
 *
 * @param intArray The existing integer Array.
 *
 * @return A list that is part of the core Java collections.
 */
public static List<Integer> convertIntegerCOSArrayToList(COSArray intArray) {
    List<Integer> retval = null;
    if (intArray != null) {
        List<Integer> numbers = new ArrayList<Integer>();
        for (int i = 0; i < intArray.size(); i++) {
            COSNumber num;
            if (intArray.get(i) instanceof COSObject) {
                num = (COSNumber) ((COSObject) intArray.get(i)).getObject();
            } else {
                num = (COSNumber) intArray.get(i);
            }
            numbers.add(num.intValue());
        }
        retval = new COSArrayList<Integer>(numbers, intArray);
    }
    return retval;
}
Also used : COSInteger(com.tom_roush.pdfbox.cos.COSInteger) COSObject(com.tom_roush.pdfbox.cos.COSObject) ArrayList(java.util.ArrayList) COSNumber(com.tom_roush.pdfbox.cos.COSNumber)

Example 13 with COSNumber

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

the class COSArrayList method convertFloatCOSArrayToList.

/**
 * This will take an array of COSNumbers and return a COSArrayList of
 * java.lang.Float values.
 *
 * @param floatArray The existing float Array.
 *
 * @return The list of Float objects.
 */
public static List<Float> convertFloatCOSArrayToList(COSArray floatArray) {
    List<Float> retval = null;
    if (floatArray != null) {
        List<Float> numbers = new ArrayList<Float>(floatArray.size());
        for (int i = 0; i < floatArray.size(); i++) {
            COSBase base = floatArray.getObject(i);
            if (base instanceof COSNumber) {
                numbers.add(((COSNumber) base).floatValue());
            } else {
                numbers.add(null);
            }
        }
        retval = new COSArrayList<Float>(numbers, floatArray);
    }
    return retval;
}
Also used : COSFloat(com.tom_roush.pdfbox.cos.COSFloat) ArrayList(java.util.ArrayList) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 14 with COSNumber

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

the class PDType3CharProc method getGlyphBBox.

/**
 * Calculate the bounding box of this glyph. This will work only if the first operator in the
 * stream is d1.
 *
 * @return the bounding box of this glyph, or null if the first operator is not d1.
 * @throws IOException If an io error occurs while parsing the stream.
 */
public PDRectangle getGlyphBBox() throws IOException {
    List<COSBase> arguments = new ArrayList<COSBase>();
    PDFStreamParser parser = new PDFStreamParser(this);
    Object token = parser.parseNextToken();
    while (token != null) {
        if (token instanceof COSObject) {
            arguments.add(((COSObject) token).getObject());
        } else if (token instanceof Operator) {
            if (((Operator) token).getName().equals("d1") && arguments.size() == 6) {
                for (int i = 0; i < 6; ++i) {
                    if (!(arguments.get(i) instanceof COSNumber)) {
                        return null;
                    }
                }
                return new PDRectangle(((COSNumber) arguments.get(2)).floatValue(), ((COSNumber) arguments.get(3)).floatValue(), ((COSNumber) arguments.get(4)).floatValue() - ((COSNumber) arguments.get(2)).floatValue(), ((COSNumber) arguments.get(5)).floatValue() - ((COSNumber) arguments.get(3)).floatValue());
            } else {
                return null;
            }
        } else {
            arguments.add((COSBase) token);
        }
        token = parser.parseNextToken();
    }
    return null;
}
Also used : Operator(com.tom_roush.pdfbox.contentstream.operator.Operator) PDFStreamParser(com.tom_roush.pdfbox.pdfparser.PDFStreamParser) COSObject(com.tom_roush.pdfbox.cos.COSObject) ArrayList(java.util.ArrayList) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) COSBase(com.tom_roush.pdfbox.cos.COSBase) COSObject(com.tom_roush.pdfbox.cos.COSObject) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle)

Example 15 with COSNumber

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

the class FDFField method getSetFieldFlags.

/**
 * This will get the SetFf entry of the cos dictionary. If it it not present then this method will return null.
 *
 * @return The field flags.
 */
public Integer getSetFieldFlags() {
    Integer retval = null;
    COSNumber ff = (COSNumber) field.getDictionaryObject(COSName.SET_FF);
    if (ff != null) {
        retval = ff.intValue();
    }
    return retval;
}
Also used : COSInteger(com.tom_roush.pdfbox.cos.COSInteger) COSNumber(com.tom_roush.pdfbox.cos.COSNumber)

Aggregations

COSNumber (com.tom_roush.pdfbox.cos.COSNumber)55 COSBase (com.tom_roush.pdfbox.cos.COSBase)29 MissingOperandException (com.tom_roush.pdfbox.contentstream.operator.MissingOperandException)18 COSArray (com.tom_roush.pdfbox.cos.COSArray)17 COSInteger (com.tom_roush.pdfbox.cos.COSInteger)10 PointF (android.graphics.PointF)6 IOException (java.io.IOException)6 COSName (com.tom_roush.pdfbox.cos.COSName)5 PDBorderStyleDictionary (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary)5 COSObject (com.tom_roush.pdfbox.cos.COSObject)4 PDAnnotationMarkup (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationMarkup)4 COSFloat (com.tom_roush.pdfbox.cos.COSFloat)3 PDFont (com.tom_roush.pdfbox.pdmodel.font.PDFont)3 ArrayList (java.util.ArrayList)3 Operator (com.tom_roush.pdfbox.contentstream.operator.Operator)2 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)2 COSObjectKey (com.tom_roush.pdfbox.cos.COSObjectKey)2 COSStream (com.tom_roush.pdfbox.cos.COSStream)2 PDFStreamParser (com.tom_roush.pdfbox.pdfparser.PDFStreamParser)2 PDRectangle (com.tom_roush.pdfbox.pdmodel.common.PDRectangle)2