From 63bc42dfb3cc4fff99f8e29d62c4d6c12d02f736 Mon Sep 17 00:00:00 2001 From: Curtis Wensley Date: Fri, 24 Jan 2025 15:30:36 -0800 Subject: [PATCH] Mac: Graphics.FillPath() should use the FillMode of the GraphicsPath --- src/Eto.Mac/Drawing/GraphicsHandler.cs | 2 +- .../UnitTests/Drawing/GraphicsPathTests.cs | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/Eto.Mac/Drawing/GraphicsHandler.cs b/src/Eto.Mac/Drawing/GraphicsHandler.cs index 54fcd79179..fb64b120a1 100644 --- a/src/Eto.Mac/Drawing/GraphicsHandler.cs +++ b/src/Eto.Mac/Drawing/GraphicsHandler.cs @@ -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(); } diff --git a/test/Eto.Test/UnitTests/Drawing/GraphicsPathTests.cs b/test/Eto.Test/UnitTests/Drawing/GraphicsPathTests.cs index ebf1b9d7b1..72ea8b6f88 100644 --- a/test/Eto.Test/UnitTests/Drawing/GraphicsPathTests.cs +++ b/test/Eto.Test/UnitTests/Drawing/GraphicsPathTests.cs @@ -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"); + } + } } } \ No newline at end of file