From 89f8e1e050f6c7d57c5db29c9209205430185ffa Mon Sep 17 00:00:00 2001 From: xiaoxiaowesley Date: Mon, 20 Mar 2023 21:04:23 +0800 Subject: [PATCH 1/3] fix ios fallback font render bug --- modules/skunicode/include/SkUnicode.h | 3 +++ modules/skunicode/src/SkUnicode_icu.cpp | 12 ++++++++++++ modules/skunicode/src/SkUnicode_icu.h | 1 + src/ports/SkFontMgr_mac_ct.cpp | 9 +++++++++ 4 files changed, 25 insertions(+) diff --git a/modules/skunicode/include/SkUnicode.h b/modules/skunicode/include/SkUnicode.h index 6a7b531bbd15..2f12d4eff3fe 100644 --- a/modules/skunicode/include/SkUnicode.h +++ b/modules/skunicode/include/SkUnicode.h @@ -150,6 +150,9 @@ class SKUNICODE_API SkUnicode { static SkString convertUtf16ToUtf8(const std::u16string& utf16); static std::u16string convertUtf8ToUtf16(const char* utf8, int utf8Units); static std::u16string convertUtf8ToUtf16(const SkString& utf8); + static bool isEmoji(SkUnichar utf8); + static bool isEmojiModifier(SkUnichar utf8); + static bool isEmojiBase(SkUnichar utf8); template bool extractUtfConversionMapping(SkSpan utf8, Appender8&& appender8, Appender16&& appender16) { diff --git a/modules/skunicode/src/SkUnicode_icu.cpp b/modules/skunicode/src/SkUnicode_icu.cpp index f8687bc61bd9..1bcedbe2524e 100644 --- a/modules/skunicode/src/SkUnicode_icu.cpp +++ b/modules/skunicode/src/SkUnicode_icu.cpp @@ -564,6 +564,18 @@ class SkUnicode_icu : public SkUnicode { } }; +bool SkUnicode::isEmoji(SkUnichar utf8) { + return sk_u_hasBinaryProperty(utf8, UCHAR_EMOJI); +} + +bool SkUnicode::isEmojiModifier(SkUnichar utf8) { + return sk_u_hasBinaryProperty(utf8, UCHAR_EMOJI_MODIFIER); +} + +bool SkUnicode::isEmojiBase(SkUnichar utf8) { + return sk_u_hasBinaryProperty(utf8, UCHAR_EMOJI_MODIFIER_BASE); +} + std::unique_ptr SkUnicode::Make() { #if defined(SK_USING_THIRD_PARTY_ICU) if (!SkLoadICU()) { diff --git a/modules/skunicode/src/SkUnicode_icu.h b/modules/skunicode/src/SkUnicode_icu.h index e36207771833..f48eef9918ce 100644 --- a/modules/skunicode/src/SkUnicode_icu.h +++ b/modules/skunicode/src/SkUnicode_icu.h @@ -24,6 +24,7 @@ SKICU_FUNC(u_iscntrl) \ SKICU_FUNC(u_isspace) \ SKICU_FUNC(u_isWhitespace) \ + SKICU_FUNC(u_hasBinaryProperty) \ SKICU_FUNC(u_strToUpper) \ SKICU_FUNC(ubidi_close) \ SKICU_FUNC(ubidi_getDirection) \ diff --git a/src/ports/SkFontMgr_mac_ct.cpp b/src/ports/SkFontMgr_mac_ct.cpp index 43edf326bb61..635217aa2e36 100644 --- a/src/ports/SkFontMgr_mac_ct.cpp +++ b/src/ports/SkFontMgr_mac_ct.cpp @@ -18,6 +18,7 @@ #include #include #include +#include "modules/skunicode/include/SkUnicode.h" #endif #include "include/core/SkData.h" @@ -507,6 +508,14 @@ class SkFontMgr_Mac : public SkFontMgr { if (!string) { return nullptr; } +#ifdef SK_BUILD_FOR_IOS + if (familyName == NULL && SkUnicode::isEmoji(character)) { + CFStringRef fontName = CFSTR("Apple Color Emoji"); + CGFloat fontSize =16; + SkUniqueCFRef ret(CTFontCreateWithName(fontName, fontSize, NULL)); + return SkTypeface_Mac::Make(std::move(ret), OpszVariation(), nullptr).release(); + } +#endif CFRange range = CFRangeMake(0, CFStringGetLength(string.get())); // in UniChar units. SkUniqueCFRef fallbackFont( CTFontCreateForString(familyFont.get(), string.get(), range)); From 4e1eb1c462ebbe62f340a79f3648ac1ce1fc90d1 Mon Sep 17 00:00:00 2001 From: xiaoxiaowesley Date: Tue, 21 Mar 2023 00:45:30 +0800 Subject: [PATCH 2/3] format code. --- modules/skunicode/include/SkUnicode.h | 2 -- modules/skunicode/src/SkUnicode_icu.cpp | 8 -------- src/ports/SkFontMgr_mac_ct.cpp | 6 ++---- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/modules/skunicode/include/SkUnicode.h b/modules/skunicode/include/SkUnicode.h index 2f12d4eff3fe..2db0229e2299 100644 --- a/modules/skunicode/include/SkUnicode.h +++ b/modules/skunicode/include/SkUnicode.h @@ -151,8 +151,6 @@ class SKUNICODE_API SkUnicode { static std::u16string convertUtf8ToUtf16(const char* utf8, int utf8Units); static std::u16string convertUtf8ToUtf16(const SkString& utf8); static bool isEmoji(SkUnichar utf8); - static bool isEmojiModifier(SkUnichar utf8); - static bool isEmojiBase(SkUnichar utf8); template bool extractUtfConversionMapping(SkSpan utf8, Appender8&& appender8, Appender16&& appender16) { diff --git a/modules/skunicode/src/SkUnicode_icu.cpp b/modules/skunicode/src/SkUnicode_icu.cpp index 1bcedbe2524e..797dafde0f00 100644 --- a/modules/skunicode/src/SkUnicode_icu.cpp +++ b/modules/skunicode/src/SkUnicode_icu.cpp @@ -568,14 +568,6 @@ bool SkUnicode::isEmoji(SkUnichar utf8) { return sk_u_hasBinaryProperty(utf8, UCHAR_EMOJI); } -bool SkUnicode::isEmojiModifier(SkUnichar utf8) { - return sk_u_hasBinaryProperty(utf8, UCHAR_EMOJI_MODIFIER); -} - -bool SkUnicode::isEmojiBase(SkUnichar utf8) { - return sk_u_hasBinaryProperty(utf8, UCHAR_EMOJI_MODIFIER_BASE); -} - std::unique_ptr SkUnicode::Make() { #if defined(SK_USING_THIRD_PARTY_ICU) if (!SkLoadICU()) { diff --git a/src/ports/SkFontMgr_mac_ct.cpp b/src/ports/SkFontMgr_mac_ct.cpp index 635217aa2e36..e46e2f2e3dab 100644 --- a/src/ports/SkFontMgr_mac_ct.cpp +++ b/src/ports/SkFontMgr_mac_ct.cpp @@ -508,11 +508,9 @@ class SkFontMgr_Mac : public SkFontMgr { if (!string) { return nullptr; } -#ifdef SK_BUILD_FOR_IOS +#if defined(SK_BUILD_FOR_IOS) if (familyName == NULL && SkUnicode::isEmoji(character)) { - CFStringRef fontName = CFSTR("Apple Color Emoji"); - CGFloat fontSize =16; - SkUniqueCFRef ret(CTFontCreateWithName(fontName, fontSize, NULL)); + SkUniqueCFRef ret(CTFontCreateWithName(CFSTR("AppleColorEmoji"), 16, NULL)); return SkTypeface_Mac::Make(std::move(ret), OpszVariation(), nullptr).release(); } #endif From 27f5fc1f1f25707ea8d5cca8a188f09de38c8eb7 Mon Sep 17 00:00:00 2001 From: xiaoxiaowesley Date: Wed, 29 Mar 2023 11:12:37 +0800 Subject: [PATCH 3/3] reset string incase of memory leak. --- src/ports/SkFontMgr_mac_ct.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ports/SkFontMgr_mac_ct.cpp b/src/ports/SkFontMgr_mac_ct.cpp index c713d280c3d6..6f3dfa711842 100644 --- a/src/ports/SkFontMgr_mac_ct.cpp +++ b/src/ports/SkFontMgr_mac_ct.cpp @@ -478,7 +478,10 @@ class SkFontMgr_Mac : public SkFontMgr { #if defined(SK_BUILD_FOR_IOS) if (familyName == NULL && SkUnicode::isEmoji(character)) { SkUniqueCFRef ret(CTFontCreateWithName(CFSTR("AppleColorEmoji"), 16, NULL)); - return SkTypeface_Mac::Make(std::move(ret), OpszVariation(), nullptr).release(); + if (ret && string) { + string.reset(); + return SkTypeface_Mac::Make(std::move(ret), OpszVariation(), nullptr).release(); + } } #endif CFRange range = CFRangeMake(0, CFStringGetLength(string.get())); // in UniChar units.