I'm using JFreeSVG in conjunction with JFreeChart and custom
XYAnnotations which basically draw composites of various
Shape objects (
Rectangles,
Ellipses and assorted
Polygons mainly). Things look fine in a
ChartPanel, however upon exporting to SVG it appears the polygonal shapes are missing their final closing edge segment stroke when viewed in various applications (GIMP, Inkscape, Firefox, etc.).
Digging into the
SVGGraphics2D code I see that the closing segments of shape paths are translated to a
moveto SVG path command in the
getSVGPathData() method:
Code: Select all
case (PathIterator.SEG_CLOSE):
if (closePt != null) {
b.append("M ").append(geomDP(closePt[0])).append(" ")
.append(geomDP(closePt[1]));
}
break;
This seems intentional as the coordinates of the most recent preceding
moveto command are stored for this purpose. However, replacing that section to use a
closepath command instead fixes the issue for me:
Code: Select all
case (PathIterator.SEG_CLOSE):
b.append("Z");
break;
Is there a specific reason to use a
moveto command over a
closepath command? I know that having a fill on a path adds an implicit closure to the stroke, but as far as I can see fills and strokes aren't combined in the
SVGGraphics2D implementation due to
draw() and
fill() being separate operations.