[prev in list] [next in list] [prev in thread] [next in thread] 

List:       batik-users
Subject:    Re: setSVGDocument in JSVGCanvas
From:       Vincent Hardy <vincent.hardy () sun ! com>
Date:       2002-05-30 14:42:48
[Download RAW message or body]

Don,

I am not quite sure why adding the value from getRoot would not work,
but I agree this is laborious. Adding a getRoot() method that would
take the svg element you want as a parameter would be simpler (this
way you would not have to stick the getRoot() <svg> element under 
the Document's root <svg> element or do what you ended up doing.

I have added an RFE for that:

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9520

I'll try to get to it soon (but if you feel like doing it, thanks for
having a go at it!).

Vincent.

Don Willems wrote:
> 
> Yes, that works, thank you Vincent.
> 
> But I'm afraid that my solution is a bit laborious.
> 
> // --> old code
> DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation();
> String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
> Document document = domImpl.createDocument(svgNS, "svg", null);
> SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
> paintRenderer(svgGenerator); //--> paints shapes on the graphics context
> Element svgRoot = document.getDocumentElement();
> svgRoot.setAttributeNS(null, "width", "400");
> svgRoot.setAttributeNS(null, "height", "450");
> // --> new code
> // gets the svg elements from the generator
> Element root = svgGenerator.getRoot();
> // adds the attributes of the generated node to the root node of the document
> NamedNodeMap attrs = root.getAttributes();
> for(int i=0;i<attrs.getLength();i++){
> Node n = attrs.item(i);
> svgRoot.setAttributeNS(null, n.getNodeName(), n.getNodeValue());
> }
> // adds the subnodes of the generated node to the root node of the document
> NodeList nl = root.getChildNodes();
> for(int i=0;i<nl.getLength();i++){
> Node n = nl.item(i);
> svgRoot.appendChild(n);
> }
> 
> The problem is that I cannot copy the generated svg node into the document. I've \
> tried using the methods importNode and appendChild on the document, but none seem \
> to work. So I had to add every subnode and every attribute of the generated node \
> explicitly. Any Ideas?
> 
> Don
> 
> Don,
> 
> The SVGGraphics2D does not populate the Document you gave it at
> construction time. It is only used as a factory for creating all
> the SVG content.
> 
> What you'll have to do is get the root from the SVGGraphics2D
> (getRoot method) and append it to your 'svgRoot'.
> 
> Good luck,
> Vincent.
> 
> Don Willems wrote:
> 
> Hi,
> I have a problem with using the setSVGDocument method in JSVGCanvas.
> The SVG document that I want to render on the JSVGCanvas is generated by
> my program. When I want to render that document nothing seems to happens
> (if I use listeners on the canvas I can see that the document is build,
> and then rendered, but nothing is shown on the canvas).
> I have tried to render SVG documents from a URI and that works. I have
> also tried to save the SVG document generated by my program to a file
> and that works also (I can view the SVG perfectly in Adobes Viewer).
> 
> What do I have to do to get the setSVGDocument method to work?
> 
> My code:
> 
> DOMImplementation domImpl =
> SVGDOMImplementation.getDOMImplementation();
> String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
> Document document = domImpl.createDocument(svgNS, "svg",
> null);
> SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
> paintRenderer(svgGenerator); //--> paints shapes on the
> graphics context
> Element svgRoot = document.getDocumentElement();
> svgRoot.setAttributeNS(null, "width", "400");
> svgRoot.setAttributeNS(null, "height", "450");
> 
> setSVGDocument((document);
> 
> Many thanks,
> Don
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> 
> ----------------------------------------------
> Don Willems
> http://www.wonco.org
> ----------------------------------------------
> don_willems@mac.com
> +31 24 388 69 44 (home)
> +31 6 25 188 497 (mobile)
> +31 24 35 21 584 (work)
> ----------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic