Example usage for org.apache.pdfbox.pdmodel.graphics.color PDDeviceN getNumberOfComponents

List of usage examples for org.apache.pdfbox.pdmodel.graphics.color PDDeviceN getNumberOfComponents

Introduction

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

Prototype

@Override
    public final int getNumberOfComponents() 

Source Link

Usage

From source file:net.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  2s  .c om
 * @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);
        }

        Map colorants = deviceN.getAttributes().getColorants();
        int numberOfColorants = 0;
        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;
    }
}

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  w w  .  j a  v a2 s  .c  om
 * @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;
    }
}