Search in sources :

Example 31 with COSNumber

use of org.apache.pdfbox.cos.COSNumber in project pdfbox by apache.

the class MoveTextSetLeading method process.

@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
    if (arguments.size() < 2) {
        throw new MissingOperandException(operator, arguments);
    }
    // move text position and set leading
    COSBase base1 = arguments.get(1);
    if (!(base1 instanceof COSNumber)) {
        return;
    }
    COSNumber y = (COSNumber) base1;
    List<COSBase> args = new ArrayList<>();
    args.add(new COSFloat(-1 * y.floatValue()));
    context.processOperator("TL", args);
    context.processOperator("Td", arguments);
}
Also used : MissingOperandException(org.apache.pdfbox.contentstream.operator.MissingOperandException) COSNumber(org.apache.pdfbox.cos.COSNumber) ArrayList(java.util.ArrayList) COSBase(org.apache.pdfbox.cos.COSBase) COSFloat(org.apache.pdfbox.cos.COSFloat)

Example 32 with COSNumber

use of org.apache.pdfbox.cos.COSNumber in project pdfbox by apache.

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;
    Point2D.Float pos = context.transformedPoint(x.floatValue(), y.floatValue());
    context.moveTo(pos.x, pos.y);
}
Also used : MissingOperandException(org.apache.pdfbox.contentstream.operator.MissingOperandException) Point2D(java.awt.geom.Point2D) COSNumber(org.apache.pdfbox.cos.COSNumber) COSBase(org.apache.pdfbox.cos.COSBase)

Example 33 with COSNumber

use of org.apache.pdfbox.cos.COSNumber in project pdfbox by apache.

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, 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(org.apache.pdfbox.pdmodel.font.PDFont) COSNumber(org.apache.pdfbox.cos.COSNumber) COSBase(org.apache.pdfbox.cos.COSBase) PDTextState(org.apache.pdfbox.pdmodel.graphics.state.PDTextState) IOException(java.io.IOException) COSString(org.apache.pdfbox.cos.COSString)

Example 34 with COSNumber

use of org.apache.pdfbox.cos.COSNumber in project pdfbox by apache.

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;
    Point2D.Float pos = context.transformedPoint(x.floatValue(), y.floatValue());
    if (context.getCurrentPoint() == null) {
        LOG.warn("LineTo (" + pos.x + "," + pos.y + ") without initial MoveTo");
        context.moveTo(pos.x, pos.y);
    } else {
        context.lineTo(pos.x, pos.y);
    }
}
Also used : MissingOperandException(org.apache.pdfbox.contentstream.operator.MissingOperandException) Point2D(java.awt.geom.Point2D) COSNumber(org.apache.pdfbox.cos.COSNumber) COSBase(org.apache.pdfbox.cos.COSBase)

Example 35 with COSNumber

use of org.apache.pdfbox.cos.COSNumber in project pdfbox by apache.

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);
    Point2D.Float point1 = context.transformedPoint(x1.floatValue(), y1.floatValue());
    Point2D.Float point2 = context.transformedPoint(x2.floatValue(), y2.floatValue());
    Point2D.Float point3 = context.transformedPoint(x3.floatValue(), y3.floatValue());
    if (context.getCurrentPoint() == null) {
        LOG.warn("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(org.apache.pdfbox.contentstream.operator.MissingOperandException) Point2D(java.awt.geom.Point2D) COSNumber(org.apache.pdfbox.cos.COSNumber)

Aggregations

COSNumber (org.apache.pdfbox.cos.COSNumber)61 COSBase (org.apache.pdfbox.cos.COSBase)29 MissingOperandException (org.apache.pdfbox.contentstream.operator.MissingOperandException)18 COSArray (org.apache.pdfbox.cos.COSArray)18 COSInteger (org.apache.pdfbox.cos.COSInteger)10 Point2D (java.awt.geom.Point2D)6 IOException (java.io.IOException)6 COSObject (org.apache.pdfbox.cos.COSObject)5 PDBorderStyleDictionary (org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary)5 ArrayList (java.util.ArrayList)4 COSDictionary (org.apache.pdfbox.cos.COSDictionary)4 COSName (org.apache.pdfbox.cos.COSName)4 COSObjectKey (org.apache.pdfbox.cos.COSObjectKey)4 PDFont (org.apache.pdfbox.pdmodel.font.PDFont)4 COSFloat (org.apache.pdfbox.cos.COSFloat)3 COSStream (org.apache.pdfbox.cos.COSStream)2 PDRectangle (org.apache.pdfbox.pdmodel.common.PDRectangle)2 ValidationError (org.apache.pdfbox.preflight.ValidationResult.ValidationError)2 Matrix (org.apache.pdfbox.util.Matrix)2 Paint (java.awt.Paint)1