Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions third_party/txt/src/txt/font_collection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,26 +209,33 @@ std::shared_ptr<minikin::FontFamily> FontCollection::CreateMinikinFontFamily(
return nullptr;
}

std::vector<minikin::Font> minikin_fonts;

// Add fonts to the Minikin font family.
std::vector<sk_sp<SkTypeface>> skia_typefaces;
for (int i = 0; i < font_style_set->count(); ++i) {
TRACE_EVENT0("flutter", "CreateMinikinFont");
// Create the skia typeface.
TRACE_EVENT0("flutter", "CreateSkiaTypeface");
sk_sp<SkTypeface> skia_typeface(
sk_sp<SkTypeface>(font_style_set->createTypeface(i)));
if (skia_typeface == nullptr) {
continue;
if (skia_typeface != nullptr) {
skia_typefaces.emplace_back(std::move(skia_typeface));
}
}

std::sort(skia_typefaces.begin(), skia_typefaces.end(),
[](const sk_sp<SkTypeface>& a, const sk_sp<SkTypeface>& b) {
SkFontStyle a_style = a->fontStyle();
SkFontStyle b_style = b->fontStyle();
return (a_style.weight() != b_style.weight())
? a_style.weight() < b_style.weight()
: a_style.slant() < b_style.slant();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the slant always different? Is it possible to have a pair of fonts with identical weight and slant?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically a font family would not include multiple fonts with the same weight and slant, but there is no guarantee against that

});

std::vector<minikin::Font> minikin_fonts;
for (const sk_sp<SkTypeface>& skia_typeface : skia_typefaces) {
// Create the minikin font from the skia typeface.
// Divide by 100 because the weights are given as "100", "200", etc.
minikin::Font minikin_font(
minikin_fonts.emplace_back(
std::make_shared<FontSkia>(skia_typeface),
minikin::FontStyle{skia_typeface->fontStyle().weight() / 100,
skia_typeface->isItalic()});

minikin_fonts.emplace_back(std::move(minikin_font));
}

return std::make_shared<minikin::FontFamily>(std::move(minikin_fonts));
Expand Down