i was trying to generate a <use> element in a Document displayed in a JSVGCanvas via the UpdateManager, but got a Batik exception
org.apache.batik.bridge.BridgeException: null:0 The URI '' specified on the element <use> is invalid
jSVGCanvas1.setDocumentState(JSVGComponent.ALWAYS_DYNAMIC);
DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; doc = (SVGDocument)impl.createDocument(svgNS, "svg", null);
Element svgRoot = doc.getDocumentElement(); svgRoot.setAttributeNS(svgNS, "overflow", "visible"); svgRoot.setAttributeNS(svgNS, "width", "800"); svgRoot.setAttributeNS(svgNS, "height", "600");
// static symbols
Element defs = doc.createElementNS(svgNS, "defs");
Element symbol = doc.createElementNS(svgNS,"symbol");
symbol.setAttributeNS(svgNS,"id","processor");
symbol.setAttributeNS(svgNS,"viewbox","0 0 40 40");
Element rect = doc.createElementNS(svgNS,"rect");
rect.setAttributeNS(svgNS,"x","0");
rect.setAttributeNS(svgNS,"y","0");
rect.setAttributeNS(svgNS,"width","40");
rect.setAttributeNS(svgNS,"height","40");
rect.setAttributeNS(svgNS,"fill","rgb(102,102,102)");
Element text = doc.createElementNS(svgNS,"text");
text.setAttributeNS(svgNS,"x","2");
text.setAttributeNS(svgNS,"y","18");
text.setAttributeNS(svgNS,"font-family","Arial Black");
text.setAttributeNS(svgNS,"font-size","12");
text.setAttributeNS(svgNS,"fill","rgb(0,174,0)");
text.appendChild(doc.createTextNode("AMD"));
symbol.appendChild(rect);
symbol.appendChild(text);
defs.appendChild(symbol);
doc.getRootElement().appendChild(defs);jSVGCanvas1.setSVGDocument(doc); jScrollPane1.getViewport().add(jSVGCanvas1, null);
a button pressed event invokes this:
jSVGCanvas1.getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable() {
public void run() {
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
Element processor = doc.createElementNS(svgNS, "use");
processor.setAttributeNS(svgNS, "x", "50");
processor.setAttributeNS(svgNS, "y", "50");
processor.setAttributeNS(svgNS, "xlink:href", "#processor");
doc.getRootElement().appendChild(processor);
}
});
Which results in the above exception (URI '')
Dumping the Document to file results in a valid and correct graphic which i could verify with Squiggle.
I know the document is transformed again when writing out, but I still can't explain how to make use of the <use> element in this way.
I also tried loading a SVG Document which contains the <defs> section and then adding the <use> element dynamically, but the same exception is thrown.
kr, Reinhard -- Reinhard Brandstaedter [EMAIL PROTECTED] GPG: 0x033B81DB - Student of Computer Science - J.K. University of Linz - - <ICQ: 73059068> <Mobile: +43 699 12419541> - - http://adelaide.dnsalias.net -
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
