try
{
ICC_Profile iccp = ICC_Profile.getInstance(iccBased.getPDStream().getByteArray());
if (iccp == null)
{
context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_ICCBASED,
"Unable to read ICCBase color space "));
return;
}
PDColorSpace altpdcs = iccBased.getAlternateColorSpace();
if (altpdcs != null)
{
ColorSpaces altCsId = ColorSpaces.valueOf(altpdcs.getName());
if (altCsId == ColorSpaces.Pattern)
{
context.addValidationError(new ValidationError(
ERROR_GRAPHIC_INVALID_PATTERN_COLOR_SPACE_FORBIDDEN,
"Pattern is forbidden as AlternateColorSpace of a ICCBased"));
}
/*
* According to the ISO-19005-1:2005
*
* A conforming reader shall render ICCBased colour spaces as specified by the ICC specification,
* and shall not use the Alternate colour space specified in an ICC profile stream dictionary
*
* We don't check the alternate ColorSpaces
*/
}
}
catch (IllegalArgumentException e)
{
// this is not a ICC_Profile
context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_ICCBASED,
"ICCBase color space is invalid. Caused By: " + e.getMessage()));
}
catch (IOException e)
{
context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE,
"Unable to read ICCBase color space. Caused by : " + e.getMessage(), e));
}
}