I've just encountered another challenge in batik.
I create a SVGDocument using this code I found on the Batik homepages:

String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory docFactory = new SAXSVGDocumentFactory(parser);
svgDocument = (SVGDocument)
    docFactory.createDocument(f.toURL().toString());

And I use this (very simplified) SVG file:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd";>


<svg width="260.0" height="450.0" xmlns:xlink="http://www.w3.org/1999/xlink"; xmlns="http://www.w3.org/2000/svg";>
<rect x="20.0" y="20.0" fill="#b04c7e" width="75.0" height="95.0" stroke="none"/>
<text x="40.0" y="40.0" fill="#ffdd22" style="font-family:arial;font-weight:bold">###TITLE###</text>
</svg>



When I now use this code:

svgCanvas.setSVGDocument(svgDocument);

What is drawn on the JSVGCanvas does not include the ###TITLE### text.
Also, when I use this code:

svgCanvas.getSVGDocument().getDocumentElement()

and print the contents of the SVGDocument (using a proprietary XML output class) I get this output:

<svg contentScriptType="text/ecmascript" width="260.0" xmlns:xlink="http://www.w3.org/1999/xlink"; zoomAndPan="magnify" contentStyleType="text/css" height="450.0" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg"; version="1.0">
<rect x="20.0" y="20.0" fill="#b04c7e" width="75.0" height="95.0" stroke="none"/>
<text fill="#ffdd22" x="40.0" y="40.0" style="font-family:arial;font-weight:bold"/>
</svg>


As you can see, the text element has been drastically cut down.

When I use the JSVGCanvas itself to read the file by this code:

svgCanvas.setURI(f.toURL().toString());

The graphical output includes the text and the XML output looks like this:

<svg contentScriptType="text/ecmascript" width="260.0" xmlns:xlink="http://www.w3.org/1999/xlink"; zoomAndPan="magnify" contentStyleType="text/css" height="450.0" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg"; version="1.0">
<rect x="20.0" y="20.0" fill="#b04c7e" width="75.0" height="95.0" stroke="none"/>
<text fill="#ffdd22" x="40.0" y="40.0" style="font-family:arial;font-weight:bold">###TITLE###</text>
</svg>


As you can see, the text is now as it should be.

How can I read the SVG file into an SVGDocument while still retaining the text element?

(I want to read the SVG file into a SVGDocument and replace the ###TITLE### with a user defined title. Using the SVGDocument itself until it's ready to be drawn is more efficient than using JSVGCanvas every time since JSVGCanvas renders the SVG each time. I only want to render it when all replacements are done.)


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



Reply via email to