Package org.apache.pdfbox.util

Examples of org.apache.pdfbox.util.Matrix


                    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


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

     * @return the transformed stroke
     */
    private BasicStroke calculateStroke()
    {
        float lineWidth = (float)getGraphicsState().getLineWidth();
        Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();
        if (ctm != null && ctm.getXScale() > 0)
        {
            lineWidth = lineWidth * ctm.getXScale();
        }
        if (lineWidth < 0.25)
        {
            lineWidth = 0.25f;
        }
        BasicStroke currentStroke = null;
        if (stroke == null)
        {
          currentStroke = new BasicStroke(lineWidth);
        }
        else
        {
            float phaseStart = stroke.getDashPhase();
            float[] dashArray = stroke.getDashArray();
            if (dashArray != null)
            {
                if (ctm != null && ctm.getXScale() > 0)
                {
                    for (int i = 0; i < dashArray.length; ++i)
                    {
                        dashArray[i] *= ctm.getXScale();
                    }
                }
                phaseStart *= ctm.getXScale();
            }
            currentStroke = new BasicStroke(lineWidth, stroke.getEndCap(), stroke.getLineJoin(),
                    stroke.getMiterLimit(), dashArray, phaseStart);
        }
        return currentStroke;
View Full Code Here

    public void shFill(COSName shadingName) throws IOException
    {
        PDShadingResources shading = getResources().getShadings().get(shadingName.getName());
        LOG.debug("Shading = " + shading.toString());
        int shadingType = shading.getShadingType();
        Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();
        Paint paint = null;
        switch (shadingType)
        {
            case 1:
                paint = new Type1ShadingPaint((PDShadingType1)shading, ctm, pageSize.height);
View Full Code Here

                int imageHeight = awtImage.getHeight();
                double pageHeight = drawer.getPageSize().getHeight();

                LOG.debug("imageWidth: " + imageWidth + "\t\timageHeight: " + imageHeight);
       
                Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix();
                float yScaling = ctm.getYScale();
                float angle = (float)Math.acos(ctm.getValue(0, 0)/ctm.getXScale());
                if (ctm.getValue(0, 1) < 0 && ctm.getValue(1, 0) > 0)
                {
                    angle = (-1)*angle;
                }
                ctm.setValue(2, 1, (float)(pageHeight - ctm.getYPosition() - Math.cos(angle)*yScaling));
                ctm.setValue(2, 0, (float)(ctm.getXPosition() - Math.sin(angle)*yScaling));
                // because of the moved 0,0-reference, we have to shear in the opposite direction
                ctm.setValue(0, 1, (-1)*ctm.getValue(0, 1));
                ctm.setValue(1, 0, (-1)*ctm.getValue(1, 0));
                AffineTransform ctmAT = ctm.createAffineTransform();
                ctmAT.scale(1f/imageWidth, 1f/imageHeight);
                drawer.drawImage( awtImage, ctmAT );
            }
            catch( Exception e )
            {
                LOG.error(e, e);
            }
        }
        else if(xobject instanceof PDXObjectForm)
        {
            // save the graphics state
            context.getGraphicsStack().push( (PDGraphicsState)context.getGraphicsState().clone() );
           
            PDXObjectForm form = (PDXObjectForm)xobject;
            COSStream formContentstream = form.getCOSStream();
            // find some optional resources, instead of using the current resources
            PDResources pdResources = form.getResources();
            // 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( context.getGraphicsState().getCurrentTransformationMatrix());
                context.getGraphicsState().setCurrentTransformationMatrix(xobjectCTM);
            }
            getContext().processSubStream( page, pdResources, formContentstream );
           
            // 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

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

    public void shFill(COSName shadingName) throws IOException
    {
        PDShadingResources shading = getResources().getShadings().get(shadingName.getName());
        LOG.debug("Shading = " + shading.toString());
        int shadingType = shading.getShadingType();
        Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();
        Paint paint = null;
        switch (shadingType)
        {
            case 1:
                paint = new Type1ShadingPaint((PDShadingType1)shading, ctm, pageSize.height);
View Full Code Here

        throw new IOException("Not Implemented");
    }

    private float transformWidth(float width)
    {
        Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();

        if (ctm == null)
        {
            // TODO does the CTM really need to use null?
            return width;
        }

        float x = ctm.getValue(0, 0) + ctm.getValue(1, 0);
        float y = ctm.getValue(0, 1) + ctm.getValue(1, 1);
        return width * (float) Math.sqrt((x * x + y * y) * 0.5);
    }
View Full Code Here

                int imageHeight = awtImage.getHeight();
                double pageHeight = drawer.getPageSize().getHeight();

                LOG.debug("imageWidth: " + imageWidth + "\t\timageHeight: " + imageHeight);
       
                Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix();
                float yScaling = ctm.getYScale();
                float angle = (float)Math.acos(ctm.getValue(0, 0)/ctm.getXScale());
                if (ctm.getValue(0, 1) < 0 && ctm.getValue(1, 0) > 0)
                {
                    angle = (-1)*angle;
                }
                ctm.setValue(2, 1, (float)(pageHeight - ctm.getYPosition() - Math.cos(angle)*yScaling));
                ctm.setValue(2, 0, (float)(ctm.getXPosition() - Math.sin(angle)*yScaling));
                // because of the moved 0,0-reference, we have to shear in the opposite direction
                ctm.setValue(0, 1, (-1)*ctm.getValue(0, 1));
                ctm.setValue(1, 0, (-1)*ctm.getValue(1, 0));
                AffineTransform ctmAT = ctm.createAffineTransform();
                ctmAT.scale(1f/imageWidth, 1f/imageHeight);
                drawer.drawImage( awtImage, ctmAT );
            }
            catch( Exception e )
            {
                LOG.error(e, e);
            }
        }
        else if(xobject instanceof PDXObjectForm)
        {
            // save the graphics state
            context.getGraphicsStack().push( (PDGraphicsState)context.getGraphicsState().clone() );
           
            PDXObjectForm form = (PDXObjectForm)xobject;
            COSStream formContentstream = form.getCOSStream();
            // find some optional resources, instead of using the current resources
            PDResources pdResources = form.getResources();
            // 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( context.getGraphicsState().getCurrentTransformationMatrix());
                context.getGraphicsState().setCurrentTransformationMatrix(xobjectCTM);
            }
            if (form.getBBox() != null)
            {
                PDGraphicsState graphicsState = context.getGraphicsState();
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.