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.

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)