So when I first read it I created an svgDocumentOrg variable into which I placed the contents of the SVG file. When I printed the contents of svgDocumentOrg now everything was as it should be (I hadn't tried that when I wrote the first message. Stupid me :) I then performed my replacements on cues in the original SVG file on a variable I called svgDocumentCopy which was assigned as SVGDocument svgDocumentCopy = svgDocumentOrg. When I now printed svgDocumentOrg (as I originally did in the first message) all the text was gone since the text had been replaced by an empty string (which was what I wanted to do on the copy but not the original). I'm sure you can see my confusion when I thought I hadn't modified svgDocumentOrg at all and it's contents are not what I expect :D
This was the basis of my problems. I fixed it by making a proper copy of the contents of the svgDocumentOrg into svgDocumentCopy instead of simply copying its reference.
For others who might run into the same problem, here's how to copy the contents of one SVGDocument variable into another:
svgDocumentCopy = (SVGDocument) DOMUtilities.deepCloneDocument( svgDocumentOrg, svgDocumentOrg.getImplementation());
Glenn Thomas Hvidsten
Thomas DeWeese wrote:
Hi Glenn,
What happens if you print the Document you get back from SAXSVGDocumentFactory?
I suspect that something in your code is deleting the text content. The code you are using is essentially the same as the code used internally.
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]
--------------------------------------------------------------------- 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]