From 7638a61518cbc9eda472f15e3c38f384d23b461d Mon Sep 17 00:00:00 2001 From: Compunet <117437050+dme-compunet@users.noreply.github.com> Date: Fri, 24 Jan 2025 00:04:51 +0200 Subject: [PATCH] Get trailing whitespace length from glyph run metrics (#17960) Co-authored-by: Julien Lebosquain Co-authored-by: Benedikt Stebner --- .../Media/TextFormatting/TextFormatterImpl.cs | 27 +++---------------- 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/src/Avalonia.Base/Media/TextFormatting/TextFormatterImpl.cs b/src/Avalonia.Base/Media/TextFormatting/TextFormatterImpl.cs index 784ee835b4..7120928696 100644 --- a/src/Avalonia.Base/Media/TextFormatting/TextFormatterImpl.cs +++ b/src/Avalonia.Base/Media/TextFormatting/TextFormatterImpl.cs @@ -951,35 +951,14 @@ namespace Avalonia.Media.TextFormatting return; } - var textSpan = shapedText.Text.Span; + var trailingWhitespaceLength = shapedText.GlyphRun.Metrics.TrailingWhitespaceLength; - if (textSpan.IsEmpty) + if (trailingWhitespaceLength == 0) { return; } - var whitespaceCharactersCount = 0; - - for (var i = textSpan.Length - 1; i >= 0; i--) - { - var isWhitespace = Codepoint.ReadAt(textSpan, i, out _).IsWhiteSpace; - - if (isWhitespace) - { - whitespaceCharactersCount++; - } - else - { - break; - } - } - - if (whitespaceCharactersCount == 0) - { - return; - } - - var splitIndex = shapedText.Length - whitespaceCharactersCount; + var splitIndex = shapedText.Length - trailingWhitespaceLength; var (textRuns, trailingWhitespaceRuns) = SplitTextRuns([shapedText], splitIndex, objectPool);