use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class DescendantFontValidator method checkMandatoryField.
@Override
protected void checkMandatoryField() {
boolean arePresent = fontDictionary.containsKey(COSName.TYPE);
arePresent &= fontDictionary.containsKey(COSName.SUBTYPE);
arePresent &= fontDictionary.containsKey(COSName.BASE_FONT);
arePresent &= fontDictionary.containsKey(COSName.CIDSYSTEMINFO);
arePresent &= fontDictionary.containsKey(COSName.FONT_DESC);
if (!arePresent) {
this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID, font.getName() + ": Required keys are missing"));
}
checkCIDSystemInfo(fontDictionary.getItem(COSName.CIDSYSTEMINFO));
checkCIDToGIDMap(fontDictionary.getItem(COSName.CID_TO_GID_MAP));
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class Type0FontValidator method compareCIDSystemInfo.
/**
* The CIDSystemInfo must have the same Registry and Ordering for CMap and CIDFont. This control is useless if CMap
* is Identity-H or Identity-V so this method is called by the checkCMap method.
*
* @param cmap
*/
private void compareCIDSystemInfo(COSDictionary cmap) {
COSDictionary fontDictionary = font.getCOSObject();
COSArray array = COSUtils.getAsArray(fontDictionary.getItem(COSName.DESCENDANT_FONTS), cosDocument);
if (array != null && array.size() > 0) {
COSDictionary cidFont = COSUtils.getAsDictionary(array.get(0), cosDocument);
COSDictionary cmsi = COSUtils.getAsDictionary(cmap.getItem(COSName.CIDSYSTEMINFO), cosDocument);
COSDictionary cfsi = COSUtils.getAsDictionary(cidFont.getItem(COSName.CIDSYSTEMINFO), cosDocument);
String regCM = COSUtils.getAsString(cmsi.getItem(COSName.REGISTRY), cosDocument);
String ordCM = COSUtils.getAsString(cmsi.getItem(COSName.ORDERING), cosDocument);
String regCF = COSUtils.getAsString(cfsi.getItem(COSName.REGISTRY), cosDocument);
String ordCF = COSUtils.getAsString(cfsi.getItem(COSName.ORDERING), cosDocument);
if (!regCF.equals(regCM) || !ordCF.equals(ordCM)) {
this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_SYSINFO, font.getName() + ": The CIDSystemInfo is inconsistent"));
}
}
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class Type0FontValidator method processDescendantFont.
/**
* Extract the single CIDFont from the descendant array. Create a FontValidator for this CIDFont
* and launch its validation.
*
* @throws org.apache.pdfbox.preflight.exception.ValidationException if there is an error
* validating the CIDFont.
*/
protected void processDescendantFont() throws ValidationException {
COSDictionary fontDictionary = font.getCOSObject();
// a CIDFont is contained in the DescendantFonts array
COSArray array = COSUtils.getAsArray(fontDictionary.getItem(COSName.DESCENDANT_FONTS), cosDocument);
if (array == null || array.size() != 1) {
/*
* in PDF 1.4, this array must contain only one element, because of a PDF/A should be a PDF 1.4, this method
* returns an error if the array has more than one element.
*/
this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_INVALID, font.getName() + ": CIDFont is missing from the DescendantFonts array or the size of array is greater than 1"));
return;
}
COSDictionary cidFont = COSUtils.getAsDictionary(array.get(0), cosDocument);
if (cidFont == null) {
this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_INVALID, font.getName() + ": The DescendantFonts array should have one element with is a dictionary."));
return;
}
FontValidator<? extends FontContainer<? extends PDCIDFont>> cidFontValidator = createDescendantValidator(cidFont);
if (cidFontValidator != null) {
this.fontContainer.setDelegateFontContainer(cidFontValidator.getFontContainer());
cidFontValidator.validate();
}
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class Type0FontValidator method checkCIDSystemInfo.
/**
* Check the content of the CIDSystemInfo dictionary. A CIDSystemInfo dictionary must contain :
* <UL>
* <li>a Name - Registry
* <li>a Name - Ordering
* <li>a Integer - Supplement
* </UL>
*
* @param sysinfo
* @return the validation result.
*/
protected boolean checkCIDSystemInfo(COSBase sysinfo) {
boolean result = true;
COSDictionary cidSysInfo = COSUtils.getAsDictionary(sysinfo, cosDocument);
if (cidSysInfo != null) {
COSBase reg = cidSysInfo.getItem(COSName.REGISTRY);
COSBase ord = cidSysInfo.getItem(COSName.ORDERING);
COSBase sup = cidSysInfo.getItem(COSName.SUPPLEMENT);
if (!(COSUtils.isString(reg, cosDocument) && COSUtils.isString(ord, cosDocument) && COSUtils.isInteger(sup, cosDocument))) {
this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_SYSINFO));
result = false;
}
} else {
this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_SYSINFO));
result = false;
}
return result;
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class Type3FontValidator method checkFontBBox.
/**
* Check that the FontBBox element has the right format as declared in the
* PDF reference document.
*/
private void checkFontBBox() {
COSBase fontBBox = fontDictionary.getItem(COSName.FONT_BBOX);
if (!COSUtils.isArray(fontBBox, cosDocument)) {
this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID, font.getName() + ": The FontBBox element isn't an array"));
return;
}
/*
* check the content of the FontBBox. Should be an array with 4 numbers
*/
COSArray bbox = COSUtils.getAsArray(fontBBox, cosDocument);
if (bbox.size() != 4) {
this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID, font.getName() + ": The FontBBox element is invalid"));
return;
}
for (int i = 0; i < 4; i++) {
COSBase elt = bbox.get(i);
if (!(COSUtils.isFloat(elt, cosDocument) || COSUtils.isInteger(elt, cosDocument))) {
this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID, font.getName() + ": An element of FontBBox isn't a number"));
return;
}
}
}
Aggregations