Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/webui/options/font_settings_utils.h" | |
| 6 | |
| 7 #include "base/strings/string_split.h" | |
| 8 #include "third_party/skia/include/core/SkTypeface.h" | |
| 9 #include "third_party/skia/include/ports/SkFontMgr.h" | |
| 10 | |
| 11 namespace options { | |
| 12 | |
| 13 bool IsFontFamilyAvailable(const std::string& family, SkFontMgr* fontManager) { | |
|
msw
2016/10/27 00:04:18
If these functions are file-local, they should go
kojii
2016/10/27 04:50:56
Done.
| |
| 14 #if defined(OS_LINUX) | |
| 15 sk_sp<SkTypeface> typeface( | |
| 16 fontManager->legacyCreateTypeface(family.c_str(), SkFontStyle())); | |
| 17 return typeface; | |
| 18 #else | |
| 19 sk_sp<SkFontStyleSet> set(fontManager->matchFamily(family.c_str())); | |
| 20 return set && set->count(); | |
| 21 #endif | |
| 22 } | |
| 23 | |
| 24 // Returns the first available font. If there is no available font, returns the | |
|
msw
2016/10/27 00:04:18
Ditto nit: say 'font name' or 'font family'.
kojii
2016/10/27 04:50:56
Done.
| |
| 25 // first font. Empty entries are ignored. | |
| 26 std::string FirstAvailableOrFirst(const std::string& font_name_list) { | |
| 27 std::vector<std::string> families = base::SplitString( | |
| 28 font_name_list, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | |
| 29 if (families.empty()) | |
| 30 return std::string(); | |
| 31 sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); | |
| 32 for (auto& family : families) { | |
|
msw
2016/10/27 00:04:18
nit: 'const auto&'
kojii
2016/10/27 04:50:56
Done.
| |
| 33 if (IsFontFamilyAvailable(family, fm.get())) | |
| 34 return family; | |
| 35 } | |
| 36 return families[0]; | |
| 37 } | |
| 38 | |
| 39 std::string FontSettingsUtilities::ResolveFontList( | |
| 40 const std::string& font_name_or_list) { | |
| 41 if (!font_name_or_list.empty() && font_name_or_list[0] == ',') | |
| 42 return FirstAvailableOrFirst(font_name_or_list); | |
| 43 return font_name_or_list; | |
| 44 } | |
| 45 | |
| 46 #if !defined(OS_WIN) | |
| 47 std::string FontSettingsUtilities::MaybeGetLocalizedFontName( | |
| 48 const std::string& font_name_or_list) { | |
| 49 return ResolveFontList(font_name_or_list); | |
| 50 } | |
| 51 #endif | |
| 52 | |
| 53 } // namespace options | |
| OLD | NEW |