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;
}
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;
}
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;
}
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;
}
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);
}
}
}
Aggregations