From 2cfdc0988682a8c0dcced83f923e5466099d7b7f Mon Sep 17 00:00:00 2001 From: Benedikt Stebner Date: Thu, 26 Oct 2023 05:02:08 +0200 Subject: [PATCH] Fix ShapedTextRun Split for sequences that contain invisible character that belong to the same cluster (#13385) --- .../Media/TextFormatting/ShapedTextRun.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Base/Media/TextFormatting/ShapedTextRun.cs b/src/Avalonia.Base/Media/TextFormatting/ShapedTextRun.cs index ef528ba73b..a1dc0827e8 100644 --- a/src/Avalonia.Base/Media/TextFormatting/ShapedTextRun.cs +++ b/src/Avalonia.Base/Media/TextFormatting/ShapedTextRun.cs @@ -107,15 +107,29 @@ namespace Avalonia.Media.TextFormatting for (var i = 0; i < ShapedBuffer.Length; i++) { var advance = ShapedBuffer[i].GlyphAdvance; + var currentCluster = ShapedBuffer[i].GlyphCluster; if (currentWidth + advance > availableWidth) { break; } - Codepoint.ReadAt(charactersSpan, length, out var count); + if(i + 1 < ShapedBuffer.Length) + { + var nextCluster = ShapedBuffer[i + 1].GlyphCluster; - length += count; + var count = nextCluster - currentCluster; + + length += count; + } + else + { + Codepoint.ReadAt(charactersSpan, length, out var count); + + length += count; + } + + currentWidth += advance; }