Search in sources :

Example 6 with MissingOperandException

use of com.tom_roush.pdfbox.contentstream.operator.MissingOperandException 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 7 with MissingOperandException

use of com.tom_roush.pdfbox.contentstream.operator.MissingOperandException in project PdfBox-Android by TomRoush.

the class AppendRectangleToPath 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 x = (COSNumber) operands.get(0);
    COSNumber y = (COSNumber) operands.get(1);
    COSNumber w = (COSNumber) operands.get(2);
    COSNumber h = (COSNumber) operands.get(3);
    float x1 = x.floatValue();
    float y1 = y.floatValue();
    // create a pair of coordinates for the transformation
    float x2 = w.floatValue() + x1;
    float y2 = h.floatValue() + y1;
    PointF p0 = context.transformedPoint(x1, y1);
    PointF p1 = context.transformedPoint(x2, y1);
    PointF p2 = context.transformedPoint(x2, y2);
    PointF p3 = context.transformedPoint(x1, y2);
    context.appendRectangle(p0, p1, p2, p3);
}
Also used : MissingOperandException(com.tom_roush.pdfbox.contentstream.operator.MissingOperandException) PointF(android.graphics.PointF) COSNumber(com.tom_roush.pdfbox.cos.COSNumber)

Example 8 with MissingOperandException

use of com.tom_roush.pdfbox.contentstream.operator.MissingOperandException in project PdfBox-Android by TomRoush.

the class CurveTo method process.

@Override
public void process(Operator operator, List<COSBase> operands) throws IOException {
    if (operands.size() < 6) {
        throw new MissingOperandException(operator, operands);
    }
    if (!checkArrayTypesClass(operands, COSNumber.class)) {
        return;
    }
    COSNumber x1 = (COSNumber) operands.get(0);
    COSNumber y1 = (COSNumber) operands.get(1);
    COSNumber x2 = (COSNumber) operands.get(2);
    COSNumber y2 = (COSNumber) operands.get(3);
    COSNumber x3 = (COSNumber) operands.get(4);
    COSNumber y3 = (COSNumber) operands.get(5);
    PointF point1 = context.transformedPoint(x1.floatValue(), y1.floatValue());
    PointF point2 = context.transformedPoint(x2.floatValue(), y2.floatValue());
    PointF point3 = context.transformedPoint(x3.floatValue(), y3.floatValue());
    if (context.getCurrentPoint() == null) {
        Log.w("PdfBox-Android", "curveTo (" + point3.x + "," + point3.y + ") without initial MoveTo");
        context.moveTo(point3.x, point3.y);
    } else {
        context.curveTo(point1.x, point1.y, point2.x, point2.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 9 with MissingOperandException

use of com.tom_roush.pdfbox.contentstream.operator.MissingOperandException in project PdfBox-Android by TomRoush.

the class CurveToReplicateInitialPoint 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 x2 = (COSNumber) operands.get(0);
    COSNumber y2 = (COSNumber) operands.get(1);
    COSNumber x3 = (COSNumber) operands.get(2);
    COSNumber y3 = (COSNumber) operands.get(3);
    PointF currentPoint = context.getCurrentPoint();
    PointF point2 = context.transformedPoint(x2.floatValue(), y2.floatValue());
    PointF point3 = context.transformedPoint(x3.floatValue(), y3.floatValue());
    if (currentPoint == null) {
        Log.w("PdfBox-Android", "curveTo (" + point3.x + "," + point3.y + ") without initial MoveTo");
        context.moveTo(point3.x, point3.y);
    } else {
        context.curveTo((float) currentPoint.x, (float) currentPoint.y, point2.x, point2.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 10 with MissingOperandException

use of com.tom_roush.pdfbox.contentstream.operator.MissingOperandException in project PdfBox-Android by TomRoush.

the class SetFontAndSize method process.

@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
    if (arguments.size() < 2) {
        throw new MissingOperandException(operator, arguments);
    }
    COSBase base0 = arguments.get(0);
    COSBase base1 = arguments.get(1);
    if (!(base0 instanceof COSName)) {
        return;
    }
    if (!(base1 instanceof COSNumber)) {
        return;
    }
    COSName fontName = (COSName) base0;
    float fontSize = ((COSNumber) base1).floatValue();
    context.getGraphicsState().getTextState().setFontSize(fontSize);
    PDFont font = context.getResources().getFont(fontName);
    if (font == null) {
        Log.w("PdfBox-Android", "font '" + fontName.getName() + "' not found in resources");
    }
    context.getGraphicsState().getTextState().setFont(font);
}
Also used : PDFont(com.tom_roush.pdfbox.pdmodel.font.PDFont) COSName(com.tom_roush.pdfbox.cos.COSName) MissingOperandException(com.tom_roush.pdfbox.contentstream.operator.MissingOperandException) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Aggregations

MissingOperandException (com.tom_roush.pdfbox.contentstream.operator.MissingOperandException)23 COSNumber (com.tom_roush.pdfbox.cos.COSNumber)18 COSBase (com.tom_roush.pdfbox.cos.COSBase)11 PointF (android.graphics.PointF)6 COSName (com.tom_roush.pdfbox.cos.COSName)5 Matrix (com.tom_roush.pdfbox.util.Matrix)3 COSArray (com.tom_roush.pdfbox.cos.COSArray)2 PDXObject (com.tom_roush.pdfbox.pdmodel.graphics.PDXObject)2 PDFormXObject (com.tom_roush.pdfbox.pdmodel.graphics.form.PDFormXObject)2 PDTransparencyGroup (com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup)2 COSFloat (com.tom_roush.pdfbox.cos.COSFloat)1 MissingResourceException (com.tom_roush.pdfbox.pdmodel.MissingResourceException)1 PDFont (com.tom_roush.pdfbox.pdmodel.font.PDFont)1 PDColor (com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor)1 PDColorSpace (com.tom_roush.pdfbox.pdmodel.graphics.color.PDColorSpace)1 PDImageXObject (com.tom_roush.pdfbox.pdmodel.graphics.image.PDImageXObject)1 PDExtendedGraphicsState (com.tom_roush.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState)1 RenderingMode (com.tom_roush.pdfbox.pdmodel.graphics.state.RenderingMode)1 PDFMarkedContentExtractor (com.tom_roush.pdfbox.text.PDFMarkedContentExtractor)1 ArrayList (java.util.ArrayList)1