diff --git a/src/Avalonia.Base/Media/TextFormatting/ShapedTextRun.cs b/src/Avalonia.Base/Media/TextFormatting/ShapedTextRun.cs index 05f3f84d45..caaaa00780 100644 --- a/src/Avalonia.Base/Media/TextFormatting/ShapedTextRun.cs +++ b/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); diff --git a/tests/Avalonia.RenderTests/Controls/TextBlockTests.cs b/tests/Avalonia.RenderTests/Controls/TextBlockTests.cs index 1a61a10919..14c56299e3 100644 --- a/tests/Avalonia.RenderTests/Controls/TextBlockTests.cs +++ b/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(); + } } } diff --git a/tests/TestFiles/Direct2D1/Controls/TextBlock/Should_Draw_Run_With_Background.expected.png b/tests/TestFiles/Direct2D1/Controls/TextBlock/Should_Draw_Run_With_Background.expected.png new file mode 100644 index 0000000000..bc6ba9f4d3 Binary files /dev/null and b/tests/TestFiles/Direct2D1/Controls/TextBlock/Should_Draw_Run_With_Background.expected.png differ diff --git a/tests/TestFiles/Skia/Controls/TextBlock/Should_Draw_Run_With_Background.expected.png b/tests/TestFiles/Skia/Controls/TextBlock/Should_Draw_Run_With_Background.expected.png new file mode 100644 index 0000000000..353e06c93b Binary files /dev/null and b/tests/TestFiles/Skia/Controls/TextBlock/Should_Draw_Run_With_Background.expected.png differ