Title: Use batik in a mixed mode

Here is my dilemma,

I am constructing a svg DOM tree in java application first without using batik:

myDOM = GenericDOMImplementation.getDOMImplementation().createDocument(svgNS, "svg", null);
Element root = myDOM.getDocumentElement();

Element child = myDOM .createElementNS(svgNS, "g");
…//many child being created in this fashion

Root.append(child);
…// append then to the root, etc

Thing are all good so far, then I used batik to generate another svg DOM from a java Swing widget:

SVGGraphics2D svgG2D = new SVGGraphics2D(myDOM );
swingPnel.paint(svgG2D);

I was hoping that the above two line will append the batik generated node to the DOM tree I created, but unfortunately,
It dost not work this way, the batik generated DOM does not show up anywhere in the document.

Then I tried another approach:

tempDOM = GenericDOMImplementation.getDOMImplementation().createDocument(svgNS, "svg", null);
SVGGraphics2D svgG2D = new SVGGraphics2D(tempDOM );
swingPnel.paint(svgG2D);

Node root = (Node)tempDOM.getDocumentElement();
myDOM.append(myDOM.importNode(root,true));

But it was not imported into myDOM either, there is only a "</svg>" being appended to myDOM.

Any ideas in how to fix it? I really appreciate your kind pointers.

My best guess so far is that by doing:

swingPnel.paint(svgG2D);

Batik does not create the DOM tree in memory immediately, that is the Document associated with SVGGraphics2D was not
Completely built in memory at this stage. This DOM tree is somehow delayed untill you do:
svgG2D.stream(filePath);

Please help, thanks in advance.

Yiling

Reply via email to