cairo ignores CAIRO_ANTIALIAS_GRAY, forces subpixel antialiasing

Maarten Baert <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
(I am sending this to [email protected] rather than
[email protected] 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:

|CAIRO_ANTIALIAS_DEFAULT|

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

|CAIRO_ANTIALIAS_NONE|

	Use a bilevel alpha mask, since 1.0

|CAIRO_ANTIALIAS_GRAY|

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

|CAIRO_ANTIALIAS_SUBPIXEL|

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

|CAIRO_ANTIALIAS_FAST|

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

|CAIRO_ANTIALIAS_GOOD|

	The backend should balance quality against performance, since 1.12

|CAIRO_ANTIALIAS_BEST|

	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
    /|CAIRO_ANTIALIAS_SUBPIXEL|/.|
    ||

|This is simply wrong, my test clearly shows different results for
CAIRO_ANTIALIAS_GOOD and CAIRO_ANTIALIAS_GRAY.

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
|

-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.