mono / libgdiplus

C-based implementation of the GDI+ API
http://www.mono-project.com/
MIT License
333 stars 171 forks source link

Don't draw the stroke when filling a path #668

Open PreferLinux opened 4 years ago

PreferLinux commented 4 years ago

When filling a GraphicsPath, a 1px stroke is also drawn. From the comment and related commits it seems that this behaviour was needed at some stage in the past, but my testing shows that it is no longer correct.

Test case (in Form Paint event):

using (var path = new GraphicsPath()) {
    path.AddRectangle(new Rectangle(10, 10, 1, 20));
    path.AddString("hi there", new FontFamily("Arial"), (int)FontStyle.Regular, 20, new Point(14, 10), StringFormat.GenericDefault);
    e.Graphics.FillPath(Brushes.Blue, path);
}

using (var path = new GraphicsPath()) {
    path.AddRectangle(new Rectangle(100, 10, 50, 50));
    e.Graphics.FillPath(Brushes.Green, path);
    using (var pen = new Pen(Color.FromArgb(128, Color.Red), 2))
        e.Graphics.DrawPath(pen, path);

    e.Graphics.TranslateTransform(100, 0);

    using (var brush = new SolidBrush(Color.FromArgb(128, Color.Red)))
        e.Graphics.FillPath(brush, path);
    e.Graphics.TranslateTransform(50, 0);
    using (var brush = new SolidBrush(Color.FromArgb(128, Color.Green)))
        e.Graphics.FillPath(brush, path);
}

Unmodified: Test showing problems such as overlapping boxes

With this change: Test without problems

For good measure, .Net Framework on Windows 8.1: Test on Windows

As you can see above, it really messes up drawing text or anything narrow via a GraphicsPath.

After this change fill_graphics_with_brush is never called with stroke set to TRUE so I guess the parameter and code for drawing the stroke should be removed, but I didn't want to add that much noise initially.