[cairo] cairo ignores CAIRO_ANTIALIAS_GRAY, forces subpixel antialiasing

Maarten Baert maarten-baert at hotmail.com
Sat Apr 20 09:22:31 PDT 2013

(I am sending this to cairo at cairographics.org rather than
cairo-bugs at cairographics.org because that's what the contact page told
me, I hope this is correct)

I recently encountered a bug in GIMP where the edge pixels of text would
become greenish rather than the intended color:

incorrect antialiasing in GIMP

By coincidence, this bug doesn't affect Ubuntu and some other
distributions, because it only appears when the fontconfig file
explicitly defines the pixel layout of the display. Ubuntu doesn't do
this, but it does enable 'lcdfilter', and apparently this causes cairo
to use RGB by default. But if you explicitly define the layout as RGB or
anything else (which seems to be required for Qt 5 applications to get
any subpixel antialiasing at all), this bug appears.

I thought this was a bug in GIMP (it doesn't disable subpixel rendering,
so this problem was to be expected), but when I tried to fix it, I
discovered that cairo simply ignores what the application says and
forces subpixel rendering even when you explicitly disable it. This
makes no sense. The documentation states:


	Use the default antialiasing for the subsystem and target device, since


	Use a bilevel alpha mask, since 1.0


	Perform single-color antialiasing (using shades of gray for black text
on a white background, for example), since 1.0


	Perform antialiasing by taking advantage of the order of subpixel
elements on devices such as LCD panels, since 1.0


	Hint that the backend should perform some antialiasing but prefer speed
over quality, since 1.12


	The backend should balance quality against performance, since 1.12


	Hint that the backend should render at the highest quality, sacrificing
speed if necessary, since 1.12

In my tests, CAIRO_ANTIALIAS_GRAY actually results in subpixel
rendering. And ironically, |CAIRO_ANTIALIAS_GOOD results in no subpixel
rendering. I could fix the bug in GIMP by using CAIRO_ANTIALIAS_GOOD
rather than CAIRO_ANTIALIAS_GRAY, but that seems like a bad idea as it
could easily break in the future, or on other platforms. Besides, the
documentation also states:|

    |In the case of glyph rendering, /|CAIRO_ANTIALIAS_FAST|/ and
    /|CAIRO_ANTIALIAS_GOOD|/ will be mapped to /|CAIRO_ANTIALIAS_GRAY|/,
    with /|CAIRO_ANTALIAS_BEST|/ being equivalent to

|This is simply wrong, my test clearly shows different results for

So I would like to propose this patch:

diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 1ab56be..6ceec03 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -1768,8 +1768,7 @@ _cairo_ft_options_merge (cairo_ft_options_t *options,
     if (other->base.antialias == CAIRO_ANTIALIAS_SUBPIXEL &&
-       (options->base.antialias == CAIRO_ANTIALIAS_DEFAULT ||
-        options->base.antialias == CAIRO_ANTIALIAS_GRAY)) {
+       options->base.antialias == CAIRO_ANTIALIAS_DEFAULT) {
        options->base.antialias = CAIRO_ANTIALIAS_SUBPIXEL;
        options->base.subpixel_order = other->base.subpixel_order;

|The effect is minimal: CAIRO_ANTIALIAS_GRAY will be respected when the
fontconfig file specifies subpixel antialiasing. I've tested this patch
for a few weeks on my computer, and I don't see any issues whatsoever.|
Most applications just use CAIRO_ANTIALIAS_DEFAULT - the only situation
where an application would ever specify |CAIRO_ANTIALIAS_GRAY is when
it's actually required, so the system settings should never override this.

I know that similar bugs have already been reported years ago, and
apparently not everyone agrees on how _cairo_ft_options_merge() should
behave. But this bug is obviously a problem, since it makes it
impossible to write an application like GIMP which requires subpixel
rendering to be disabled reliably. I hope this can get fixed soon, so I
can fix this bug in GIMP.

Maarten Baert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20130420/c64707ee/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gimp-text-aa-default.png
Type: image/png
Size: 4661 bytes
Desc: not available
URL: <http://lists.cairographics.org/archives/cairo/attachments/20130420/c64707ee/attachment.png>

More information about the cairo mailing list