OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/shell/app/webkit_test_platform_support.h" | 5 #include "content/shell/app/webkit_test_platform_support.h" |
6 | 6 |
7 #include <fontconfig/fontconfig.h> | 7 #include <fontconfig/fontconfig.h> |
8 #include <unistd.h> | 8 #include <unistd.h> |
9 | 9 |
10 #include <iostream> | 10 #include <iostream> |
11 | 11 |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/logging.h" |
14 #include "base/path_service.h" | 15 #include "base/path_service.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 bool CheckAndLoadFontFile( | 21 bool CheckAndLoadFontFile( |
21 FcConfig* fontcfg, const char* path1, const char* path2) { | 22 FcConfig* fontcfg, const char* path1, const char* path2) { |
22 const char* font = path1; | 23 const char* font = path1; |
23 if (access(font, R_OK) < 0) { | 24 if (access(font, R_OK) < 0) { |
24 font = path2; | 25 font = path2; |
25 if (access(font, R_OK) < 0) { | 26 if (access(font, R_OK) < 0) { |
26 std::cerr << "You are missing " << path1 << " or " << path2 << ". " | 27 LOG(WARNING) << "You are missing " << path1 << " or " << path2 << ". " |
27 << "Without this, some layout tests may fail. See " | 28 << "Without this, some layout tests may fail. See " |
28 << "http://code.google.com/p/chromium/wiki/LayoutTestsLinux " | 29 << "http://code.google.com/p/chromium/wiki/LayoutTestsLinux " |
29 << "for more.\n"; | 30 << "for more.\n"; |
30 return false; | 31 return false; |
31 } | 32 } |
32 } | 33 } |
33 if (!FcConfigAppFontAddFile( | 34 if (!FcConfigAppFontAddFile( |
34 fontcfg, reinterpret_cast<const FcChar8*>(font))) { | 35 fontcfg, reinterpret_cast<const FcChar8*>(font))) { |
35 std::cerr << "Failed to load font " << font << "\n"; | 36 LOG(ERROR) << "Failed to load font " << font << "\n"; |
36 return false; | 37 return false; |
37 } | 38 } |
38 return true; | 39 return true; |
39 } | 40 } |
40 | 41 |
| 42 static bool LoadFontResources(const base::FilePath& base_path, |
| 43 FcConfig* font_config) { |
| 44 const char* const own_fonts[] = {"AHEM____.TTF", "GardinerModBug.ttf", |
| 45 "GardinerModCat.ttf"}; |
| 46 |
| 47 for (size_t i = 0; i < arraysize(own_fonts); ++i) { |
| 48 base::FilePath font_path = base_path.Append(own_fonts[i]); |
| 49 if (access(font_path.value().c_str(), R_OK) < 0 || |
| 50 !FcConfigAppFontAddFile( |
| 51 font_config, |
| 52 reinterpret_cast<const FcChar8*>(font_path.value().c_str()))) { |
| 53 LOG(ERROR) << "Failed to load test font resource " |
| 54 << font_path.value().c_str() << ".\n"; |
| 55 return false; |
| 56 } |
| 57 } |
| 58 return true; |
| 59 } |
| 60 |
41 const char* const kFonts[] = { | 61 const char* const kFonts[] = { |
42 "/usr/share/fonts/truetype/kochi/kochi-gothic.ttf", | 62 "/usr/share/fonts/truetype/kochi/kochi-gothic.ttf", |
43 "/usr/share/fonts/truetype/kochi/kochi-mincho.ttf", | 63 "/usr/share/fonts/truetype/kochi/kochi-mincho.ttf", |
44 "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", | 64 "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", |
45 "/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf", | 65 "/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf", |
46 "/usr/share/fonts/truetype/msttcorefonts/Arial_Bold_Italic.ttf", | 66 "/usr/share/fonts/truetype/msttcorefonts/Arial_Bold_Italic.ttf", |
47 "/usr/share/fonts/truetype/msttcorefonts/Arial_Italic.ttf", | 67 "/usr/share/fonts/truetype/msttcorefonts/Arial_Italic.ttf", |
48 "/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS.ttf", | 68 "/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS.ttf", |
49 "/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS_Bold.ttf", | 69 "/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS_Bold.ttf", |
50 "/usr/share/fonts/truetype/msttcorefonts/Courier_New.ttf", | 70 "/usr/share/fonts/truetype/msttcorefonts/Courier_New.ttf", |
(...skipping 29 matching lines...) Expand all Loading... |
80 | 100 |
81 base::FilePath base_path; | 101 base::FilePath base_path; |
82 PathService::Get(base::DIR_MODULE, &base_path); | 102 PathService::Get(base::DIR_MODULE, &base_path); |
83 base::FilePath fonts_conf = base_path.Append(FILE_PATH_LITERAL("fonts.conf")); | 103 base::FilePath fonts_conf = base_path.Append(FILE_PATH_LITERAL("fonts.conf")); |
84 | 104 |
85 FcConfig* font_config = FcConfigCreate(); | 105 FcConfig* font_config = FcConfigCreate(); |
86 if (!FcConfigParseAndLoad( | 106 if (!FcConfigParseAndLoad( |
87 font_config, | 107 font_config, |
88 reinterpret_cast<const FcChar8*>(fonts_conf.value().c_str()), | 108 reinterpret_cast<const FcChar8*>(fonts_conf.value().c_str()), |
89 true)) { | 109 true)) { |
90 std::cerr << "Failed to parse fontconfig config file\n"; | 110 LOG(ERROR) << "Failed to parse fontconfig config file\n"; |
91 return false; | 111 return false; |
92 } | 112 } |
93 | 113 |
94 for (size_t i = 0; i < arraysize(kFonts); ++i) { | 114 for (size_t i = 0; i < arraysize(kFonts); ++i) { |
95 if (access(kFonts[i], R_OK) < 0) { | 115 if (access(kFonts[i], R_OK) < 0) { |
96 std::cerr << "You are missing " << kFonts[i] << ". Try re-running " | 116 LOG(ERROR) << "You are missing " << kFonts[i] << ". Try re-running " |
97 << "build/install-build-deps.sh. Also see " | 117 << "build/install-build-deps.sh. Also see " |
98 << "http://code.google.com/p/chromium/wiki/LayoutTestsLinux"; | 118 << "http://code.google.com/p/chromium/wiki/LayoutTestsLinux"; |
99 return false; | 119 return false; |
100 } | 120 } |
101 if (!FcConfigAppFontAddFile( | 121 if (!FcConfigAppFontAddFile( |
102 font_config, reinterpret_cast<const FcChar8*>(kFonts[i]))) { | 122 font_config, reinterpret_cast<const FcChar8*>(kFonts[i]))) { |
103 std::cerr << "Failed to load font " << kFonts[i] << "\n"; | 123 LOG(ERROR) << "Failed to load font " << kFonts[i] << "\n"; |
104 return false; | 124 return false; |
105 } | 125 } |
106 } | 126 } |
107 | 127 |
108 if (!CheckAndLoadFontFile( | 128 if (!CheckAndLoadFontFile( |
109 font_config, | 129 font_config, |
110 "/usr/share/fonts/truetype/thai/Garuda.ttf", | 130 "/usr/share/fonts/truetype/thai/Garuda.ttf", |
111 "/usr/share/fonts/truetype/tlwg/Garuda.ttf")) { | 131 "/usr/share/fonts/truetype/tlwg/Garuda.ttf")) { |
112 return false; | 132 return false; |
113 } | 133 } |
114 | 134 |
115 // We special case these fonts because they're only needed in a few layout | 135 // We special case these fonts because they're only needed in a few layout |
116 // tests. | 136 // tests. |
117 CheckAndLoadFontFile( | 137 CheckAndLoadFontFile( |
118 font_config, | 138 font_config, |
119 "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_pa.ttf", | 139 "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_pa.ttf", |
120 "/usr/share/fonts/truetype/ttf-punjabi-fonts/lohit_pa.ttf"); | 140 "/usr/share/fonts/truetype/ttf-punjabi-fonts/lohit_pa.ttf"); |
121 | 141 |
122 base::FilePath ahem_font = base_path.Append("AHEM____.TTF"); | 142 if (!LoadFontResources(base_path, font_config)) |
123 if (!FcConfigAppFontAddFile( | 143 return false; |
124 font_config, | 144 |
125 reinterpret_cast<const FcChar8*>(ahem_font.value().c_str()))) { | 145 if (!FcConfigSetCurrent(font_config)) { |
126 std::cerr << "Failed to load font " << ahem_font.value() << "\n"; | 146 LOG(ERROR) << "Failed to set the default font configuration\n"; |
127 return false; | 147 return false; |
128 } | 148 } |
129 | 149 |
130 if (!FcConfigSetCurrent(font_config)) { | |
131 std::cerr << "Failed to set the default font configuration\n"; | |
132 return false; | |
133 } | |
134 | |
135 return true; | 150 return true; |
136 } | 151 } |
137 | 152 |
138 } // namespace | 153 } // namespace |
139 | 154 |
140 bool CheckLayoutSystemDeps() { | 155 bool CheckLayoutSystemDeps() { |
141 return true; | 156 return true; |
142 } | 157 } |
143 | 158 |
144 bool WebKitTestPlatformInitialize() { | 159 bool WebKitTestPlatformInitialize() { |
145 return SetupFontConfig(); | 160 return SetupFontConfig(); |
146 } | 161 } |
147 | 162 |
148 } // namespace content | 163 } // namespace content |
OLD | NEW |