Chromium Code Reviews| Index: ui/gfx/font.cc |
| diff --git a/ui/gfx/font.cc b/ui/gfx/font.cc |
| index ac7b7491a6cdcb98caa8e889900db693f454d9f6..b657cde7bb0253b4b024d0ecedb06940fcd33a02 100644 |
| --- a/ui/gfx/font.cc |
| +++ b/ui/gfx/font.cc |
| @@ -4,8 +4,11 @@ |
| #include "ui/gfx/font.h" |
| +#include "base/strings/string_split.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "build/build_config.h" |
| +#include "third_party/skia/include/core/SkTypeface.h" |
| +#include "third_party/skia/include/ports/SkFontMgr.h" |
| #include "ui/gfx/platform_font.h" |
| namespace gfx { |
| @@ -91,6 +94,30 @@ NativeFont Font::GetNativeFont() const { |
| } |
| #endif |
| +bool IsFontFamilyAvailable(const std::string& family, SkFontMgr* fontManager) { |
| +#if defined(OS_LINUX) |
| + sk_sp<SkTypeface> typeface( |
| + fontManager->legacyCreateTypeface(family.c_str(), SkFontStyle())); |
|
msw
2016/10/26 20:33:49
Why are we using a legacy skia codepath here and a
kojii
2016/10/26 22:20:03
Because if I create gfx::Font("that does not exist
msw
2016/10/27 00:04:18
Since FontList::ParseDescription requires a size,
|
| + return typeface; |
| +#else |
| + sk_sp<SkFontStyleSet> sset(fontManager->matchFamily(family.c_str())); |
|
msw
2016/10/26 20:33:49
nit: |style_set| or just |set|
kojii
2016/10/26 22:20:03
Done.
|
| + return sset && sset->count(); |
| +#endif |
| +} |
| + |
| +std::string Font::FirstAvailableOrFirst(const std::string& font_name_list) { |
| + std::vector<std::string> families = base::SplitString( |
|
msw
2016/10/26 20:33:49
Could we use gfx::FontList's constructor that take
kojii
2016/10/26 22:20:03
Hmm...FontList::ParseDescription() needs size, and
msw
2016/10/27 00:04:18
Hmm, perhaps derat or asvitkine would have a bette
|
| + font_name_list, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| + if (families.empty()) |
| + return std::string(); |
| + sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); |
| + for (auto& family : families) { |
| + if (IsFontFamilyAvailable(family, fm.get())) |
| + return family; |
| + } |
| + return families[0]; |
| +} |
| + |
| #ifndef NDEBUG |
| std::ostream& operator<<(std::ostream& stream, const Font::Weight weight) { |
| return stream << static_cast<int>(weight); |