Browse Source
Convert control codepoints into zero width space during shaping (#17004)
pull/17021/head
Benedikt Stebner
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
13 additions and
0 deletions
-
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<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); |
|
|
|
|