Browse Source

Get trailing whitespace length from glyph run metrics (#17960)

Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
Co-authored-by: Benedikt Stebner <Gillibald@users.noreply.github.com>
pull/18049/head
Compunet 1 year ago
committed by GitHub
parent
commit
7638a61518
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 27
      src/Avalonia.Base/Media/TextFormatting/TextFormatterImpl.cs

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

@ -951,35 +951,14 @@ namespace Avalonia.Media.TextFormatting
return; return;
} }
var textSpan = shapedText.Text.Span; var trailingWhitespaceLength = shapedText.GlyphRun.Metrics.TrailingWhitespaceLength;
if (textSpan.IsEmpty) if (trailingWhitespaceLength == 0)
{ {
return; return;
} }
var whitespaceCharactersCount = 0; var splitIndex = shapedText.Length - trailingWhitespaceLength;
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 (textRuns, trailingWhitespaceRuns) = SplitTextRuns([shapedText], splitIndex, objectPool); var (textRuns, trailingWhitespaceRuns) = SplitTextRuns([shapedText], splitIndex, objectPool);

Loading…
Cancel
Save