Package org.apache.pdfbox.util

Examples of org.apache.pdfbox.util.Matrix


        }
        int imageWidth = awtImage.getWidth();
        int imageHeight = awtImage.getHeight();
        double pageHeight = pageSize.getHeight();
       
        Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix();
        int pageRotation = page.findRotation();

        AffineTransform ctmAT = ctm.createAffineTransform();
        ctmAT.scale(1f/imageWidth, 1f/imageHeight);
        Matrix rotationMatrix = new Matrix();
        rotationMatrix.setFromAffineTransform( ctmAT );
        if (pageRotation == 0 || pageRotation == 180)
        {
            rotationMatrix.setValue(2,1,(float)pageHeight-ctm.getYPosition()-ctm.getYScale());
        }
        else if (pageRotation == 90 || pageRotation == 270)
        {
            rotationMatrix.setValue(2,0,(float)ctm.getXPosition()-ctm.getYScale());
            rotationMatrix.setValue(2,1,(float)pageHeight-ctm.getYPosition());
        }
        rotationMatrix.setValue(0, 1, (-1)*rotationMatrix.getValue(0, 1));
        rotationMatrix.setValue(1, 0, (-1)*rotationMatrix.getValue(1, 0));
        AffineTransform at = new AffineTransform(
                rotationMatrix.getValue(0,0),rotationMatrix.getValue(0,1),
                rotationMatrix.getValue(1,0), rotationMatrix.getValue( 1, 1),
                rotationMatrix.getValue(2,0),rotationMatrix.getValue(2,1)
                );

        graphics.setClip(context.getGraphicsState().getCurrentClippingPath());
        graphics.drawImage( awtImage, at, null );
    }
View Full Code Here


            COSBase next = array.get( i );
            if( next instanceof COSNumber )
            {
                adjustment = ((COSNumber)next).floatValue();

                Matrix adjMatrix = new Matrix();
                adjustment=(-adjustment/1000)*context.getGraphicsState().getTextState().getFontSize() *
                    (context.getGraphicsState().getTextState().getHorizontalScalingPercent()/100);
                adjMatrix.setValue( 2, 0, adjustment );
                context.setTextMatrix( adjMatrix.multiply( context.getTextMatrix() ) );
            }
            else if( next instanceof COSString )
            {
                context.processEncodedText( ((COSString)next).getBytes() );
            }
View Full Code Here

     */
    public void process(PDFOperator operator, List arguments)
    {
        COSNumber x = (COSNumber)arguments.get( 0 );
        COSNumber y = (COSNumber)arguments.get( 1 );
        Matrix td = new Matrix();
        td.setValue( 2, 0, x.floatValue() );//.* textMatrix.getValue(0,0) );
        td.setValue( 2, 1, y.floatValue() );//* textMatrix.getValue(1,1) );
        //log.debug( "textLineMatrix before " + textLineMatrix );
        context.setTextLineMatrix( td.multiply( context.getTextLineMatrix() ) ); //textLineMatrix.multiply( td );
        //log.debug( "textLineMatrix after " + textLineMatrix );
        context.setTextMatrix( context.getTextLineMatrix().copy() );
    }
View Full Code Here

                int imageHeight = awtImage.getHeight();
                double pageHeight = pageSize.getHeight();

                log.info("imageWidth: " + imageWidth + "\t\timageHeight: " + imageHeight);
       
                Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix();
                int pageRotation = page.findRotation();

                AffineTransform ctmAT = ctm.createAffineTransform();
                ctmAT.scale(1f/imageWidth, 1f/imageHeight);
                Matrix rotationMatrix = new Matrix();
                rotationMatrix.setFromAffineTransform( ctmAT );
                if (pageRotation == 0 || pageRotation == 180)
                {
                    rotationMatrix.setValue(2,1,(float)pageHeight-ctm.getYPosition()-ctm.getYScale());
                }
                else if (pageRotation == 90 || pageRotation == 270)
                {
                    rotationMatrix.setValue(2,0,(float)ctm.getXPosition()-ctm.getYScale());
                    rotationMatrix.setValue(2,1,(float)pageHeight-ctm.getYPosition());
                }
                rotationMatrix.setValue(0, 1, (-1)*rotationMatrix.getValue(0, 1));
                rotationMatrix.setValue(1, 0, (-1)*rotationMatrix.getValue(1, 0));

                AffineTransform at = new AffineTransform(
                        rotationMatrix.getValue(0,0),rotationMatrix.getValue(0,1),
                        rotationMatrix.getValue(1,0), rotationMatrix.getValue( 1, 1),
                        rotationMatrix.getValue(2,0),rotationMatrix.getValue(2,1)
                    );
                graphics.setClip(context.getGraphicsState().getCurrentClippingPath());
                graphics.drawImage( awtImage, at, null );
            }
            catch( Exception e )
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 newMatrix = new Matrix();
        newMatrix.setValue(0, 0, a.floatValue());
        newMatrix.setValue(0, 1, b.floatValue());
        newMatrix.setValue(1, 0, c.floatValue());
        newMatrix.setValue(1, 1, d.floatValue());
        newMatrix.setValue(2, 0, e.floatValue());
        newMatrix.setValue(2, 1, f.floatValue());

        //this line has changed
        context.getGraphicsState().setCurrentTransformationMatrix(
                newMatrix.multiply( context.getGraphicsState().getCurrentTransformationMatrix() ) );


    }
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

                            + " 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, 0) * 1000f);
            graphics.setClip(getGraphicsState().getCurrentClippingPath());
            font.drawString( text.getCharacter(), graphics, text.getFontSize(), at, x, y );
        }
