Преглед на файлове

Fixes ShapedTextRun background rendering (#16594)

* Add failing test

* Fix ShapedTextRun background rendering
Benedikt Stebner преди 1 година
родител
ревизия
e55dfcd1a2

+ 1 - 1
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 - 0
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


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