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

Mac: Graphics.FillPath() should use the FillMode of the GraphicsPath #2728

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Eto.Mac/Drawing/GraphicsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public void FillPath(Brush brush, IGraphicsPath path)
Control.BeginPath();
Control.AddPath(path.ToCG());
Control.ClosePath();
brush.Draw(this, false, FillMode.Winding);
brush.Draw(this, false, path.FillMode);
EndDrawing();
}

Expand Down
54 changes: 54 additions & 0 deletions test/Eto.Test/UnitTests/Drawing/GraphicsPathTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,59 @@ public void GraphicsPathStrokeContainsShouldWork()
Assert.That(path.StrokeContains(pen, new PointF(10, 1)), Is.True, "#1.3");
Assert.That(path.StrokeContains(pen, new PointF(10, 10)), Is.True, "#1.4");
}

[Test]
public void GraphicsPathShouldFillAlternateCorrectly()
{
var bmp = new Bitmap(100, 100, PixelFormat.Format32bppRgba);
using (var g = new Graphics(bmp))
{
using var maskingPath = new GraphicsPath();

maskingPath.AddRectangle(20, 20, 90, 90);

maskingPath.AddRectangle(40, 40, 80, 10);
maskingPath.FillMode = FillMode.Alternate;

g.FillPath(Colors.Blue, maskingPath);
}

// bmp.Save(Path.Combine(EtoEnvironment.GetFolderPath(EtoSpecialFolder.Downloads), "test.png"), ImageFormat.Png);

using (var bd = bmp.Lock())
{
Assert.That(bd.GetPixel(20, 20), Is.EqualTo(Colors.Blue), "#1.1");
Assert.That(bd.GetPixel(40, 40), Is.EqualTo(Colors.Transparent), "#1.2");
Assert.That(bd.GetPixel(50, 50), Is.EqualTo(Colors.Blue), "#1.3");
Assert.That(bd.GetPixel(19, 19), Is.EqualTo(Colors.Transparent), "#1.4");
}
}

[Test]
public void GraphicsPathShouldFillWindingCorrectly()
{
var bmp = new Bitmap(100, 100, PixelFormat.Format32bppRgba);
using (var g = new Graphics(bmp))
{
using var maskingPath = new GraphicsPath();

maskingPath.AddRectangle(20, 20, 90, 90);

maskingPath.AddRectangle(40, 40, 80, 10);
maskingPath.FillMode = FillMode.Winding;

g.FillPath(Colors.Blue, maskingPath);
}

// bmp.Save(Path.Combine(EtoEnvironment.GetFolderPath(EtoSpecialFolder.Downloads), "test.png"), ImageFormat.Png);

using (var bd = bmp.Lock())
{
Assert.That(bd.GetPixel(20, 20), Is.EqualTo(Colors.Blue), "#1.1");
Assert.That(bd.GetPixel(40, 40), Is.EqualTo(Colors.Blue), "#1.2");
Assert.That(bd.GetPixel(50, 50), Is.EqualTo(Colors.Blue), "#1.3");
Assert.That(bd.GetPixel(19, 19), Is.EqualTo(Colors.Transparent), "#1.4");
}
}
}
}
Loading