Search in sources :

Example 16 with COSNumber

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

the class PDPolylineAppearanceHandler method getLineWidth.

// TODO DRY, this code is from polygonAppearanceHandler so it's double
/**
 * Get the line with of the border.
 *
 * Get the width of the line used to draw a border around the annotation.
 * This may either be specified by the annotation dictionaries Border
 * setting or by the W entry in the BS border style dictionary. If both are
 * missing the default width is 1.
 *
 * @return the line width
 */
// TODO: according to the PDF spec the use of the BS entry is annotation
// specific
// so we will leave that to be implemented by individual handlers.
// If at the end all annotations support the BS entry this can be handled
// here and removed from the individual handlers.
float getLineWidth() {
    PDAnnotationPolyline annotation = (PDAnnotationPolyline) getAnnotation();
    PDBorderStyleDictionary bs = annotation.getBorderStyle();
    if (bs != null) {
        return bs.getWidth();
    } else {
        COSArray borderCharacteristics = annotation.getBorder();
        if (borderCharacteristics.size() >= 3) {
            COSBase base = borderCharacteristics.getObject(2);
            if (base instanceof COSNumber) {
                return ((COSNumber) base).floatValue();
            }
        }
    }
    return 1;
}
Also used : COSArray(org.apache.pdfbox.cos.COSArray) PDAnnotationPolyline(org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationPolyline) COSNumber(org.apache.pdfbox.cos.COSNumber) COSBase(org.apache.pdfbox.cos.COSBase) PDBorderStyleDictionary(org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary)

Example 17 with COSNumber

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

the class PDSquareAppearanceHandler method getLineWidth.

/**
 * Get the line with of the border.
 *
 * Get the width of the line used to draw a border around the annotation.
 * This may either be specified by the annotation dictionaries Border
 * setting or by the W entry in the BS border style dictionary. If both are
 * missing the default width is 1.
 *
 * @return the line width
 */
// TODO: according to the PDF spec the use of the BS entry is annotation
// specific
// so we will leave that to be implemented by individual handlers.
// If at the end all annotations support the BS entry this can be handled
// here and removed from the individual handlers.
float getLineWidth() {
    PDAnnotationSquare annotation = (PDAnnotationSquare) getAnnotation();
    PDBorderStyleDictionary bs = annotation.getBorderStyle();
    if (bs != null) {
        return bs.getWidth();
    } else {
        COSArray borderCharacteristics = annotation.getBorder();
        if (borderCharacteristics.size() >= 3) {
            COSBase base = borderCharacteristics.getObject(2);
            if (base instanceof COSNumber) {
                return ((COSNumber) base).floatValue();
            }
        }
    }
    return 1;
}
Also used : PDAnnotationSquare(org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquare) COSArray(org.apache.pdfbox.cos.COSArray) COSNumber(org.apache.pdfbox.cos.COSNumber) COSBase(org.apache.pdfbox.cos.COSBase) PDBorderStyleDictionary(org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary)

Example 18 with COSNumber

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

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(org.apache.pdfbox.cos.COSNumber)

Example 19 with COSNumber

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

the class CatalogValidationProcess method validateICCProfileNEntry.

private boolean validateICCProfileNEntry(COSStream stream, PreflightContext ctx, ICC_Profile iccp) {
    COSDictionary streamDict = (COSDictionary) stream.getCOSObject();
    if (!streamDict.containsKey(COSName.N)) {
        addValidationError(ctx, new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_INVALID_ENTRY, "/N entry of ICC profile is mandatory"));
        return false;
    }
    COSBase nValue = streamDict.getItem(COSName.N);
    if (!(nValue instanceof COSNumber)) {
        addValidationError(ctx, new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_INVALID_ENTRY, "/N entry of ICC profile must be a number, but is " + nValue));
        return false;
    }
    int nNumberValue = ((COSNumber) nValue).intValue();
    if (nNumberValue != 1 && nNumberValue != 3 && nNumberValue != 4) {
        addValidationError(ctx, new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_INVALID_ENTRY, "/N entry of ICC profile must be 1, 3 or 4, but is " + nNumberValue));
        return false;
    }
    if (iccp.getNumComponents() != nNumberValue) {
        addValidationError(ctx, new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_INVALID_ENTRY, "/N entry of ICC profile is " + nNumberValue + " but the ICC profile has " + iccp.getNumComponents() + " components"));
        return false;
    }
    return true;
}
Also used : COSDictionary(org.apache.pdfbox.cos.COSDictionary) COSNumber(org.apache.pdfbox.cos.COSNumber) COSBase(org.apache.pdfbox.cos.COSBase) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError)

Example 20 with COSNumber

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

the class ExtGStateValidationProcess method checkFont.

/**
 * This method checks a Font array in the ExtGState dictionary.
 *
 * @param context the preflight context.
 * @param egs the Graphic state to check
 * @throws ValidationException
 */
private void checkFont(PreflightContext context, COSDictionary egs) throws ValidationException {
    COSBase base = egs.getItem(COSName.FONT);
    if (base == null) {
        return;
    }
    if (!(base instanceof COSArray) || ((COSArray) base).size() != 2) {
        context.addValidationError(new ValidationError(ERROR_SYNTAX_COMMON, "/Font entry in /ExtGState must be an array with 2 elements"));
        return;
    }
    COSArray ar = (COSArray) base;
    COSBase base0 = ar.get(0);
    if (!(base0 instanceof COSObject)) {
        context.addValidationError(new ValidationError(ERROR_SYNTAX_COMMON, "1st element in /Font entry in /ExtGState must be an indirect object"));
        return;
    }
    COSBase base1 = ar.getObject(1);
    if (!(base1 instanceof COSNumber)) {
        context.addValidationError(new ValidationError(ERROR_SYNTAX_COMMON, "2nd element in /Font entry in /ExtGState must be a number"));
        return;
    }
    COSNumber fontSize = (COSNumber) ar.getObject(1);
    if (fontSize.floatValue() > MAX_POSITIVE_FLOAT || fontSize.floatValue() < MAX_NEGATIVE_FLOAT) {
        context.addValidationError(new ValidationError(ERROR_SYNTAX_NUMERIC_RANGE, "invalid float range in 2nd element in /Font entry in /ExtGState"));
    }
    if (ar.getObject(0) instanceof COSDictionary) {
        COSDictionary fontDict = (COSDictionary) ar.getObject(0);
        try {
            PDFont newFont = PDFontFactory.createFont(fontDict);
            ContextHelper.validateElement(context, newFont, FONT_PROCESS);
        } catch (IOException e) {
            addFontError(fontDict, context, e);
        }
    }
}
Also used : PDFont(org.apache.pdfbox.pdmodel.font.PDFont) COSArray(org.apache.pdfbox.cos.COSArray) COSDictionary(org.apache.pdfbox.cos.COSDictionary) COSObject(org.apache.pdfbox.cos.COSObject) COSNumber(org.apache.pdfbox.cos.COSNumber) COSBase(org.apache.pdfbox.cos.COSBase) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError) IOException(java.io.IOException)

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