Search in sources :

Example 21 with COSNumber

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

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

the class PDStandardAttributeObject method getNumberOrArrayOfNumber.

/**
 * Gets a number or an array of numbers.
 *
 * @param name the attribute name
 * @param defaultValue the default value
 * @return a Float or an array of floats
 */
protected Object getNumberOrArrayOfNumber(String name, float defaultValue) {
    COSBase v = this.getCOSObject().getDictionaryObject(name);
    if (v instanceof COSArray) {
        COSArray array = (COSArray) v;
        float[] values = new float[array.size()];
        for (int i = 0; i < array.size(); i++) {
            COSBase item = array.getObject(i);
            if (item instanceof COSNumber) {
                values[i] = ((COSNumber) item).floatValue();
            }
        }
        return values;
    }
    if (v instanceof COSNumber) {
        return ((COSNumber) v).floatValue();
    }
    if (defaultValue == UNSPECIFIED) {
        return null;
    }
    return defaultValue;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 23 with COSNumber

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

the class PDExtendedGraphicsState method getFloatItem.

/**
 * This will get a float item from the dictionary.
 *
 * @param key The key to the item.
 *
 * @return The value for that item.
 */
private Float getFloatItem(COSName key) {
    Float retval = null;
    COSBase base = dict.getDictionaryObject(key);
    if (base instanceof COSNumber) {
        COSNumber value = (COSNumber) base;
        retval = value.floatValue();
    }
    return retval;
}
Also used : COSFloat(com.tom_roush.pdfbox.cos.COSFloat) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 24 with COSNumber

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

the class PDDefaultAppearanceString method processSetFont.

/**
 * Process the set font and font size operator.
 *
 * @param operands the font name and size
 * @throws IOException in case there are missing operators or the font is not within the resources
 */
private void processSetFont(List<COSBase> operands) throws IOException {
    if (operands.size() < 2) {
        throw new IOException("Missing operands for set font operator " + Arrays.toString(operands.toArray()));
    }
    COSBase base0 = operands.get(0);
    COSBase base1 = operands.get(1);
    if (!(base0 instanceof COSName)) {
        return;
    }
    if (!(base1 instanceof COSNumber)) {
        return;
    }
    COSName fontName = (COSName) base0;
    PDFont font = defaultResources.getFont(fontName);
    float fontSize = ((COSNumber) base1).floatValue();
    // todo: handle cases where font == null with special mapping logic (see PDFBOX-2661)
    if (font == null) {
        throw new IOException("Could not find font: /" + fontName.getName());
    }
    setFontName(fontName);
    setFont(font);
    setFontSize(fontSize);
}
Also used : PDFont(com.tom_roush.pdfbox.pdmodel.font.PDFont) COSName(com.tom_roush.pdfbox.cos.COSName) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) COSBase(com.tom_roush.pdfbox.cos.COSBase) IOException(java.io.IOException)

Example 25 with COSNumber

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

the class PDVariableText method getQ.

/**
 * This will get the 'quadding' or justification of the text to be displayed.
 *
 * This is an inheritable attribute.
 * <br>
 * 0 - Left (default)<br>
 * 1 - Centered<br>
 * 2 - Right<br>
 * Please see the QUADDING_CONSTANTS.
 *
 * @return The justification of the text strings.
 */
public int getQ() {
    int retval = 0;
    COSNumber number = (COSNumber) getInheritableAttribute(COSName.Q);
    if (number != null) {
        retval = number.intValue();
    }
    return retval;
}
Also used : 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