Non-closing paths

A discussion forum for JFreeSVG (a fast, lightweight, SVG generator for the Java platform).

Non-closing paths

Postby 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.
Spassmarine
 
Posts: 1
Joined: Fri Aug 15, 2014 12:09 pm

Re: Non-closing paths

Postby 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: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited
david.gilbert
JFreeChart Project Leader
 
Posts: 11653
Joined: Fri Mar 14, 2003 10:29 am


Return to JFreeSVG

Who is online

Users browsing this forum: No registered users and 1 guest