use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class FontMetaDataValidation method analyseRights.
/**
* If XMP MetaData are present, they must have followings information :
* <UL>
* <li>dc:rights
* <li>Marked (with the value true)
* <li>Owner
* <li>UsageTerms
* </UL>
*
* @param metadata
* XMPMetaData of the Font File Stream
* @param fontDesc
* The FontDescriptor dictionary
* @param ve
* the list of validation error to update if the validation fails
* @return true if the analysis found no problems, false if it did.
*/
public boolean analyseRights(XMPMetadata metadata, PDFontDescriptor fontDesc, List<ValidationError> ve) {
DublinCoreSchema dc = metadata.getDublinCoreSchema();
if (dc != null) {
ArrayProperty copyrights = dc.getRightsProperty();
if (copyrights == null || copyrights.getContainer() == null || copyrights.getContainer().getAllProperties().isEmpty()) {
ve.add(new ValidationError(PreflightConstants.ERROR_METADATA_PROPERTY_MISSING, "CopyRights is missing from the XMP information (dc:rights) of the Font File Stream."));
return false;
}
}
XMPRightsManagementSchema rights = metadata.getXMPRightsManagementSchema();
if (rights != null) {
BooleanType marked = rights.getMarkedProperty();
if (marked != null && !marked.getValue()) {
ve.add(new ValidationError(PreflightConstants.ERROR_METADATA_PROPERTY_MISSING, "the XMP information (xmpRights:Marked) is invalid for the Font File Stream."));
return false;
}
/*
* rights.getUsageTerms() & rights.getOwnerValue() should be present but it is only a recommendation : may
* be it should be useful to append a Warning if these entries are missing.
*/
}
return true;
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class StandardColorSpaceHelper method processIndexedColorSpace.
/**
* Method called by the processAllColorSpace if the ColorSpace to check is Indexed. Because this kind of ColorSpace
* can have a Base color space, the processAllColorSpace is called to check this base color space. (Indexed and
* Pattern can't be a Base color space)
*
* @param colorSpace
* the color space object to check.
*/
protected void processIndexedColorSpace(PDColorSpace colorSpace) {
PDIndexed indexed = (PDIndexed) colorSpace;
PDColorSpace based = indexed.getBaseColorSpace();
ColorSpaces cs = ColorSpaces.valueOf(based.getName());
if (cs == ColorSpaces.Indexed || cs == ColorSpaces.I) {
context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_INDEXED, "Indexed color space can't be used as Base color space"));
return;
}
if (cs == ColorSpaces.Pattern) {
context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_INDEXED, "Pattern color space can't be used as Base color space"));
return;
}
processAllColorSpace(based);
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class StandardColorSpaceHelper method processICCBasedColorSpace.
/**
* Method called by the processAllColorSpace if the ColorSpace to check is a ICCBased color space. Because this kind
* of ColorSpace can have alternate color space, the processAllColorSpace is called to check this alternate color
* space. (Pattern is forbidden as Alternate Color Space)
*
* @param colorSpace
* the color space object to check.
*/
protected void processICCBasedColorSpace(PDColorSpace colorSpace) {
PDICCBased iccBased = (PDICCBased) colorSpace;
try {
ICC_Profile.getInstance(iccBased.getPDStream().createInputStream());
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, "ICCBased color space is invalid: " + e.getMessage(), e));
} catch (IOException e) {
context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE, "Unable to read ICCBase color space: " + e.getMessage(), e));
}
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class StandardColorSpaceHelper method processSeparationColorSpace.
/**
* Method called by the processAllColorSpace if the ColorSpace to check is Separation. Because this kind of
* ColorSpace can have an alternate color space, the processAllColorSpace is called to check this alternate color
* space. (Indexed, Separation, DeviceN and Pattern can't be a Base color space)
*
* @param colorSpace
* the color space object to check.
*/
protected void processSeparationColorSpace(PDColorSpace colorSpace) {
try {
COSBase cosAlt = ((COSArray) colorSpace.getCOSObject()).getObject(2);
PDColorSpace altCol = PDColorSpace.create(cosAlt);
if (altCol != null) {
ColorSpaces acs = ColorSpaces.valueOf(altCol.getName());
switch(acs) {
case Separation:
case DeviceN:
case Pattern:
case Indexed:
case I:
context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_ALTERNATE, acs.getLabel() + " color space can't be used as alternate color space"));
break;
default:
processAllColorSpace(altCol);
}
}
} catch (IOException e) {
context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE, "Unable to read Separation color space : " + e.getMessage(), e));
}
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError 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));
}
}
Aggregations