Permalink
Browse files

font: Provide our own fontconfig settings (bug #20337)

Due to an unfortunate combination of Cairo's use of premultiplied alpha
and our engine expecting to be able to blit pre-rasterized text surfaces
with an alpha channel into arbitrary surfaces, we can't safely use RGB
subpixel hinting without getting glyph color glitches. This is
particularly noticeable in GUI2 dialogs when the system fontconfig
settings dictate subpixel hinting to be enabled. Bug #21648 is just a
Windows-specific case of the same issue exacerbated by an as of yet
unaddressed peculiarity of Cairo's premultiplied alpha format on
Windows.

SDL_ttf avoids the issue entirely by always using an equivalent of
hintstyle=full and rgba=none with FreeType directly. There are very few
UI components in Wesnoth using SDL_ttf anymore, but they are still large
enough to make the rendering differences rather jarring (MP lobby,
preferences dialog, parts of the theme UI).

Our new custom fontconfig settings use hintstyle=full and rgba=none to
produce the same results with both SDL_ttf and Pango/Cairo render paths,
and eliminate the subpixel hinting glitches. This Works For Me™, but
fontconfig and Cairo generally seem unwilling to cooperate with me and
may produce different results on other systems.

It remains to be seen exactly how this patch impacts Apple OS X users
due to bugs #23560 and #23628. Windows users are unaffected and still
depend on the "fix" for #21648 because fontconfig is apparently disabled
for most intents and purposes on that particular platform (see also
commit cad8798).
  • Loading branch information...
shikadiqueen committed Jun 1, 2015
1 parent 1c21924 commit 5a557bfecabae5d76c5dc753caf265cab52f0891
Showing with 51 additions and 0 deletions.
  1. +3 −0 changelog
  2. +34 −0 fonts/fonts.conf
  3. +3 −0 players_changelog
  4. +11 −0 src/font.cpp
View
@@ -26,6 +26,9 @@ Version 1.13.0+dev:
* Fixed minimap buttons appearing without contents or in the wrong state
during WML start events until they are interacted with or control is given
to the player for the first time or some other unspecified thing happens.
* Force uniform font rendering settings across X11 and Apple OS X, avoiding
color glitches resulting from incorrect applications of subpixel hinting
(bug #20337).
* WML engine:
* Added support for [object] duration=turn end
* New or updated image path functions:
View
@@ -0,0 +1,34 @@
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<!--
Wesnoth's text rendering code is not very well suited to RGB subpixel hinting
with Pango/Cairo (bug #20337), so we need to disable this feature to avoid
color glitches in GUI2 dialogs and other places. We also force a uniform
hintstyle for all platforms while at it.
-->
<match target="font">
<edit mode="assign" name="rgba">
<const>none</const>
</edit>
</match>
<match target="font">
<edit mode="assign" name="hinting">
<bool>true</bool>
</edit>
</match>
<match target="font">
<edit mode="assign" name="hintstyle">
<const>hintfull</const>
</edit>
</match>
<match target="font">
<edit mode="assign" name="antialias">
<bool>true</bool>
</edit>
</match>
</fontconfig>
View
@@ -22,6 +22,9 @@ Version 1.13.0+dev:
* Fixed minimap buttons appearing without contents or in the wrong state
during WML start events until they are interacted with or control is given
to the player for the first time or some other unspecified thing happens.
* Force uniform font rendering settings across X11 and Apple OS X, avoiding
color glitches resulting from incorrect applications of subpixel hinting
(bug #20337).
* Miscellaneous and bug fixes:
* Fixed a segfault in [move_units_fake]
View
@@ -409,6 +409,17 @@ void manager::init() const
ERR_FT << "Could not load the true type fonts" << std::endl;
throw error();
}
if(!FcConfigParseAndLoad(FcConfigGetCurrent(),
reinterpret_cast<const FcChar8*>((game_config::path + "/fonts/fonts.conf").c_str()),
FcFalse))
{
ERR_FT << "Could not load local font configuration\n";
}
else
{
LOG_FT << "Local font configuration loaded\n";
}
#endif
#if CAIRO_HAS_WIN32_FONT

0 comments on commit 5a557bf

Please sign in to comment.