Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Make GetDefaultFontFamilies return a vector<string> instead of a string. #16928

Merged
merged 4 commits into from
Mar 4, 2020

Conversation

gspencergoog
Copy link
Contributor

@gspencergoog gspencergoog commented Mar 4, 2020

On Linux, there is rarely just one default font that can reasonably be expected to be on the platform. This PR changes the GetDefaultFontFamily call to be GetDefaultFontFamilies, and it now returns a vector<string> so that the font collection code can look up all of them, and if any of them exist, add them to the fallback list.

For Linux, I supplied the list "Ubuntu", "Cantarell", "DejaVu Sans", "Liberation Sans", and "Arial", which should cover a large proportion of linux machines. For the other platforms, I supplied a list of length one, containing the one fallback font that used to be defined. On Windows, I added "Segoe UI" as a default, since that is the default system font on newer Windows.

The goal of this function is to provide at least one font family that is installed, since otherwise linux (or any platform) will just have no font at all if the default font isn't found.

@auto-assign auto-assign bot requested a review from franciscojma86 March 4, 2020 16:20
@gspencergoog gspencergoog force-pushed the linux_default_font branch 2 times, most recently from e2d581f to 859b851 Compare March 4, 2020 16:28
@gspencergoog gspencergoog requested review from jason-simmons and removed request for franciscojma86 March 4, 2020 16:35
@gspencergoog
Copy link
Contributor Author

/cc @stuartmorgan

@@ -319,7 +321,7 @@ FontCollection::CreateSktFontCollection() {
skt_collection_ = sk_make_sp<skia::textlayout::FontCollection>();

skt_collection_->setDefaultFontManager(default_font_manager_,
GetDefaultFontFamily().c_str());
GetDefaultFontFamilies()[0].c_str());
Copy link
Member

Choose a reason for hiding this comment

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

The SkParagraph FontCollection API in Skia will need to be extended to handle multiple default fonts. I'll look into this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I wasn't sure what to do about that yet, so I just punted and provided the first one. I suppose I could do a similar thing to what I did above and just supply the first existing one.

FindFontFamilyInManagers(family);
if (minikin_family != nullptr) {
minikin_families.push_back(minikin_family);
}
Copy link
Member

Choose a reason for hiding this comment

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

Exit the loop here. It should be sufficient to provide the first available default font instead of merging all available default fonts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, good point! Done.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants