SVG Shape 2 Java2D Code
A couple weeks ago I needed to write some Java2D code to draw a water droplet. If you have ever tried coding bezier paths off the top of you head it is not the simplest of things and can be frustrating. So I ended up drawing it in Illustrator and saving as SVG. The next stage was hacking with some code I had from before to take the path and spit out Java2D code for the shape. I have been thinking since that I could cleanup the code when I get the time and make a little application for extracting path shapes from SVG and writing out the Java2D code for them. Well I finally got the time and here is what I came up with.

Download:
SvgShapeExtractor.jar (Executable Jar)
SvgShapeExtractorSrc.zip (Src)
Hopefully you will find this useful next time you need to write some Java2D shape code.
July 8th, 2007 at 9:06 pm
I wrote a similar tool back a few months ago. It supports almost everything in SVG (not a single path) except texts.
July 8th, 2007 at 9:59 pm
[…] Shape 2 SVB is available from Jasper’s blog. […]
July 10th, 2007 at 7:32 am
Another way to generate shape easily is to have function that return GeneralPath with parameter SVG path string
public GeneralPath generatPath(String s) {
// code to return GeneralPath, should be similar to above with slight modification
}
use case:
String s = “M 167.0 197.0 C 177.0 169.0 177.0 169.0 177.0 169.0 C 191.0 143.0 191.0 143.0 191.0 143.0 C 215.0 117.0 215.0 117.0 215.0 117.0″;
GeneralPath path = generatePath(s);
// draw the path to output media