Commit 454ffd8a authored by derat@chromium.org's avatar derat@chromium.org

linux: Force full hinting when antialiasing is disabled.

Make the Linux implementation of FontRenderParams force full
hinting (along with disabling subpixel rendering and
positioning) when antialiasing is disabled. Cairo also
forces full hinting in this case.

BUG=396239

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285462 0039d316-1c4b-4281-b951-d872f2087c98
parent eeaba874
...@@ -128,15 +128,25 @@ FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query, ...@@ -128,15 +128,25 @@ FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query,
params = delegate->GetDefaultFontRenderParams(); params = delegate->GetDefaultFontRenderParams();
QueryFontconfig(query, &params, family_out); QueryFontconfig(query, &params, family_out);
// Fontconfig doesn't support configuring subpixel positioning; check a flag. if (!params.antialiasing) {
params.subpixel_positioning = CommandLine::ForCurrentProcess()->HasSwitch( // Cairo forces full hinting when antialiasing is disabled, since anything
query.for_web_contents ? // less than that looks awful; do the same here. Requesting subpixel
switches::kEnableWebkitTextSubpixelPositioning : // rendering or positioning doesn't make sense either.
switches::kEnableBrowserTextSubpixelPositioning); params.hinting = FontRenderParams::HINTING_FULL;
params.subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE;
// To enable subpixel positioning, we need to disable hinting. params.subpixel_positioning = false;
if (params.subpixel_positioning) } else {
params.hinting = FontRenderParams::HINTING_NONE; // Fontconfig doesn't support configuring subpixel positioning; check a
// flag.
params.subpixel_positioning = CommandLine::ForCurrentProcess()->HasSwitch(
query.for_web_contents ?
switches::kEnableWebkitTextSubpixelPositioning :
switches::kEnableBrowserTextSubpixelPositioning);
// To enable subpixel positioning, we need to disable hinting.
if (params.subpixel_positioning)
params.hinting = FontRenderParams::HINTING_NONE;
}
// Use the first family from the list if Fontconfig didn't suggest a family. // Use the first family from the list if Fontconfig didn't suggest a family.
if (family_out && family_out->empty() && !query.families.empty()) if (family_out && family_out->empty() && !query.families.empty())
......
...@@ -158,18 +158,19 @@ TEST_F(FontRenderParamsTest, Size) { ...@@ -158,18 +158,19 @@ TEST_F(FontRenderParamsTest, Size) {
TEST_F(FontRenderParamsTest, Style) { TEST_F(FontRenderParamsTest, Style) {
ASSERT_TRUE(LoadSystemFont("arial.ttf")); ASSERT_TRUE(LoadSystemFont("arial.ttf"));
// Load a config that disables antialiasing for bold text and disables // Load a config that disables subpixel rendering for bold text and disables
// hinting for italic text. // hinting for italic text.
ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(),
std::string(kFontconfigFileHeader) + std::string(kFontconfigFileHeader) +
kFontconfigMatchHeader + kFontconfigMatchHeader +
CreateFontconfigEditStanza("antialias", "bool", "true") + CreateFontconfigEditStanza("antialias", "bool", "true") +
CreateFontconfigEditStanza("hinting", "bool", "true") + CreateFontconfigEditStanza("hinting", "bool", "true") +
CreateFontconfigEditStanza("hintstyle", "const", "hintfull") + CreateFontconfigEditStanza("hintstyle", "const", "hintslight") +
CreateFontconfigEditStanza("rgba", "const", "rgb") +
kFontconfigMatchFooter + kFontconfigMatchFooter +
kFontconfigMatchHeader + kFontconfigMatchHeader +
CreateFontconfigTestStanza("weight", "eq", "const", "bold") + CreateFontconfigTestStanza("weight", "eq", "const", "bold") +
CreateFontconfigEditStanza("antialias", "bool", "false") + CreateFontconfigEditStanza("rgba", "const", "none") +
kFontconfigMatchFooter + kFontconfigMatchFooter +
kFontconfigMatchHeader + kFontconfigMatchHeader +
CreateFontconfigTestStanza("slant", "eq", "const", "italic") + CreateFontconfigTestStanza("slant", "eq", "const", "italic") +
...@@ -180,23 +181,27 @@ TEST_F(FontRenderParamsTest, Style) { ...@@ -180,23 +181,27 @@ TEST_F(FontRenderParamsTest, Style) {
FontRenderParamsQuery query(false); FontRenderParamsQuery query(false);
query.style = Font::NORMAL; query.style = Font::NORMAL;
FontRenderParams params = GetFontRenderParams(query, NULL); FontRenderParams params = GetFontRenderParams(query, NULL);
EXPECT_TRUE(params.antialiasing); EXPECT_EQ(FontRenderParams::HINTING_SLIGHT, params.hinting);
EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB,
params.subpixel_rendering);
query.style = Font::BOLD; query.style = Font::BOLD;
params = GetFontRenderParams(query, NULL); params = GetFontRenderParams(query, NULL);
EXPECT_FALSE(params.antialiasing); EXPECT_EQ(FontRenderParams::HINTING_SLIGHT, params.hinting);
EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE,
params.subpixel_rendering);
query.style = Font::ITALIC; query.style = Font::ITALIC;
params = GetFontRenderParams(query, NULL); params = GetFontRenderParams(query, NULL);
EXPECT_TRUE(params.antialiasing);
EXPECT_EQ(FontRenderParams::HINTING_NONE, params.hinting); EXPECT_EQ(FontRenderParams::HINTING_NONE, params.hinting);
EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB,
params.subpixel_rendering);
query.style = Font::BOLD | Font::ITALIC; query.style = Font::BOLD | Font::ITALIC;
params = GetFontRenderParams(query, NULL); params = GetFontRenderParams(query, NULL);
EXPECT_FALSE(params.antialiasing);
EXPECT_EQ(FontRenderParams::HINTING_NONE, params.hinting); EXPECT_EQ(FontRenderParams::HINTING_NONE, params.hinting);
EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE,
params.subpixel_rendering);
} }
TEST_F(FontRenderParamsTest, Scalable) { TEST_F(FontRenderParamsTest, Scalable) {
...@@ -242,6 +247,31 @@ TEST_F(FontRenderParamsTest, UseBitmaps) { ...@@ -242,6 +247,31 @@ TEST_F(FontRenderParamsTest, UseBitmaps) {
EXPECT_TRUE(params.use_bitmaps); EXPECT_TRUE(params.use_bitmaps);
} }
TEST_F(FontRenderParamsTest, ForceFullHintingWhenAntialiasingIsDisabled) {
// Load a config that disables antialiasing and hinting while requesting
// subpixel rendering.
ASSERT_TRUE(LoadSystemFont("arial.ttf"));
ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(),
std::string(kFontconfigFileHeader) +
kFontconfigMatchHeader +
CreateFontconfigEditStanza("antialias", "bool", "false") +
CreateFontconfigEditStanza("hinting", "bool", "false") +
CreateFontconfigEditStanza("hintstyle", "const", "hintnone") +
CreateFontconfigEditStanza("rgba", "const", "rgb") +
kFontconfigMatchFooter +
kFontconfigFileFooter));
// Full hinting should be forced. See the comment in GetFontRenderParams() for
// more information.
FontRenderParams params = GetFontRenderParams(
FontRenderParamsQuery(false), NULL);
EXPECT_FALSE(params.antialiasing);
EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting);
EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE,
params.subpixel_rendering);
EXPECT_FALSE(params.subpixel_positioning);
}
TEST_F(FontRenderParamsTest, OnlySetConfiguredValues) { TEST_F(FontRenderParamsTest, OnlySetConfiguredValues) {
// Configure the LinuxFontDelegate (which queries GtkSettings on desktop // Configure the LinuxFontDelegate (which queries GtkSettings on desktop
// Linux) to request subpixel rendering. // Linux) to request subpixel rendering.
......
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