From 2e83ac1a04c22e94948b0407416545ff926edebd Mon Sep 17 00:00:00 2001 From: Benedikt Stebner Date: Sat, 14 Sep 2024 17:11:08 +0200 Subject: [PATCH] Convert control codepoints into zero width space during shaping (#17004) --- src/Skia/Avalonia.Skia/TextShaperImpl.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Skia/Avalonia.Skia/TextShaperImpl.cs b/src/Skia/Avalonia.Skia/TextShaperImpl.cs index 963edd604f..768e8f3a2f 100644 --- a/src/Skia/Avalonia.Skia/TextShaperImpl.cs +++ b/src/Skia/Avalonia.Skia/TextShaperImpl.cs @@ -14,7 +14,10 @@ namespace Avalonia.Skia { internal class TextShaperImpl : ITextShaperImpl { + private const uint ZeroWidthSpace = '\u200b'; + private static readonly ConcurrentDictionary s_cachedLanguage = new(); + public ShapedBuffer ShapeText(ReadOnlyMemory text, TextShaperOptions options) { var textSpan = text.Span; @@ -68,6 +71,16 @@ namespace Avalonia.Skia var glyphCluster = (int)(sourceInfo.Cluster); + if (glyphIndex == 0) + { + var codepoint = Codepoint.ReadAt(textSpan, glyphCluster, out _); + + if (codepoint.GeneralCategory == GeneralCategory.Control) + { + glyphIndex = options.Typeface.GetGlyph(ZeroWidthSpace); + } + } + var glyphAdvance = GetGlyphAdvance(glyphPositions, i, textScale) + options.LetterSpacing; var glyphOffset = GetGlyphOffset(glyphPositions, i, textScale);