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

Commit 8ff6948

Browse files
authored
Make GetDefaultFontFamilies return a vector<string> instead of… (#16928)
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.
1 parent d20f6d7 commit 8ff6948

File tree

10 files changed

+27
-23
lines changed

10 files changed

+27
-23
lines changed

shell/platform/linux/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ group("linux") {
1616
}
1717
}
1818

19-
# Temporary workraround for the issue describe in
19+
# Temporary workaround for the issue describe in
2020
# https://github.com/flutter/flutter/issues/14509 and
2121
# https://github.com/flutter/flutter/issues/14438
2222
# Remove once the build infrastructure moves to Ubuntu 18.04 or newer, where

third_party/txt/src/txt/font_collection.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,14 @@ FontCollection::GetMinikinFontCollectionForFamilies(
150150
}
151151
// Search for default font family if no user font families were found.
152152
if (minikin_families.empty()) {
153-
const auto default_font_family = GetDefaultFontFamily();
154-
std::shared_ptr<minikin::FontFamily> minikin_family =
155-
FindFontFamilyInManagers(default_font_family);
156-
if (minikin_family != nullptr) {
157-
minikin_families.push_back(minikin_family);
153+
const auto default_font_families = GetDefaultFontFamilies();
154+
for (auto family : default_font_families) {
155+
std::shared_ptr<minikin::FontFamily> minikin_family =
156+
FindFontFamilyInManagers(family);
157+
if (minikin_family != nullptr) {
158+
minikin_families.push_back(minikin_family);
159+
break;
160+
}
158161
}
159162
}
160163
// Default font family also not found. We fail to get a FontCollection.
@@ -319,7 +322,7 @@ FontCollection::CreateSktFontCollection() {
319322
skt_collection_ = sk_make_sp<skia::textlayout::FontCollection>();
320323

321324
skt_collection_->setDefaultFontManager(default_font_manager_,
322-
GetDefaultFontFamily().c_str());
325+
GetDefaultFontFamilies()[0].c_str());
323326
skt_collection_->setAssetFontManager(asset_font_manager_);
324327
skt_collection_->setDynamicFontManager(dynamic_font_manager_);
325328
skt_collection_->setTestFontManager(test_font_manager_);

third_party/txt/src/txt/platform.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
namespace txt {
88

9-
std::string GetDefaultFontFamily() {
10-
return "Arial";
9+
std::vector<std::string> GetDefaultFontFamilies() {
10+
return {"Arial"};
1111
}
1212

1313
sk_sp<SkFontMgr> GetDefaultFontManager() {

third_party/txt/src/txt/platform.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
#define TXT_PLATFORM_H_
77

88
#include <string>
9+
#include <vector>
10+
911
#include "flutter/fml/macros.h"
1012

1113
#include "third_party/skia/include/core/SkFontMgr.h"
1214

1315
namespace txt {
1416

15-
std::string GetDefaultFontFamily();
17+
std::vector<std::string> GetDefaultFontFamilies();
1618

1719
sk_sp<SkFontMgr> GetDefaultFontManager();
1820

third_party/txt/src/txt/platform_android.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
namespace txt {
88

9-
std::string GetDefaultFontFamily() {
10-
return "sans-serif";
9+
std::vector<std::string> GetDefaultFontFamilies() {
10+
return {"sans-serif"};
1111
}
1212

1313
sk_sp<SkFontMgr> GetDefaultFontManager() {

third_party/txt/src/txt/platform_fuchsia.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
namespace txt {
88

9-
std::string GetDefaultFontFamily() {
10-
return "Roboto";
9+
std::vector<std::string> GetDefaultFontFamilies() {
10+
return {"Roboto"};
1111
}
1212

1313
sk_sp<SkFontMgr> GetDefaultFontManager() {

third_party/txt/src/txt/platform_linux.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
namespace txt {
1414

15-
std::string GetDefaultFontFamily() {
16-
return "Arial";
15+
std::vector<std::string> GetDefaultFontFamilies() {
16+
return {"Ubuntu", "Cantarell", "DejaVu Sans", "Liberation Sans", "Arial"};
1717
}
1818

1919
sk_sp<SkFontMgr> GetDefaultFontManager() {

third_party/txt/src/txt/platform_mac.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
namespace txt {
1818

19-
std::string GetDefaultFontFamily() {
19+
std::vector<std::string> GetDefaultFontFamilies() {
2020
if (fml::IsPlatformVersionAtLeast(9)) {
21-
return [FONT_CLASS systemFontOfSize:14].familyName.UTF8String;
21+
return {[FONT_CLASS systemFontOfSize:14].familyName.UTF8String};
2222
} else {
23-
return "Helvetica";
23+
return {"Helvetica"};
2424
}
2525
}
2626

third_party/txt/src/txt/platform_windows.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
namespace txt {
99

10-
std::string GetDefaultFontFamily() {
11-
return "Arial";
10+
std::vector<std::string> GetDefaultFontFamilies() {
11+
return {"Segoe UI", "Arial"};
1212
}
1313

1414
sk_sp<SkFontMgr> GetDefaultFontManager() {

third_party/txt/src/txt/text_style.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323

2424
namespace txt {
2525

26-
TextStyle::TextStyle()
27-
: font_families(std::vector<std::string>(1, GetDefaultFontFamily())) {}
26+
TextStyle::TextStyle() : font_families(GetDefaultFontFamilies()) {}
2827

2928
bool TextStyle::equals(const TextStyle& other) const {
3029
if (color != other.color)

0 commit comments

Comments
 (0)