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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


----------------------------------------------
Don Willems
http://www.wonco.org
----------------------------------------------
[EMAIL PROTECTED]
+31 24 388 69 44 (home)
+31 6 25 188 497 (mobile)
+31 24 35 21 584 (work)
----------------------------------------------

Reply via email to