use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class SimpleFontValidator method checkMandatoryField.
protected void checkMandatoryField() {
String missingFields = "";
boolean areFieldsPresent = fontDictionary.containsKey(COSName.TYPE);
if (!areFieldsPresent) {
missingFields = "type, ";
}
boolean subType = fontDictionary.containsKey(COSName.SUBTYPE);
areFieldsPresent &= subType;
if (!subType) {
missingFields += "subType, ";
}
boolean baseFont = fontDictionary.containsKey(COSName.BASE_FONT);
areFieldsPresent &= baseFont;
if (!baseFont) {
missingFields += "baseFont, ";
}
boolean firstChar = fontDictionary.containsKey(COSName.FIRST_CHAR);
areFieldsPresent &= firstChar;
if (!firstChar) {
missingFields += "firstChar, ";
}
boolean lastChar = fontDictionary.containsKey(COSName.LAST_CHAR);
areFieldsPresent &= lastChar;
if (!lastChar) {
missingFields += "lastChar, ";
}
boolean widths = fontDictionary.containsKey(COSName.WIDTHS);
areFieldsPresent &= widths;
if (!widths) {
missingFields += "widths, ";
}
if (!areFieldsPresent) {
if (missingFields.endsWith(", ")) {
missingFields = missingFields.substring(0, missingFields.length() - 2);
}
this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID, this.font.getName() + ": some required fields are missing from the Font dictionary: " + missingFields + "."));
}
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class TrueTypeFontValidator method checkEncoding.
@Override
protected void checkEncoding() {
PDTrueTypeFont ttFont = (PDTrueTypeFont) font;
PDFontDescriptor fd = ttFont.getFontDescriptor();
if (fd != null) {
/*
* only MacRomanEncoding or WinAnsiEncoding are allowed for a non symbolic font.
*/
if (fd.isNonSymbolic()) {
Encoding encodingValue = ttFont.getEncoding();
if (!(encodingValue instanceof MacRomanEncoding || encodingValue instanceof WinAnsiEncoding)) {
this.fontContainer.push(new ValidationError(ERROR_FONTS_ENCODING, fd.getFontName() + ": The Encoding is invalid for the NonSymbolic TTF"));
}
}
/*
* For symbolic font, no encoding entry is allowed and only one encoding entry is expected into the FontFile
* CMap (Check latter when the FontFile stream will be checked)
*/
if (fd.isSymbolic() && fontDictionary.getItem(COSName.ENCODING) != null) {
this.fontContainer.push(new ValidationError(ERROR_FONTS_ENCODING, fd.getFontName() + ": The Encoding should be missing for the Symbolic TTF"));
}
}
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class Type0FontValidator method checkMandatoryFields.
/**
* This methods extracts from the Font dictionary all mandatory fields. If a mandatory field is missing, the list of
* ValidationError in the FontContainer is updated.
*/
protected void checkMandatoryFields() {
COSDictionary fontDictionary = font.getCOSObject();
boolean areFieldsPResent = fontDictionary.containsKey(COSName.TYPE);
areFieldsPResent &= fontDictionary.containsKey(COSName.SUBTYPE);
areFieldsPResent &= fontDictionary.containsKey(COSName.BASE_FONT);
areFieldsPResent &= fontDictionary.containsKey(COSName.DESCENDANT_FONTS);
areFieldsPResent &= fontDictionary.containsKey(COSName.ENCODING);
if (!areFieldsPResent) {
this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID, font.getName() + ": Some keys are missing from composite font dictionary"));
}
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class Type0FontValidator method processCMapAsStream.
/**
* This method checks mandatory fields of the CMap stream. This method also checks if the CMap
* stream is damaged using the CMapParser of the fontbox api. The standard information of a
* stream element will be checked by the StreamValidationProcess.
*
* @param aCMap the cmap stream.
*/
private void processCMapAsStream(COSStream aCMap) {
COSBase sysinfo = aCMap.getItem(COSName.CIDSYSTEMINFO);
checkCIDSystemInfo(sysinfo);
try (InputStream cmapStream = aCMap.createInputStream()) {
// extract information from the CMap stream
CMap fontboxCMap = new CMapParser().parse(cmapStream);
int wmValue = fontboxCMap.getWMode();
String cmnValue = fontboxCMap.getName();
/*
* According to the getInt javadoc, -1 is returned if there is no result. In the PDF Reference v1.7 p449,
* we can read that the default value is 0.
*/
int wmode = aCMap.getInt(COSName.getPDFName(FONT_DICTIONARY_KEY_CMAP_WMODE), FONT_DICTIONARY_DEFAULT_CMAP_WMODE);
String type = aCMap.getNameAsString(COSName.TYPE);
String cmapName = aCMap.getNameAsString(COSName.getPDFName(FONT_DICTIONARY_KEY_CMAP_NAME));
if (cmapName == null || "".equals(cmapName) || wmode > 1) {
this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_CMAP_INVALID_OR_MISSING, font.getName() + ": Some elements in the CMap dictionary are missing or invalid"));
} else if (!(wmValue == wmode && cmapName.equals(cmnValue))) {
this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_CMAP_INVALID_OR_MISSING, font.getName() + ": CMapName or WMode is inconsistent"));
} else if (!FONT_DICTIONARY_VALUE_TYPE_CMAP.equals(type)) {
this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_CMAP_INVALID_OR_MISSING, font.getName() + ": The CMap type is invalid"));
}
} catch (IOException e) {
this.fontContainer.push(new ValidationError(ERROR_FONTS_CID_CMAP_DAMAGED, font.getName() + ": The CMap type is damaged", e));
}
COSDictionary cmapUsed = (COSDictionary) aCMap.getDictionaryObject(COSName.getPDFName(FONT_DICTIONARY_KEY_CMAP_USECMAP));
if (cmapUsed != null) {
checkCMapEncoding(cmapUsed);
}
compareCIDSystemInfo(aCMap);
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class Type3FontValidator method checkMandatoryField.
protected void checkMandatoryField() {
boolean areFieldsPResent = fontDictionary.containsKey(COSName.FONT_BBOX);
areFieldsPResent &= fontDictionary.containsKey(COSName.FONT_MATRIX);
areFieldsPResent &= fontDictionary.containsKey(COSName.CHAR_PROCS);
areFieldsPResent &= fontDictionary.containsKey(COSName.ENCODING);
areFieldsPResent &= fontDictionary.containsKey(COSName.FIRST_CHAR);
areFieldsPResent &= fontDictionary.containsKey(COSName.LAST_CHAR);
areFieldsPResent &= fontDictionary.containsKey(COSName.WIDTHS);
if (!areFieldsPResent) {
this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID, font.getName() + ": Some required fields are missing from the Font dictionary."));
}
}
Aggregations