Commit 9232de03 authored by derat@chromium.org's avatar derat@chromium.org

linux: Avoid using unset Fontconfig properties.

Check the return values from FcPatternGet*() so unset
properties won't override the defaults from
LinuxFontDelegate. Most properties have default values
assigned to them by Fontconfig, but subpixel rendering
notably doesn't.

BUG=395014

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284697 0039d316-1c4b-4281-b951-d872f2087c98
parent ec83a4dd
......@@ -394,7 +394,6 @@ source_set("gfx_test_support") {
test("gfx_unittests") {
sources = [
"font_render_params_linux_unittest.cc",
"geometry/box_unittest.cc",
"geometry/cubic_bezier_unittest.cc",
"geometry/insets_unittest.cc",
......@@ -423,7 +422,10 @@ test("gfx_unittests") {
]
if (use_pango) {
sources += [ "platform_font_pango_unittest.cc" ]
sources += [
"font_render_params_linux_unittest.cc",
"platform_font_pango_unittest.cc",
]
configs += [
"//build/config/linux:pangocairo",
"//build/config/linux:pangoft2",
......
......@@ -86,27 +86,34 @@ bool QueryFontconfig(const std::vector<std::string>* family_list,
if (params_out) {
FcBool fc_antialias = 0;
FcPatternGetBool(match, FC_ANTIALIAS, 0, &fc_antialias);
params_out->antialiasing = fc_antialias;
if (FcPatternGetBool(match, FC_ANTIALIAS, 0, &fc_antialias) ==
FcResultMatch) {
params_out->antialiasing = fc_antialias;
}
FcBool fc_autohint = 0;
FcPatternGetBool(match, FC_AUTOHINT, 0, &fc_autohint);
params_out->autohinter = fc_autohint;
if (FcPatternGetBool(match, FC_AUTOHINT, 0, &fc_autohint) ==
FcResultMatch) {
params_out->autohinter = fc_autohint;
}
FcBool fc_bitmap = 0;
FcPatternGetBool(match, FC_EMBEDDED_BITMAP, 0, &fc_bitmap);
params_out->use_bitmaps = fc_bitmap;
if (FcPatternGetBool(match, FC_EMBEDDED_BITMAP, 0, &fc_bitmap) ==
FcResultMatch) {
params_out->use_bitmaps = fc_bitmap;
}
FcBool fc_hinting = 0;
int fc_hint_style = FC_HINT_NONE;
FcPatternGetBool(match, FC_HINTING, 0, &fc_hinting);
if (fc_hinting)
FcPatternGetInteger(match, FC_HINT_STYLE, 0, &fc_hint_style);
params_out->hinting = ConvertFontconfigHintStyle(fc_hint_style);
if (FcPatternGetBool(match, FC_HINTING, 0, &fc_hinting) == FcResultMatch) {
int fc_hint_style = FC_HINT_NONE;
if (fc_hinting)
FcPatternGetInteger(match, FC_HINT_STYLE, 0, &fc_hint_style);
params_out->hinting = ConvertFontconfigHintStyle(fc_hint_style);
}
int fc_rgba = FC_RGBA_NONE;
FcPatternGetInteger(match, FC_RGBA, 0, &fc_rgba);
params_out->subpixel_rendering = ConvertFontconfigRgba(fc_rgba);
if (FcPatternGetInteger(match, FC_RGBA, 0, &fc_rgba) == FcResultMatch)
params_out->subpixel_rendering = ConvertFontconfigRgba(fc_rgba);
}
FcPatternDestroy(match);
......
......@@ -10,12 +10,42 @@
#include "base/macros.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/font.h"
#include "ui/gfx/linux_font_delegate.h"
#include "ui/gfx/pango_util.h"
#include "ui/gfx/test/fontconfig_util_linux.h"
namespace gfx {
namespace {
// Implementation of LinuxFontDelegate that returns a canned FontRenderParams
// struct. This is used to isolate tests from the system's local configuration.
class TestFontDelegate : public LinuxFontDelegate {
public:
TestFontDelegate() {}
virtual ~TestFontDelegate() {}
void set_params(const FontRenderParams& params) { params_ = params; }
virtual FontRenderParams GetDefaultFontRenderParams() const OVERRIDE {
return params_;
}
virtual scoped_ptr<ScopedPangoFontDescription>
GetDefaultPangoFontDescription() const OVERRIDE {
NOTIMPLEMENTED();
return scoped_ptr<ScopedPangoFontDescription>();
}
virtual double GetFontDPI() const OVERRIDE {
NOTIMPLEMENTED();
return 96.0;
}
private:
FontRenderParams params_;
DISALLOW_COPY_AND_ASSIGN(TestFontDelegate);
};
// 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) {
......@@ -35,14 +65,20 @@ class FontRenderParamsTest : public testing::Test {
FontRenderParamsTest() {
SetUpFontconfig();
CHECK(temp_dir_.CreateUniqueTempDir());
original_font_delegate_ = LinuxFontDelegate::instance();
LinuxFontDelegate::SetInstance(&test_font_delegate_);
}
virtual ~FontRenderParamsTest() {
LinuxFontDelegate::SetInstance(
const_cast<LinuxFontDelegate*>(original_font_delegate_));
TearDownFontconfig();
}
protected:
base::ScopedTempDir temp_dir_;
const LinuxFontDelegate* original_font_delegate_;
TestFontDelegate test_font_delegate_;
private:
DISALLOW_COPY_AND_ASSIGN(FontRenderParamsTest);
......@@ -210,4 +246,27 @@ TEST_F(FontRenderParamsTest, UseBitmaps) {
EXPECT_TRUE(params.use_bitmaps);
}
TEST_F(FontRenderParamsTest, OnlySetConfiguredValues) {
// Configure the LinuxFontDelegate (which queries GtkSettings on desktop
// Linux) to request subpixel rendering.
FontRenderParams system_params;
system_params.subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_RGB;
test_font_delegate_.set_params(system_params);
// Load a Fontconfig config that enables antialiasing but doesn't say anything
// about subpixel rendering.
ASSERT_TRUE(LoadSystemFont("arial.ttf"));
ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(),
std::string(kFontconfigFileHeader) +
kFontconfigMatchHeader +
CreateFontconfigEditStanza("antialias", "bool", "true") +
kFontconfigMatchFooter +
kFontconfigFileFooter));
// The subpixel rendering setting from the delegate should make it through.
FontRenderParams params = GetCustomFontRenderParams(
false, NULL, NULL, NULL, NULL, NULL);
EXPECT_EQ(system_params.subpixel_rendering, params.subpixel_rendering);
}
} // namespace gfx
......@@ -43,7 +43,6 @@
'display_change_notifier_unittest.cc',
'display_unittest.cc',
'font_list_unittest.cc',
'font_render_params_linux_unittest.cc',
'geometry/box_unittest.cc',
'geometry/cubic_bezier_unittest.cc',
'geometry/insets_unittest.cc',
......@@ -104,6 +103,7 @@
'../../build/linux/system.gyp:pangocairo',
],
'sources': [
'font_render_params_linux_unittest.cc',
'platform_font_pango_unittest.cc',
],
'conditions': [
......
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