Convert control codepoints into zero width space during shaping (#17004)

This commit is contained in:
Benedikt Stebner 2024-09-14 17:11:08 +02:00 коммит произвёл GitHub
Родитель d5f0188ccf
Коммит 2e83ac1a04
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 13 добавлений и 0 удалений

Просмотреть файл

@ -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;
@ -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);