managed-commons / SvgNet

Fork of the SVG library for .NET that makes a GdiGraphics that "draws" on a SVG model
BSD 3-Clause "New" or "Revised" License
84 stars 37 forks source link

The interiors of closed paths are not exported correctly #22

Closed glopesdev closed 5 years ago

glopesdev commented 5 years ago

The default FillMode for graphics path is Alternate, where the interiors of closed paths are automatically excluded to form holes. Unfortunately, this is currently not supported by SvgNet, as demonstrated by the following snippet which can be added to the end of the path sample in GdiTestForm:

GraphicsPath myPath3 = new GraphicsPath();
myPath3.AddEllipse(120, 50, 50, 50);
myPath3.AddEllipse(135, 65, 30, 30);
ig.FillPath(Brushes.Blue, myPath3);

gditest

Looking at the exported SVG code, it looks like the inner path is exported as an independent path, whereas in the SVG specification it may be necessary to merge everything into a single path, as in this example: https://www.w3.org/TR/SVG/images/painting/fillrule-evenodd.svg

glopesdev commented 5 years ago

Also the style for SvgPathElement instances created by FillBeziers needs to be set to use fill-rule:evenodd. For some reason this was done for polygons, but not for beziers, even though FillMode is one of the parameters for the method (which is never used inside):

private void FillBeziers(Brush brush, PointF[] points, FillMode fillmode)

...

if (fillmode == FillMode.Alternate)
{
    bez.Style.Set("fill-rule", "evenodd");
} else
{
    bez.Style.Set("fill-rule", "nonzero");
}
monoman commented 5 years ago

Merged and published as nuget 2.0.1 - still validating but should be listed soon.