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

Side by Side Diff: content/common/font_list_fontconfig.cc

Issue 2278143002: Filter font list, use Fontconfig and build on Ozone (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments by derat@ addressed, trying to fix mac and Android builds Created 4 years, 3 months 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) 2011 The Chromium Authors. All rights reserved.
Avi (use Gerrit) 2016/08/25 19:54:54 Copyright 2016 ...
drott 2016/08/25 20:09:12 Done.
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 "content/common/font_list.h"
6
7 #include <memory>
8 #include <set>
9 #include <string>
10 #include <utility>
11
12 #include <fontconfig/fontconfig.h>
13
14 #include "base/values.h"
15
16 namespace content {
17
18 std::unique_ptr<FcPattern, decltype(&FcPatternDestroy)> CreateFormatPattern(
19 const char* format) {
20 std::unique_ptr<FcPattern, decltype(&FcPatternDestroy)> pattern(
21 FcPatternCreate(), FcPatternDestroy);
22 FcPatternAddBool(pattern.get(), FC_SCALABLE, FcTrue);
23 FcPatternAddString(pattern.get(), FC_FONTFORMAT,
24 reinterpret_cast<const FcChar8*>(format));
25 return pattern;
26 }
27
28 std::unique_ptr<base::ListValue> GetFontList_SlowBlocking() {
29 std::unique_ptr<base::ListValue> font_list(new base::ListValue);
30
31 std::unique_ptr<FcObjectSet, decltype(&FcObjectSetDestroy)> object_set(
32 FcObjectSetBuild(FC_FAMILY, NULL), FcObjectSetDestroy);
33
34 std::set<std::string> sorted_families;
35
36 // See https://www.freetype.org/freetype2/docs/reference/ft2-font_formats.html
37 // for the list of possible formats.
38 const char* allowed_formats[] = { "TrueType", "CFF" };
39 for (size_t i = 0; i < arraysize(allowed_formats); ++i) {
40 auto format_pattern = CreateFormatPattern(allowed_formats[i]);
41 std::unique_ptr<FcFontSet, decltype(&FcFontSetDestroy)> fontset(
42 FcFontList(0, format_pattern.get(), object_set.get()),
43 FcFontSetDestroy);
44 for (int j = 0; j < fontset->nfont; ++j) {
45 char* family_string;
46 FcPatternGetString(fontset->fonts[j], FC_FAMILY, 0,
47 reinterpret_cast<FcChar8**>(&family_string));
48 sorted_families.insert(family_string);
49 }
50 }
51
52 // For backwards compatibility with the older pango implementation, add the
53 // three Fontconfig aliases that pango added. Our linux default settings for
54 // fixed-width was "Monospace". If we remove that, this entry is not found in
55 // the list anymore, see also:
56 // https://git.gnome.org/browse/pango/tree/pango/pangofc-fontmap.c?h=1.40.1#n1 351
57 sorted_families.insert("Monospace");
58 sorted_families.insert("Sans");
59 sorted_families.insert("Serif");
60
61 for (std::set<std::string>::const_iterator iter = sorted_families.begin();
Avi (use Gerrit) 2016/08/25 19:54:54 for (const auto& family : sorted_families) ?
drott 2016/08/25 20:09:12 Much nicer indeed, thanks.
62 iter != sorted_families.end(); ++iter) {
63 std::unique_ptr<base::ListValue> font_item(new base::ListValue());
64 font_item->AppendString(*iter);
65 font_item->AppendString(*iter); // localized name.
66 // TODO(yusukes): Support localized family names.
67 font_list->Append(std::move(font_item));
68 }
69
70 return font_list;
71 }
72
73 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698