Examples of PDGraphicsState


Examples of org.apache.pdfbox.pdmodel.graphics.PDGraphicsState

     * @param windingRule The winding rule this path will use.
     *
     */
    public void setClippingPath(int windingRule)
    {
        PDGraphicsState graphicsState = getGraphicsState();
        GeneralPath clippingPath = (GeneralPath)getLinePath().clone();
        clippingPath.setWindingRule(windingRule);
        // If there is already set a clipping path, we have to intersect the new with the existing one
        if (graphicsState.getCurrentClippingPath() != null)
        {
            Area currentArea = new Area(getGraphicsState().getCurrentClippingPath());
            Area newArea = new Area(clippingPath);
            currentArea.intersect(newArea);
            graphicsState.setCurrentClippingPath(currentArea);
        }
        else
        {
            graphicsState.setCurrentClippingPath(clippingPath);
        }
        getLinePath().reset();
    }
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.graphics.PDGraphicsState

     * @param windingRule The winding rule this path will use.
     *
     */
    public void setClippingPath(int windingRule)
    {
        PDGraphicsState graphicsState = getGraphicsState();
        GeneralPath clippingPath = (GeneralPath)getLinePath().clone();
        clippingPath.setWindingRule(windingRule);
        // If there is already set a clipping path, we have to intersect the new with the existing one
        if (graphicsState.getCurrentClippingPath() != null)
        {
            Area currentArea = new Area(getGraphicsState().getCurrentClippingPath());
            Area newArea = new Area(clippingPath);
            currentArea.intersect(newArea);
            graphicsState.setCurrentClippingPath(currentArea);
        }
        else
        {
            graphicsState.setCurrentClippingPath(clippingPath);
        }
        getLinePath().reset();
    }
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.graphics.PDGraphicsState

     *
     * @throws IOException if there is an error accessing the stream.
     */
    public void processStream( PDPage aPage, PDResources resources, COSStream cosStream ) throws IOException
    {
        graphicsState = new PDGraphicsState();
        textMatrix = null;
        textLineMatrix = null;
        graphicsStack.clear();
        streamResourcesStack.clear();

View Full Code Here

Examples of org.apache.pdfbox.pdmodel.graphics.PDGraphicsState

     * @param windingRule The winding rule this path will use.
     *
     */
    public void setClippingPath(int windingRule)
    {
        PDGraphicsState graphicsState = getGraphicsState();
        GeneralPath clippingPath = (GeneralPath)getLinePath().clone();
        clippingPath.setWindingRule(windingRule);
        // If there is already set a clipping path, we have to intersect the new with the existing one
        if (graphicsState.getCurrentClippingPath() != null)
        {
            Area currentArea = new Area(getGraphicsState().getCurrentClippingPath());
            Area newArea = new Area(clippingPath);
            currentArea.intersect(newArea);
            graphicsState.setCurrentClippingPath(currentArea);
        }
        else
        {
            graphicsState.setCurrentClippingPath(clippingPath);
        }
        getLinePath().reset();
    }
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.graphics.PDGraphicsState

     */
    protected void processTextPosition( TextPosition text )
    {
        try
        {
            PDGraphicsState graphicsState = getGraphicsState();
            Composite composite;
            Paint paint;
            switch(graphicsState.getTextState().getRenderingMode())
            {
                case PDTextState.RENDERING_MODE_FILL_TEXT:
                    composite = graphicsState.getNonStrokeJavaComposite();
                    paint = graphicsState.getNonStrokingColor().getJavaColor();
                    if (paint == null)
                    {
                        paint = graphicsState.getNonStrokingColor().getPaint(pageSize.height);
                    }
                    break;
                case PDTextState.RENDERING_MODE_STROKE_TEXT:
                    composite = graphicsState.getStrokeJavaComposite();
                    paint = graphicsState.getStrokingColor().getJavaColor();
                    if (paint == null)
                    {
                        paint = graphicsState.getStrokingColor().getPaint(pageSize.height);
                    }
                    break;
                case PDTextState.RENDERING_MODE_NEITHER_FILL_NOR_STROKE_TEXT:
                    //basic support for text rendering mode "invisible"
                    Color nsc = graphicsState.getStrokingColor().getJavaColor();
                    float[] components = {Color.black.getRed(),Color.black.getGreen(),Color.black.getBlue()};
                    paint = new Color(nsc.getColorSpace(),components,0f);
                    composite = graphicsState.getStrokeJavaComposite();
                    break;
                default:
                    // TODO : need to implement....
                    LOG.debug("Unsupported RenderingMode "
                            + this.getGraphicsState().getTextState().getRenderingMode()
                            + " in PageDrawer.processTextPosition()."
                            + " Using RenderingMode "
                            + PDTextState.RENDERING_MODE_FILL_TEXT
                            + " instead");
                    composite = graphicsState.getNonStrokeJavaComposite();
                    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 )
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.graphics.PDGraphicsState

     */
    public void endPath()
    {
        if (clippingWindingRule > -1)
        {
            PDGraphicsState graphicsState = getGraphicsState();
            GeneralPath clippingPath = (GeneralPath)getLinePath().clone();
            clippingPath.setWindingRule(clippingWindingRule);
            // If there is already set a clipping path, we have to intersect the new with the existing one
            if (graphicsState.getCurrentClippingPath() != null)
            {
                Area currentArea = new Area(getGraphicsState().getCurrentClippingPath());
                Area newArea = new Area(clippingPath);
                currentArea.intersect(newArea);
                graphicsState.setCurrentClippingPath(currentArea);
            }
            else
            {
                graphicsState.setCurrentClippingPath(clippingPath);
            }
            clippingWindingRule = -1;
        }
        getLinePath().reset();
    }
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.graphics.PDGraphicsState

     * @param windingRule The winding rule this path will use.
     *
     */
    public void setClippingPath(int windingRule)
    {
        PDGraphicsState graphicsState = getGraphicsState();
        GeneralPath clippingPath = (GeneralPath)getLinePath().clone();
        clippingPath.setWindingRule(windingRule);
        // If there is already set a clipping path, we have to intersect the new with the existing one
        if (graphicsState.getCurrentClippingPath() != null)
        {
            Area currentArea = new Area(getGraphicsState().getCurrentClippingPath());
            Area newArea = new Area(clippingPath);
            currentArea.intersect(newArea);
            graphicsState.setCurrentClippingPath(currentArea);
        }
        else
        {
            graphicsState.setCurrentClippingPath(clippingPath);
        }
        getLinePath().reset();
    }
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.graphics.PDGraphicsState

     *
     * @throws IOException if there is an error accessing the stream.
     */
    public void processStream( PDPage aPage, PDResources resources, COSStream cosStream ) throws IOException
    {
        graphicsState = new PDGraphicsState(aPage.findCropBox());
        textMatrix = null;
        textLineMatrix = null;
        graphicsStack.clear();
        streamResourcesStack.clear();

View Full Code Here

Examples of org.apache.pdfbox.pdmodel.graphics.state.PDGraphicsState

        {
            throw new IllegalArgumentException("Page cannot be null");
        }
        currentPage = page;
        graphicsStack.clear();
        graphicsStack.push(new PDGraphicsState(page.getCropBox()));
        textMatrix = null;
        textLineMatrix = null;
        resources = null;
    }
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.graphics.state.PDGraphicsState

     * @param string the encoded text
     * @throws IOException if there is an error processing the string
     */
    protected void showText(byte[] string) throws IOException
    {
        PDGraphicsState state = getGraphicsState();
        PDTextState textState = state.getTextState();

        // get the current font
        PDFont font = textState.getFont();
        if (font == null)
        {
            LOG.warn("No current font, will use default");
            font = PDFontFactory.createDefaultFont();
        }

        float fontSize = textState.getFontSize();
        float horizontalScaling = textState.getHorizontalScaling() / 100f;
        float charSpacing = textState.getCharacterSpacing();

        // put the text state parameters into matrix form
        Matrix parameters = new Matrix(
                fontSize * horizontalScaling, 0, // 0
                0, fontSize,                     // 0
                0, textState.getRise());         // 1

        // read the stream until it is empty
        InputStream in = new ByteArrayInputStream(string);
        while (in.available() > 0)
        {
            // decode a character
            int before = in.available();
            int code = font.readCode(in);
            int codeLength = before - in.available();
            String unicode = font.toUnicode(code);

            // Word spacing shall be applied to every occurrence of the single-byte character code
            // 32 in a string when using a simple font or a composite font that defines code 32 as
            // a single-byte code.
            float wordSpacing = 0;
            if (codeLength == 1 && code == 32)
            {
                wordSpacing += textState.getWordSpacing();
            }

            // text rendering matrix (text space -> device space)
            Matrix ctm = state.getCurrentTransformationMatrix();
            Matrix textRenderingMatrix = parameters.multiply(textMatrix).multiply(ctm);

            // get glyph's position vector if this is vertical text
            // changes to vertical text should be tested with PDFBOX-2294 and PDFBOX-1422
            if (font.isVertical())
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.