Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(451)

Unified Diff: ui/gfx/font_list.cc

Issue 2441343003: Allow the default generic font family settings to find the first available font (Closed)
Patch Set: msw review Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/font_list.h ('k') | ui/gfx/font_list_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/font_list.cc
diff --git a/ui/gfx/font_list.cc b/ui/gfx/font_list.cc
index 235778510031e2c9f817dce5f906fcb042c93fde..4ff43eccd302f0a351192f0b1b95b66f4052b317 100644
--- a/ui/gfx/font_list.cc
+++ b/ui/gfx/font_list.cc
@@ -8,6 +8,8 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
+#include "third_party/skia/include/core/SkTypeface.h"
+#include "third_party/skia/include/ports/SkFontMgr.h"
#include "ui/gfx/font_list_impl.h"
namespace {
@@ -21,6 +23,17 @@ base::LazyInstance<scoped_refptr<gfx::FontListImpl> >::Leaky g_default_impl =
LAZY_INSTANCE_INITIALIZER;
bool g_default_impl_initialized = false;
+bool IsFontFamilyAvailable(const std::string& family, SkFontMgr* fontManager) {
+#if defined(OS_LINUX)
+ sk_sp<SkTypeface> typeface(
+ fontManager->legacyCreateTypeface(family.c_str(), SkFontStyle()));
+ return typeface;
+#else
+ sk_sp<SkFontStyleSet> set(fontManager->matchFamily(family.c_str()));
+ return set && set->count();
+#endif
+}
+
} // namespace
namespace gfx {
@@ -223,4 +236,20 @@ const scoped_refptr<FontListImpl>& FontList::GetDefaultImpl() {
return g_default_impl.Get();
}
+// static
+std::string FontList::FirstAvailableOrFirst(const std::string& font_name_list) {
+ std::vector<std::string> families = base::SplitString(
+ font_name_list, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
+ if (families.empty())
+ return std::string();
+ if (families.size() == 1)
+ return families[0];
+ sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
+ for (const auto& family : families) {
+ if (IsFontFamilyAvailable(family, fm.get()))
+ return family;
+ }
+ return families[0];
+}
+
} // namespace gfx
« no previous file with comments | « ui/gfx/font_list.h ('k') | ui/gfx/font_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698