Browse Source

Fix TextLineMetrics calculation for TextLines that contain a TextEndOfLine run

pull/9896/head
Benedikt Stebner 4 years ago
parent
commit
13280eecf5
  1. 13
      src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs

13
src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs

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

Loading…
Cancel
Save