Non-closing paths

A discussion forum for JFreeSVG (a fast, lightweight, SVG generator for the Java platform).
Locked
Spassmarine
Posts: 1
Joined: Fri Aug 15, 2014 12:09 pm
antibot: No, of course not.

Non-closing paths

Post by Spassmarine » Fri Aug 15, 2014 1:28 pm

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.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Non-closing paths

Post by david.gilbert » Fri Aug 15, 2014 4:20 pm

You are right. I guess I intended the SEG_CLOSE to be implemented as a lineto rather than a moveto but, in any case, even that doesn't seem as correct as appending 'Z' to the SVG path. I have committed the fix for inclusion in the next release (2.2). Thanks for reporting it.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked