Example usage for org.apache.pdfbox.pdmodel.graphics.color PDDeviceNAttributes getColorants

List of usage examples for org.apache.pdfbox.pdmodel.graphics.color PDDeviceNAttributes getColorants

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel.graphics.color PDDeviceNAttributes getColorants.

Prototype

public Map<String, PDSeparation> getColorants() throws IOException 

Source Link

Document

Returns a map of colorants and their associated Separation color space.

Usage

From source file:org.apache.padaf.preflight.graphics.color.StandardColorSpaceHelper.java

License:Apache License

/**
 * 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)
 * //w ww  . ja  va  2 s  .  c o m
 * @param pdcs
 *          the color space object to check.
 * @param result
 *          the list of error to update if the validation fails.
 * @return true if the color space is valid, false otherwise.
 */
protected boolean processDeviceNColorSpace(PDColorSpace pdcs, List<ValidationError> result) {
    PDDeviceN deviceN = (PDDeviceN) pdcs;
    try {
        if (iccpw == null) {
            result.add(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_MISSING,
                    "DestOutputProfile is missing"));
            return false;
        }

        PDColorSpace altColor = deviceN.getAlternateColorSpace();
        boolean res = true;
        if (altColor != null) {
            res = processAllColorSpace(altColor, result);
        }

        int numberOfColorants = 0;
        PDDeviceNAttributes attr = deviceN.getAttributes();
        if (attr != null) {
            Map colorants = attr.getColorants();
            if (colorants != null) {
                numberOfColorants = colorants.size();
                for (Object col : colorants.values()) {
                    if (col != null) {
                        res = res && processAllColorSpace((PDColorSpace) col, result);
                    }
                }
            }
        }
        int numberOfComponents = deviceN.getNumberOfComponents();
        if (numberOfColorants > MAX_DEVICE_N_LIMIT || numberOfComponents > MAX_DEVICE_N_LIMIT) {
            result.add(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_TOO_MANY_COMPONENTS_DEVICEN,
                    "DeviceN has too many tint components or colorants"));
            res = false;
        }
        return res;
    } catch (IOException e) {
        result.add(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE,
                "Unable to read DeviceN color space : " + e.getMessage()));
        return false;
    }
}