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