Details
-
Bug
-
Status: Resolved
-
Resolution: Fixed
-
1.8
-
None
-
None
-
Operating System: other
Platform: Other
Description
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:
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++)
> // 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++)
>
> 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)
> ----------------------------------------------