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

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

Issue 854713003: More old files deletion. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fix tryjobs? Created 5 years, 11 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
« no previous file with comments | « ui/gfx/font_fallback.h ('k') | ui/gfx/font_fallback_mac.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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 "ui/gfx/font_fallback.h"
6
7 #include <fontconfig/fontconfig.h>
8
9 #include <map>
10 #include <string>
11 #include <vector>
12
13 #include "base/lazy_instance.h"
14
15 namespace gfx {
16
17 namespace {
18
19 typedef std::map<std::string, std::vector<std::string> > FallbackCache;
20 base::LazyInstance<FallbackCache>::Leaky g_fallback_cache =
21 LAZY_INSTANCE_INITIALIZER;
22
23 } // namespace
24
25 std::vector<std::string> GetFallbackFontFamilies(
26 const std::string& font_family) {
27 std::vector<std::string>* fallback_fonts =
28 &g_fallback_cache.Get()[font_family];
29 if (!fallback_fonts->empty())
30 return *fallback_fonts;
31
32 FcPattern* pattern = FcPatternCreate();
33 FcValue family;
34 family.type = FcTypeString;
35 family.u.s = reinterpret_cast<const FcChar8*>(font_family.c_str());
36 FcPatternAdd(pattern, FC_FAMILY, family, FcFalse);
37 if (FcConfigSubstitute(NULL, pattern, FcMatchPattern) == FcTrue) {
38 FcDefaultSubstitute(pattern);
39 FcResult result;
40 FcFontSet* fonts = FcFontSort(NULL, pattern, FcTrue, NULL, &result);
41 if (fonts) {
42 for (int i = 0; i < fonts->nfont; ++i) {
43 char* name = NULL;
44 FcPatternGetString(fonts->fonts[i], FC_FAMILY, 0,
45 reinterpret_cast<FcChar8**>(&name));
46 // FontConfig returns multiple fonts with the same family name and
47 // different configurations. Check to prevent duplicate family names.
48 if (fallback_fonts->empty() || fallback_fonts->back() != name)
49 fallback_fonts->push_back(std::string(name));
50 }
51 FcFontSetDestroy(fonts);
52 }
53 }
54 FcPatternDestroy(pattern);
55
56 if (fallback_fonts->empty())
57 fallback_fonts->push_back(font_family);
58
59 return *fallback_fonts;
60 }
61
62 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/font_fallback.h ('k') | ui/gfx/font_fallback_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698