Browse Source

Fixes ShapedTextRun background rendering (#16594)

* Add failing test

* Fix ShapedTextRun background rendering
pull/16604/head
Benedikt Stebner 2 years ago
committed by GitHub
parent
commit
e55dfcd1a2
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      src/Avalonia.Base/Media/TextFormatting/ShapedTextRun.cs
  2. 31
      tests/Avalonia.RenderTests/Controls/TextBlockTests.cs
  3. BIN
      tests/TestFiles/Direct2D1/Controls/TextBlock/Should_Draw_Run_With_Background.expected.png
  4. BIN
      tests/TestFiles/Skia/Controls/TextBlock/Should_Draw_Run_With_Background.expected.png

2
src/Avalonia.Base/Media/TextFormatting/ShapedTextRun.cs

@ -64,7 +64,7 @@ namespace Avalonia.Media.TextFormatting
if (Properties.BackgroundBrush != null)
{
drawingContext.DrawRectangle(Properties.BackgroundBrush, null, GlyphRun.Bounds.Translate(new Vector(0, -Baseline)));
drawingContext.DrawRectangle(Properties.BackgroundBrush, null, GlyphRun.Bounds);
}
drawingContext.DrawGlyphRun(Properties.ForegroundBrush, GlyphRun);

31
tests/Avalonia.RenderTests/Controls/TextBlockTests.cs

@ -1,6 +1,7 @@
using System.Net;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Controls.Documents;
using Avalonia.Layout;
using Avalonia.Media;
using Xunit;
@ -145,5 +146,35 @@ namespace Avalonia.Direct2D1.RenderTests.Controls
await RenderToFile(target);
CompareImages();
}
[Win32Fact("Has text")]
public async Task Should_Draw_Run_With_Background()
{
Decorator target = new Decorator
{
Padding = new Thickness(8),
Width = 200,
Height = 50,
Child = new TextBlock
{
FontFamily = new FontFamily("Courier New"),
FontSize = 12,
Foreground = Brushes.Black,
VerticalAlignment = VerticalAlignment.Top,
TextWrapping = TextWrapping.NoWrap,
Inlines = new InlineCollection
{
new Run
{
Text = "Neque porro quisquam",
Background = Brushes.Red
}
}
}
};
await RenderToFile(target);
CompareImages();
}
}
}

BIN
tests/TestFiles/Direct2D1/Controls/TextBlock/Should_Draw_Run_With_Background.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 947 B

BIN
tests/TestFiles/Skia/Controls/TextBlock/Should_Draw_Run_With_Background.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

Loading…
Cancel
Save