Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/font.h" | 5 #include "ui/gfx/font.h" |
| 6 | 6 |
| 7 #include "base/strings/string_split.h" | |
| 7 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 8 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "third_party/skia/include/core/SkTypeface.h" | |
| 11 #include "third_party/skia/include/ports/SkFontMgr.h" | |
| 9 #include "ui/gfx/platform_font.h" | 12 #include "ui/gfx/platform_font.h" |
| 10 | 13 |
| 11 namespace gfx { | 14 namespace gfx { |
| 12 | 15 |
| 13 //////////////////////////////////////////////////////////////////////////////// | 16 //////////////////////////////////////////////////////////////////////////////// |
| 14 // Font, public: | 17 // Font, public: |
| 15 | 18 |
| 16 Font::Font() : platform_font_(PlatformFont::CreateDefault()) { | 19 Font::Font() : platform_font_(PlatformFont::CreateDefault()) { |
| 17 } | 20 } |
| 18 | 21 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 const FontRenderParams& Font::GetFontRenderParams() const { | 87 const FontRenderParams& Font::GetFontRenderParams() const { |
| 85 return platform_font_->GetFontRenderParams(); | 88 return platform_font_->GetFontRenderParams(); |
| 86 } | 89 } |
| 87 | 90 |
| 88 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_IOS) | 91 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_IOS) |
| 89 NativeFont Font::GetNativeFont() const { | 92 NativeFont Font::GetNativeFont() const { |
| 90 return platform_font_->GetNativeFont(); | 93 return platform_font_->GetNativeFont(); |
| 91 } | 94 } |
| 92 #endif | 95 #endif |
| 93 | 96 |
| 97 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.
| |
| 98 | |
| 99 bool IsFontFamilyAvailable(const std::string& family, SkFontMgr* fontManager) { | |
| 100 #if defined(OS_LINUX) | |
| 101 sk_sp<SkTypeface> typeface( | |
| 102 fontManager->legacyCreateTypeface(family.c_str(), SkFontStyle())); | |
| 103 return typeface; | |
| 104 #else | |
| 105 sk_sp<SkFontStyleSet> set(fontManager->matchFamily(family.c_str())); | |
| 106 return set && set->count(); | |
| 107 #endif | |
| 108 } | |
| 109 | |
| 110 } // namespace | |
| 111 | |
| 112 std::string Font::FirstAvailableOrFirst(const std::string& font_name_list) { | |
| 113 std::vector<std::string> families = base::SplitString( | |
| 114 font_name_list, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | |
| 115 if (families.empty()) | |
| 116 return std::string(); | |
| 117 sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); | |
| 118 for (const auto& family : families) { | |
| 119 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.
| |
| 120 return family; | |
| 121 } | |
| 122 return families[0]; | |
| 123 } | |
| 124 | |
| 94 #ifndef NDEBUG | 125 #ifndef NDEBUG |
| 95 std::ostream& operator<<(std::ostream& stream, const Font::Weight weight) { | 126 std::ostream& operator<<(std::ostream& stream, const Font::Weight weight) { |
| 96 return stream << static_cast<int>(weight); | 127 return stream << static_cast<int>(weight); |
| 97 } | 128 } |
| 98 #endif | 129 #endif |
| 99 | 130 |
| 100 } // namespace gfx | 131 } // namespace gfx |
| OLD | NEW |