Package org.apache.xmlgraphics.java2d

Examples of org.apache.xmlgraphics.java2d.Graphics2DImagePainter


        // Create Graphics2DImagePainter
        final RendererContextWrapper wrappedContext = RendererContext.wrapRendererContext(
                rendererContext);
        Dimension imageSize = getImageSize(wrappedContext);
        final Graphics2DImagePainter painter = createGraphics2DImagePainter(
                root, bridgeContext, imageSize);

        //Let the painter paint the SVG on the Graphics2D instance
        Graphics2DAdapter g2dAdapter = rendererContext.getRenderer().getGraphics2DAdapter();
View Full Code Here


    public void handleImage(RenderingContext context, Image image, Rectangle pos)
                throws IOException {
        PSRenderingContext psContext = (PSRenderingContext)context;
        PSGenerator gen = psContext.getGenerator();
        ImageGraphics2D imageG2D = (ImageGraphics2D)image;
        Graphics2DImagePainter painter = imageG2D.getGraphics2DImagePainter();

        float fx = (float)pos.getX() / 1000f;
        float fy = (float)pos.getY() / 1000f;
        float fwidth = (float)pos.getWidth() / 1000f;
        float fheight = (float)pos.getHeight() / 1000f;

        // get the 'width' and 'height' attributes of the SVG document
        Dimension dim = painter.getImageSize();
        float imw = (float)dim.getWidth() / 1000f;
        float imh = (float)dim.getHeight() / 1000f;

        float sx = fwidth / (float)imw;
        float sy = fheight / (float)imh;

        gen.commentln("%FOPBeginGraphics2D");
        gen.saveGraphicsState();
        final boolean clip = false;
        if (clip) {
            // Clip to the image area.
            gen.writeln("newpath");
            gen.defineRect(fx, fy, fwidth, fheight);
            gen.writeln("clip");
        }

        // transform so that the coordinates (0,0) is from the top left
        // and positive is down and to the right. (0,0) is where the
        // viewBox puts it.
        gen.concatMatrix(sx, 0, 0, sy, fx, fy);

        final boolean textAsShapes = false;
        PSGraphics2D graphics = new PSGraphics2D(textAsShapes, gen);
        graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
        AffineTransform transform = new AffineTransform();
        // scale to viewbox
        transform.translate(fx, fy);
        gen.getCurrentState().concatMatrix(transform);
        Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
        painter.paint(graphics, area);
        gen.restoreGraphicsState();
        gen.commentln("%FOPEndGraphics2D");
    }
