Package org.apache.batik.gvt

Examples of org.apache.batik.gvt.ImageNode


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

        ImageNode imgNode = (ImageNode)instantiateGraphicsNode();
        if (imgNode == null) {
            return null;
        }

        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++;
        }

        Rectangle2D b = getImageBounds(ctx, e);

        // System.out.println("Bounds: " + bounds);
        // System.out.println("ImgB: " + imgBounds);
       

        GraphicsNode node = new MultiResGraphicsNode(e, b, uary, dary);

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

        imgNode.setImage(node);

        return imgNode;
    }
View Full Code Here


                                            GraphicsNode node) {
        this.e = e;
        this.node = node;
        this.ctx = ctx;
        // HACK due to the way images are represented in GVT
        ImageNode imgNode = (ImageNode)node;
        ctx.bind(e, imgNode.getImage());
        ((SVGOMElement)e).setSVGContext(this);
    }
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;
        }

        GraphicsNode node = buildImageGraphicsNode(ctx,e);

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

        imageNode.setImage(node);

        // 'image-rendering' and 'color-rendering'
        RenderingHints hints = CSSUtilities.convertImageRendering(e, null);
        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

                                            GraphicsNode node) {
        this.e = e;
        this.node = node;
        this.ctx = ctx;
        // HACK due to the way images are represented in GVT
        ImageNode imgNode = (ImageNode)node;
        if (imgNode.getImage() instanceof RasterImageNode) {
            // register the RasterImageNode instead
            ctx.bind(e, imgNode.getImage());
        } else {
            ctx.bind(e, node);
        }
        ((SVGOMElement)e).setSVGContext(this);
    }
View Full Code Here

            if (inode == null) {
                String uriStr = XLinkSupport.getXLinkHref(e);
                throw new BridgeException(e, ERR_URI_IMAGE_INVALID,
                                          new Object[] {uriStr});
            }
            ImageNode imgNode = (ImageNode)node;
            //HACK : see 'initializeDynamicSupport'
            if (imgNode.getImage() instanceof RasterImageNode) {
                // register the RasterImageNode instead
                ctx.unbind(e);
                ctx.bind(e, inode );
            }
            else{
                //it was an svg file referenced
                //dispose it
                if ( oldSVGDoc != null ){
                    disposeTree(oldSVGDoc);
                }
            }
            imgNode.setImage(inode);
           
  } else {
      super.handleDOMAttrModifiedEvent(evt);
  }
    }
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;
        }

        // '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();

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

        if (node == null) {
            String baseURI = XMLBaseSupport.getCascadedXMLBase(e);
            ParsedURL purl;
            if (baseURI == null)
                purl = new ParsedURL(uriStr);
            else
                purl = new ParsedURL(baseURI, uriStr);

            // 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});
        }

        imageNode.setImage(node);

        // 'image-rendering' and 'color-rendering'
        RenderingHints hints = CSSUtilities.convertImageRendering(e, null);
        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

                                            GraphicsNode node) {
        this.e = e;
        this.node = node;
        this.ctx = ctx;
        // HACK due to the way images are represented in GVT
        ImageNode imgNode = (ImageNode)node;
        if (imgNode.getImage() instanceof RasterImageNode) {
            // register the RasterImageNode instead
            ctx.bind(e, imgNode.getImage());
        } else {
            ctx.bind(e, node);
        }
        ((SVGOMElement)e).setSVGContext(this);
    }
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);
        node.setImageBounds(imgB);

        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

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.