Package org.apache.batik.gvt

Examples of org.apache.batik.gvt.ImageNode


    protected void initializeDynamicSupport(BridgeContext ctx,
                                            Element e,
                                            GraphicsNode node) {
        if (ctx.isInteractive()) {
            // HACK due to the way images are represented in GVT
            ImageNode imgNode = (ImageNode)node;
            ctx.bind(e, imgNode.getImage());
        }
    }
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) {
        ImageNode imageNode = (ImageNode)super.createGraphicsNode(ctx, e);
        if (imageNode == null) {
            return null;
        }

        associateSVGContext(ctx, e, imageNode);

        hitCheckChildren = false;
        GraphicsNode node = buildImageGraphicsNode(ctx,e);

        if (node == null) {
            SVGImageElement ie = (SVGImageElement) e;
            String uriStr = ie.getHref().getAnimVal();
            throw new BridgeException(ctx, e, ERR_URI_IMAGE_INVALID,
                                      new Object[] {uriStr});
        }

        imageNode.setImage(node);
        imageNode.setHitCheckChildren(hitCheckChildren);

        // 'image-rendering' and 'color-rendering'
        RenderingHints hints = null;
        hints = CSSUtilities.convertImageRendering(e, hints);
        hints = CSSUtilities.convertColorRendering(e, hints);
        if (hints != null)
            imageNode.setRenderingHints(hints);

        return imageNode;
    }
View Full Code Here

    /**
     * Creates an <tt>ImageNode</tt>.
     */
    protected GraphicsNode instantiateGraphicsNode() {
        return new ImageNode();
    }
