Package org.apache.batik.gvt

Examples of org.apache.batik.gvt.GraphicsNodeRenderContext


        return (Rectangle2D)filterRegion.clone();
    }

    public RenderedImage createRendering(RenderContext rc) {

        GraphicsNodeRenderContext gnrc =
               GraphicsNodeRenderContext.getGraphicsNodeRenderContext(rc);
        //
        // Get the mask content
        //
        Filter maskSrc = new GraphicsNodeRable8Bit(getMaskNode(), gnrc);
View Full Code Here


        UnitProcessor.Context uctx
            = UnitProcessor.createContext(ctx, filteredElement);

        switch (unitsType) {
        case OBJECT_BOUNDING_BOX:
            GraphicsNodeRenderContext rc = ctx.getGraphicsNodeRenderContext();
            Rectangle2D bounds = filteredNode.getGeometryBounds(rc);
            if (xStr.length() != 0) {
                x = UnitProcessor.svgHorizontalCoordinateToObjectBoundingBox
                    (xStr, SVG_X_ATTRIBUTE, uctx);
                x = bounds.getX() + x*bounds.getWidth();
 
View Full Code Here

        } else {
            coordSystemType = SVGUtilities.parseCoordinateSystem
                (clipElement, SVG_CLIP_PATH_UNITS_ATTRIBUTE, s);
        }
        // additional transform to move to objectBoundingBox coordinate system
        GraphicsNodeRenderContext rc = ctx.getGraphicsNodeRenderContext();
        if (coordSystemType == SVGUtilities.OBJECT_BOUNDING_BOX) {
            Tx = SVGUtilities.toObjectBBox(Tx, clipedNode, rc);
        }

        // Build the GVT tree that represents the clip path
View Full Code Here

                (paintElement, SVG_GRADIENT_UNITS_ATTRIBUTE, s);
        }

        // additional transform to move to objectBoundingBox coordinate system
        if (coordSystemType == SVGUtilities.OBJECT_BOUNDING_BOX) {
            GraphicsNodeRenderContext rc = ctx.getGraphicsNodeRenderContext();
            transform = SVGUtilities.toObjectBBox(transform,
                                                  paintedNode,
                                                  rc);
        }
        UnitProcessor.Context uctx
View Full Code Here

        //     patternContentUnits attribute.
        //
        // Note that there is an additional transform from the tiling space to the
        // user space (patternTransform) that is passed separately to the PatternPaintContext.
        //
        GraphicsNodeRenderContext rc = ctx.getGraphicsNodeRenderContext();
        AffineTransform patternContentTransform
            = new AffineTransform();
       
        //
        // Process viewPortTranslation
View Full Code Here

                (paintElement, SVG_GRADIENT_UNITS_ATTRIBUTE, s);
        }

        // additional transform to move to objectBoundingBox coordinate system
        if (coordSystemType == SVGUtilities.OBJECT_BOUNDING_BOX) {
            GraphicsNodeRenderContext rc = ctx.getGraphicsNodeRenderContext();
            transform = SVGUtilities.toObjectBBox(transform,
                                                  paintedNode,
                                                  rc);
        }
        UnitProcessor.Context uctx
