Package org.apache.batik.gvt

Examples of org.apache.batik.gvt.CanvasGraphicsNode


                            (AbstractSVGAnimatedLength) se.getY();
                        float y = _y.getCheckedValue();

                        AffineTransform positionTransform =
                            AffineTransform.getTranslateInstance(x, y);
                        CanvasGraphicsNode cgn;
                        cgn = (CanvasGraphicsNode)node;

                        cgn.setPositionTransform(positionTransform);
                        return;
                    }
                } else if (ln.equals(SVG_VIEW_BOX_ATTRIBUTE)
                        || ln.equals(SVG_PRESERVE_ASPECT_RATIO_ATTRIBUTE)) {
                    SVGDocument doc = (SVGDocument)e.getOwnerDocument();
                    SVGOMSVGElement se = (SVGOMSVGElement) e;
                    boolean isOutermost = doc.getRootElement() == e;

                    // X & Y are ignored on outermost SVG.
                    float x = 0;
                    float y = 0;
                    if (!isOutermost) {
                        // 'x' attribute - default is 0
                        AbstractSVGAnimatedLength _x =
                            (AbstractSVGAnimatedLength) se.getX();
                        x = _x.getCheckedValue();

                        // 'y' attribute - default is 0
                        AbstractSVGAnimatedLength _y =
                            (AbstractSVGAnimatedLength) se.getY();
                        y = _y.getCheckedValue();
                    }
                   
                    // 'width' attribute - default is 100%
                    AbstractSVGAnimatedLength _width =
                        (AbstractSVGAnimatedLength) se.getWidth();
                    float w = _width.getCheckedValue();
                   
                    // 'height' attribute - default is 100%
                    AbstractSVGAnimatedLength _height =
                        (AbstractSVGAnimatedLength) se.getHeight();
                    float h = _height.getCheckedValue();
                   
                    CanvasGraphicsNode cgn;
                    cgn = (CanvasGraphicsNode)node;
                   
                    // 'viewBox' and "preserveAspectRatio' attributes
                    SVGOMAnimatedRect vb = (SVGOMAnimatedRect) se.getViewBox();
                    SVGAnimatedPreserveAspectRatio par = se.getPreserveAspectRatio();
                    AffineTransform newVT = ViewBox.getPreserveAspectRatioTransform
                        (e, vb, par, w, h, ctx);

                    AffineTransform oldVT = cgn.getViewingTransform();
                    if ((newVT.getScaleX() != oldVT.getScaleX()) ||
                        (newVT.getScaleY() != oldVT.getScaleY()) ||
                        (newVT.getShearX() != oldVT.getShearX()) ||
                        (newVT.getShearY() != oldVT.getShearY()))
                        rebuild = true;
                    else {
                        // Only differs in translate.
                        cgn.setViewingTransform(newVT);
                       
                        // 'overflow' and 'clip'
                        Shape clip = null;
                        if (CSSUtilities.convertOverflow(e)) { // overflow:hidden
                            float [] offsets = CSSUtilities.convertClip(e);
                            if (offsets == null) { // clip:auto
                                clip = new Rectangle2D.Float(x, y, w, h);
                            } else { // clip:rect(<x> <y> <w> <h>)
                                // offsets[0] = top
                                // offsets[1] = right
                                // offsets[2] = bottom
                                // offsets[3] = left
                                clip = new Rectangle2D.Float(x+offsets[3],
                                                             y+offsets[0],
                                                             w-offsets[1]-offsets[3],
                                                             h-offsets[2]-offsets[0]);
                            }
                        }
                       
                        if (clip != null) {
                            try {
                                AffineTransform at;
                                at = cgn.getPositionTransform();
                                if (at == null) at = new AffineTransform();
                                else            at = new AffineTransform(at);
                                at.concatenate(newVT);
                                at = at.createInverse(); // clip in user space
                                clip = at.createTransformedShape(clip);
                                Filter filter = cgn.getGraphicsNodeRable(true);
                                cgn.setClip(new ClipRable8Bit(filter, clip));
                            } catch (NoninvertibleTransformException ex) {}
                        }
                    }
                }
