OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #include "config.h" | |
32 #include "TestShell.h" | |
33 | |
34 #include <fontconfig/fontconfig.h> | |
35 #include <unistd.h> | |
36 | |
37 #if USE(GTK) | |
38 #include <gtk/gtk.h> | |
39 | |
40 void openStartupDialog() | |
41 { | |
42 GtkWidget* dialog = gtk_message_dialog_new( | |
43 0, GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Attach to me?"); | |
44 gtk_window_set_title(GTK_WINDOW(dialog), "DumpRenderTree"); | |
45 gtk_dialog_run(GTK_DIALOG(dialog)); // Runs a nested message loop. | |
46 gtk_widget_destroy(dialog); | |
47 } | |
48 | |
49 bool checkLayoutTestSystemDependencies() | |
50 { | |
51 return true; | |
52 } | |
53 #endif // USE(GTK) | |
54 | |
55 static bool checkAndLoadFontFile(FcConfig* fontcfg, const char* path1, const cha
r* path2) | |
56 { | |
57 const char* font = path1; | |
58 if (access(font, R_OK) < 0) { | |
59 font = path2; | |
60 if (access(font, R_OK) < 0) { | |
61 fprintf(stderr, "You are missing %s or %s. Without this, some layout
tests may fail. " | |
62 "See http://code.google.com/p/chromium/wiki/LayoutTe
stsLinux " | |
63 "for more.\n", path1, path2); | |
64 return false; | |
65 } | |
66 } | |
67 if (!FcConfigAppFontAddFile(fontcfg, (FcChar8 *) font)) { | |
68 fprintf(stderr, "Failed to load font %s\n", font); | |
69 return false; | |
70 } | |
71 return true; | |
72 } | |
73 | |
74 static void setupFontconfig() | |
75 { | |
76 // We wish to make the layout tests reproducable with respect to fonts. Skia | |
77 // uses fontconfig to resolve font family names from WebKit into actual font | |
78 // files found on the current system. This means that fonts vary based on th
e | |
79 // system and also on the fontconfig configuration. | |
80 // | |
81 // To avoid this we initialise fontconfig here and install a configuration | |
82 // which only knows about a few, select, fonts. | |
83 | |
84 // We have fontconfig parse a config file from our resources file. This | |
85 // sets a number of aliases ("sans"->"Arial" etc), but doesn't include any | |
86 // font directories. | |
87 FcInit(); | |
88 | |
89 char drtPath[PATH_MAX + 1]; | |
90 int drtPathSize = readlink("/proc/self/exe", drtPath, PATH_MAX); | |
91 if (drtPathSize < 0 || drtPathSize > PATH_MAX) { | |
92 fputs("Unable to resolve /proc/self/exe.", stderr); | |
93 exit(1); | |
94 } | |
95 drtPath[drtPathSize] = 0; | |
96 std::string drtDirPath(drtPath); | |
97 size_t lastPathPos = drtDirPath.rfind("/"); | |
98 ASSERT(lastPathPos != std::string::npos); | |
99 drtDirPath.erase(lastPathPos + 1); | |
100 | |
101 FcConfig* fontcfg = FcConfigCreate(); | |
102 std::string fontconfigPath = drtDirPath + "fonts.conf"; | |
103 if (!FcConfigParseAndLoad(fontcfg, reinterpret_cast<const FcChar8*>(fontconf
igPath.c_str()), true)) { | |
104 fputs("Failed to parse fontconfig config file\n", stderr); | |
105 exit(1); | |
106 } | |
107 | |
108 // This is the list of fonts that fontconfig will know about. It | |
109 // will try its best to match based only on the fonts here in. The | |
110 // paths are where these fonts are found on our Ubuntu boxes. | |
111 static const char *const fonts[] = { | |
112 "/usr/share/fonts/truetype/kochi/kochi-gothic.ttf", | |
113 "/usr/share/fonts/truetype/kochi/kochi-mincho.ttf", | |
114 "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", | |
115 "/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf", | |
116 "/usr/share/fonts/truetype/msttcorefonts/Arial_Bold_Italic.ttf", | |
117 "/usr/share/fonts/truetype/msttcorefonts/Arial_Italic.ttf", | |
118 "/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS.ttf", | |
119 "/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS_Bold.ttf", | |
120 "/usr/share/fonts/truetype/msttcorefonts/Courier_New.ttf", | |
121 "/usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold.ttf", | |
122 "/usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold_Italic.ttf", | |
123 "/usr/share/fonts/truetype/msttcorefonts/Courier_New_Italic.ttf", | |
124 "/usr/share/fonts/truetype/msttcorefonts/Georgia.ttf", | |
125 "/usr/share/fonts/truetype/msttcorefonts/Georgia_Bold.ttf", | |
126 "/usr/share/fonts/truetype/msttcorefonts/Georgia_Bold_Italic.ttf", | |
127 "/usr/share/fonts/truetype/msttcorefonts/Georgia_Italic.ttf", | |
128 "/usr/share/fonts/truetype/msttcorefonts/Impact.ttf", | |
129 "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS.ttf", | |
130 "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Bold.ttf", | |
131 "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Bold_Italic.ttf", | |
132 "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Italic.ttf", | |
133 "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf", | |
134 "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Bold.ttf", | |
135 "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Bold_Italic.ttf
", | |
136 "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Italic.ttf", | |
137 "/usr/share/fonts/truetype/msttcorefonts/Verdana.ttf", | |
138 "/usr/share/fonts/truetype/msttcorefonts/Verdana_Bold.ttf", | |
139 "/usr/share/fonts/truetype/msttcorefonts/Verdana_Bold_Italic.ttf", | |
140 "/usr/share/fonts/truetype/msttcorefonts/Verdana_Italic.ttf", | |
141 // The DejaVuSans font is used by the css2.1 tests. | |
142 "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", | |
143 "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_hi.ttf", | |
144 "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_ta.ttf", | |
145 "/usr/share/fonts/truetype/ttf-indic-fonts-core/MuktiNarrow.ttf", | |
146 }; | |
147 for (size_t i = 0; i < arraysize(fonts); ++i) { | |
148 if (access(fonts[i], R_OK)) { | |
149 fprintf(stderr, "You are missing %s. Try re-running build/install-bu
ild-deps.sh. Also see " | |
150 "http://code.google.com/p/chromium/wiki/LayoutTestsL
inux", | |
151 fonts[i]); | |
152 exit(1); | |
153 } | |
154 if (!FcConfigAppFontAddFile(fontcfg, (FcChar8 *) fonts[i])) { | |
155 fprintf(stderr, "Failed to load font %s\n", fonts[i]); | |
156 exit(1); | |
157 } | |
158 } | |
159 | |
160 if (!checkAndLoadFontFile(fontcfg, "/usr/share/fonts/truetype/thai/Garuda.tt
f", | |
161 "/usr/share/fonts/truetype/tlwg/Garuda.ttf")) | |
162 exit(1); | |
163 | |
164 // We special case these fonts because they're only needed in a | |
165 // few layout tests. | |
166 checkAndLoadFontFile(fontcfg, "/usr/share/fonts/truetype/ttf-indic-fonts-cor
e/lohit_pa.ttf", | |
167 "/usr/share/fonts/truetype/ttf-punjabi-fonts/lohit_pa.t
tf"); | |
168 | |
169 // Also load the layout-test-specific "Ahem" font. | |
170 std::string ahemPath = drtDirPath + "AHEM____.TTF"; | |
171 if (!FcConfigAppFontAddFile(fontcfg, reinterpret_cast<const FcChar8*>(ahemPa
th.c_str()))) { | |
172 fprintf(stderr, "Failed to load font %s\n", ahemPath.c_str()); | |
173 exit(1); | |
174 } | |
175 | |
176 if (!FcConfigSetCurrent(fontcfg)) { | |
177 fputs("Failed to set the default font configuration\n", stderr); | |
178 exit(1); | |
179 } | |
180 } | |
181 | |
182 void platformInit(int* argc, char*** argv) | |
183 { | |
184 // FIXME: It's better call gtk_init() only when we run plugin tests. | |
185 // See http://groups.google.com/a/chromium.org/group/chromium-dev/browse_thr
ead/thread/633ea167cde196ca# | |
186 #if USE(GTK) | |
187 gtk_init(argc, argv); | |
188 #endif | |
189 | |
190 setupFontconfig(); | |
191 } | |
OLD | NEW |