Examples of PDFont


Examples of org.apache.pdfbox.pdmodel.font.PDFont

            PDPage page = new PDPage();
            doc.addPage( page );

            // load the font as this needs to be embedded as part of PDF/A
            PDFont font = PDTrueTypeFont.loadTTF(doc, new File(fontfile));
           
            // create a page with the message where needed
            PDPageContentStream contentStream = new PDPageContentStream(doc, page);
            contentStream.beginText();
            contentStream.setFont( font, 12 );
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.font.PDFont

    public void validText(byte[] string) throws IOException
    {
        // TextSize accessible through the TextState
        PDTextState textState = getGraphicsState().getTextState();
        final RenderingMode renderingMode = textState.getRenderingMode();
        final PDFont font = textState.getFont();
        if (font == null)
        {
            // Unable to decode the Text without Font
            registerError("Text operator can't be process without Font", ERROR_FONTS_UNKNOWN_FONT_REF);
            return;
        }

        FontContainer fontContainer = context.getFontContainer(font.getCOSObject());
        if (renderingMode == RenderingMode.NEITHER && (fontContainer == null || !fontContainer.isEmbeddedFont()))
        {
            // font not embedded and rendering mode is 3. Valid case and nothing to check
            return;
        }
        else if (fontContainer == null)
        {
            // Font Must be embedded if the RenderingMode isn't 3
            registerError(font.getName() + " is unknown wasn't found by the FontHelperValdiator",
                    ERROR_FONTS_UNKNOWN_FONT_REF);
            return;
        }
        else if (!fontContainer.isValid() && !fontContainer.errorsAleadyMerged())
        {
            context.addValidationErrors(fontContainer.getAllErrors());
            fontContainer.setErrorsAlreadyMerged(true);
            return;
        }
        if (!fontContainer.isValid() && fontContainer.errorsAleadyMerged())
        {
            // font already computed
            return;
        }

        InputStream in = new ByteArrayInputStream(string);
        while (in.available() > 0)
        {
            try
            {
                int code = font.readCode(in);
                fontContainer.checkGlyphWidth(code);
            }
            catch (IOException e)
            {
                registerError("Encoding can't interpret the character code", ERROR_FONTS_ENCODING_ERROR, e);
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.font.PDFont

    public void validText(byte[] string) throws IOException
    {
        // TextSize accessible through the TextState
        PDTextState textState = getGraphicsState().getTextState();
        final int renderingMode = textState.getRenderingMode();
        final PDFont font = textState.getFont();
        if (font == null)
        {
            // Unable to decode the Text without Font
            registerError("Text operator can't be process without Font", ERROR_FONTS_UNKNOWN_FONT_REF);
            return;
        }

        FontContainer fontContainer = context.getFontContainer(font.getCOSObject());
        if (renderingMode == 3 && (fontContainer == null || !fontContainer.isEmbeddedFont()))
        {
            // font not embedded and rendering mode is 3. Valid case and nothing to check
            return;
        }
        else if (fontContainer == null)
        {
            // Font Must be embedded if the RenderingMode isn't 3
            registerError(font.getBaseFont() + " is unknown wasn't found by the FontHelperValdiator",
                    ERROR_FONTS_UNKNOWN_FONT_REF);
            return;
        }
        else if (!fontContainer.isValid() && !fontContainer.errorsAleadyMerged())
        {
            context.addValidationErrors(fontContainer.getAllErrors());
            fontContainer.setErrorsAleadyMerged(true);
            return;
        }
        if (!fontContainer.isValid() && fontContainer.errorsAleadyMerged())
        {
            // font already computed
            return;
        }

        int codeLength = 1;
        for (int i = 0; i < string.length; i += codeLength)
        {
            // explore the string to detect character code (length can be 1 or 2 bytes)
            int cid = -1;
            codeLength = 1;
            try
            {
                // according to the encoding, extract the character identifier
                cid = font.encodeToCID(string, i, codeLength);
                if (cid == -1 && i + 1 < string.length)
                {
                    // maybe a multibyte encoding
                    codeLength++;
                    cid = font.encodeToCID(string, i, codeLength);
                }
                fontContainer.checkGlyphWith(cid);
            }
            catch (IOException e)
            {
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.font.PDFont

                    COSBase item = dicFonts.getItem((COSName) key);
                    COSDictionary xObjFont = COSUtils.getAsDictionary(item, cosDocument);

                    try
                    {
                        PDFont aFont = PDFontFactory.createFont(xObjFont);
                        FontContainer aContainer = this.context.getFontContainer(aFont.getCOSObject());
                        // another font is used in the Type3, check if the font is valid.
                        if (!aContainer.isValid())
                        {
                            this.fontContainer.push(new ValidationError(ERROR_FONTS_TYPE3_DAMAGED,
                                    "The Resources dictionary of type 3 font contains invalid font"));
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.font.PDFont

            PDPage page = new PDPage();
            doc.addPage( page );

            // load the font from pdfbox.jar
            InputStream fontStream = CreatePDFA.class.getResourceAsStream("/org/apache/pdfbox/resources/ttf/ArialMT.ttf");
            PDFont font = PDTrueTypeFont.loadTTF(doc, fontStream);
           
            // create a page with the message where needed
            PDPageContentStream contentStream = new PDPageContentStream(doc, page);
            contentStream.beginText();
            contentStream.setFont( font, 12 );
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.font.PDFont

                    paint = graphicsState.getNonStrokingColor().getJavaColor();
            }
            graphics.setComposite(composite);
            graphics.setPaint(paint);
           
            PDFont font = text.getFont();
            Matrix textPos = text.getTextPos().copy();
            float x = textPos.getXPosition();
            // the 0,0-reference has to be moved from the lower left (PDF) to the upper left (AWT-graphics)
            float y = pageSize.height - textPos.getYPosition();
            // Set translation to 0,0. We only need the scaling and shearing
            textPos.setValue(2, 0, 0);
            textPos.setValue(2, 1, 0);
            // because of the moved 0,0-reference, we have to shear in the opposite direction
            textPos.setValue(0, 1, (-1)*textPos.getValue(0, 1));
            textPos.setValue(1, 0, (-1)*textPos.getValue(1, 0));
            AffineTransform at = textPos.createAffineTransform();
            PDMatrix fontMatrix = font.getFontMatrix();
            at.scale(fontMatrix.getValue(0, 0) * 1000f, fontMatrix.getValue(1, 1) * 1000f);
            //TODO setClip() is a massive performance hot spot. Investigate optimization possibilities
            graphics.setClip(graphicsState.getCurrentClippingPath());
            // the fontSize is no longer needed as it is already part of the transformation
            // we should remove it from the parameter list in the long run
            font.drawString( text.getCharacter(), text.getCodePoints(), graphics, 1, at, x, y );
        }
        catch( IOException io )
        {
            io.printStackTrace();
        }
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.font.PDFont

                    appearance.setNormalAppearance( appearanceStream );
                }

                List tokens = getStreamTokens( appearanceStream );
                List daTokens = getStreamTokens( getDefaultAppearance() );
                PDFont pdFont = getFontAndUpdateResources( tokens, appearanceStream );

                if (!containsMarkedContent( tokens ))
                {
                    ByteArrayOutputStream output = new ByteArrayOutputStream();
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.font.PDFont

    }

    private PDFont getFontAndUpdateResources( List tokens, PDAppearanceStream appearanceStream ) throws IOException
    {

        PDFont retval = null;
        PDResources streamResources = appearanceStream.getResources();
        PDResources formResources = acroForm.getDefaultResources();
        if( formResources != null )
        {
            if( streamResources == null )
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.font.PDFont

        //We won't know the actual number of characters until
        //we process the byte data(could be two bytes each) but
        //it won't ever be more than string.length*2(there are some cases
        //were a single byte will result in two output characters "fi"
       
        final PDFont font = graphicsState.getTextState().getFont();
        // all fonts are providing the width/height of a character in thousandths of a unit of text space
        float fontMatrixXScaling = 1/1000f;
        float fontMatrixYScaling = 1/1000f;
        float glyphSpaceToTextSpaceFactor = 1/1000f;
        // expect Type3 fonts, those are providing the width of a character in glyph space units
        if (font instanceof PDType3Font)
        {
            PDMatrix fontMatrix = font.getFontMatrix();
            fontMatrixXScaling = fontMatrix.getValue(0, 0);
            fontMatrixYScaling = fontMatrix.getValue(1, 1);
            //This will typically be 1000 but in the case of a type3 font
            //this might be a different number
            glyphSpaceToTextSpaceFactor = 1f/fontMatrix.getValue( 0, 0 );
        }
        float spaceWidthText=0;
        try
        {  
            // to avoid crash as described in PDFBOX-614
            // lets see what the space displacement should be
            spaceWidthText = (font.getSpaceWidth()*glyphSpaceToTextSpaceFactor);
        }
        catch (Throwable exception)
        {
            LOG.warn( exception, exception);
        }
       
        if( spaceWidthText == 0 )
        {
            spaceWidthText = (font.getAverageFontWidth()*glyphSpaceToTextSpaceFactor);
            //The average space width appears to be higher than necessary
            //so lets make it a little bit smaller.
            spaceWidthText *= .80f;
        }
       
        float maxVerticalDisplacementText = 0;

        Matrix textStateParameters = new Matrix();
        textStateParameters.setValue(0,0, fontSizeText*horizontalScalingText);
        textStateParameters.setValue(1,1, fontSizeText);
        textStateParameters.setValue(2,1, riseText);

        int pageRotation = page.findRotation();
        float pageHeight = page.findCropBox().getHeight();
        float pageWidth = page.findCropBox().getWidth();

        Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();
        Matrix textXctm = new Matrix();
        Matrix textMatrixEnd = new Matrix();
        Matrix td = new Matrix();
        Matrix tempMatrix = new Matrix();

        int codeLength = 1;
        for( int i=0; i<string.length; i+=codeLength)
        {
            // Decode the value to a Unicode character
            codeLength = 1;
            String c = font.encode( string, i, codeLength );
            int[] codePoints = null;
            if( c == null && i+1<string.length)
            {
                //maybe a multibyte encoding
                codeLength++;
                c = font.encode( string, i, codeLength );
                codePoints = new int[] {font.getCodeFromArray(string, i, codeLength)};
            }

            // the space width has to be transformed into display units
            float spaceWidthDisp = spaceWidthText * fontSizeText * horizontalScalingText
                                    * textMatrix.getValue(0, 0) * ctm.getValue(0, 0);

            //todo, handle horizontal displacement
            // get the width and height of this character in text units
            float characterHorizontalDisplacementText = font.getFontWidth( string, i, codeLength );
            float characterVerticalDisplacementText = font.getFontHeight( string, i, codeLength );

            // multiply the width/height with the scaling factor
            characterHorizontalDisplacementText = characterHorizontalDisplacementText * fontMatrixXScaling;
            characterVerticalDisplacementText = characterVerticalDisplacementText * fontMatrixYScaling;

 
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.font.PDFont

        {
            context.addValidationError(new ValidationError(PreflightConstants.ERROR_FONTS_INVALID_DATA, "Font validation process needs at least one PDFont object"));
        }
        else
        {
            PDFont font = (PDFont) vPath.peek();
            FontContainer fontContainer = context.getFontContainer(font.getCOSObject());
            if (fontContainer == null)
            { // if fontContainer isn't null the font is already checked
                FontValidator<? extends FontContainer> validator = getFontValidator(context, font);
                if (validator != null) validator.validate();
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.