View Full Code Here

                    updateImageBounds();
                    return;
                } else if (ln.equals(SVG_WIDTH_ATTRIBUTE)
                        || ln.equals(SVG_HEIGHT_ATTRIBUTE)) {
                    SVGImageElement ie = (SVGImageElement) e;
                    ImageNode imageNode = (ImageNode) node;
                    float val;
                    if (ln.charAt(0) == 'w') {
                        val = ie.getWidth().getAnimVal().getValue();
                    } else {
                        val = ie.getHeight().getAnimVal().getValue();
                    }
                    if (val == 0 || imageNode.getImage() instanceof ShapeNode) {
                        rebuildImageNode();
                    } else {
                        updateImageBounds();
                    }
                    return;
View Full Code Here

        subCtx = null;

        //update of the reference of the image.
        GraphicsNode inode = buildImageGraphicsNode(ctx,e);

        ImageNode imgNode = (ImageNode)node;
        imgNode.setImage(inode);

        if (inode == null) {
            SVGImageElement ie = (SVGImageElement) e;
            String uriStr = ie.getHref().getAnimVal();
            throw new BridgeException(ctx, e, ERR_URI_IMAGE_INVALID,
View Full Code Here

     * @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) {

        ImageNode imageNode = (ImageNode)super.createGraphicsNode(ctx, e);

        // 'xlink:href' attribute - required
        String uriStr = XLinkSupport.getXLinkHref(e);
        if (uriStr.length() == 0) {
            throw new BridgeException(e, ERR_ATTRIBUTE_MISSING,
                                      new Object[] {"xlink:href"});
        }
        if (uriStr.indexOf('#') != -1) {
            throw new BridgeException(e, ERR_ATTRIBUTE_VALUE_MALFORMED,
                                      new Object[] {"xlink:href", uriStr});
        }
        GraphicsNode node = null;
        // try to load the image as an svg document
        SVGDocument svgDoc = (SVGDocument)e.getOwnerDocument();
        ParsedURL purl;
        URL baseURL = ((SVGOMDocument)svgDoc).getURLObject();
        if (baseURL != null)
            purl = new ParsedURL(baseURL.toString(), uriStr);
        else
            purl = new ParsedURL(uriStr);
       
        // try to load an SVG document
        DocumentLoader loader = ctx.getDocumentLoader();
        URIResolver resolver = new URIResolver(svgDoc, loader);
        try {
            Node n = resolver.getNode(purl.toString());
            if (n.getNodeType() == n.DOCUMENT_NODE) {
                SVGDocument imgDocument = (SVGDocument)n;
                node = createSVGImageNode(ctx, e, imgDocument);
            }
        } catch (BridgeException ex) {
            throw ex;
        } catch (Exception ex) { /* Nothing to do */ }

        if (node == null) {
            // try to load the image as a raster image (JPG or PNG)
            node = createRasterImageNode(ctx, e, purl);
        }

        if (node == null) {
            throw new BridgeException(e, ERR_URI_IMAGE_INVALID,
                                      new Object[] {uriStr});
        }

        // 'image-rendering' and 'color-rendering'
        Map imageHints = CSSUtilities.convertImageRendering(e);
        Map colorHints = CSSUtilities.convertColorRendering(e);
        if (imageHints != null || colorHints != null) {
            RenderingHints hints;
            if (imageHints == null) {
                hints = new RenderingHints(colorHints);
            } else if (colorHints == null) {
                hints = new RenderingHints(imageHints);
            } else {
                hints = new RenderingHints(imageHints);
                hints.putAll(colorHints);
            }
            node.setRenderingHints(hints);
        }

        imageNode.setImage(node);
        return imageNode;
    }
View Full Code Here

    /**
     * Creates an <tt>ImageNode</tt>.
     */
    protected GraphicsNode instantiateGraphicsNode() {
        return new ImageNode();
    }
View Full Code Here

        // 'requiredFeatures', 'requiredExtensions' and 'systemLanguage'
        if (!SVGUtilities.matchUserAgent(e, ctx.getUserAgent())) {
            return null;
        }

        ImageNode imageNode = (ImageNode)instantiateGraphicsNode();

        // 'transform'
        String s = e.getAttributeNS(null, SVG_TRANSFORM_ATTRIBUTE);
        if (s.length() != 0) {
            imageNode.setTransform
                (SVGUtilities.convertTransform(e, SVG_TRANSFORM_ATTRIBUTE, s));
        }
        // 'visibility'
        imageNode.setVisible(CSSUtilities.convertVisibility(e));

        RasterImageNode node = new RasterImageNode();

        List dims = new LinkedList();
        List uris = new LinkedList();
        addInfo(e, dims, uris);

        for (Node n = e.getFirstChild(); n != null; n = n.getNextSibling()) {
            if (n.getNodeType() != Node.ELEMENT_NODE)
                continue;
           
            Element se = (Element)n;
            if (!(se.getNamespaceURI().equals(BATIK_EXT_NAMESPACE_URI)) ||
                !(se.getLocalName().equals(BATIK_EXT_SUB_IMAGE_TAG)))
                continue;

            addInfo(se, dims, uris);
        }

        Dimension [] dary = new Dimension[uris.size()];
        ParsedURL [] uary = new ParsedURL[uris.size()];
        Iterator di = dims.iterator();
        Iterator ui = uris.iterator();
        int n=0;
        while (di.hasNext()) {
            int i;
            Dimension d = (Dimension)di.next();
            for (i=0; i<n; i++) {
                if (d.width > dary[i].width) break;
            }
            for (int j=n; j>i; j--) {
                dary[j] = dary[j-1];
                uary[j] = uary[j-1];
            }
            dary[i] = d;
            uary[i] = (ParsedURL)ui.next();
            n++;
        }

        Filter f = new MultiResRable(uary, dary);

        Rectangle2D imgB, b;
        imgB = f.getBounds2D();
        b = getImageBounds(ctx, e);

        node.setImage(f);

        float []vb = new float[4];
        vb[0] = 0;
        vb[1] = 0;
        vb[2] = (float)imgB.getWidth();
        vb[3] = (float)imgB.getHeight();
        initializeViewport(ctx, e, node, vb, b);

        imageNode.setImage(node);
        return imageNode;
    }
View Full Code Here

     * @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) {

        ImageNode imageNode = (ImageNode)super.createGraphicsNode(ctx, e);

        // 'xlink:href' attribute - required
        String uriStr = XLinkSupport.getXLinkHref(e);
        if (uriStr.length() == 0) {
            throw new BridgeException(e, ERR_ATTRIBUTE_MISSING,
                                      new Object[] {"xlink:href"});
        }
        if (uriStr.indexOf('#') != -1) {
            throw new BridgeException(e, ERR_ATTRIBUTE_VALUE_MALFORMED,
                                      new Object[] {"xlink:href", uriStr});
        }
        GraphicsNode node = null;
        // try to load the image as an svg document
        SVGDocument svgDoc = (SVGDocument)e.getOwnerDocument();
        ParsedURL purl;
        URL baseURL = ((SVGOMDocument)svgDoc).getURLObject();
        if (baseURL != null)
            purl = new ParsedURL(baseURL.toString(), uriStr);
        else
            purl = new ParsedURL(uriStr);


        // try to load an SVG document
        DocumentLoader loader = ctx.getDocumentLoader();
        URIResolver resolver = new URIResolver(svgDoc, loader);
        try {
            Node n = resolver.getNode(purl.toString());
            if (n.getNodeType() == n.DOCUMENT_NODE) {
                SVGDocument imgDocument = (SVGDocument)n;
                node = createSVGImageNode(ctx, e, imgDocument);
            }
        } catch (BridgeException ex) {
            throw ex;
        } catch (Exception ex) { /* Nothing to do */ }

        if (node == null) {
            // try to load the image as a raster image (JPG or PNG)
            node = createRasterImageNode(ctx, e, purl);
        }

        if (node == null) {
            throw new BridgeException(e, ERR_URI_IMAGE_INVALID,
                                      new Object[] {uriStr});
        }

        // 'image-rendering' and 'color-rendering'
        Map imageHints = CSSUtilities.convertImageRendering(e);
        Map colorHints = CSSUtilities.convertColorRendering(e);
        if (imageHints != null || colorHints != null) {
            RenderingHints hints;
            if (imageHints == null) {
                hints = new RenderingHints(colorHints);
            } else if (colorHints == null) {
                hints = new RenderingHints(imageHints);
            } else {
                hints = new RenderingHints(imageHints);
                hints.putAll(colorHints);
            }
            node.setRenderingHints(hints);
        }

        imageNode.setImage(node);
        return imageNode;
    }
View Full Code Here

    /**
     * Creates an <tt>ImageNode</tt>.
     */
    protected GraphicsNode instantiateGraphicsNode() {
        return new ImageNode();
    }
View Full Code Here

TOP

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

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.