Skip to content

Commit

Permalink
Use Skia's CSS3 style matcher for dynamically loaded font sets (flutt…
Browse files Browse the repository at this point in the history
…er#15468)

This will improve font matching for SkParagraph, which relies on the
FontStyleSet's matchStyle implementation to find the closest match for a
FontStyle.
  • Loading branch information
jason-simmons committed Jan 14, 2020
1 parent 0235a50 commit fd269f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions third_party/txt/src/txt/typeface_font_asset_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(index) < typefaces_.size());
if (style) {
*style = typefaces_[index]->fontStyle();
}
if (name) {
name->reset();
}
}

SkTypeface* TypefaceFontStyleSet::createTypeface(int i) {
Expand All @@ -105,14 +113,7 @@ SkTypeface* TypefaceFontStyleSet::createTypeface(int i) {
}

SkTypeface* TypefaceFontStyleSet::matchStyle(const SkFontStyle& pattern) {
if (typefaces_.empty())
return nullptr;

for (const sk_sp<SkTypeface>& typeface : typefaces_)
if (typeface->fontStyle() == pattern)
return SkRef(typeface.get());

return SkRef(typefaces_[0].get());
return matchStyleCSS3(pattern);
}

} // namespace txt
2 changes: 1 addition & 1 deletion third_party/txt/src/txt/typeface_font_asset_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fd269f6

Please sign in to comment.