View Full Code Here


        CSSStyleDeclaration cssDecl
            = ctx.getViewCSS().getComputedStyle(element, null);
        UnitProcessor.Context uctx
            = new DefaultUnitProcessorContext(ctx,
                                              cssDecl);
        CanvasGraphicsNode node
            = ctx.getGVTFactory().createCanvasGraphicsNode();
        float x;
        float y;
        float w;
        float h;
        String s;
        if (svgElement.getOwnerSVGElement() != null) {
            // parse the x attribute, (default is 0)
            s = svgElement.getAttributeNS(null, ATTR_X);
            x = 0;
            if (s.length() != 0) {
               x = SVGUtilities.svgToUserSpace(svgElement,
                                               ATTR_X, s,
                                               uctx,
                                               UnitProcessor.HORIZONTAL_LENGTH);
            }

            // parse the y attribute, (default is 0)
            s = svgElement.getAttributeNS(null, ATTR_Y);
            y = 0;
            if (s.length() != 0) {
                y = SVGUtilities.svgToUserSpace(svgElement,
                                                ATTR_Y, s,
                                                uctx,
                                                UnitProcessor.VERTICAL_LENGTH);
            }
        } else {
            x = 0;
            y = 0;
        }

        // parse the width attribute (default is 100%)
        s = svgElement.getAttributeNS(null, ATTR_WIDTH);
        if (s.length() == 0) {
            s = "100%";
        }
        w = SVGUtilities.svgToUserSpace(svgElement,
                                        ATTR_WIDTH, s,
                                        uctx,
                                        UnitProcessor.HORIZONTAL_LENGTH);

        // parse the height attribute (default is 100%)
        s = svgElement.getAttributeNS(null, ATTR_HEIGHT);
        if (s.length() == 0) {
            s = "100%";
        }
        h = SVGUtilities.svgToUserSpace(svgElement,
                                        ATTR_HEIGHT, s,
                                        uctx,
                                        UnitProcessor.VERTICAL_LENGTH);

        // parse the tranform attribute
        AffineTransform at;
        at = SVGUtilities.getPreserveAspectRatioTransform
            (svgElement, w, h, ctx.getParserFactory());
        at.preConcatenate(AffineTransform.getTranslateInstance(x, y));
        if (svgElement.getOwnerSVGElement() != null) {
            // <!> as it is already done in the JSVGCanvas, we don't have to
            // do it for the top most svg element
            node.setTransform(at);
        }
        try {
            at = at.createInverse(); // clip in user space

            GraphicsNodeRableFactory gnrFactory
                = ctx.getGraphicsNodeRableFactory();

            Filter filter = gnrFactory.createGraphicsNodeRable(node);

            Shape clip = at.createTransformedShape
                (new Rectangle2D.Float(x, y, w, h));

            node.setClip(new ConcreteClipRable(filter, clip));

        } catch (java.awt.geom.NoninvertibleTransformException ex) {}

        // <!> TODO only when binding is enabled
        BridgeEventSupport.addDOMListener(ctx, element);
