Browse Source

Fix Skia rendering hairline width strokes when Pen thickness is 0.

pull/2349/head
Dariusz Komosinski 7 years ago
parent
commit
6727bbe3df
  1. 8
      src/Skia/Avalonia.Skia/DrawingContextImpl.cs
  2. 20
      tests/Avalonia.RenderTests/Shapes/RectangleTests.cs
  3. BIN
      tests/TestFiles/Direct2D1/Shapes/Rectangle/Rectangle_0px_Stroke.expected.png
  4. BIN
      tests/TestFiles/Skia/Shapes/Rectangle/Rectangle_0px_Stroke.expected.png

8
src/Skia/Avalonia.Skia/DrawingContextImpl.cs

@ -501,7 +501,6 @@ namespace Avalonia.Skia
{
var paint = new SKPaint
{
IsStroke = false,
IsAntialias = true
};
@ -558,6 +557,13 @@ namespace Avalonia.Skia
/// <returns></returns>
private PaintWrapper CreatePaint(Pen pen, Size targetSize)
{
// In Skia 0 thickness means - use hairline rendering
// and for us it means - there is nothing rendered.
if (pen.Thickness == 0d)
{
return default;
}
var rv = CreatePaint(pen.Brush, targetSize);
var paint = rv.Paint;

20
tests/Avalonia.RenderTests/Shapes/RectangleTests.cs

@ -20,6 +20,26 @@ namespace Avalonia.Direct2D1.RenderTests.Shapes
{
}
[Fact]
public async Task Rectangle_0px_Stroke()
{
Decorator target = new Decorator
{
Padding = new Thickness(8),
Width = 200,
Height = 200,
Child = new Rectangle
{
Fill = Brushes.Transparent,
Stroke = Brushes.Black,
StrokeThickness = 0
}
};
await RenderToFile(target);
CompareImages();
}
[Fact]
public async Task Rectangle_1px_Stroke()
{

BIN
tests/TestFiles/Direct2D1/Shapes/Rectangle/Rectangle_0px_Stroke.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B

BIN
tests/TestFiles/Skia/Shapes/Rectangle/Rectangle_0px_Stroke.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B

Loading…
Cancel
Save