You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Glenn Thomas Hvidsten <gt...@corena.no> on 2005/03/08 11:32:34 UTC
SVGDocument - Difference when building my own or using autogenerated
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: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org
Re: SVGDocument - Difference when building my own or using
autogenerated
Posted by Tonny Kohar <to...@kiyut.com>.
Hi,
If the output can be parsed back by JSVGCanvas correctly, it seem that
your propietary XML output do things incorrectly. In your propietary XML
output, how do you print Text node? Make sure from the element, it get
the firstChild which is the text node, then print the Text Node.
Regards
Tonny Kohar
On Tue, 2005-03-08 at 11:32 +0100, Glenn Thomas Hvidsten wrote:
> 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: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org
Re: SVGDocument - Difference when building my own or using autogenerated
Posted by Glenn Thomas Hvidsten <gt...@corena.no>.
My problem appeared because I thought I was working on a copy of the
SVGDocument, but since I was only working on a copy of the reference, I
was working on the actual SVGDocument itself.
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: batik-users-unsubscribe@xml.apache.org
>> For additional commands, e-mail: batik-users-help@xml.apache.org
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org
Re: SVGDocument - Difference when building my own or using autogenerated
Posted by Thomas DeWeese <Th...@Kodak.com>.
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.
Finally on the last point of modifying the document
before it is displayed, you can register a listener for
the SVGLoad event which would allow you to modify the document
before the document is displayed. However the two should
be essentially identical.
Glenn Thomas Hvidsten wrote:
> 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: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org