Skip to content

Commit 7638a61

Browse files
dme-compunetMrJulGillibald
authored
Get trailing whitespace length from glyph run metrics (#17960)
Co-authored-by: Julien Lebosquain <[email protected]> Co-authored-by: Benedikt Stebner <[email protected]>
1 parent 2d8376c commit 7638a61

File tree

1 file changed

+3
-24
lines changed

1 file changed

+3
-24
lines changed

src/Avalonia.Base/Media/TextFormatting/TextFormatterImpl.cs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -951,35 +951,14 @@ private static void ResetTrailingWhitespaceBidiLevels(RentedList<TextRun> lineTe
951951
return;
952952
}
953953

954-
var textSpan = shapedText.Text.Span;
954+
var trailingWhitespaceLength = shapedText.GlyphRun.Metrics.TrailingWhitespaceLength;
955955

956-
if (textSpan.IsEmpty)
956+
if (trailingWhitespaceLength == 0)
957957
{
958958
return;
959959
}
960960

961-
var whitespaceCharactersCount = 0;
962-
963-
for (var i = textSpan.Length - 1; i >= 0; i--)
964-
{
965-
var isWhitespace = Codepoint.ReadAt(textSpan, i, out _).IsWhiteSpace;
966-
967-
if (isWhitespace)
968-
{
969-
whitespaceCharactersCount++;
970-
}
971-
else
972-
{
973-
break;
974-
}
975-
}
976-
977-
if (whitespaceCharactersCount == 0)
978-
{
979-
return;
980-
}
981-
982-
var splitIndex = shapedText.Length - whitespaceCharactersCount;
961+
var splitIndex = shapedText.Length - trailingWhitespaceLength;
983962

984963
var (textRuns, trailingWhitespaceRuns) = SplitTextRuns([shapedText], splitIndex, objectPool);
985964

0 commit comments

Comments
 (0)