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

Side by Side Diff: ui/gfx/font.cc

Issue 2441343003: Allow the default generic font family settings to find the first available font (Closed)
Patch Set: Add more tests Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
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
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 bool IsFontFamilyAvailable(const std::string& family, SkFontMgr* fontManager) {
98 #if defined(OS_LINUX)
99 sk_sp<SkTypeface> typeface(
100 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,
101 return typeface;
102 #else
103 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.
104 return sset && sset->count();
105 #endif
106 }
107
108 std::string Font::FirstAvailableOrFirst(const std::string& font_name_list) {
109 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
110 font_name_list, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
111 if (families.empty())
112 return std::string();
113 sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
114 for (auto& family : families) {
115 if (IsFontFamilyAvailable(family, fm.get()))
116 return family;
117 }
118 return families[0];
119 }
120
94 #ifndef NDEBUG 121 #ifndef NDEBUG
95 std::ostream& operator<<(std::ostream& stream, const Font::Weight weight) { 122 std::ostream& operator<<(std::ostream& stream, const Font::Weight weight) {
96 return stream << static_cast<int>(weight); 123 return stream << static_cast<int>(weight);
97 } 124 }
98 #endif 125 #endif
99 126
100 } // namespace gfx 127 } // namespace gfx
OLDNEW
« ui/gfx/font.h ('K') | « ui/gfx/font.h ('k') | ui/gfx/font_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698