View Full Code Here

        }
        if (top != null || bottom != null || left != null || right != null) {
            final Rectangle boundingBox = rect;
            final Dimension dim = boundingBox.getSize();

            Graphics2DImagePainter painter = new Graphics2DImagePainter() {

                public void paint(Graphics2D g2d, Rectangle2D area) {
                    g2d.translate(-rect.x, -rect.y);

                    Java2DPainter painter = new Java2DPainter(g2d,
                            getContext(), parent.getFontInfo(), state);
                    try {
                        painter.drawBorderRect(rect, top, bottom, left, right);
                    } catch (IFException e) {
                        //This should never happen with the Java2DPainter
                        throw new RuntimeException("Unexpected error while painting borders", e);
                    }
                }
View Full Code Here

            return;
        }
        final Rectangle boundingBox = getLineBoundingBox(start, end, width);
        final Dimension dim = boundingBox.getSize();

        Graphics2DImagePainter painter = new Graphics2DImagePainter() {

            public void paint(Graphics2D g2d, Rectangle2D area) {
                g2d.translate(-boundingBox.x, -boundingBox.y);

                Java2DPainter painter = new Java2DPainter(g2d,
                        getContext(), parent.getFontInfo(), state);
                try {
                    painter.drawLine(start, end, width, color, style);
                } catch (IFException e) {
                    //This should never happen with the Java2DPainter
                    throw new RuntimeException("Unexpected error while painting a line", e);
                }
            }
View Full Code Here

        final Rectangle boundingBox = getTextBoundingBox(x, y,
                letterSpacing, wordSpacing, dp, text, font, mapper);
        final Dimension dim = boundingBox.getSize();

        Graphics2DImagePainter painter = new Graphics2DImagePainter() {

            public void paint(Graphics2D g2d, Rectangle2D area) {
                if (DEBUG) {
                    g2d.setBackground(Color.LIGHT_GRAY);
                    g2d.clearRect(0, 0, (int)area.getWidth(), (int)area.getHeight());
                }
                g2d.translate(-x, -y + baselineOffset);

                if (DEBUG) {
                    Rectangle rect = new Rectangle(x, y - maxAscent, 3000, maxAscent);
                    g2d.draw(rect);
                    rect = new Rectangle(x, y - ascent, 2000, ascent);
                    g2d.draw(rect);
                    rect = new Rectangle(x, y, 1000, -descent);
                    g2d.draw(rect);
                }
                Java2DPainter painter = new Java2DPainter(g2d,
                        getContext(), parent.getFontInfo(), state);
                try {
                    painter.drawText(x, y, letterSpacing, wordSpacing, dp, text);
                } catch (IFException e) {
                    //This should never happen with the Java2DPainter
                    throw new RuntimeException("Unexpected error while painting text", e);
                }
            }
View Full Code Here

        /** {@inheritDoc} */
        public void primitivePaint(Graphics2D g2d) {
            int width = image.getSize().getWidthPx();
            int height = image.getSize().getHeightPx();
            Rectangle2D area = new Rectangle2D.Double(0, 0, width, height);
            Graphics2DImagePainter painter = image.getGraphics2DImagePainter();
            painter.paint(g2d, area);
        }
View Full Code Here

        //Set up painter and target
        graphicsObjectInfo.setGraphics2D(g2d);
        // Create Graphics2DImagePainter
        Dimension imageSize = image.getSize().getDimensionMpt();
        Graphics2DImagePainter painter = new Graphics2DImagePainterImpl(
                root, bridgeContext, imageSize);
        graphicsObjectInfo.setPainter(painter);

        // Create the GOCA GraphicsObject in the DataStream
        AFPResourceManager resourceManager = afpContext.getResourceManager();
View Full Code Here

        // Create Graphics2DImagePainter
        final RendererContextWrapper wrappedContext
            = RendererContext.wrapRendererContext(rendererContext);
        Dimension imageSize = getImageSize(wrappedContext);
        Graphics2DImagePainter painter
            = createGraphics2DImagePainter(bridgeContext, root, imageSize);

        // Create AFPObjectAreaInfo
        RendererContextWrapper rctx = RendererContext.wrapRendererContext(rendererContext);
        int x = rctx.getCurrentXPosition();
View Full Code Here

        context.setProperty(AFPRendererContextConstants.AFP_GRAYSCALE, Boolean.FALSE);
    }

    private Graphics2DImagePainter createGraphics2DImagePainter(BridgeContext ctx,
            GraphicsNode root, Dimension imageSize) {
        Graphics2DImagePainter painter = null;
        if (paintAsBitmap()) {
            // paint as IOCA Image
            painter = super.createGraphics2DImagePainter(root, ctx, imageSize);
        } else {
            // paint as GOCA Graphics
View Full Code Here

    /** {@inheritDoc} */
    public Image convert(Image src, Map hints) {
        checkSourceFlavor(src);
        ImageWMF wmf = (ImageWMF)src;

        Graphics2DImagePainter painter;
        painter = new Graphics2DImagePainterWMF(wmf);

        ImageGraphics2D g2dImage = new ImageGraphics2D(src.getInfo(), painter);
        return g2dImage;
    }
View Full Code Here

TOP

Related Classes of org.apache.xmlgraphics.java2d.Graphics2DImagePainter

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.