Chromium Code Reviews| Index: ui/gfx/font.cc |
| diff --git a/ui/gfx/font.cc b/ui/gfx/font.cc |
| index ac7b7491a6cdcb98caa8e889900db693f454d9f6..e19ac7dc7aeca181fd01a567f3421066f6f41592 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,34 @@ NativeFont Font::GetNativeFont() const { |
| } |
| #endif |
| +namespace { |
|
msw
2016/10/28 07:05:06
nit: put anon namespaces at the top of the file.
kojii
2016/10/28 07:57:30
Done.
|
| + |
| +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 |
| + |
| +std::string Font::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(); |
| + sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); |
| + for (const auto& family : families) { |
| + if (IsFontFamilyAvailable(family, fm.get())) |
|
msw
2016/10/28 07:05:06
Is it worth skipping this and early-returning fami
kojii
2016/10/28 07:57:30
Done, unlikely for now but still good to have it.
|
| + return family; |
| + } |
| + return families[0]; |
| +} |
| + |
| #ifndef NDEBUG |
| std::ostream& operator<<(std::ostream& stream, const Font::Weight weight) { |
| return stream << static_cast<int>(weight); |