Hi Teck,

Teck Hua Lee <gteck...@gmail.com> wrote on 05/11/2010 01:53:41 PM:

> Let's say I want to draw a blue rectangle with a red border.
> Ideally the SVG element should look like this: 
        <rect style="fill:blue;stroke:red"/>

> The generated code makes sense from a Java2D perspective, but it is
> not optimal for SVG since it effectively doubles the footprint of the
> output.
> Does anyone know if Batik provides a way to generate the optimal
> single element syntax?

        It does not.

> It sounds like I need to extend my own SVGGraphics2D to associate a
> shape instance to a cached element instance and set the fill/stroke
> manually based on the drawing commands.

        You need to be very careful here since, the shape element
passed in can change between calls, and in the case of 'fillRect'
'drawRect' the two shape elements will be different.  This means
that the code needs to iterate over the shape element to see if 
it matches the previous shape element (which it needed to copy from
the last call).  Also care needs to be taken that 'other methods'
like transform calls haven't intervened to make it impossible to
collapse the two elements.

        I've actually thought that walking the output tree might
be easier since it's fairly simple to see if the two adjacent
elements match except for fill/stroke.  This could of course
make the 'current element' a bit of a tricky concept.

Reply via email to