未验证 提交 9c6e29c4 编写于 作者: J Jason Simmons 提交者: GitHub

libtxt: lazily populate the fallback font cache (#4720)

上级 0d4e72e8
......@@ -292,6 +292,14 @@ const std::shared_ptr<FontFamily>& FontCollection::getFamilyForChar(
uint32_t langListId,
int variant) const {
if (ch >= mMaxChar) {
// libtxt: check if the fallback font provider can match this character
if (mFallbackFontProvider) {
const std::shared_ptr<FontFamily>& fallback =
mFallbackFontProvider->matchFallbackFont(ch);
if (fallback) {
return fallback;
}
}
return mFamilies[0];
}
......
......@@ -32,15 +32,6 @@ namespace txt {
namespace {
// Example characters representing character classes that may require a
// fallback font.
const std::vector<SkUnichar> fallback_characters{
0x1f600, // emoji
0x4e00, // CJK
0x5d0, // Hebrew
0x627, // Arabic
};
// Font families that will be used as a last resort if no font manager provides
// a font matching a particular character.
const std::vector<std::string> last_resort_fonts{
......@@ -201,19 +192,6 @@ FontCollection::GetFontFamilyForTypeface(const sk_sp<SkTypeface>& typeface) {
}
void FontCollection::UpdateFallbackFonts(sk_sp<SkFontMgr> manager) {
// Prepopulate the fallback font cache with fonts matching some widely
// used character classes.
for (SkUnichar fallback_char : fallback_characters) {
sk_sp<SkTypeface> typeface(manager->matchFamilyStyleCharacter(
0, SkFontStyle(), nullptr, 0, fallback_char));
if (typeface) {
// Create a Minikin font family for this typeface if one does not already
// exist.
GetFontFamilyForTypeface(typeface);
}
}
// Add additional font families to be used if nothing else matches.
for (const std::string& family : last_resort_fonts) {
sk_sp<SkTypeface> typeface(
manager->matchFamilyStyle(family.c_str(), SkFontStyle()));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册