Skip to content

Commit

Permalink
Merge pull request #2728 from cwensley/curtis/mac-path-fill-mode
Browse files Browse the repository at this point in the history
Mac: Graphics.FillPath() should use the FillMode of the GraphicsPath
  • Loading branch information
cwensley authored Jan 24, 2025
2 parents 20f47aa + 63bc42d commit 3c810ee
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
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");
}
}
}
}

0 comments on commit 3c810ee

Please sign in to comment.