Search in sources :

Example 1 with PDSeparation

use of org.apache.pdfbox.pdmodel.graphics.color.PDSeparation in project pdfbox by apache.

the class StandardColorSpaceHelper method processDeviceNColorSpace.

/**
 * Method called by the processAllColorSpace if the ColorSpace to check is DeviceN. Because this kind of ColorSpace
 * can have alternate color space, the processAllColorSpace is called to check this alternate color space. (There
 * are no restrictions on the Alternate Color space)
 *
 * @param colorSpace
 *            the color space object to check.
 */
protected void processDeviceNColorSpace(PDColorSpace colorSpace) {
    PDDeviceN deviceN = (PDDeviceN) colorSpace;
    try {
        if (iccpw == null) {
            context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_MISSING, "DestOutputProfile is missing"));
            return;
        }
        COSBase cosAlt = ((COSArray) colorSpace.getCOSObject()).getObject(2);
        PDColorSpace altColor = PDColorSpace.create(cosAlt);
        if (altColor != null) {
            processAllColorSpace(altColor);
        }
        int numberOfColorants = 0;
        PDDeviceNAttributes attr = deviceN.getAttributes();
        if (attr != null) {
            final Map<String, PDSeparation> colorants = attr.getColorants();
            if (colorants != null) {
                numberOfColorants = colorants.size();
                for (PDSeparation col : colorants.values()) {
                    if (col != null) {
                        processAllColorSpace(col);
                    }
                }
            }
        }
        int numberOfComponents = deviceN.getNumberOfComponents();
        if (numberOfColorants > MAX_DEVICE_N_LIMIT || numberOfComponents > MAX_DEVICE_N_LIMIT) {
            context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_TOO_MANY_COMPONENTS_DEVICEN, "DeviceN has too many tint components or colorants"));
        }
    } catch (IOException e) {
        context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE, "Unable to read DeviceN color space : " + e.getMessage(), e));
    }
}
Also used : PDSeparation(org.apache.pdfbox.pdmodel.graphics.color.PDSeparation) COSArray(org.apache.pdfbox.cos.COSArray) PDDeviceN(org.apache.pdfbox.pdmodel.graphics.color.PDDeviceN) COSBase(org.apache.pdfbox.cos.COSBase) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError) IOException(java.io.IOException) PDColorSpace(org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace) PDDeviceNAttributes(org.apache.pdfbox.pdmodel.graphics.color.PDDeviceNAttributes)

Aggregations

IOException (java.io.IOException)1 COSArray (org.apache.pdfbox.cos.COSArray)1 COSBase (org.apache.pdfbox.cos.COSBase)1 PDColorSpace (org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace)1 PDDeviceN (org.apache.pdfbox.pdmodel.graphics.color.PDDeviceN)1 PDDeviceNAttributes (org.apache.pdfbox.pdmodel.graphics.color.PDDeviceNAttributes)1 PDSeparation (org.apache.pdfbox.pdmodel.graphics.color.PDSeparation)1 ValidationError (org.apache.pdfbox.preflight.ValidationResult.ValidationError)1