View Full Code Here

  public boolean isItalic(TextPosition text) {
    if (isItalic(text.getFont().getFontDescriptor())) {
      return true;
    }
    Matrix textPos = text.getTextPos();
    if (textPos != null && textPos.getXScale() < textPos.getYScale()) {
      return true;
    }
    if (textPos != null && textPos.getXScale() > textPos.getYScale()) {
      return true;
    }
    return false;
  }
View Full Code Here

        PDPage page = getCurrentPage();
        int imageWidth = image.getWidth();
        int imageHeight = image.getHeight();
        double pageHeight = page.getMediaBox().getHeight();

        Matrix ctmNew = getGraphicsState().getCurrentTransformationMatrix();
        float yScaling = ctmNew.getYScale();
        float angle = (float) Math.acos(ctmNew.getValue(0, 0) / ctmNew.getXScale());
        if (ctmNew.getValue(0, 1) < 0 && ctmNew.getValue(1, 0) > 0) {
          angle = (-1) * angle;
        }
        ctmNew.setValue(2, 1, (float) (pageHeight - ctmNew.getYPosition() - Math.cos(angle) * yScaling));
        ctmNew.setValue(2, 0, (float) (ctmNew.getXPosition() - Math.sin(angle) * yScaling));
        // because of the moved 0,0-reference, we have to shear in the opposite direction
        ctmNew.setValue(0, 1, (-1) * ctmNew.getValue(0, 1));
        ctmNew.setValue(1, 0, (-1) * ctmNew.getValue(1, 0));
        AffineTransform ctmAT = ctmNew.createAffineTransform();
        ctmAT.scale(1f / imageWidth, 1f / imageHeight);

        Image entry = new Image();
        entry.x = ctmNew.getXPosition();
        entry.image = image;
        entry.name = objectName.getName();
        images.put(page, ctmNew.getYPosition(), entry);

      } else if (xobject instanceof PDXObjectForm) {
        // save the graphics state
        getGraphicsStack().push((PDGraphicsState) getGraphicsState().clone());
        PDPage page = getCurrentPage();

        PDXObjectForm form = (PDXObjectForm) xobject;
        COSStream invoke = (COSStream) form.getCOSObject();
        PDResources pdResources = form.getResources();
        if (pdResources == null) {
          pdResources = page.findResources();
        }
        // if there is an optional form matrix, we have to
        // map the form space to the user space
        Matrix matrix = form.getMatrix();
        if (matrix != null) {
          Matrix xobjectCTM = matrix.multiply(getGraphicsState().getCurrentTransformationMatrix());
          getGraphicsState().setCurrentTransformationMatrix(xobjectCTM);
        }
        processSubStream(page, pdResources, invoke);

        // restore the graphics state
View Full Code Here

                    PDAppearanceStream appearance =
                        (PDAppearanceStream)appearanceMap.get( appearanceName );
                    if( appearance != null )
                    {
                        Point2D point = new Point2D.Float(rect.getLowerLeftX(), rect.getLowerLeftY());
                        Matrix matrix = appearance.getMatrix();
                        if (matrix != null)
                        {
                            // transform the rectangle using the given matrix
                            AffineTransform at = matrix.createAffineTransform();
                            at.transform(point, point);
                        }
                        g.translate( (int)point.getX(), -(int)point.getY() );
                        processSubStream( page, appearance.getResources(), appearance.getStream() );
                        g.translate( -(int)point.getX(), (int)point.getY() );
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.