From 6a2e36c37f684907f48d0edfbe5ff9d36baefda9 Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Thu, 5 Mar 2020 00:45:53 +0100 Subject: [PATCH] =?UTF-8?q?Make=20GetDefaultFontFamilies=20return=20a=20ve?= =?UTF-8?q?ctor=20instead=20of=E2=80=A6=20(flutter/engine#16928)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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. --- engine/src/flutter/shell/platform/linux/BUILD.gn | 2 +- .../third_party/txt/src/txt/font_collection.cc | 15 +++++++++------ .../flutter/third_party/txt/src/txt/platform.cc | 4 ++-- .../flutter/third_party/txt/src/txt/platform.h | 4 +++- .../third_party/txt/src/txt/platform_android.cc | 4 ++-- .../third_party/txt/src/txt/platform_fuchsia.cc | 4 ++-- .../third_party/txt/src/txt/platform_linux.cc | 4 ++-- .../third_party/txt/src/txt/platform_mac.mm | 6 +++--- .../third_party/txt/src/txt/platform_windows.cc | 4 ++-- .../flutter/third_party/txt/src/txt/text_style.cc | 3 +-- 10 files changed, 27 insertions(+), 23 deletions(-) diff --git a/engine/src/flutter/shell/platform/linux/BUILD.gn b/engine/src/flutter/shell/platform/linux/BUILD.gn index db36000e0d..54e1bbbd7c 100644 --- a/engine/src/flutter/shell/platform/linux/BUILD.gn +++ b/engine/src/flutter/shell/platform/linux/BUILD.gn @@ -16,7 +16,7 @@ group("linux") { } } -# Temporary workraround for the issue describe in +# Temporary workaround for the issue describe in # https://github.com/flutter/flutter/issues/14509 and # https://github.com/flutter/flutter/issues/14438 # Remove once the build infrastructure moves to Ubuntu 18.04 or newer, where diff --git a/engine/src/flutter/third_party/txt/src/txt/font_collection.cc b/engine/src/flutter/third_party/txt/src/txt/font_collection.cc index 70104d90f8..3b550f7f31 100644 --- a/engine/src/flutter/third_party/txt/src/txt/font_collection.cc +++ b/engine/src/flutter/third_party/txt/src/txt/font_collection.cc @@ -150,11 +150,14 @@ FontCollection::GetMinikinFontCollectionForFamilies( } // Search for default font family if no user font families were found. if (minikin_families.empty()) { - const auto default_font_family = GetDefaultFontFamily(); - std::shared_ptr minikin_family = - FindFontFamilyInManagers(default_font_family); - if (minikin_family != nullptr) { - minikin_families.push_back(minikin_family); + const auto default_font_families = GetDefaultFontFamilies(); + for (auto family : default_font_families) { + std::shared_ptr minikin_family = + FindFontFamilyInManagers(family); + if (minikin_family != nullptr) { + minikin_families.push_back(minikin_family); + break; + } } } // Default font family also not found. We fail to get a FontCollection. @@ -319,7 +322,7 @@ FontCollection::CreateSktFontCollection() { skt_collection_ = sk_make_sp(); skt_collection_->setDefaultFontManager(default_font_manager_, - GetDefaultFontFamily().c_str()); + GetDefaultFontFamilies()[0].c_str()); skt_collection_->setAssetFontManager(asset_font_manager_); skt_collection_->setDynamicFontManager(dynamic_font_manager_); skt_collection_->setTestFontManager(test_font_manager_); diff --git a/engine/src/flutter/third_party/txt/src/txt/platform.cc b/engine/src/flutter/third_party/txt/src/txt/platform.cc index 41831870d5..c60731b375 100644 --- a/engine/src/flutter/third_party/txt/src/txt/platform.cc +++ b/engine/src/flutter/third_party/txt/src/txt/platform.cc @@ -6,8 +6,8 @@ namespace txt { -std::string GetDefaultFontFamily() { - return "Arial"; +std::vector GetDefaultFontFamilies() { + return {"Arial"}; } sk_sp GetDefaultFontManager() { diff --git a/engine/src/flutter/third_party/txt/src/txt/platform.h b/engine/src/flutter/third_party/txt/src/txt/platform.h index 3df3433011..6c3a3cc53a 100644 --- a/engine/src/flutter/third_party/txt/src/txt/platform.h +++ b/engine/src/flutter/third_party/txt/src/txt/platform.h @@ -6,13 +6,15 @@ #define TXT_PLATFORM_H_ #include +#include + #include "flutter/fml/macros.h" #include "third_party/skia/include/core/SkFontMgr.h" namespace txt { -std::string GetDefaultFontFamily(); +std::vector GetDefaultFontFamilies(); sk_sp GetDefaultFontManager(); diff --git a/engine/src/flutter/third_party/txt/src/txt/platform_android.cc b/engine/src/flutter/third_party/txt/src/txt/platform_android.cc index ae7fa2c77e..1e42a7c770 100644 --- a/engine/src/flutter/third_party/txt/src/txt/platform_android.cc +++ b/engine/src/flutter/third_party/txt/src/txt/platform_android.cc @@ -6,8 +6,8 @@ namespace txt { -std::string GetDefaultFontFamily() { - return "sans-serif"; +std::vector GetDefaultFontFamilies() { + return {"sans-serif"}; } sk_sp GetDefaultFontManager() { diff --git a/engine/src/flutter/third_party/txt/src/txt/platform_fuchsia.cc b/engine/src/flutter/third_party/txt/src/txt/platform_fuchsia.cc index fd5dc73fcf..23b0e96900 100644 --- a/engine/src/flutter/third_party/txt/src/txt/platform_fuchsia.cc +++ b/engine/src/flutter/third_party/txt/src/txt/platform_fuchsia.cc @@ -6,8 +6,8 @@ namespace txt { -std::string GetDefaultFontFamily() { - return "Roboto"; +std::vector GetDefaultFontFamilies() { + return {"Roboto"}; } sk_sp GetDefaultFontManager() { diff --git a/engine/src/flutter/third_party/txt/src/txt/platform_linux.cc b/engine/src/flutter/third_party/txt/src/txt/platform_linux.cc index 36df613eec..9e13898d49 100644 --- a/engine/src/flutter/third_party/txt/src/txt/platform_linux.cc +++ b/engine/src/flutter/third_party/txt/src/txt/platform_linux.cc @@ -12,8 +12,8 @@ namespace txt { -std::string GetDefaultFontFamily() { - return "Arial"; +std::vector GetDefaultFontFamilies() { + return {"Ubuntu", "Cantarell", "DejaVu Sans", "Liberation Sans", "Arial"}; } sk_sp GetDefaultFontManager() { diff --git a/engine/src/flutter/third_party/txt/src/txt/platform_mac.mm b/engine/src/flutter/third_party/txt/src/txt/platform_mac.mm index 3dce7b6ca3..da98474589 100644 --- a/engine/src/flutter/third_party/txt/src/txt/platform_mac.mm +++ b/engine/src/flutter/third_party/txt/src/txt/platform_mac.mm @@ -16,11 +16,11 @@ namespace txt { -std::string GetDefaultFontFamily() { +std::vector GetDefaultFontFamilies() { if (fml::IsPlatformVersionAtLeast(9)) { - return [FONT_CLASS systemFontOfSize:14].familyName.UTF8String; + return {[FONT_CLASS systemFontOfSize:14].familyName.UTF8String}; } else { - return "Helvetica"; + return {"Helvetica"}; } } diff --git a/engine/src/flutter/third_party/txt/src/txt/platform_windows.cc b/engine/src/flutter/third_party/txt/src/txt/platform_windows.cc index c16e303862..da44b9fd1c 100644 --- a/engine/src/flutter/third_party/txt/src/txt/platform_windows.cc +++ b/engine/src/flutter/third_party/txt/src/txt/platform_windows.cc @@ -7,8 +7,8 @@ namespace txt { -std::string GetDefaultFontFamily() { - return "Arial"; +std::vector GetDefaultFontFamilies() { + return {"Segoe UI", "Arial"}; } sk_sp GetDefaultFontManager() { diff --git a/engine/src/flutter/third_party/txt/src/txt/text_style.cc b/engine/src/flutter/third_party/txt/src/txt/text_style.cc index 8ca0c42a1e..04589659b6 100644 --- a/engine/src/flutter/third_party/txt/src/txt/text_style.cc +++ b/engine/src/flutter/third_party/txt/src/txt/text_style.cc @@ -23,8 +23,7 @@ namespace txt { -TextStyle::TextStyle() - : font_families(std::vector(1, GetDefaultFontFamily())) {} +TextStyle::TextStyle() : font_families(GetDefaultFontFamilies()) {} bool TextStyle::equals(const TextStyle& other) const { if (color != other.color)