| 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
|
|
|