Skip to content

Commit

Permalink
fix(TextBlock): [Skia] Fix unsupported symbols rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Aug 25, 2023
1 parent 5999814 commit a8d063f
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions src/Uno.UI/UI/Xaml/Documents/Run.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using HarfBuzzSharp;
using SkiaSharp;
using Uno.Foundation.Logging;
using Windows.UI.Xaml.Documents.TextFormatting;

#nullable enable
Expand Down Expand Up @@ -65,15 +66,13 @@ private List<Segment> GetSegments()
else
{
// Count leading spaces

while (i < text.Length && char.IsWhiteSpace(text[i]) && !Unicode.IsLineBreak(text[i]))
{
leadingSpaces++;
i++;
}

// Keep the segment going until we hit a word break opportunity or a line break

while (i < text.Length)
{
if (ProcessLineBreak(text, ref i, ref lineBreakLength))
Expand All @@ -96,6 +95,21 @@ private List<Segment> GetSegments()
{
symbolTypeface = SKFontManager.Default
.MatchCharacter(text[i]);

if (symbolTypeface is null)
{
// Under some Linux systems, the symbol may not be found
// in the default font and
// we have to skip the character and continue segments
// evaluation.
if (this.Log().IsEnabled(LogLevel.Trace))
{
this.Log().Trace($"Failed to match symbol in the default system font (0x{(int)text[i]:X4}, {text[i]})");
}

i++;
}

break;
}
else if (i + 1 < text.Length
Expand All @@ -106,7 +120,25 @@ private List<Segment> GetSegments()
var codepoint = (int)((text[i] - 0xD800) * 0x400 + (text[i + 1] - 0xDC00) + 0x10000);
symbolTypeface = fontManager
.MatchCharacter(codepoint);
surrogate = symbolTypeface is { };

if (symbolTypeface is not null)
{
surrogate = true;
}
else
{
// Under some Linux systems, the symbol may not be found
// in the default font and
// we have to skip the character and continue segments
// evaluation.

if (this.Log().IsEnabled(LogLevel.Trace))
{
this.Log().Trace($"Failed to match surrogate in the default system font (0x{codepoint:X4}, {(char)codepoint})");
}

i++;
}
break;
}
i++;
Expand Down

0 comments on commit a8d063f

Please sign in to comment.