Differences between revisions 4 and 5
Revision 4 as of 2006-10-27 16:26:08
Size: 1977
Editor: ArchieCobbs
Comment: Added counter-example from Thomas DeWeese
Revision 5 as of 2009-09-20 23:47:35
Size: 1989
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
 * '''SVG <path> normalizer''' (attachment:svgpathnormalizer.xsl) converts <rect>, <circle>, <ellipse>, <line>, <polygon>, and <polyline> tags into <path> tags.
 * '''SVG <path> consolidator''' (attachment:svgpathconsolidater.xsl) consolidates consecutive <path> elements into a single element.
 * '''XML whitespace eliminator''' (attachment:whitespacesqueezer.xsl) eliminates unnecessary whitespace in any XML document.
 * '''SVG <path> normalizer''' ([[attachment:svgpathnormalizer.xsl]]) converts <rect>, <circle>, <ellipse>, <line>, <polygon>, and <polyline> tags into <path> tags.
 * '''SVG <path> consolidator''' ([[attachment:svgpathconsolidater.xsl]]) consolidates consecutive <path> elements into a single element.
 * '''XML whitespace eliminator''' ([[attachment:whitespacesqueezer.xsl]]) eliminates unnecessary whitespace in any XML document.

The following XSL transforms can be helpful in optimizing SVG documents, especially for certain machine generated documents that have a zillion consecutive <path> elements. Batik's memory usage scales with the number of elements in the document. When multiple <path> elements can be replaced by a single <path> with a longer "d" list, memory is saved.

  • SVG <path> normalizer (svgpathnormalizer.xsl) converts <rect>, <circle>, <ellipse>, <line>, <polygon>, and <polyline> tags into <path> tags.

  • SVG <path> consolidator (svgpathconsolidater.xsl) consolidates consecutive <path> elements into a single element.

  • XML whitespace eliminator (whitespacesqueezer.xsl) eliminates unnecessary whitespace in any XML document.

For best results, run all three transformations in the order shown.

Note: These optimizations may change the rendering in certain cases. Use at your own risk. Here's a "counterexample" document that demonstrates some ways in which the path consolidation will fail:

<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="400" height="400">
<!-- outline issue -->
  <g transform="translate(0, 0)">
<!-- two elements -->
    <path fill="#DDD" stroke="#000" d="m0,0 100,0 0,100 -100,0 z"/>
    <path fill="#DDD" stroke="#000" d="m50,50 100,0 0,100 -100,0 z"/>
  </g>
  <g transform="translate(200, 0)">
<!-- one element -->
    <path fill="#DDD" stroke="#000" d="m0,0 100,0 0,100 -100,0 z m50,50 100,0 0,100 -100,0 z"/>
  </g>
  <g transform="translate(0, 200)">
    <style type="text/css">
      path.button        { fill: #00F; }
      path + path.button { fill: #888; }
    </style>
<!-- this will be blue -->
    <path class="button" fill="#F00" d="m0,0 100,0 0,100 -100,0 z"/>
<!-- this will be grey -->
    <path class="button" fill="#F00" d="m50,50 100,0 0,100 -100,0 z"/>
  </g>
</svg>

OptimizingStylesheets (last edited 2009-09-20 23:47:35 by localhost)