diff --git a/src/Eto.Mac/Drawing/GraphicsHandler.cs b/src/Eto.Mac/Drawing/GraphicsHandler.cs index 54fcd7917..fb64b120a 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 ebf1b9d7b..72ea8b6f8 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