From ccc65adf95c1e7043b1a8d1b853f041f535fe00f Mon Sep 17 00:00:00 2001 From: Brad Robinson Date: Sun, 10 May 2020 23:04:43 +1000 Subject: [PATCH] Fix for multi-character emoji --- .../FontFallback/FontFallback.cs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Topten.RichTextKit/FontFallback/FontFallback.cs b/Topten.RichTextKit/FontFallback/FontFallback.cs index 380a711..06e9888 100644 --- a/Topten.RichTextKit/FontFallback/FontFallback.cs +++ b/Topten.RichTextKit/FontFallback/FontFallback.cs @@ -71,13 +71,27 @@ namespace Topten.RichTextKit { // Find fallback font RunFace = fontManager.MatchCharacter(typeface.FamilyName, typeface.FontWeight, typeface.FontWidth, typeface.FontSlant, null, pch[pos]); - - // If couldn't use the specified font + count = 1; if (RunFace == null) + { RunFace = typeface; + count = 1; + } + else + { + // Consume as many as possible + count = RunFace.GetGlyphs((IntPtr)(pch + pos), length - pos, SKEncoding.Utf32, out var glyphs); - // Consume as many characters as possible using the requested type face - count = 1;// RunFace.GetGlyphs((IntPtr)(pch + pos), length - pos, SKEncoding.Utf32, out var glyphs); + // But don't take control characters or spaces... + for (int i = 1; i < count; i++) + { + if (pch[pos] <= 32) + { + count = i; + break; + } + } + } } // Do we need to start a new Run?