Bjoern Voigt created BATIK-1337:
-----------------------------------
Summary: XmlWriter produces ugly and often big SVG files
Key: BATIK-1337
URL: https://issues.apache.org/jira/browse/BATIK-1337
Project: Batik
Issue Type: Bug
Components: SVGGraphics2D
Affects Versions: 1.15
Reporter: Bjoern Voigt
The XmlWriter used by the SVGGraphics2D.stream() functions produces very ugly
formatted XML. For instance the example source
[TestSVGGen|https://xmlgraphics.apache.org/batik/using/svg-generator.html]
produces the following XML output:
{code:java}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN'
'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>
<svg xmlns:xlink="http://www.w3.org/1999/xlink" style="fill-opacity:1;
color-rendering:auto; color-interpolation:auto; text-re
ndering:auto; stroke:black; stroke-linecap:square; stroke-miterlimit:10;
shape-rendering:auto; stroke-opacity:1; fill:black; s
troke-dasharray:none; font-weight:normal; stroke-width:1; font-family:'Dialog';
font-style:normal; stroke-linejoin:miter; font
-size:12px; stroke-dashoffset:0; image-rendering:auto;"
xmlns="http://www.w3.org/2000/svg"
><!--Generated by the Batik Graphics2D SVG Generator--><defs id="genericDefs"
/><g
><g style="fill:red; stroke:red;"
><rect x="10" width="100" height="100" y="10" style="stroke:none;"
/><rect x="20" width="100" height="100" y="20" style="stroke:none;"
/><rect x="30" width="100" height="100" y="30" style="stroke:none;"
/><rect x="40" width="100" height="100" y="40" style="stroke:none;"
/><rect x="50" width="100" height="100" y="50" style="stroke:none;"
/><rect x="60" width="100" height="100" y="60" style="stroke:none;"
/><rect x="70" width="100" height="100" y="70" style="stroke:none;"
/><rect x="80" width="100" height="100" y="80" style="stroke:none;"
/><rect x="90" width="100" height="100" y="90" style="stroke:none;"
/><rect x="100" width="100" height="100" y="100" style="stroke:none;"
/></g
></g
></svg
>{code}
Every closing tag ">" and "/>" is printed on a new line. Still this looks Okay
for an easy SVG example. In big read-world SVG files with many layers and many
elements the XML output looks much worse. See this small extract from an SVG
output with many elements and layers:
{code:java}
>TXT</text
>
</g
></g
>
</g
><g id="x1243"
transform="translate(160.0,0.0)"
>
{code}
The bad indentation makes the SVG output files big. Gzip compression only helps
partially. See this statistics from my real-world SVG output from a drawing
(which is private an can't be shared here).
||File||XmlWriter output size [bytes]||Gzipped size [bytes]||
|output.svg from XmlWriter|204009|10219|
|output.svg from XmlWriter (post-processed with xmllint --format)|86911|6936|
The indentation itself does not make the files big. It's the bad indentation.
The tool xmllint can produce pretty printed XML, which is not bigger than
necessary. The output from the example file processed with "xmllinit --format":
{code:java}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg" style="fill-opacity:1; color-rendering:auto;
color-interpolation:auto; text-rendering:auto; stroke:black;
stroke-linecap:square; stroke-miterlimit:10; shape-rendering:auto;
stroke-opacity:1; fill:black; stroke-dasharray:none; font-weight:normal;
stroke-width:1; font-family:'Dialog'; font-style:normal; stroke-linejoin:miter;
font-size:12px; stroke-dashoffset:0; image-rendering:auto;">
<!--Generated by the Batik Graphics2D SVG Generator-->
<defs id="genericDefs"/>
<g>
<g style="fill:red; stroke:red;">
<rect x="10" width="100" height="100" y="10" style="stroke:none;"/>
<rect x="20" width="100" height="100" y="20" style="stroke:none;"/>
<rect x="30" width="100" height="100" y="30" style="stroke:none;"/>
<rect x="40" width="100" height="100" y="40" style="stroke:none;"/>
<rect x="50" width="100" height="100" y="50" style="stroke:none;"/>
<rect x="60" width="100" height="100" y="60" style="stroke:none;"/>
<rect x="70" width="100" height="100" y="70" style="stroke:none;"/>
<rect x="80" width="100" height="100" y="80" style="stroke:none;"/>
<rect x="90" width="100" height="100" y="90" style="stroke:none;"/>
<rect x="100" width="100" height="100" y="100" style="stroke:none;"/>
</g>
</g>
</svg>
{code}
Also the extract looks more compact with xmllint --format.
{code:java}
>MB1</text>
</g>
</g>
</g>
<g id="x1243" transform="translate(160.0,0.0)">
{code}
It is probably not necessary to change XmlWriter so, that it produces "pretty
printed XML". But the output should be somewhat more pretty and somewhat
smaller.
Currently own implementations of a XmlWriter are impossible. See this related
bug:
BATIK-502
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]