Forráskód Böngészése

Fix TextLineMetrics calculation for TextLines that contain a TextEndOfLine run

Benedikt Stebner 2 éve
szülő
commit
13280eecf5
1 módosított fájl, 10 hozzáadás és 3 törlés
  1. 10 3
      src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs

+ 10 - 3
src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs

@@ -1436,6 +1436,13 @@ namespace Avalonia.Media.TextFormatting
 
             var lineHeight = _paragraphProperties.LineHeight;
 
+            var lastRunIndex = _textRuns.Count - 1;
+
+            if (_textRuns[lastRunIndex] is TextEndOfLine && lastRunIndex > 0)
+            {
+                lastRunIndex--;
+            }
+
             for (var index = 0; index < _textRuns.Count; index++)
             {
                 switch (_textRuns[index])
@@ -1470,7 +1477,7 @@ namespace Avalonia.Media.TextFormatting
                                 }
                             }
 
-                            if (index == _textRuns.Count - 1)
+                            if (index == lastRunIndex)
                             {
                                 width = widthIncludingWhitespace + textRun.GlyphRun.Metrics.Width;
                                 trailingWhitespaceLength = textRun.GlyphRun.Metrics.TrailingWhitespaceLength;
@@ -1490,7 +1497,7 @@ namespace Avalonia.Media.TextFormatting
                             {
                                 case FlowDirection.LeftToRight:
                                     {
-                                        if (index == _textRuns.Count - 1)
+                                        if (index == lastRunIndex)
                                         {
                                             width = widthIncludingWhitespace;
                                             trailingWhitespaceLength = 0;
@@ -1502,7 +1509,7 @@ namespace Avalonia.Media.TextFormatting
 
                                 case FlowDirection.RightToLeft:
                                     {
-                                        if (index == _textRuns.Count - 1)
+                                        if (index == lastRunIndex)
                                         {
                                             width = widthIncludingWhitespace;
                                             trailingWhitespaceLength = 0;