Skip to content

Commit

Permalink
Revert "Use all font managers to discover fonts for strut. (flutter#7734
Browse files Browse the repository at this point in the history
)" (flutter#7801)

This reverts commit c4a5555.
  • Loading branch information
GaryQian authored Feb 12, 2019
1 parent 769016c commit 74d94e5
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 69 deletions.
20 changes: 20 additions & 0 deletions third_party/txt/src/txt/font_collection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,26 @@ FontCollection::GetMinikinFontCollectionForFamilies(
return font_collection;
}

minikin::MinikinFont* FontCollection::GetMinikinFontForFamilies(
const std::vector<std::string>& font_families,
minikin::FontStyle style) {
std::shared_ptr<minikin::FontFamily> font_family = nullptr;
for (std::string family_name : font_families) {
font_family = FindFontFamilyInManagers(family_name);
if (font_family != nullptr) {
break;
}
}
if (font_family == nullptr) {
const auto default_font_family = GetDefaultFontFamily();
font_family = FindFontFamilyInManagers(default_font_family);
}
if (font_family == nullptr) {
return nullptr;
}
return font_family.get()->getClosestMatch(style).font;
}

std::shared_ptr<minikin::FontFamily> FontCollection::FindFontFamilyInManagers(
const std::string& family_name) {
// Search for the font family in each font manager.
Expand Down
4 changes: 4 additions & 0 deletions third_party/txt/src/txt/font_collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class FontCollection : public std::enable_shared_from_this<FontCollection> {
const std::vector<std::string>& font_families,
const std::string& locale);

minikin::MinikinFont* GetMinikinFontForFamilies(
const std::vector<std::string>& font_families,
minikin::FontStyle style);

// Provides a FontFamily that contains glyphs for ch. This caches previously
// matched fonts. Also see FontCollection::DoMatchFallbackFont.
const std::shared_ptr<minikin::FontFamily>& MatchFallbackFont(
Expand Down
26 changes: 12 additions & 14 deletions third_party/txt/src/txt/paragraph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -441,20 +441,18 @@ void Paragraph::ComputeStrut(StrutMetrics* strut, SkFont& font) {
// force_strut makes all lines have exactly the strut metrics, and ignores all
// actual metrics. We only force the strut if the strut is non-zero and valid.
strut->force_strut = paragraph_style_.force_strut_height && valid_strut;
minikin::FontStyle minikin_font_style(
0, GetWeight(paragraph_style_.strut_font_weight),
paragraph_style_.strut_font_style == FontStyle::italic);

std::shared_ptr<minikin::FontCollection> collection =
font_collection_->GetMinikinFontCollectionForFamilies(
paragraph_style_.strut_font_families, "");
if (!collection) {
return;
}
minikin::FakedFont faked_font = collection->baseFontFaked(minikin_font_style);

if (faked_font.font != nullptr) {
font.setTypeface(static_cast<FontSkia*>(faked_font.font)->GetSkTypeface());
const FontSkia* font_skia =
static_cast<const FontSkia*>(font_collection_->GetMinikinFontForFamilies(
paragraph_style_.strut_font_families,
// TODO(garyq): The variant is currently set to 0 (default) as we do
// not have a property to set it with. We should eventually support
// default, compact, and elegant variants.
minikin::FontStyle(
0, GetWeight(paragraph_style_.strut_font_weight),
paragraph_style_.strut_font_style == FontStyle::italic)));

if (font_skia != nullptr) {
font.setTypeface(font_skia->GetSkTypeface());
font.setSize(paragraph_style_.strut_font_size);
SkFontMetrics strut_metrics;
font.getMetrics(&strut_metrics);
Expand Down
Loading

0 comments on commit 74d94e5

Please sign in to comment.