Package org.apache.pdfbox.util

Examples of org.apache.pdfbox.util.Matrix


        try
        {
            PageDrawer drawer = (PageDrawer)context;
   
            float lineWidth = (float)context.getGraphicsState().getLineWidth();
            Matrix ctm = context.getGraphicsState().getCurrentTransformationMatrix();
            if ( ctm != null && ctm.getXScale() > 0)
            {
                lineWidth = lineWidth * ctm.getXScale();
            }
           
            BasicStroke stroke = (BasicStroke)drawer.getStroke();
            if (stroke == null)
            {
View Full Code Here


                            + " instead");
                    graphics.setColor( this.getGraphicsState().getNonStrokingColor().getJavaColor() );
            }

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

        COSNumber c = (COSNumber)arguments.get( 2 );
        COSNumber d = (COSNumber)arguments.get( 3 );
        COSNumber e = (COSNumber)arguments.get( 4 );
        COSNumber f = (COSNumber)arguments.get( 5 );

        Matrix textMatrix = new Matrix();
        textMatrix.setValue( 0, 0, a.floatValue() );
        textMatrix.setValue( 0, 1, b.floatValue() );
        textMatrix.setValue( 1, 0, c.floatValue() );
        textMatrix.setValue( 1, 1, d.floatValue() );
        textMatrix.setValue( 2, 0, e.floatValue() );
        textMatrix.setValue( 2, 1, f.floatValue() );
        context.setTextMatrix( textMatrix );
        context.setTextLineMatrix( textMatrix.copy() );
    }
View Full Code Here

        {
            COSBase next = array.get( i );
            if( next instanceof COSNumber )
            {
                float adjustment = ((COSNumber)next).floatValue();
                Matrix adjMatrix = new Matrix();
                adjustment=-(adjustment/1000)*horizontalScaling*fontsize;
                // TODO vertical writing mode
                adjMatrix.setValue( 2, 0, adjustment );
                context.setTextMatrix( adjMatrix.multiply(context.getTextMatrix(), adjMatrix) );
            }
            else if( next instanceof COSString )
            {
                context.processEncodedText( ((COSString)next).getBytes() );
            }
View Full Code Here

     */
    public void process(PDFOperator operator, List<COSBase> arguments)
    {
        COSNumber x = (COSNumber)arguments.get( 0 );
        COSNumber y = (COSNumber)arguments.get( 1 );
        Matrix td = new Matrix();
        td.setValue( 2, 0, x.floatValue() );
        td.setValue( 2, 1, y.floatValue() );
        context.setTextLineMatrix( td.multiply( context.getTextLineMatrix() ) );
        context.setTextMatrix( context.getTextLineMatrix().copy() );
    }
View Full Code Here

            {
                try
                {
                    PDXObjectImage image = (PDXObjectImage)xobject;
                    PDPage page = getCurrentPage();
                    Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();
                    double rotationInRadians =(page.findRotation() * Math.PI)/180;


                    AffineTransform rotation = new AffineTransform();
                    rotation.setToRotation( rotationInRadians );
                    AffineTransform rotationInverse = rotation.createInverse();
                    Matrix rotationInverseMatrix = new Matrix();
                    rotationInverseMatrix.setFromAffineTransform( rotationInverse );
                    Matrix rotationMatrix = new Matrix();
                    rotationMatrix.setFromAffineTransform( rotation );

                    Matrix unrotatedCTM = ctm.multiply( rotationInverseMatrix );
                    float xScale = unrotatedCTM.getXScale();
                    float yScale = unrotatedCTM.getYScale();

                    System.out.println( "Found image[" + objectName.getName() + "] " +
                            "at " + unrotatedCTM.getXPosition() + "," + unrotatedCTM.getYPosition() +
                            " size=" + (xScale/100f*image.getWidth()) + "," + (yScale/100f*image.getHeight() ));
                }
                catch( NoninvertibleTransformException e )
                {
                    throw new WrappedIOException( e );
View Full Code Here

                        + " instead");
                graphics.setColor( this.getGraphicsState().getNonStrokingColor().getJavaColor() );
            }
            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();
            graphics.setClip(getGraphicsState().getCurrentClippingPath());
            font.drawString( text.getCharacter(), graphics, text.getFontSize(), at, x, y );
        }
        catch( IOException io )
        {
View Full Code Here

            {
                try
                {
                    PDXObjectImage image = (PDXObjectImage)xobject;
                    PDPage page = getCurrentPage();
                    Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();
                    double rotationInRadians =(page.findRotation() * Math.PI)/180;


                    AffineTransform rotation = new AffineTransform();
                    rotation.setToRotation( rotationInRadians );
                    AffineTransform rotationInverse = rotation.createInverse();
                    Matrix rotationInverseMatrix = new Matrix();
                    rotationInverseMatrix.setFromAffineTransform( rotationInverse );
                    Matrix rotationMatrix = new Matrix();
                    rotationMatrix.setFromAffineTransform( rotation );

                    Matrix unrotatedCTM = ctm.multiply( rotationInverseMatrix );
                    float xScale = unrotatedCTM.getXScale();
                    float yScale = unrotatedCTM.getYScale();

                    System.out.println( "Found image[" + objectName.getName() + "] " +
                            "at " + unrotatedCTM.getXPosition() + "," + unrotatedCTM.getYPosition() +
                            " size=" + (xScale/100f*image.getWidth()) + "," + (yScale/100f*image.getHeight() ));
                }
                catch( NoninvertibleTransformException e )
                {
                    throw new WrappedIOException( e );
View Full Code Here

     * @param operator The operator that is being executed.
     * @param arguments List
     */
    public void process(PDFOperator operator, List arguments)
    {
        context.setTextMatrix( new Matrix());
        context.setTextLineMatrix( new Matrix() );
    }
View Full Code Here

        try
        {
            PageDrawer drawer = (PageDrawer)context;
   
            float lineWidth = (float)context.getGraphicsState().getLineWidth();
            Matrix ctm = context.getGraphicsState().getCurrentTransformationMatrix();
            if ( ctm != null && ctm.getXScale() > 0)
            {
                lineWidth = lineWidth * ctm.getXScale();
            }
            Graphics2D graphics = ((PageDrawer)context).getGraphics();
            BasicStroke stroke = (BasicStroke)graphics.getStroke();
            if (stroke == null)
            {
View Full Code Here

TOP

Related Classes of org.apache.pdfbox.util.Matrix

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.