use of org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace in project pdfbox by apache.
the class PDDefaultAppearanceString method processSetFontColor.
/**
* Process the font color operator.
*
* This is assumed to be an RGB color.
*
* @param operands the color components
* @throws IOException in case of the color components not matching
*/
private void processSetFontColor(List<COSBase> operands) throws IOException {
PDColorSpace colorSpace;
switch(operands.size()) {
case 1:
colorSpace = PDDeviceGray.INSTANCE;
break;
case 3:
colorSpace = PDDeviceRGB.INSTANCE;
break;
case 4:
colorSpace = PDDeviceCMYK.INSTANCE;
break;
default:
throw new IOException("Missing operands for set non stroking color operator " + Arrays.toString(operands.toArray()));
}
COSArray array = new COSArray();
array.addAll(operands);
setFontColor(new PDColor(array, colorSpace));
}
use of org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace in project pdfbox by apache.
the class ShadingPatternValidationProcess method checkColorSpace.
/**
* Checks if the ColorSapce entry is consistent which rules of the PDF Reference and the ISO 190005-1:2005
* Specification.
*
* This method is called by the validate method.
*
* @param context the preflight context.
* @param page the page to check.
* @param shadingRes the Shading pattern to check.
* @throws ValidationException
*/
protected void checkColorSpace(PreflightContext context, PDPage page, PDShading shadingRes) throws ValidationException {
try {
PDColorSpace pColorSpace = shadingRes.getColorSpace();
PreflightConfiguration config = context.getConfig();
ColorSpaceHelperFactory csFact = config.getColorSpaceHelperFact();
ColorSpaceHelper csh = csFact.getColorSpaceHelper(context, pColorSpace, ColorSpaceRestriction.NO_PATTERN);
csh.validate();
} catch (IOException e) {
LOGGER.debug("Unable to get the color space", e);
context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_UNKNOWN_COLOR_SPACE, e.getMessage()));
}
}
use of org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace in project pdfbox by apache.
the class SinglePageValidationProcess method validateColorSpaces.
/**
* Check that all ColorSpace present in the Resource dictionary are conforming to the ISO 19005:2005-1
* specification.
*
* @param context the preflight context.
* @param page the page to check.
*/
protected void validateColorSpaces(PreflightContext context, PDPage page) {
PDResources resources = page.getResources();
if (resources != null) {
PreflightConfiguration config = context.getConfig();
ColorSpaceHelperFactory colorSpaceFactory = config.getColorSpaceHelperFact();
for (COSName name : resources.getColorSpaceNames()) {
try {
PDColorSpace pdCS = resources.getColorSpace(name);
ColorSpaceHelper csHelper = colorSpaceFactory.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.NO_RESTRICTION);
csHelper.validate();
} catch (IOException e) {
// fixme: this code was previously in PDResources
LOGGER.debug("Unable to create colorspace", e);
}
}
}
}
use of org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace in project pdfbox by apache.
the class DeviceColorSpaceHelper method processIndexedColorSpace.
/**
* Indexed color space is authorized only if the BaseColorSpace is a DeviceXXX color space. In all other cases the
* given list is updated with a ValidationError (ERROR_GRAPHIC_INVALID_PATTERN_COLOR_SPACE_FORBIDDEN) and returns
* false.
*/
@Override
protected void processIndexedColorSpace(PDColorSpace colorSpace) {
PDIndexed indexed = (PDIndexed) colorSpace;
PDColorSpace baseColorSpace = indexed.getBaseColorSpace();
ColorSpaces colorSpaces = ColorSpaces.valueOf(baseColorSpace.getName());
switch(colorSpaces) {
case Indexed:
case I:
case Pattern:
context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_FORBIDDEN, colorSpaces.getLabel() + " ColorSpace is forbidden"));
break;
default:
processAllColorSpace(baseColorSpace);
}
}
use of org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace in project pdfbox by apache.
the class StandardColorSpaceHelper method processDefaultColorSpace.
/**
* Look up in the closest PDResources objects if there are a default ColorSpace. If there are, check that is a
* authorized ColorSpace.
*
* @param colorSpace
* @return true if the default colorspace is a right one, false otherwise.
*/
protected boolean processDefaultColorSpace(PDColorSpace colorSpace) {
boolean result = false;
// get default color space
PreflightPath vPath = context.getValidationPath();
PDResources resources = vPath.getClosestPathElement(PDResources.class);
if (resources != null) {
PDColorSpace defaultCS = null;
try {
if (colorSpace.getName().equals(ColorSpaces.DeviceCMYK.getLabel()) && resources.hasColorSpace(COSName.DEFAULT_CMYK)) {
defaultCS = resources.getColorSpace(COSName.DEFAULT_CMYK);
} else if (colorSpace.getName().equals(ColorSpaces.DeviceRGB.getLabel()) && resources.hasColorSpace(COSName.DEFAULT_RGB)) {
defaultCS = resources.getColorSpace(COSName.DEFAULT_RGB);
} else if (colorSpace.getName().equals(ColorSpaces.DeviceGray.getLabel()) && resources.hasColorSpace(COSName.DEFAULT_GRAY)) {
defaultCS = resources.getColorSpace(COSName.DEFAULT_GRAY);
}
} catch (IOException e) {
context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE, "Unable to read default color space : " + e.getMessage(), e));
}
if (defaultCS != null) {
// defaultCS is valid if the number of errors hasn't changed
int nbOfErrors = context.getDocument().getResult().getErrorsList().size();
processAllColorSpace(defaultCS);
int newNbOfErrors = context.getDocument().getResult().getErrorsList().size();
result = (nbOfErrors == newNbOfErrors);
}
}
return result;
}
Aggregations