Examples of PDMatrix


Examples of org.apache.pdfbox.pdmodel.common.PDMatrix

                array.add( COSInteger.ZERO );
                array.add( new COSFloat( 0.001f ) );
                array.add( COSInteger.ZERO );
                array.add( COSInteger.ZERO );
            }
            fontMatrix = new PDMatrix(array);
        }
        return fontMatrix;
    }
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.common.PDMatrix

                COSArray array = new COSArray();
                for(Number number : numbers)
                {
                    array.add(new COSFloat(number.floatValue()));
                }
                fontMatrix = new PDMatrix(array);
            }
            else
            {
                super.getFontMatrix();
            }
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.common.PDMatrix

                                    for (int i=0;i<6;i++)
                                    {
                                        COSFloat floatValue = new COSFloat(Float.parseFloat(st.nextToken()));
                                        array.add(floatValue);
                                    }
                                    fontMatrix = new PDMatrix(array);
                                }
                                catch (NumberFormatException exception)
                                {
                                    log.error("Can't read the fontmatrix from embedded font file!");
                                }
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.common.PDMatrix

     *
     * @return The matrix to transform from glyph space to text space.
     */
    public PDMatrix getFontMatrix()
    {
        PDMatrix matrix = null;
        COSArray array = (COSArray)font.getDictionaryObject( COSName.FONT_MATRIX );
        if( array == null )
        {
            array = new COSArray();
            array.add( new COSFloat( 0.001f ) );
            array.add( COSInteger.ZERO );
            array.add( COSInteger.ZERO );
            array.add( new COSFloat( 0.001f ) );
            array.add( COSInteger.ZERO );
            array.add( COSInteger.ZERO );
        }
        matrix = new PDMatrix(array);

        return matrix;
    }
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.common.PDMatrix

            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, 0) * 1000f);
            graphics.setClip(getGraphicsState().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(), graphics, 1, at, x, y );
        }
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.common.PDMatrix

        //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();
        PDMatrix fontMatrix = font.getFontMatrix();
       
        //This will typically be 1000 but in the case of a type3 font
        //this might be a different number
        final float glyphSpaceToTextSpaceFactor = 1f/font.getFontMatrix().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.getFontWidth( SPACE_BYTES, 0, 1 )/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.findMediaBox().getHeight();
        float pageWidth = page.findMediaBox().getWidth();

        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 );
            if( c == null && i+1<string.length)
            {
                //maybe a multibyte encoding
                codeLength++;
                c = font.encode( string, i, codeLength );
            }

            // the space width has to be transformed into display units
            float spaceWidthDisp = spaceWidthText * fontSizeText * horizontalScalingText * textMatrix.getValue(0, 0) * getGraphicsState().getCurrentTransformationMatrix().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 );
            // Type3 fonts are providing the width of a character in glyph space units
            if (font instanceof PDType3Font)
            {
                // multiply the witdh with the scaling factor of the font matrix
                characterHorizontalDisplacementText = characterHorizontalDisplacementText * fontMatrix.getValue(0, 0);
            }
            // all other fonts are providing the width of a character in thousandths of a unit of text space
            else
            {
                characterHorizontalDisplacementText = characterHorizontalDisplacementText/1000f;
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.common.PDMatrix

        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
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.common.PDMatrix

            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 );
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.common.PDMatrix

                                    for (int i=0;i<6;i++)
                                    {
                                        COSFloat floatValue = new COSFloat(Float.parseFloat(st.nextToken()));
                                        array.add(floatValue);
                                    }
                                    fontMatrix = new PDMatrix(array);
                                }
                                catch (NumberFormatException exception)
                                {
                                    log.error("Can't read the fontmatrix from embedded font file!");
                                }
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.common.PDMatrix

                COSArray array = new COSArray();
                for(Number number : numbers)
                {
                    array.add(new COSFloat(number.floatValue()));
                }
                fontMatrix = new PDMatrix(array);
            }
            else
            {
                super.getFontMatrix();
            }
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.