Commit b635d872 authored by derat@chromium.org's avatar derat@chromium.org

linux: Add tests for FontRenderParams on Linux.

Add some tests for FontRenderParams's interactions with
Fontconfig, which is used on desktop Linux and Chrome OS.

Also re-add platform_font_pango_unittest.cc for gn.

BUG=125235

Review URL: https://codereview.chromium.org/394963002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283969 0039d316-1c4b-4281-b951-d872f2087c98
parent 75bd01e9
...@@ -47,6 +47,10 @@ pkg_config("pangocairo") { ...@@ -47,6 +47,10 @@ pkg_config("pangocairo") {
packages = [ "pangocairo" ] packages = [ "pangocairo" ]
} }
pkg_config("pangoft2") {
packages = [ "pangoft2" ]
}
pkg_config("udev") { pkg_config("udev") {
packages = [ "libudev" ] packages = [ "libudev" ]
} }
......
...@@ -4,160 +4,65 @@ ...@@ -4,160 +4,65 @@
#include "content/shell/app/webkit_test_platform_support.h" #include "content/shell/app/webkit_test_platform_support.h"
#include <fontconfig/fontconfig.h> #include "base/file_util.h"
#include <unistd.h>
#include <iostream>
#include "base/files/file_path.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "ui/gfx/test/fontconfig_util_linux.h"
namespace content { namespace content {
namespace { namespace {
bool CheckAndLoadFontFile( const char* const kLocalFonts[] = {
FcConfig* fontcfg, const char* path1, const char* path2) { "AHEM____.TTF",
const char* font = path1; "GardinerModBug.ttf",
if (access(font, R_OK) < 0) { "GardinerModCat.ttf",
font = path2; };
if (access(font, R_OK) < 0) {
LOG(WARNING) << "You are missing " << path1 << " or " << path2 << ". "
<< "Without this, some layout tests may fail. See "
<< "http://code.google.com/p/chromium/wiki/LayoutTestsLinux "
<< "for more.\n";
return false;
}
}
if (!FcConfigAppFontAddFile(
fontcfg, reinterpret_cast<const FcChar8*>(font))) {
LOG(ERROR) << "Failed to load font " << font << "\n";
return false;
}
return true;
}
static bool LoadFontResources(const base::FilePath& base_path, } // namespace
FcConfig* font_config) {
const char* const own_fonts[] = {"AHEM____.TTF", "GardinerModBug.ttf",
"GardinerModCat.ttf"};
for (size_t i = 0; i < arraysize(own_fonts); ++i) { bool CheckLayoutSystemDeps() {
base::FilePath font_path = base_path.Append(own_fonts[i]);
if (access(font_path.value().c_str(), R_OK) < 0 ||
!FcConfigAppFontAddFile(
font_config,
reinterpret_cast<const FcChar8*>(font_path.value().c_str()))) {
LOG(ERROR) << "Failed to load test font resource "
<< font_path.value().c_str() << ".\n";
return false;
}
}
return true; return true;
} }
const char* const kFonts[] = { bool WebKitTestPlatformInitialize() {
"/usr/share/fonts/truetype/kochi/kochi-gothic.ttf", gfx::SetUpFontconfig();
"/usr/share/fonts/truetype/kochi/kochi-mincho.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Arial.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Arial_Bold_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Arial_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS_Bold.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Courier_New.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Courier_New_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Georgia.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Georgia_Bold.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Georgia_Bold_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Georgia_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Impact.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Bold.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Bold_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Bold.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Bold_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Verdana.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Verdana_Bold.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Verdana_Bold_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Verdana_Italic.ttf",
// The DejaVuSans font is used by the css2.1 tests.
"/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf",
"/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_hi.ttf",
"/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_ta.ttf",
"/usr/share/fonts/truetype/ttf-indic-fonts-core/MuktiNarrow.ttf",
};
bool SetupFontConfig() {
FcInit();
base::FilePath base_path; base::FilePath base_path;
PathService::Get(base::DIR_MODULE, &base_path); PathService::Get(base::DIR_MODULE, &base_path);
base::FilePath fonts_conf = base_path.Append(FILE_PATH_LITERAL("fonts.conf")); if (!gfx::LoadConfigFileIntoFontconfig(
base_path.Append(FILE_PATH_LITERAL("fonts.conf"))))
FcConfig* font_config = FcConfigCreate();
if (!FcConfigParseAndLoad(
font_config,
reinterpret_cast<const FcChar8*>(fonts_conf.value().c_str()),
true)) {
LOG(ERROR) << "Failed to parse fontconfig config file\n";
return false; return false;
}
for (size_t i = 0; i < arraysize(kFonts); ++i) { for (size_t i = 0; i < gfx::kNumSystemFontsForFontconfig; ++i) {
if (access(kFonts[i], R_OK) < 0) { if (!gfx::LoadFontIntoFontconfig(
LOG(ERROR) << "You are missing " << kFonts[i] << ". Try re-running " base::FilePath(gfx::kSystemFontsForFontconfig[i]))) {
<< "build/install-build-deps.sh. Also see "
<< "http://code.google.com/p/chromium/wiki/LayoutTestsLinux";
return false; return false;
} }
if (!FcConfigAppFontAddFile(
font_config, reinterpret_cast<const FcChar8*>(kFonts[i]))) {
LOG(ERROR) << "Failed to load font " << kFonts[i] << "\n";
return false;
} }
for (size_t i = 0; i < arraysize(kLocalFonts); ++i) {
if (!gfx::LoadFontIntoFontconfig(base_path.Append(kLocalFonts[i])))
return false;
} }
if (!CheckAndLoadFontFile( base::FilePath garuda_path("/usr/share/fonts/truetype/thai/Garuda.ttf");
font_config, if (!base::PathExists(garuda_path))
"/usr/share/fonts/truetype/thai/Garuda.ttf", garuda_path = base::FilePath("/usr/share/fonts/truetype/tlwg/Garuda.ttf");
"/usr/share/fonts/truetype/tlwg/Garuda.ttf")) { if (!gfx::LoadFontIntoFontconfig(garuda_path))
return false; return false;
}
// We special case these fonts because they're only needed in a few layout // We special case these fonts because they're only needed in a few layout
// tests. // tests.
CheckAndLoadFontFile( base::FilePath lohit_path(
font_config, "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_pa.ttf");
"/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_pa.ttf", if (!base::PathExists(lohit_path)) {
lohit_path = base::FilePath(
"/usr/share/fonts/truetype/ttf-punjabi-fonts/lohit_pa.ttf"); "/usr/share/fonts/truetype/ttf-punjabi-fonts/lohit_pa.ttf");
if (!LoadFontResources(base_path, font_config))
return false;
if (!FcConfigSetCurrent(font_config)) {
LOG(ERROR) << "Failed to set the default font configuration\n";
return false;
} }
gfx::LoadFontIntoFontconfig(lohit_path);
return true; return true;
} }
} // namespace
bool CheckLayoutSystemDeps() {
return true;
}
bool WebKitTestPlatformInitialize() {
return SetupFontConfig();
}
} // namespace content } // namespace content
...@@ -360,6 +360,8 @@ component("gfx") { ...@@ -360,6 +360,8 @@ component("gfx") {
source_set("gfx_test_support") { source_set("gfx_test_support") {
sources = [ sources = [
"test/fontconfig_util_linux.cc",
"test/fontconfig_util_linux.h",
"test/gfx_util.cc", "test/gfx_util.cc",
"test/gfx_util.h", "test/gfx_util.h",
"test/ui_cocoa_test_helper.h", "test/ui_cocoa_test_helper.h",
...@@ -380,10 +382,14 @@ source_set("gfx_test_support") { ...@@ -380,10 +382,14 @@ source_set("gfx_test_support") {
"test/ui_cocoa_test_helper.mm", "test/ui_cocoa_test_helper.mm",
] ]
} }
if (is_linux) {
configs += [ "//build/config/linux:fontconfig" ]
}
} }
test("gfx_unittests") { test("gfx_unittests") {
sources = [ sources = [
"font_render_params_linux_unittest.cc",
"geometry/box_unittest.cc", "geometry/box_unittest.cc",
"geometry/cubic_bezier_unittest.cc", "geometry/cubic_bezier_unittest.cc",
"geometry/insets_unittest.cc", "geometry/insets_unittest.cc",
...@@ -409,6 +415,14 @@ test("gfx_unittests") { ...@@ -409,6 +415,14 @@ test("gfx_unittests") {
"//ui/base", "//ui/base",
"//ui/gfx/geometry", "//ui/gfx/geometry",
] ]
if (use_pango) {
sources += [ "platform_font_pango_unittest.cc" ]
configs += [
"//build/config/linux:pangocairo",
"//build/config/linux:pangoft2",
]
}
} }
if (is_android) { if (is_android) {
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gfx/font_render_params.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/logging.h"
#include "base/macros.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/test/fontconfig_util_linux.h"
namespace gfx {
namespace {
// Loads the first system font defined by fontconfig_util_linux.h with a base
// filename of |basename|. Case is ignored.
bool LoadSystemFont(const std::string& basename) {
for (size_t i = 0; i < kNumSystemFontsForFontconfig; ++i) {
base::FilePath path(gfx::kSystemFontsForFontconfig[i]);
if (strcasecmp(path.BaseName().value().c_str(), basename.c_str()) == 0)
return LoadFontIntoFontconfig(path);
}
LOG(ERROR) << "Unable to find system font named " << basename;
return false;
}
} // namespace
class FontRenderParamsTest : public testing::Test {
public:
FontRenderParamsTest() {
SetUpFontconfig();
CHECK(temp_dir_.CreateUniqueTempDir());
}
virtual ~FontRenderParamsTest() {
TearDownFontconfig();
}
protected:
base::ScopedTempDir temp_dir_;
private:
DISALLOW_COPY_AND_ASSIGN(FontRenderParamsTest);
};
TEST_F(FontRenderParamsTest, Default) {
// Fontconfig needs to know about at least one font to return a match.
ASSERT_TRUE(LoadSystemFont("arial.ttf"));
ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(),
std::string(kFontconfigFileHeader) +
kFontconfigMatchHeader +
CreateFontconfigEditStanza("antialias", "bool", "true") +
CreateFontconfigEditStanza("autohint", "bool", "false") +
CreateFontconfigEditStanza("hinting", "bool", "true") +
CreateFontconfigEditStanza("hintstyle", "const", "hintfull") +
CreateFontconfigEditStanza("rgba", "const", "rgb") +
kFontconfigMatchFooter +
kFontconfigFileFooter));
FontRenderParams params = GetDefaultFontRenderParams();
#if defined(OS_CHROMEOS)
// Chrome OS uses its own defaults for everything except subpixel rendering,
// which comes from Fontconfig.
EXPECT_TRUE(params.antialiasing);
EXPECT_TRUE(params.autohinter);
EXPECT_TRUE(params.use_bitmaps);
EXPECT_EQ(FontRenderParams::HINTING_SLIGHT, params.hinting);
#else
// Desktop Linux gets all settings from fontconfig.
EXPECT_TRUE(params.antialiasing);
EXPECT_FALSE(params.autohinter);
EXPECT_TRUE(params.use_bitmaps);
EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting);
#endif
EXPECT_FALSE(params.subpixel_positioning);
EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB,
params.subpixel_rendering);
}
// Chrome OS ignores most Fontconfig settings.
#if !defined(OS_CHROMEOS)
TEST_F(FontRenderParamsTest, Size) {
// Fontconfig needs to know about at least one font to return a match.
ASSERT_TRUE(LoadSystemFont("arial.ttf"));
ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(),
std::string(kFontconfigFileHeader) +
kFontconfigMatchHeader +
CreateFontconfigEditStanza("antialias", "bool", "true") +
CreateFontconfigEditStanza("hinting", "bool", "true") +
CreateFontconfigEditStanza("hintstyle", "const", "hintfull") +
CreateFontconfigEditStanza("rgba", "const", "none") +
kFontconfigMatchFooter +
kFontconfigMatchHeader +
CreateFontconfigTestStanza("pixelsize", "less_eq", "double", "10") +
CreateFontconfigEditStanza("antialias", "bool", "false") +
kFontconfigMatchFooter +
kFontconfigMatchHeader +
CreateFontconfigTestStanza("size", "more_eq", "double", "20") +
CreateFontconfigEditStanza("hintstyle", "const", "hintslight") +
CreateFontconfigEditStanza("rgba", "const", "rgb") +
kFontconfigMatchFooter +
kFontconfigFileFooter));
// The defaults should be used when the supplied size isn't matched by the
// second or third blocks.
int pixel_size = 12;
FontRenderParams params = GetCustomFontRenderParams(
false, NULL, &pixel_size, NULL, NULL);
EXPECT_TRUE(params.antialiasing);
EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting);
EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE,
params.subpixel_rendering);
pixel_size = 10;
params = GetCustomFontRenderParams(false, NULL, &pixel_size, NULL, NULL);
EXPECT_FALSE(params.antialiasing);
EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting);
EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE,
params.subpixel_rendering);
int point_size = 20;
params = GetCustomFontRenderParams(false, NULL, NULL, &point_size, NULL);
EXPECT_TRUE(params.antialiasing);
EXPECT_EQ(FontRenderParams::HINTING_SLIGHT, params.hinting);
EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB,
params.subpixel_rendering);
}
#endif // !defined(OS_CHROMEOS)
} // namespace gfx
...@@ -417,6 +417,8 @@ ...@@ -417,6 +417,8 @@
'target_name': 'gfx_test_support', 'target_name': 'gfx_test_support',
'type': 'static_library', 'type': 'static_library',
'sources': [ 'sources': [
'test/fontconfig_util_linux.cc',
'test/fontconfig_util_linux.h',
'test/gfx_util.cc', 'test/gfx_util.cc',
'test/gfx_util.h', 'test/gfx_util.h',
'test/ui_cocoa_test_helper.h', 'test/ui_cocoa_test_helper.h',
...@@ -441,6 +443,11 @@ ...@@ -441,6 +443,11 @@
['exclude', 'cocoa'] ['exclude', 'cocoa']
], ],
}], }],
['OS=="linux"', {
'dependencies': [
'../../build/linux/system.gyp:fontconfig',
],
}],
], ],
}, },
], ],
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
'color_utils_unittest.cc', 'color_utils_unittest.cc',
'display_unittest.cc', 'display_unittest.cc',
'font_list_unittest.cc', 'font_list_unittest.cc',
'font_render_params_linux_unittest.cc',
'geometry/box_unittest.cc', 'geometry/box_unittest.cc',
'geometry/cubic_bezier_unittest.cc', 'geometry/cubic_bezier_unittest.cc',
'geometry/insets_unittest.cc', 'geometry/insets_unittest.cc',
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gfx/test/fontconfig_util_linux.h"
#include <fontconfig/fontconfig.h>
#include "base/file_util.h"
#include "base/logging.h"
#include "base/strings/stringprintf.h"
namespace gfx {
const char* const kSystemFontsForFontconfig[] = {
"/usr/share/fonts/truetype/kochi/kochi-gothic.ttf",
"/usr/share/fonts/truetype/kochi/kochi-mincho.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Arial.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Arial_Bold_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Arial_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS_Bold.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Courier_New.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Courier_New_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Georgia.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Georgia_Bold.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Georgia_Bold_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Georgia_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Impact.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Bold.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Bold_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Bold.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Bold_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Verdana.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Verdana_Bold.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Verdana_Bold_Italic.ttf",
"/usr/share/fonts/truetype/msttcorefonts/Verdana_Italic.ttf",
// The DejaVuSans font is used by the css2.1 tests.
"/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf",
"/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_hi.ttf",
"/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_ta.ttf",
"/usr/share/fonts/truetype/ttf-indic-fonts-core/MuktiNarrow.ttf",
};
const size_t kNumSystemFontsForFontconfig =
arraysize(kSystemFontsForFontconfig);
const char kFontconfigFileHeader[] =
"<?xml version=\"1.0\"?>\n"
"<!DOCTYPE fontconfig SYSTEM \"fonts.dtd\">\n"
"<fontconfig>\n";
const char kFontconfigFileFooter[] = "</fontconfig>";
const char kFontconfigMatchHeader[] = " <match>\n";
const char kFontconfigMatchFooter[] = " </match>\n";
void SetUpFontconfig() {
FcInit();
// A primer on undocumented FcConfig reference-counting:
//
// - FcConfigCreate() creates a config with a refcount of 1.
// - FcConfigReference() increments a config's refcount.
// - FcConfigDestroy() decrements a config's refcount, deallocating the
// config when the count reaches 0.
// - FcConfigSetCurrent() calls FcConfigDestroy() on the old config, but
// interestingly does not call FcConfigReference() on the new config.
CHECK(FcConfigSetCurrent(FcConfigCreate()));
}
void TearDownFontconfig() {
FcFini();
}
bool LoadFontIntoFontconfig(const base::FilePath& path) {
if (!base::PathExists(path)) {
LOG(ERROR) << "You are missing " << path.value() << ". Try re-running "
<< "build/install-build-deps.sh. Also see "
<< "http://code.google.com/p/chromium/wiki/LayoutTestsLinux";
return false;
}
if (!FcConfigAppFontAddFile(
NULL, reinterpret_cast<const FcChar8*>(path.value().c_str()))) {
LOG(ERROR) << "Failed to load font " << path.value();
return false;
}
return true;
}
bool LoadConfigFileIntoFontconfig(const base::FilePath& path) {
// Unlike other FcConfig functions, FcConfigParseAndLoad() doesn't default to
// the current config when passed NULL. So that's cool.
if (!FcConfigParseAndLoad(FcConfigGetCurrent(),
reinterpret_cast<const FcChar8*>(path.value().c_str()), FcTrue)) {
LOG(ERROR) << "Fontconfig failed to load " << path.value();
return false;
}
return true;
}
bool LoadConfigDataIntoFontconfig(const base::FilePath& temp_dir,
const std::string& data) {
base::FilePath path;
if (!CreateTemporaryFileInDir(temp_dir, &path)) {
PLOG(ERROR) << "Unable to create temporary file in " << temp_dir.value();
return false;
}
if (base::WriteFile(path, data.data(), data.size()) !=
static_cast<int>(data.size())) {
PLOG(ERROR) << "Unable to write config data to " << path.value();
return false;
}
return LoadConfigFileIntoFontconfig(path);
}
std::string CreateFontconfigEditStanza(const std::string& name,
const std::string& type,
const std::string& value) {
return base::StringPrintf(
" <edit name=\"%s\" mode=\"assign\">\n"
" <%s>%s</%s>\n"
" </edit>\n",
name.c_str(), type.c_str(), value.c_str(), type.c_str());
}
std::string CreateFontconfigTestStanza(const std::string& name,
const std::string& op,
const std::string& type,
const std::string& value) {
return base::StringPrintf(
" <test name=\"%s\" compare=\"%s\" qual=\"any\">\n"
" <%s>%s</%s>\n"
" </test>\n",
name.c_str(), op.c_str(), type.c_str(), value.c_str(), type.c_str());
}
} // namespace gfx
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_GFX_TEST_FONTCONFIG_UTIL_LINUX_H_
#define UI_GFX_TEST_FONTCONFIG_UTIL_LINUX_H_
#include <string>
#include "base/files/file_path.h"
namespace gfx {
// Array of paths to font files that are expected to exist on machines where
// tests are run.
extern const char* const kSystemFontsForFontconfig[];
extern const size_t kNumSystemFontsForFontconfig;
// Strings appearing at the beginning and end of Fontconfig XML files.
extern const char kFontconfigFileHeader[];
extern const char kFontconfigFileFooter[];
// Strings appearing at the beginning and end of Fontconfig <match> stanzas.
extern const char kFontconfigMatchHeader[];
extern const char kFontconfigMatchFooter[];
// Initializes Fontconfig and creates and swaps in a new, empty config.
void SetUpFontconfig();
// Deinitializes Fontconfig.
void TearDownFontconfig();
// Loads the font file at |path| into the current config, returning true on
// success.
bool LoadFontIntoFontconfig(const base::FilePath& path);
// Instructs Fontconfig to load |path|, an XML configuration file, into the
// current config, returning true on success.
bool LoadConfigFileIntoFontconfig(const base::FilePath& path);
// Writes |data| to a file in |temp_dir| and passes it to
// LoadConfigFileIntoFontconfig().
bool LoadConfigDataIntoFontconfig(const base::FilePath& temp_dir,
const std::string& data);
// Returns a Fontconfig <edit> stanza.
std::string CreateFontconfigEditStanza(const std::string& name,
const std::string& type,
const std::string& value);
// Returns a Fontconfig <test> stanza.
std::string CreateFontconfigTestStanza(const std::string& name,
const std::string& op,
const std::string& type,
const std::string& value);
} // namespace gfx
#endif // UI_GFX_TEST_FONTCONFIG_UTIL_LINUX_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment