Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Text] Convert control codepoints into zero width space during shaping #17004

Merged
merged 2 commits into from
Sep 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading