use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class CIDType0DescriptorHelper method extractFontFile.
@Override
public PDStream extractFontFile(PDFontDescriptor fontDescriptor) {
PDStream ff3 = fontDescriptor.getFontFile3();
if (ff3 != null) {
// Stream validation should be done by the StreamValidateHelper. Process font specific check
COSStream stream = ff3.getCOSObject();
if (stream == null) {
this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile is missing"));
this.fContainer.notEmbedded();
} else {
// Length1/2/3 aren't mandatory for this type of font
// But the Subtype is a mandatory field with specific values
String st = stream.getNameAsString(COSName.SUBTYPE);
if (!(FONT_DICTIONARY_VALUE_TYPE0C.equals(st) || FONT_DICTIONARY_VALUE_TYPE1C.equals(st))) {
this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": invalid /Subtype /" + st + " in /FontFile3 stream"));
}
checkCIDSet(fontDescriptor);
}
}
return ff3;
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class FontDescriptorHelper method validate.
public void validate() {
PDFontDescriptor fd = this.font.getFontDescriptor();
boolean isStandard14 = false;
if (this.font instanceof PDFont) {
isStandard14 = ((PDFont) font).isStandard14();
}
// Only a PDFontDescriptorDictionary provides a way to embedded the font program.
if (fd != null) {
fontDescriptor = fd;
if (!isStandard14) {
checkMandatoryFields(fontDescriptor.getCOSObject());
}
if (hasOnlyOneFontFile(fontDescriptor)) {
PDStream fontFile = extractFontFile(fontDescriptor);
if (fontFile != null) {
processFontFile(fontDescriptor, fontFile);
checkFontFileMetaData(fontDescriptor, fontFile);
}
} else {
if (fontFileNotEmbedded(fontDescriptor)) {
this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": FontFile entry is missing from FontDescriptor"));
this.fContainer.notEmbedded();
} else {
this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": They is more than one FontFile"));
}
}
} else {
this.fContainer.push(new ValidationError(ERROR_FONTS_DESCRIPTOR_INVALID, this.font.getName() + ": FontDescriptor is null or is an AFM Descriptor"));
this.fContainer.notEmbedded();
}
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class FontDescriptorHelper method checkMandatoryFields.
protected boolean checkMandatoryFields(COSDictionary fDescriptor) {
boolean result = true;
StringBuilder missingFields = new StringBuilder();
for (String field : MANDATORYFIELDS) {
if (!fDescriptor.containsKey(field)) {
if (missingFields.length() > 1) {
missingFields.append(", ");
}
missingFields.append(field);
}
}
if (fDescriptor.containsKey(COSName.TYPE)) {
COSBase type = fDescriptor.getItem(COSName.TYPE);
if (!COSName.FONT_DESC.equals(type)) {
this.fContainer.push(new ValidationError(ERROR_FONTS_DESCRIPTOR_INVALID, this.font.getName() + ": /Type in FontDescriptor must be /FontDescriptor, but is " + type));
result = false;
}
}
if (missingFields.length() > 0) {
this.fContainer.push(new ValidationError(ERROR_FONTS_DESCRIPTOR_INVALID, this.font.getName() + ": some mandatory fields are missing from the FontDescriptor: " + missingFields + "."));
result = false;
}
return result;
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class TrueTypeDescriptorHelper method extractFontFile.
@Override
public PDStream extractFontFile(PDFontDescriptor fontDescriptor) {
PDStream fontFile = fontDescriptor.getFontFile2();
COSStream stream = (fontFile == null ? null : fontFile.getCOSObject());
if (stream == null) {
this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile2 is missing"));
this.fContainer.notEmbedded();
return null;
}
if (stream.getInt(COSName.LENGTH1) <= 0) {
this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile entry /Length1 is invalid"));
return null;
}
return fontFile;
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class Type1DescriptorHelper method checkMandatoryFields.
@Override
protected boolean checkMandatoryFields(COSDictionary fDescriptor) {
boolean result = super.checkMandatoryFields(fDescriptor);
/*
* if this font is a subset, the CharSet entry must be present in the FontDescriptor
*/
if (isSubSet(fontDescriptor.getFontName())) {
String charsetStr = fontDescriptor.getCharSet();
if (charsetStr == null || "".equals(charsetStr)) {
this.fContainer.push(new ValidationError(ERROR_FONTS_CHARSET_MISSING_FOR_SUBSET, fontDescriptor.getFontName() + ": The Charset entry is missing for the Type1 Subset"));
result = false;
}
}
return result;
}
Aggregations