From 0a68d8b149ce7e29dbbd584e72d462c5135ea601 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Mon, 13 Jan 2020 17:35:56 -0800 Subject: [PATCH] Use Skia's CSS3 style matcher for dynamically loaded font sets (flutter/engine#15468) This will improve font matching for SkParagraph, which relies on the FontStyleSet's matchStyle implementation to find the closest match for a FontStyle. --- .../src/txt/typeface_font_asset_provider.cc | 21 ++++++++++--------- .../src/txt/typeface_font_asset_provider.h | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/engine/src/flutter/third_party/txt/src/txt/typeface_font_asset_provider.cc b/engine/src/flutter/third_party/txt/src/txt/typeface_font_asset_provider.cc index fa1c30ce146..c62c43265df 100644 --- a/engine/src/flutter/third_party/txt/src/txt/typeface_font_asset_provider.cc +++ b/engine/src/flutter/third_party/txt/src/txt/typeface_font_asset_provider.cc @@ -92,8 +92,16 @@ int TypefaceFontStyleSet::count() { return typefaces_.size(); } -void TypefaceFontStyleSet::getStyle(int index, SkFontStyle*, SkString* style) { - FML_DCHECK(false); +void TypefaceFontStyleSet::getStyle(int index, + SkFontStyle* style, + SkString* name) { + FML_DCHECK(static_cast(index) < typefaces_.size()); + if (style) { + *style = typefaces_[index]->fontStyle(); + } + if (name) { + name->reset(); + } } SkTypeface* TypefaceFontStyleSet::createTypeface(int i) { @@ -105,14 +113,7 @@ SkTypeface* TypefaceFontStyleSet::createTypeface(int i) { } SkTypeface* TypefaceFontStyleSet::matchStyle(const SkFontStyle& pattern) { - if (typefaces_.empty()) - return nullptr; - - for (const sk_sp& typeface : typefaces_) - if (typeface->fontStyle() == pattern) - return SkRef(typeface.get()); - - return SkRef(typefaces_[0].get()); + return matchStyleCSS3(pattern); } } // namespace txt diff --git a/engine/src/flutter/third_party/txt/src/txt/typeface_font_asset_provider.h b/engine/src/flutter/third_party/txt/src/txt/typeface_font_asset_provider.h index 2d75838f532..a2c49122130 100644 --- a/engine/src/flutter/third_party/txt/src/txt/typeface_font_asset_provider.h +++ b/engine/src/flutter/third_party/txt/src/txt/typeface_font_asset_provider.h @@ -39,7 +39,7 @@ class TypefaceFontStyleSet : public SkFontStyleSet { int count() override; // |SkFontStyleSet| - void getStyle(int index, SkFontStyle*, SkString* style) override; + void getStyle(int index, SkFontStyle* style, SkString* name) override; // |SkFontStyleSet| SkTypeface* createTypeface(int index) override;