View Full Code Here

     * @param ctx the bridge context to use
     * @param e the element that describes the graphics node to build
     * @return a graphics node that represents the specified element
     */
    public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
        CanvasGraphicsNode gn = new CanvasGraphicsNode();

        UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, e);
        String s;

        boolean isOutermost = (((SVGElement)e).getOwnerSVGElement() == null);
        float x = 0;
        float y = 0;
        // x and y have no meaning on the outermost 'svg' element
        if (!isOutermost) {
            // 'x' attribute - default is 0
            s = e.getAttributeNS(null, SVG_X_ATTRIBUTE);
            if (s.length() != 0) {
                x = UnitProcessor.svgHorizontalCoordinateToUserSpace
                    (s, SVG_X_ATTRIBUTE, uctx);
            }
            // 'y' attribute - default is 0
            s = e.getAttributeNS(null, SVG_Y_ATTRIBUTE);
            if (s.length() != 0) {
                y = UnitProcessor.svgVerticalCoordinateToUserSpace
                    (s, SVG_Y_ATTRIBUTE, uctx);
            }
        }

        // 'width' attribute - default is 100%
        s = e.getAttributeNS(null, SVG_WIDTH_ATTRIBUTE);
        if (s.length() == 0) {
            s = SVG_SVG_WIDTH_DEFAULT_VALUE;
        }
        float w = UnitProcessor.svgHorizontalLengthToUserSpace
            (s, SVG_WIDTH_ATTRIBUTE, uctx);

        // 'height' attribute - default is 100%
        s = e.getAttributeNS(null, SVG_HEIGHT_ATTRIBUTE);
        if (s.length() == 0) {
            s = SVG_SVG_HEIGHT_DEFAULT_VALUE;
        }
        float h = UnitProcessor.svgVerticalLengthToUserSpace
            (s, SVG_HEIGHT_ATTRIBUTE, uctx);

        // 'visibility'
        gn.setVisible(CSSUtilities.convertVisibility(e));

        // 'viewBox' and "preserveAspectRatio' attributes
        AffineTransform at =
            ViewBox.getPreserveAspectRatioTransform(e, w, h);

        float actualWidth = w;
        float actualHeight = h;
        try {
            AffineTransform atInv = at.createInverse();
            actualWidth = (float) (w*atInv.getScaleX());
            actualHeight = (float) (h*atInv.getScaleY());
        } catch (NoninvertibleTransformException ex) {}

        at.preConcatenate(AffineTransform.getTranslateInstance(x, y));

        // 'overflow' and 'clip'
        // The outermost preserveAspectRatio matrix is set by the user
        // agent, so we don't need to set the transform for outermost svg
        Shape clip = null;
        if (!isOutermost) {
            gn.setTransform(at);
        } else {
            // <!> FIXME: hack to compute the original document's size
            if (ctx.getDocumentSize() == null) {
                ctx.setDocumentSize(new Dimension((int)w, (int)h));
            }
        }

        if (CSSUtilities.convertOverflow(e)) { // overflow:hidden
            float [] offsets = CSSUtilities.convertClip(e);
            if (offsets == null) { // clip:auto
                clip = new Rectangle2D.Float(x, y, w, h);
            } else { // clip:rect(<x> <y> <w> <h>)
                // offsets[0] = top
                // offsets[1] = right
                // offsets[2] = bottom
                // offsets[3] = left
                clip = new Rectangle2D.Float(x+offsets[3],
                                             y+offsets[0],
                                             w-offsets[1]-offsets[3],
                                             h-offsets[2]-offsets[0]);
            }
        }

        if (clip != null) {
            try {
                at = at.createInverse(); // clip in user space
                clip = at.createTransformedShape(clip);
                Filter filter = gn.getGraphicsNodeRable();
                gn.setClip(new ClipRable8Bit(filter, clip));
            } catch (NoninvertibleTransformException ex) {}
        }

        // 'enable-background'
        Rectangle2D r = CSSUtilities.convertEnableBackground(e, uctx);
        if (r != null) {
            gn.setBackgroundEnable(r);
        }

        ctx.openViewport
            (e, new SVGSVGElementViewport((SVGSVGElement)e,
                                          actualWidth,
View Full Code Here

     * @param ctx the bridge context to use
     * @param e the element that describes the graphics node to build
     * @return a graphics node that represents the specified element
     */
    public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
        CanvasGraphicsNode gn = new CanvasGraphicsNode();

        UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, e);
        String s;

        boolean isOutermost = (((SVGElement)e).getOwnerSVGElement() == null);
        float x = 0;
        float y = 0;
        // x and y have no meaning on the outermost 'svg' element
        if (!isOutermost) {
            // 'x' attribute - default is 0
            s = e.getAttributeNS(null, SVG_X_ATTRIBUTE);
            if (s.length() != 0) {
                x = UnitProcessor.svgHorizontalCoordinateToUserSpace
                    (s, SVG_X_ATTRIBUTE, uctx);
            }
            // 'y' attribute - default is 0
            s = e.getAttributeNS(null, SVG_Y_ATTRIBUTE);
            if (s.length() != 0) {
                y = UnitProcessor.svgVerticalCoordinateToUserSpace
                    (s, SVG_Y_ATTRIBUTE, uctx);
            }
        }

        // 'width' attribute - default is 100%
        s = e.getAttributeNS(null, SVG_WIDTH_ATTRIBUTE);
        if (s.length() == 0) {
            s = SVG_SVG_WIDTH_DEFAULT_VALUE;
        }
        float w = UnitProcessor.svgHorizontalLengthToUserSpace
            (s, SVG_WIDTH_ATTRIBUTE, uctx);

        // 'height' attribute - default is 100%
        s = e.getAttributeNS(null, SVG_HEIGHT_ATTRIBUTE);
        if (s.length() == 0) {
            s = SVG_SVG_HEIGHT_DEFAULT_VALUE;
        }
        float h = UnitProcessor.svgVerticalLengthToUserSpace
            (s, SVG_HEIGHT_ATTRIBUTE, uctx);

        // 'visibility'
        gn.setVisible(CSSUtilities.convertVisibility(e));

        // 'viewBox' and "preserveAspectRatio' attributes
        AffineTransform at =
            ViewBox.getPreserveAspectRatioTransform(e, w, h);

        float actualWidth = w;
        float actualHeight = h;
        try {
            AffineTransform atInv = at.createInverse();
            actualWidth = (float) (w*atInv.getScaleX());
            actualHeight = (float) (h*atInv.getScaleY());
        } catch (NoninvertibleTransformException ex) {}

        at.preConcatenate(AffineTransform.getTranslateInstance(x, y));

        // 'overflow' and 'clip'
        // The outermost preserveAspectRatio matrix is set by the user
        // agent, so we don't need to set the transform for outermost svg
        Shape clip = null;
        if (!isOutermost) {
            gn.setTransform(at);
        } else {
            // <!> FIXME: hack to compute the original document's size
            if (ctx.getDocumentSize() == null) {
                ctx.setDocumentSize(new Dimension((int)w, (int)h));
            }
        }

        if (CSSUtilities.convertOverflow(e)) { // overflow:hidden
            float [] offsets = CSSUtilities.convertClip(e);
            if (offsets == null) { // clip:auto
                clip = new Rectangle2D.Float(x, y, w, h);
            } else { // clip:rect(<x> <y> <w> <h>)
                // offsets[0] = top
                // offsets[1] = right
                // offsets[2] = bottom
                // offsets[3] = left
                clip = new Rectangle2D.Float(x+offsets[3],
                                             y+offsets[0],
                                             w-offsets[1],
                                             h-offsets[2]);
            }
        }

        if (clip != null) {
            try {
                at = at.createInverse(); // clip in user space
                clip = at.createTransformedShape(clip);
                Filter filter = new GraphicsNodeRable8Bit
                    (gn, ctx.getGraphicsNodeRenderContext());
                gn.setClip(new ClipRable8Bit(filter, clip));
            } catch (NoninvertibleTransformException ex) {}
        }

        ctx.openViewport
            (e, new SVGSVGElementViewport((SVGSVGElement)e,
View Full Code Here

     * @param ctx the bridge context to use
     * @param e the element that describes the graphics node to build
     * @return a graphics node that represents the specified element
     */
    public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
        CanvasGraphicsNode gn = new CanvasGraphicsNode();

        UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, e);
        String s;

        boolean isOutermost = (((SVGElement)e).getOwnerSVGElement() == null);
        float x = 0;
        float y = 0;
        // x and y have no meaning on the outermost 'svg' element
        if (!isOutermost) {
            // 'x' attribute - default is 0
            s = e.getAttributeNS(null, SVG_X_ATTRIBUTE);
            if (s.length() != 0) {
                x = UnitProcessor.svgHorizontalCoordinateToUserSpace
                    (s, SVG_X_ATTRIBUTE, uctx);
            }
            // 'y' attribute - default is 0
            s = e.getAttributeNS(null, SVG_Y_ATTRIBUTE);
            if (s.length() != 0) {
                y = UnitProcessor.svgVerticalCoordinateToUserSpace
                    (s, SVG_Y_ATTRIBUTE, uctx);
            }
        }

        // 'width' attribute - default is 100%
        s = e.getAttributeNS(null, SVG_WIDTH_ATTRIBUTE);
        if (s.length() == 0) {
            s = SVG_SVG_WIDTH_DEFAULT_VALUE;
        }
        float w = UnitProcessor.svgHorizontalLengthToUserSpace
            (s, SVG_WIDTH_ATTRIBUTE, uctx);

        // 'height' attribute - default is 100%
        s = e.getAttributeNS(null, SVG_HEIGHT_ATTRIBUTE);
        if (s.length() == 0) {
            s = SVG_SVG_HEIGHT_DEFAULT_VALUE;
        }
        float h = UnitProcessor.svgVerticalLengthToUserSpace
            (s, SVG_HEIGHT_ATTRIBUTE, uctx);

        // 'visibility'
        gn.setVisible(CSSUtilities.convertVisibility(e));

        // 'viewBox' and "preserveAspectRatio' attributes
        AffineTransform at =
            ViewBox.getPreserveAspectRatioTransform(e, w, h);

        float actualWidth = w;
        float actualHeight = h;
        try {
            AffineTransform atInv = at.createInverse();
            actualWidth = (float) (w*atInv.getScaleX());
            actualHeight = (float) (h*atInv.getScaleY());
        } catch (NoninvertibleTransformException ex) {}

        at.preConcatenate(AffineTransform.getTranslateInstance(x, y));

        // 'overflow' and 'clip'
        // The outermost preserveAspectRatio matrix is set by the user
        // agent, so we don't need to set the transform for outermost svg
        Shape clip = null;
        if (!isOutermost) {
            gn.setTransform(at);
        } else {
            // <!> FIXME: hack to compute the original document's size
            if (ctx.getDocumentSize() == null) {
                ctx.setDocumentSize(new Dimension((int)w, (int)h));
            }
        }

        if (CSSUtilities.convertOverflow(e)) { // overflow:hidden
            float [] offsets = CSSUtilities.convertClip(e);
            if (offsets == null) { // clip:auto
                clip = new Rectangle2D.Float(x, y, w, h);
            } else { // clip:rect(<x> <y> <w> <h>)
                // offsets[0] = top
                // offsets[1] = right
                // offsets[2] = bottom
                // offsets[3] = left
                clip = new Rectangle2D.Float(x+offsets[3],
                                             y+offsets[0],
                                             w-offsets[1]-offsets[3],
                                             h-offsets[2]-offsets[0]);
            }
        }

        if (clip != null) {
            try {
                at = at.createInverse(); // clip in user space
                clip = at.createTransformedShape(clip);
                Filter filter = new GraphicsNodeRable8Bit
                    (gn, ctx.getGraphicsNodeRenderContext());
                gn.setClip(new ClipRable8Bit(filter, clip));
            } catch (NoninvertibleTransformException ex) {}
        }

        ctx.openViewport
            (e, new SVGSVGElementViewport((SVGSVGElement)e,
View Full Code Here

TOP

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

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.