Search code examples
javaswingjava-2dbatik

Gradient paints not working in Apache Batik's svggen


I am using Apache Batik's SVGGraphics2D class to bridge my swing drawing calls to SVG. It works fine with the exception that LinearGradientPaint elements are ignored completely. The setup code is taken from the svggen tutorial and as simple as it can be.

The svg-file reports "fill:none". Is there something that I am missing or is this a bug? The code uses Batik ver. 1.7 on JRE 1.6 Swing classes.


Solution

  • The problem was, as lbalazscs noted, the extension handler. I did not find a proper implementation of the svggen ExtensionHandler on the web, so I wrote one myself.

    The code processes LinearGradientPaint and RadialGradientPaint (feel free to add more)

    https://gist.github.com/4509119

    The snippet has also been reported on Batik's issue tracker:

    https://issues.apache.org/jira/browse/BATIK-1032