OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 "content/shell/webkit_test_platform_support.h" |
| 6 |
| 7 #include <iostream> |
| 8 |
| 9 #include <fontconfig/fontconfig.h> |
| 10 #include <unistd.h> |
| 11 |
| 12 #include "base/file_path.h" |
| 13 #include "base/file_path.h" |
| 14 #include "base/path_service.h" |
| 15 |
| 16 namespace { |
| 17 |
| 18 bool CheckAndLoadFontFile( |
| 19 FcConfig* fontcfg, const char* path1, const char* path2) { |
| 20 const char* font = path1; |
| 21 if (access(font, R_OK) < 0) { |
| 22 font = path2; |
| 23 if (access(font, R_OK) < 0) { |
| 24 std::cerr << "Your are missing " << path1 << " or " << path2 << ". " |
| 25 << "Without this, some layout tests may fail. See " |
| 26 << "http://code.google.com/p/chromium/wiki/LayoutTestsLinux " |
| 27 << "for more.\n"; |
| 28 return false; |
| 29 } |
| 30 } |
| 31 if (!FcConfigAppFontAddFile( |
| 32 fontcfg, reinterpret_cast<const FcChar8*>(font))) { |
| 33 std::cerr << "Failed to load font " << font << "\n"; |
| 34 return false; |
| 35 } |
| 36 return true; |
| 37 } |
| 38 |
| 39 const char* const kFonts[] = { |
| 40 "/usr/share/fonts/truetype/kochi/kochi-gothic.ttf", |
| 41 "/usr/share/fonts/truetype/kochi/kochi-mincho.ttf", |
| 42 "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", |
| 43 "/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf", |
| 44 "/usr/share/fonts/truetype/msttcorefonts/Arial_Bold_Italic.ttf", |
| 45 "/usr/share/fonts/truetype/msttcorefonts/Arial_Italic.ttf", |
| 46 "/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS.ttf", |
| 47 "/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS_Bold.ttf", |
| 48 "/usr/share/fonts/truetype/msttcorefonts/Courier_New.ttf", |
| 49 "/usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold.ttf", |
| 50 "/usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold_Italic.ttf", |
| 51 "/usr/share/fonts/truetype/msttcorefonts/Courier_New_Italic.ttf", |
| 52 "/usr/share/fonts/truetype/msttcorefonts/Georgia.ttf", |
| 53 "/usr/share/fonts/truetype/msttcorefonts/Georgia_Bold.ttf", |
| 54 "/usr/share/fonts/truetype/msttcorefonts/Georgia_Bold_Italic.ttf", |
| 55 "/usr/share/fonts/truetype/msttcorefonts/Georgia_Italic.ttf", |
| 56 "/usr/share/fonts/truetype/msttcorefonts/Impact.ttf", |
| 57 "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS.ttf", |
| 58 "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Bold.ttf", |
| 59 "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Bold_Italic.ttf", |
| 60 "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Italic.ttf", |
| 61 "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf", |
| 62 "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Bold.ttf", |
| 63 "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Bold_Italic.ttf", |
| 64 "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Italic.ttf", |
| 65 "/usr/share/fonts/truetype/msttcorefonts/Verdana.ttf", |
| 66 "/usr/share/fonts/truetype/msttcorefonts/Verdana_Bold.ttf", |
| 67 "/usr/share/fonts/truetype/msttcorefonts/Verdana_Bold_Italic.ttf", |
| 68 "/usr/share/fonts/truetype/msttcorefonts/Verdana_Italic.ttf", |
| 69 // The DejaVuSans font is used by the css2.1 tests. |
| 70 "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", |
| 71 "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_hi.ttf", |
| 72 "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_ta.ttf", |
| 73 "/usr/share/fonts/truetype/ttf-indic-fonts-core/MuktiNarrow.ttf", |
| 74 }; |
| 75 |
| 76 bool SetupFontConfig() { |
| 77 FcInit(); |
| 78 |
| 79 FilePath base_path; |
| 80 PathService::Get(base::DIR_MODULE, &base_path); |
| 81 FilePath fonts_conf = base_path.Append(FILE_PATH_LITERAL("fonts.conf")); |
| 82 |
| 83 FcConfig* font_config = FcConfigCreate(); |
| 84 if (!FcConfigParseAndLoad( |
| 85 font_config, |
| 86 reinterpret_cast<const FcChar8*>(fonts_conf.value().c_str()), |
| 87 true)) { |
| 88 std::cerr << "Failed to parse fontconfig config file\n"; |
| 89 return false; |
| 90 } |
| 91 |
| 92 for (size_t i = 0; i < arraysize(kFonts); ++i) { |
| 93 if (access(kFonts[i], R_OK) < 0) { |
| 94 std::cerr << "You are missing " << kFonts[i] << ". Try re-running " |
| 95 << "build/install-build-deps.sh. Also see " |
| 96 << "http://code.google.com/p/chromium/wiki/LayoutTestsLinux"; |
| 97 return false; |
| 98 } |
| 99 if (!FcConfigAppFontAddFile( |
| 100 font_config, reinterpret_cast<const FcChar8*>(kFonts[i]))) { |
| 101 std::cerr << "Failed to load font " << kFonts[i] << "\n"; |
| 102 return false; |
| 103 } |
| 104 } |
| 105 |
| 106 if (!CheckAndLoadFontFile( |
| 107 font_config, |
| 108 "/usr/share/fonts/truetype/thai/Garuda.ttf", |
| 109 "/usr/share/fonts/truetype/tlwg/Garuda.ttf")) { |
| 110 return false; |
| 111 } |
| 112 |
| 113 // We special case these fonts because they're only needed in a few layout |
| 114 // tests. |
| 115 CheckAndLoadFontFile( |
| 116 font_config, |
| 117 "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_pa.ttf", |
| 118 "/usr/share/fonts/truetype/ttf-punjabi-fonts/lohit_pa.ttf"); |
| 119 |
| 120 FilePath ahem_font = base_path.Append("AHEM____.TTF"); |
| 121 if (!FcConfigAppFontAddFile( |
| 122 font_config, |
| 123 reinterpret_cast<const FcChar8*>(ahem_font.value().c_str()))) { |
| 124 std::cerr << "Failed to load font " << ahem_font.value() << "\n"; |
| 125 return false; |
| 126 } |
| 127 |
| 128 if (!FcConfigSetCurrent(font_config)) { |
| 129 std::cerr << "Failed to set the default font configuration\n"; |
| 130 return false; |
| 131 } |
| 132 |
| 133 return true; |
| 134 } |
| 135 |
| 136 } // namespace |
| 137 |
| 138 bool WebKitTestPlatformInitialize() { |
| 139 return SetupFontConfig(); |
| 140 } |
OLD | NEW |