Skip to content

Commit

Permalink
Convert control codepoints into zero width space during shaping (#17004)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gillibald authored Sep 14, 2024
1 parent d5f0188 commit 2e83ac1
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Skia/Avalonia.Skia/TextShaperImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ namespace Avalonia.Skia
{
internal class TextShaperImpl : ITextShaperImpl
{
private const uint ZeroWidthSpace = '\u200b';

private static readonly ConcurrentDictionary<int, Language> s_cachedLanguage = new();

public ShapedBuffer ShapeText(ReadOnlyMemory<char> text, TextShaperOptions options)
{
var textSpan = text.Span;
Expand Down Expand Up @@ -68,6 +71,16 @@ public ShapedBuffer ShapeText(ReadOnlyMemory<char> text, TextShaperOptions optio

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);
Expand Down

0 comments on commit 2e83ac1

Please sign in to comment.