View Full Code Here

        ((SVGOMDocument) document).setSVGContext(svgCtx);

        // build the GVT tree
        GVTBuilder builder = new GVTBuilder();
        ImageRendererFactory rendFactory = new StaticRendererFactory();
        GraphicsNodeRenderContext rc = getRenderContext();
        BridgeContext ctx = new BridgeContext(userAgent, rc);
        GraphicsNode gvtRoot;
        try {
            gvtRoot = builder.build(ctx, svgDoc);
        } catch (BridgeException ex) {
            throw new TranscoderException(ex);
        }
        // get the 'width' and 'height' attributes of the SVG document
        float docWidth = (float) ctx.getDocumentSize().getWidth();
        float docHeight = (float) ctx.getDocumentSize().getHeight();
        ctx = null;
        builder = null;

        // compute the image's width and height according the hints
        float imgWidth = -1;
        if (hints.containsKey(ImageTranscoder.KEY_WIDTH)) {
            imgWidth = ((Float) hints.get(ImageTranscoder.KEY_WIDTH)).floatValue();
        }
        float imgHeight = -1;
        if (hints.containsKey(ImageTranscoder.KEY_HEIGHT)) {
            imgHeight = ((Float) hints.get(ImageTranscoder.KEY_HEIGHT)).floatValue();
        }
        float width, height;
        if (imgWidth > 0 && imgHeight > 0) {
            width = imgWidth;
            height = imgHeight;
        } else if (imgHeight > 0) {
            width = (docWidth * imgHeight) / docHeight;
            height = imgHeight;
        } else if (imgWidth > 0) {
            width = imgWidth;
            height = (docHeight * imgWidth) / docWidth;
        } else {
            width = docWidth;
            height = docHeight;
        }
        // compute the preserveAspectRatio matrix
        AffineTransform Px;
        String ref = null;
        try {
            ref = new URL(uri).getRef();
        } catch (MalformedURLException ex) {
            // nothing to do, catched previously
        }

        try {
            Px = ViewBox.getViewTransform(ref, root, width, height);
        } catch (BridgeException ex) {
            throw new TranscoderException(ex);
        }

        if (Px.isIdentity() && (width != docWidth || height != docHeight)) {
            // The document has no viewBox, we need to resize it by hand.
            // we want to keep the document size ratio
            float d = Math.max(docWidth, docHeight);
            float dd = Math.max(width, height);
            float scale = dd / d;
            Px = AffineTransform.getScaleInstance(scale, scale);
        }
        // take the AOI into account if any
        if (hints.containsKey(ImageTranscoder.KEY_AOI)) {
            Rectangle2D aoi = (Rectangle2D) hints.get(ImageTranscoder.KEY_AOI);
            // transform the AOI into the image's coordinate system
            aoi = Px.createTransformedShape(aoi).getBounds2D();
            AffineTransform Mx = new AffineTransform();
            double sx = width / aoi.getWidth();
            double sy = height / aoi.getHeight();
            Mx.scale(sx, sy);
            double tx = -aoi.getX();
            double ty = -aoi.getY();
            Mx.translate(tx, ty);
            // take the AOI transformation matrix into account
            // we apply first the preserveAspectRatio matrix
            Px.preConcatenate(Mx);
        }
        // prepare the image to be painted
        int w = (int) width;
        int h = (int) height;

        PDFDocumentGraphics2D graphics = new PDFDocumentGraphics2D(true,
                                         output.getOutputStream(), w, h);
        graphics.setSVGDimension(docWidth, docHeight);
        if (hints.containsKey(ImageTranscoder.KEY_BACKGROUND_COLOR)) {
            graphics.setBackgroundColor((Color) hints.get(ImageTranscoder.KEY_BACKGROUND_COLOR));
        }
        //        GraphicsNodeRenderContext rc = getRenderContext();
        graphics.setGraphicContext(
          new org.apache.batik.ext.awt.g2d.GraphicContext());
        graphics.setRenderingHints(rc.getRenderingHints());

        gvtRoot.paint(graphics, rc);

        try {
            graphics.finish();
View Full Code Here

            throw new TranscoderException(ex);
        }
    }

    public GraphicsNodeRenderContext getRenderContext() {
        GraphicsNodeRenderContext nodeRenderContext = null;
        if (nodeRenderContext == null) {
            RenderingHints hints = new RenderingHints(null);
            hints.put(RenderingHints.KEY_ANTIALIASING,
                      RenderingHints.VALUE_ANTIALIAS_ON);

            hints.put(RenderingHints.KEY_INTERPOLATION,
                      RenderingHints.VALUE_INTERPOLATION_BILINEAR);

            FontRenderContext fontRenderContext =
              new FontRenderContext(new AffineTransform(), true,
                                    true);

            TextPainter textPainter = new StrokingTextPainter();

            GraphicsNodeRableFactory gnrFactory =
              new ConcreteGraphicsNodeRableFactory();

            nodeRenderContext = new GraphicsNodeRenderContext(
                                  new AffineTransform(), null, hints,
                                  fontRenderContext, textPainter, gnrFactory);
            nodeRenderContext.setTextPainter(textPainter);
        }

        return nodeRenderContext;
    }
View Full Code Here

        GraphicsNodeRableFactory gnrFactory =
            new ConcreteGraphicsNodeRableFactory();

        this.nodeRenderContext =
            new GraphicsNodeRenderContext(new AffineTransform(),
                                          null,
                                          hints,
                                          fontRenderContext,
                                          textPainter,
                                          gnrFactory);
View Full Code Here

        ((SVGOMDocument)document).setSVGContext(svgCtx);

        // build the GVT tree
        GVTBuilder builder = new GVTBuilder();
        ImageRendererFactory rendFactory = new StaticRendererFactory();
        GraphicsNodeRenderContext rc = rendFactory.getRenderContext();
        BridgeContext ctx = new BridgeContext(userAgent, rc);
        GraphicsNode gvtRoot;
        try {
            gvtRoot = builder.build(ctx, svgDoc);
        } catch (BridgeException ex) {
View Full Code Here

TOP

Related Classes of org.apache.batik.gvt.GraphicsNodeRenderContext

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.