Skip to content

Commit c4a5555

Browse files
authored
Use all font managers to discover fonts for strut. (flutter#7734)
1 parent 17b7d1e commit c4a5555

File tree

4 files changed

+69
-91
lines changed

4 files changed

+69
-91
lines changed

third_party/txt/src/txt/font_collection.cc

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -178,26 +178,6 @@ FontCollection::GetMinikinFontCollectionForFamilies(
178178
return font_collection;
179179
}
180180

181-
minikin::MinikinFont* FontCollection::GetMinikinFontForFamilies(
182-
const std::vector<std::string>& font_families,
183-
minikin::FontStyle style) {
184-
std::shared_ptr<minikin::FontFamily> font_family = nullptr;
185-
for (std::string family_name : font_families) {
186-
font_family = FindFontFamilyInManagers(family_name);
187-
if (font_family != nullptr) {
188-
break;
189-
}
190-
}
191-
if (font_family == nullptr) {
192-
const auto default_font_family = GetDefaultFontFamily();
193-
font_family = FindFontFamilyInManagers(default_font_family);
194-
}
195-
if (font_family == nullptr) {
196-
return nullptr;
197-
}
198-
return font_family.get()->getClosestMatch(style).font;
199-
}
200-
201181
std::shared_ptr<minikin::FontFamily> FontCollection::FindFontFamilyInManagers(
202182
const std::string& family_name) {
203183
// Search for the font family in each font manager.

third_party/txt/src/txt/font_collection.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ class FontCollection : public std::enable_shared_from_this<FontCollection> {
4949
const std::vector<std::string>& font_families,
5050
const std::string& locale);
5151

52-
minikin::MinikinFont* GetMinikinFontForFamilies(
53-
const std::vector<std::string>& font_families,
54-
minikin::FontStyle style);
55-
5652
// Provides a FontFamily that contains glyphs for ch. This caches previously
5753
// matched fonts. Also see FontCollection::DoMatchFallbackFont.
5854
const std::shared_ptr<minikin::FontFamily>& MatchFallbackFont(

third_party/txt/src/txt/paragraph.cc

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -441,18 +441,20 @@ void Paragraph::ComputeStrut(StrutMetrics* strut, SkFont& font) {
441441
// force_strut makes all lines have exactly the strut metrics, and ignores all
442442
// actual metrics. We only force the strut if the strut is non-zero and valid.
443443
strut->force_strut = paragraph_style_.force_strut_height && valid_strut;
444-
const FontSkia* font_skia =
445-
static_cast<const FontSkia*>(font_collection_->GetMinikinFontForFamilies(
446-
paragraph_style_.strut_font_families,
447-
// TODO(garyq): The variant is currently set to 0 (default) as we do
448-
// not have a property to set it with. We should eventually support
449-
// default, compact, and elegant variants.
450-
minikin::FontStyle(
451-
0, GetWeight(paragraph_style_.strut_font_weight),
452-
paragraph_style_.strut_font_style == FontStyle::italic)));
453-
454-
if (font_skia != nullptr) {
455-
font.setTypeface(font_skia->GetSkTypeface());
444+
minikin::FontStyle minikin_font_style(
445+
0, GetWeight(paragraph_style_.strut_font_weight),
446+
paragraph_style_.strut_font_style == FontStyle::italic);
447+
448+
std::shared_ptr<minikin::FontCollection> collection =
449+
font_collection_->GetMinikinFontCollectionForFamilies(
450+
paragraph_style_.strut_font_families, "");
451+
if (!collection) {
452+
return;
453+
}
454+
minikin::FakedFont faked_font = collection->baseFontFaked(minikin_font_style);
455+
456+
if (faked_font.font != nullptr) {
457+
font.setTypeface(static_cast<FontSkia*>(faked_font.font)->GetSkTypeface());
456458
font.setSize(paragraph_style_.strut_font_size);
457459
SkFontMetrics strut_metrics;
458460
font.getMetrics(&strut_metrics);

0 commit comments

Comments
 (0)