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

Side by Side Diff: chrome/browser/ui/webui/options/font_settings_utils.cc

Issue 2441343003: Allow the default generic font family settings to find the first available font (Closed)
Patch Set: Add font_settings_utils_unittest 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
(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) {
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()));
msw 2016/10/27 00:04:18 How does this non-linux code align with Mac and Wi
kojii 2016/10/27 04:50:56 First, this function needs to return available fon
msw 2016/10/27 17:18:11 Sorry for not being clear, "GenericFont" was meant
20 return set && set->count();
21 #endif
22 }
23
24 // Returns the first available font. If there is no available font, returns the
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) {
33 if (IsFontFamilyAvailable(family, fm.get()))
34 return family;
35 }
36 return families[0];
37 }
Dan Beam 2016/10/27 02:07:24 ^ why are we duplicating this with the blink code?
kojii 2016/10/27 04:50:56 Two reasons: 1. No good place to share the code. T
msw 2016/10/27 17:18:11 I'm not sure if ui/gfx makes sense, because this i
Dan Beam 2016/10/27 17:29:41 ui/base?
msw 2016/10/27 18:24:02 If ui/ is the right top-level dir, then gfx/ would
kojii 2016/10/28 04:59:41 Blink can't use ui/base (yet?); only ui/gfx and se
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698