Package org.apache.pdfbox.preflight.ValidationResult

Examples of org.apache.pdfbox.preflight.ValidationResult.ValidationError


    @Override
    protected void processFontFile(PDFontDescriptor fontDescriptor, PDStream fontFile)
    {
        if (font.isDamaged())
        {
            this.fContainer.push(new ValidationError(ERROR_FONTS_TRUETYPE_DAMAGED,
                    "The FontFile can't be read for " + this.font.getName()));
        }
        else
        {
            // there must be exactly one encoding in the "cmap" table if the font is symbolic
            TrueTypeFont ttf = pdTrueTypeFont.getTrueTypeFont();
            try
            {
                if (pdTrueTypeFont.isSymbolic() && ttf.getCmap().getCmaps().length != 1)
                {
                    this.fContainer.push(new ValidationError(ERROR_FONTS_ENCODING,
                            "Symbolic TrueType font has more than one 'cmap' entry for " +
                            this.font.getName()));
                }
            }
            catch (IOException e)
            {
                this.fContainer.push(new ValidationError(ERROR_FONTS_TRUETYPE_DAMAGED,
                        "The TTF 'cmap' could not be read for " + this.font.getName()));
            }
        }
    }
View Full Code Here


                }
                else
                {
                    if (fontFileNotEmbedded(fontDescriptor))
                    {
                        this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID,
                                "FontFile entry is missing from FontDescriptor for " + fontDescriptor.getFontName()));
                        this.fContainer.notEmbedded();
                    }
                    else
                    {
                        this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID,
                                "They are more than one FontFile for " + fontDescriptor.getFontName()));
                    }
                }
            }
        }
        else
        {
            this.fContainer.push(new ValidationError(ERROR_FONTS_DESCRIPTOR_INVALID,
                    "FontDescriptor is null or is a AFM Descriptor"));
            this.fContainer.notEmbedded();
        }
    }
View Full Code Here

        {
            if (missingFields.endsWith(", "))
            {
                missingFields = missingFields.substring(0, missingFields.length() - 2);
            }
            this.fContainer.push(new ValidationError(ERROR_FONTS_DESCRIPTOR_INVALID,
                    this.font.getName()
                    + ": some mandatory fields are missing from the FontDescriptor: " + missingFields + "."));
        }
        return areFieldsPresent;
    }
View Full Code Here

            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,
                            "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<ValidationError>();
                    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()));
                    }
                    else if (e.getErrorType() == ErrorType.XpacketBadEnd)
                    {
                        this.fContainer.push(new ValidationError(ERROR_METADATA_FORMAT_XPACKET,
                                "Unable to parse font metadata due to : " + e.getMessage()));
                    }
                    else
                    {
                        this.fContainer.push(new ValidationError(ERROR_METADATA_FORMAT, e.getMessage()));
                    }
                }
            }
        }
        catch (IllegalStateException e)
        {
            this.fContainer.push(new ValidationError(ERROR_METADATA_FORMAT_UNKOWN,
                    "The Metadata entry doesn't reference a stream object"));
        }
    }
View Full Code Here

            IOUtils.copyLarge(metaDataContent, bos);
            result = bos.toByteArray();
        }
        catch (IOException e)
        {
            this.fContainer.push(new ValidationError(ERROR_METADATA_FORMAT_STREAM,
                    "Unable to read font metadata due to : " + e.getMessage()));
        }
        finally
        {
            IOUtils.closeQuietly(metaDataContent);
View Full Code Here

                        || encodingName.equals(FONT_DICTIONARY_VALUE_ENCODING_MAC_EXP)
                        || encodingName.equals(FONT_DICTIONARY_VALUE_ENCODING_WIN)
                        || encodingName.equals(FONT_DICTIONARY_VALUE_ENCODING_PDFDOC) || encodingName
                            .equals(FONT_DICTIONARY_VALUE_ENCODING_STD)))
                {
                    this.fontContainer.push(new ValidationError(ERROR_FONTS_ENCODING));
                }
            }
            else if (!COSUtils.isDictionary(encoding, cosDocument))
            {
                this.fontContainer.push(new ValidationError(ERROR_FONTS_ENCODING));
            }
        }
    }
View Full Code Here

        areFieldsPResent &= fontDictionary.containsKey(COSName.LAST_CHAR);
        areFieldsPResent &= fontDictionary.containsKey(COSName.WIDTHS);

        if (!areFieldsPResent)
        {
            this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID,
                    "Some required fields are missing from the Font dictionary."));
        }
    }
View Full Code Here

    {
        COSBase fontBBox = fontDictionary.getItem(COSName.FONT_BBOX);

        if (!COSUtils.isArray(fontBBox, cosDocument))
        {
            this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID,
                    "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,
                    "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,
                        "An element of FontBBox isn't a number"));
                return;
            }
        }
    }
View Full Code Here

    {
        COSBase fontMatrix = fontDictionary.getItem(COSName.FONT_MATRIX);

        if (!COSUtils.isArray(fontMatrix, cosDocument))
        {
            this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID,
                    "The FontMatrix element isn't an array"));
            return;
        }

        /*
         * Check the content of the FontMatrix. Should be an array with 6 numbers
         */
        COSArray matrix = COSUtils.getAsArray(fontMatrix, cosDocument);
        if (matrix.size() != 6)
        {
            this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID,
                    "The FontMatrix element is invalid"));
            return;
        }

        for (int i = 0; i < 6; i++)
        {
            COSBase elt = matrix.get(i);
            if (!(COSUtils.isFloat(elt, cosDocument) || COSUtils.isInteger(elt, cosDocument)))
            {
                this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID,
                        "An element of FontMatrix isn't a number"));
                return;
            }
        }
    }
View Full Code Here

            checkEncodingAsDictionary(fontEncoding);
        }
        else
        {
            // the encoding entry is invalid
            this.fontContainer.push(new ValidationError(ERROR_FONTS_TYPE3_DAMAGED,
                    "The Encoding entry doesn't have the right type"));
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.pdfbox.preflight.ValidationResult.ValidationError

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.