use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class CIDType2DescriptorHelper method extractFontFile.
@Override
public PDStream extractFontFile(PDFontDescriptor fontDescriptor) {
PDStream ff2 = fontDescriptor.getFontFile2();
if (ff2 != null) {
// Stream validation should be done by the StreamValidateHelper. Process font specific check
COSStream stream = ff2.getCOSObject();
if (stream == null) {
this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile is missing"));
this.fContainer.notEmbedded();
}
}
checkCIDSet(fontDescriptor);
return ff2;
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class FontDescriptorHelper method checkFontFileMetaData.
/**
* Type0, Type1 and TrueType FontValidator call this method to check the FontFile meta data.
*
* @param fontDescriptor
* The FontDescriptor which contains the FontFile stream
* @param fontFile
* The font file stream to check
*/
protected void checkFontFileMetaData(PDFontDescriptor fontDescriptor, PDStream fontFile) {
try {
PDMetadata metadata = fontFile.getMetadata();
if (metadata != null) {
// Filters are forbidden in a XMP stream
if (metadata.getFilters() != null && !metadata.getFilters().isEmpty()) {
this.fContainer.push(new ValidationError(ERROR_SYNTAX_STREAM_INVALID_FILTER, this.font.getName() + ": Filter specified in font file metadata dictionnary"));
return;
}
byte[] mdAsBytes = getMetaDataStreamAsBytes(metadata);
try {
DomXmpParser xmpBuilder = new DomXmpParser();
XMPMetadata xmpMeta = xmpBuilder.parse(mdAsBytes);
FontMetaDataValidation fontMDval = new FontMetaDataValidation();
List<ValidationError> ve = new ArrayList<>();
fontMDval.analyseFontName(xmpMeta, fontDescriptor, ve);
fontMDval.analyseRights(xmpMeta, fontDescriptor, ve);
this.fContainer.push(ve);
} catch (XmpParsingException e) {
if (e.getErrorType() == ErrorType.NoValueType) {
this.fContainer.push(new ValidationError(ERROR_METADATA_UNKNOWN_VALUETYPE, e.getMessage(), e));
} else if (e.getErrorType() == ErrorType.XpacketBadEnd) {
this.fContainer.push(new ValidationError(ERROR_METADATA_FORMAT_XPACKET, this.font.getName() + ": Unable to parse font metadata due to : " + e.getMessage(), e));
} else {
this.fContainer.push(new ValidationError(ERROR_METADATA_FORMAT, e.getMessage(), e));
}
}
}
} catch (IllegalStateException e) {
this.fContainer.push(new ValidationError(ERROR_METADATA_FORMAT_UNKOWN, this.font.getName() + ": The Metadata entry doesn't reference a stream object", e));
}
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class Type1DescriptorHelper method extractFontFile.
@Override
public PDStream extractFontFile(PDFontDescriptor fontDescriptor) {
PDStream ff1 = fontDescriptor.getFontFile();
PDStream ff3 = fontDescriptor.getFontFile3();
if (ff1 != null) {
COSStream stream = ff1.getCOSObject();
if (stream == null) {
this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile is missing"));
this.fContainer.notEmbedded();
return null;
}
boolean hasLength1 = stream.getInt(COSName.LENGTH1) > 0;
boolean hasLength2 = stream.getInt(COSName.getPDFName(FONT_DICTIONARY_KEY_LENGTH2)) > 0;
boolean hasLength3 = stream.getInt(COSName.getPDFName(FONT_DICTIONARY_KEY_LENGTH3)) >= 0;
if (!(hasLength1 && hasLength2 && hasLength3)) {
this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile is invalid"));
return null;
}
return ff1;
} else {
return ff3;
}
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class FontMetaDataValidation method analyseFontName.
/**
* Value of the dc:title must be the same as the FontName in the font descriptor.
*
* @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
*/
public boolean analyseFontName(XMPMetadata metadata, PDFontDescriptor fontDesc, List<ValidationError> ve) {
String fontName = fontDesc.getFontName();
String noSubSetName = fontName;
if (FontDescriptorHelper.isSubSet(fontName)) {
noSubSetName = fontName.split("\\+")[1];
}
DublinCoreSchema dc = metadata.getDublinCoreSchema();
if (dc != null && dc.getTitleProperty() != null) {
String defaultTitle = dc.getTitle("x-default");
if (defaultTitle != null) {
if (!defaultTitle.equals(fontName) && (noSubSetName != null && !defaultTitle.equals(noSubSetName))) {
StringBuilder sb = new StringBuilder(80);
sb.append("FontName").append(" present in the FontDescriptor dictionary doesn't match with XMP information dc:title of the Font File Stream.");
ve.add(new ValidationError(PreflightConstants.ERROR_METADATA_MISMATCH, sb.toString()));
return false;
}
// --- default value is the right one
return true;
} else {
Iterator<AbstractField> it = dc.getTitleProperty().getContainer().getAllProperties().iterator();
boolean empty = true;
while (it.hasNext()) {
empty = false;
AbstractField tmp = it.next();
if (tmp instanceof TextType) {
String val = ((TextType) tmp).getStringValue();
if (val.equals(fontName) || val.equals(noSubSetName)) {
// value found, return
return true;
}
}
}
// title doesn't match, it is an error.
StringBuilder sb = new StringBuilder(80);
sb.append("FontName");
if (empty) {
sb.append(" present in the FontDescriptor dictionary can't be found in XMP information the Font File Stream.");
ve.add(new ValidationError(PreflightConstants.ERROR_METADATA_PROPERTY_MISSING, sb.toString()));
} else {
sb.append(" present in the FontDescriptor dictionary doesn't match with XMP information dc:title of the Font File Stream.");
ve.add(new ValidationError(PreflightConstants.ERROR_METADATA_MISMATCH, sb.toString()));
}
return false;
}
}
return true;
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class DeviceColorSpaceHelper method processIndexedColorSpace.
/**
* Indexed color space is authorized only if the BaseColorSpace is a DeviceXXX color space. In all other cases the
* given list is updated with a ValidationError (ERROR_GRAPHIC_INVALID_PATTERN_COLOR_SPACE_FORBIDDEN) and returns
* false.
*/
@Override
protected void processIndexedColorSpace(PDColorSpace colorSpace) {
PDIndexed indexed = (PDIndexed) colorSpace;
PDColorSpace baseColorSpace = indexed.getBaseColorSpace();
ColorSpaces colorSpaces = ColorSpaces.valueOf(baseColorSpace.getName());
switch(colorSpaces) {
case Indexed:
case I:
case Pattern:
context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_FORBIDDEN, colorSpaces.getLabel() + " ColorSpace is forbidden"));
break;
default:
processAllColorSpace(baseColorSpace);
}
}
Aggregations