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

Side by Side Diff: ui/gfx/test/fontconfig_util_linux.cc

Issue 394963002: linux: Add tests for FontRenderParams on Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add pangoft2 to BUILD.gn Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « ui/gfx/test/fontconfig_util_linux.h ('k') | no next file » | 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/test/fontconfig_util_linux.h"
6
7 #include <fontconfig/fontconfig.h>
8
9 #include "base/file_util.h"
10 #include "base/logging.h"
11 #include "base/strings/stringprintf.h"
12
13 namespace gfx {
14
15 const char* const kSystemFontsForFontconfig[] = {
16 "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf",
17 "/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf",
18 "/usr/share/fonts/truetype/msttcorefonts/Arial_Bold_Italic.ttf",
19 "/usr/share/fonts/truetype/msttcorefonts/Arial_Italic.ttf",
20 "/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS.ttf",
21 "/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS_Bold.ttf",
22 "/usr/share/fonts/truetype/msttcorefonts/Courier_New.ttf",
23 "/usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold.ttf",
24 "/usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold_Italic.ttf",
25 "/usr/share/fonts/truetype/msttcorefonts/Courier_New_Italic.ttf",
26 "/usr/share/fonts/truetype/msttcorefonts/Georgia.ttf",
27 "/usr/share/fonts/truetype/msttcorefonts/Georgia_Bold.ttf",
28 "/usr/share/fonts/truetype/msttcorefonts/Georgia_Bold_Italic.ttf",
29 "/usr/share/fonts/truetype/msttcorefonts/Georgia_Italic.ttf",
30 "/usr/share/fonts/truetype/msttcorefonts/Impact.ttf",
31 "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS.ttf",
32 "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Bold.ttf",
33 "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Bold_Italic.ttf",
34 "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Italic.ttf",
35 "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf",
36 "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Bold.ttf",
37 "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Bold_Italic.ttf",
38 "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Italic.ttf",
39 "/usr/share/fonts/truetype/msttcorefonts/Verdana.ttf",
40 "/usr/share/fonts/truetype/msttcorefonts/Verdana_Bold.ttf",
41 "/usr/share/fonts/truetype/msttcorefonts/Verdana_Bold_Italic.ttf",
42 "/usr/share/fonts/truetype/msttcorefonts/Verdana_Italic.ttf",
43 // The DejaVuSans font is used by the css2.1 tests.
44 "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf",
45 "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_hi.ttf",
46 "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_ta.ttf",
47 "/usr/share/fonts/truetype/ttf-indic-fonts-core/MuktiNarrow.ttf",
48 "/usr/share/fonts/truetype/kochi/kochi-gothic.ttf",
msw 2014/07/16 22:38:07 nit: Why reorder these? They previously were alpha
Daniel Erat 2014/07/16 23:10:18 sure, changed the order back and added a new helpe
49 "/usr/share/fonts/truetype/kochi/kochi-mincho.ttf",
50 NULL,
msw 2014/07/16 22:38:07 Can users do arraysize(kSystemFontsForFontconfig)
Daniel Erat 2014/07/16 23:10:18 i wasn't sure this would work with a const extern
51 };
52
53 const char kFontconfigFileHeader[] =
54 "<?xml version=\"1.0\"?>\n"
55 "<!DOCTYPE fontconfig SYSTEM \"fonts.dtd\">\n"
56 "<fontconfig>\n";
57 const char kFontconfigFileFooter[] = "</fontconfig>";
58 const char kFontconfigMatchHeader[] = " <match>\n";
59 const char kFontconfigMatchFooter[] = " </match>\n";
60
61 void SetUpFontconfig() {
62 FcInit();
63
64 // A primer on undocumented FcConfig reference-counting:
65 //
66 // - FcConfigCreate() creates a config with a refcount of 1.
67 // - FcConfigReference() increments a config's refcount.
68 // - FcConfigDestroy() decrements a config's refcount, deallocating the
69 // config when the count reaches 0.
70 // - FcConfigSetCurrent() calls FcConfigDestroy() on the old config, but
71 // interestingly does not call FcConfigReference() on the new config.
72 CHECK(FcConfigSetCurrent(FcConfigCreate()));
73 }
74
75 void TearDownFontconfig() {
76 FcFini();
77 }
78
79 bool LoadFontIntoFontconfig(const base::FilePath& path) {
80 if (!base::PathExists(path)) {
81 LOG(ERROR) << "You are missing " << path.value() << ". Try re-running "
82 << "build/install-build-deps.sh. Also see "
83 << "http://code.google.com/p/chromium/wiki/LayoutTestsLinux";
84 return false;
85 }
86
87 if (!FcConfigAppFontAddFile(
88 NULL, reinterpret_cast<const FcChar8*>(path.value().c_str()))) {
89 LOG(ERROR) << "Failed to load font " << path.value();
90 return false;
91 }
92
93 return true;
94 }
95
96 bool LoadConfigFileIntoFontconfig(const base::FilePath& path) {
97 // Unlike other FcConfig functions, FcConfigParseAndLoad() doesn't default to
98 // the current config when passed NULL. So that's cool.
99 if (!FcConfigParseAndLoad(FcConfigGetCurrent(),
100 reinterpret_cast<const FcChar8*>(path.value().c_str()), FcTrue)) {
101 LOG(ERROR) << "Fontconfig failed to load " << path.value();
102 return false;
103 }
104 return true;
105 }
106
107 bool LoadConfigDataIntoFontconfig(const base::FilePath& temp_dir,
msw 2014/07/16 22:38:07 nit: consider encapsulating the TempDir creation h
Daniel Erat 2014/07/16 23:10:18 i believe that fontconfig watches config files for
msw 2014/07/16 23:19:23 Hmmm, Maybe it doesn't automatically rescan the fi
108 const std::string& data) {
109 base::FilePath path;
110 if (!CreateTemporaryFileInDir(temp_dir, &path)) {
111 PLOG(ERROR) << "Unable to create temporary file in " << temp_dir.value();
112 return false;
113 }
114 VLOG(1) << "Writing config to " << path.value() << ":\n" << data;
msw 2014/07/16 22:38:07 nit: is logging the entire file content helpful or
Daniel Erat 2014/07/16 23:10:18 i found it useful when writing a test that generat
msw 2014/07/16 23:19:23 It's not output by default, so it's probably fine
115 if (base::WriteFile(path, data.data(), data.size()) !=
116 static_cast<int>(data.size())) {
117 PLOG(ERROR) << "Unable to write config data to " << path.value();
118 return false;
119 }
120 return LoadConfigFileIntoFontconfig(path);
121 }
122
123 std::string CreateFontconfigEditStanza(const std::string& name,
124 const std::string& type,
125 const std::string& value) {
126 return base::StringPrintf(
127 " <edit name=\"%s\" mode=\"assign\">\n"
128 " <%s>%s</%s>\n"
129 " </edit>\n",
130 name.c_str(), type.c_str(), value.c_str(), type.c_str());
131 }
132
133 std::string CreateFontconfigTestStanza(const std::string& name,
134 const std::string& op,
135 const std::string& type,
136 const std::string& value) {
137 return base::StringPrintf(
138 " <test name=\"%s\" compare=\"%s\" qual=\"any\">\n"
139 " <%s>%s</%s>\n"
140 " </test>\n",
141 name.c_str(), op.c_str(), type.c_str(), value.c_str(), type.c_str());
142 }
143
144 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/test/fontconfig_util_linux.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698