Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

PreferLinux
Copy link
Contributor

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.

While it may have been needed once, it isn't now.
Base automatically changed from master to main March 12, 2021 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant