Search in sources :

Example 46 with COSNumber

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

the class PDAnnotation method getRectangle.

/**
 * The annotation rectangle, defining the location of the annotation on the page in default user space units. This
 * is usually required and should not return null on valid PDF documents. But where this is a parent form field with
 * children, such as radio button collections then the rectangle will be null.
 *
 * @return The Rect value of this annotation.
 */
public PDRectangle getRectangle() {
    COSArray rectArray = (COSArray) dictionary.getDictionaryObject(COSName.RECT);
    PDRectangle rectangle = null;
    if (rectArray != null) {
        if (rectArray.size() == 4 && rectArray.getObject(0) instanceof COSNumber && rectArray.getObject(1) instanceof COSNumber && rectArray.getObject(2) instanceof COSNumber && rectArray.getObject(3) instanceof COSNumber) {
            rectangle = new PDRectangle(rectArray);
        } else {
            Log.w("PdfBox-Android", rectArray + " is not a rectangle array, returning null");
        }
    }
    return rectangle;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle)

Example 47 with COSNumber

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

the class PDFStreamEngine method showTextStrings.

/**
 * Called when a string of text with spacing adjustments is to be shown.
 *
 * @param array array of encoded text strings and adjustments
 * @throws IOException if there was an error showing the text
 */
public void showTextStrings(COSArray array) throws IOException {
    PDTextState textState = getGraphicsState().getTextState();
    float fontSize = textState.getFontSize();
    float horizontalScaling = textState.getHorizontalScaling() / 100f;
    PDFont font = textState.getFont();
    boolean isVertical = false;
    if (font != null) {
        isVertical = font.isVertical();
    }
    for (COSBase obj : array) {
        if (obj instanceof COSNumber) {
            float tj = ((COSNumber) obj).floatValue();
            // calculate the combined displacements
            float tx;
            float ty;
            if (isVertical) {
                tx = 0;
                ty = -tj / 1000 * fontSize;
            } else {
                tx = -tj / 1000 * fontSize * horizontalScaling;
                ty = 0;
            }
            applyTextAdjustment(tx, ty);
        } else if (obj instanceof COSString) {
            byte[] string = ((COSString) obj).getBytes();
            showText(string);
        } else {
            throw new IOException("Unknown type in array for TJ operation:" + obj);
        }
    }
}
Also used : PDFont(com.tom_roush.pdfbox.pdmodel.font.PDFont) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDTextState(com.tom_roush.pdfbox.pdmodel.graphics.state.PDTextState) IOException(java.io.IOException) COSString(com.tom_roush.pdfbox.cos.COSString)

Example 48 with COSNumber

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

the class CurveToReplicateFinalPoint method process.

@Override
public void process(Operator operator, List<COSBase> operands) throws IOException {
    if (operands.size() < 4) {
        throw new MissingOperandException(operator, operands);
    }
    if (!checkArrayTypesClass(operands, COSNumber.class)) {
        return;
    }
    COSNumber x1 = (COSNumber) operands.get(0);
    COSNumber y1 = (COSNumber) operands.get(1);
    COSNumber x3 = (COSNumber) operands.get(2);
    COSNumber y3 = (COSNumber) operands.get(3);
    PointF point1 = context.transformedPoint(x1.floatValue(), y1.floatValue());
    PointF point3 = context.transformedPoint(x3.floatValue(), y3.floatValue());
    context.curveTo(point1.x, point1.y, point3.x, point3.y, point3.x, point3.y);
}
Also used : MissingOperandException(com.tom_roush.pdfbox.contentstream.operator.MissingOperandException) PointF(android.graphics.PointF) COSNumber(com.tom_roush.pdfbox.cos.COSNumber)

Example 49 with COSNumber

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

the class LineTo 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;
    }
    // append straight line segment from the current point to the point
    COSNumber x = (COSNumber) base0;
    COSNumber y = (COSNumber) base1;
    PointF pos = context.transformedPoint(x.floatValue(), y.floatValue());
    if (context.getCurrentPoint() == null) {
        Log.w("PdfBox-Android", "LineTo (" + pos.x + "," + pos.y + ") without initial MoveTo");
        context.moveTo(pos.x, pos.y);
    } else {
        context.lineTo(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 50 with COSNumber

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

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