Bug 4792

Summary: CAIRO_ANTIALIAS_GRAY font option doesn't turn off subpixel rendering
Product: cairo Reporter: Ilmari Heikkinen <irkheikk>
Component: freetype font backendAssignee: Jinghua Luo <sunmoon1997>
Status: RESOLVED DUPLICATE QA Contact: cairo-bugs mailing list <cairo-bugs>
Severity: normal    
Priority: high CC: keithp, otaylor, sunmoon1997
Version: 1.0.2   
Hardware: x86 (IA32)   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: a proposed patch

Description Ilmari Heikkinen 2005-10-17 16:55:28 UTC
Setting context's font_options->antialias to CAIRO_ANTIALIAS_GRAY leaves
FT_LOAD_TARGET_LCD on in cairo-ft-font.c. 

This causes FT to load the glyphs with subpixel antialiasing. 

Manually zeroing the FT_LOAD_TARGET_LCD flag from load_flags in
_cairo_ft_scaled_font_create_toy made it use grayscale antialiasing.

Quick hack workaround is to do something like this before the call to
_cairo_ft_scaled_font_create:

    if (options->antialias == CAIRO_ANTIALIAS_GRAY)
      load_flags &= !FT_LOAD_TARGET_LCD;

I don't know where the correct place to do the flag zeroing is (ie. what
function is responsible.)
Comment 1 Jinghua Luo 2006-06-17 02:14:45 UTC
Created attachment 5949 [details] [review]
a proposed patch

I just attached a patch that should fix this problem. 
Could you apply this patch to cairo HEAD and see what happens?
Comment 2 Jinghua Luo 2006-06-25 22:18:09 UTC
You can't disable subpixel rendering by setting antialias to 
CAIRO_ANTIALIAS_GRAY in some cases such as you set argb in fontconfig. 
The font options is a hint for font backend, somethings the font backend
may ignore them completely. I think this is expected behavior and user expects 
this, otherwise people will complain fontconfig doesn't work any more which is 
bad.

http://gitweb.freedesktop.org/?
p=cairo;a=commitdiff;h=54b4a2fccdcaa4fbc126818c7cb7b96a1a8acf35
With above commit, the freetype backend uses the font options combined with 
options from font pattern and doesn't set load target to FT_LOAD_TARGET_LCD
[_V] while antialias in combined font options is CAIRO_ANTIALIAS_DEFAULT or 
CAIRO_ANTIALIAS_GRAY. So, I'm going to close this bug. Any further comments?
Comment 3 Carl Worth 2006-06-26 05:01:48 UTC
The interaction of the various font options can get tricky.

I thought at one point that Owen Taylor had written a description of the various
places font options can come from, (fontconfig, per-surface defaults, explicit
calls to cairo_set_font_options, etc.), and also described which options should
override the others.

I can't find the email I was imagining on that subject, but I'd love to add a
paragraph like that to the cairo documentation.

Keith or Owen?

-Carl
Comment 4 Carl Worth 2006-06-26 05:06:37 UTC
In this specific case of this bug, I think that if code using cairo explicitly
passes ANTIALIAS_GRAY then the font backend should respect that (if it is
capable of doing so, obviously).

If the user of such an application would complain that an "argb" option set
through fontconfig was being overriden then that user should complain to the
author of the program.

That is, the explicit calls to cairo_set_font_options should be the final word
on font options and should override any previous implicit settings.

-Carl
Comment 5 Keith Packard 2006-06-26 15:24:24 UTC
The default fontconfig settings respect application settings for all rendering
options. User customizations may override these.

That's how it's supposed to work; users should always be able to override
application developers choices as it is imperative that end users be able to
override broken environments (and, frankly, broken applications).
Comment 6 Chris Wilson 2008-10-10 15:20:01 UTC
Forward dup to 11838, as the semantics of applying font options are the same and should be covered in the same review of _ft_font_options().

*** This bug has been marked as a duplicate of bug 11838 ***

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.