[cairo] API to disable subpixel antialiasing per-surface
behdad at behdad.org
Mon Jan 10 05:08:27 PST 2011
On 01/10/11 07:58, Robert O'Callahan wrote:
> When drawing to RGBA surfaces, we often want to disable subpixel antialiasing
> and use grayscale antialiasing instead, because however one crams three mask
> alpha values into a single destination alpha value, the results are often bad.
> Using cairo_font_options_set_antialias to disable subpixel antialiasing is
> problematic. There is no way to request "the default, unless it's subpixel, in
> which case grayscale". More importantly, it's difficult (in our application at
> least) to route information about the target surface to all the places where
> we might create fonts, where we'd need to call
> cairo_font_options_set_antialias with the right options. This is especially
> tricky because we cache fonts, so drawing the same objects to different
> surfaces could require us to destroy and recreate fonts just to switch their
> antialiasing mode.
> A much simpler and more elegant solution is to add a new cairo surface API
> that lets us disable subpixel antialiasing for all rendering to a given
> surface, and let the surface backend text rendering code be responsible for
> disabling subpixel antialiasing. This can be implemented with a very small
> amount of code. To preserve cairo API compatibility, subpixel antialiasing
> must be enabled by default (even for RGBA surfaces).
I found both the API and the implementation less than elegant. In fact, both
are dirty hacks!
On the API level, it defeats the whole purpose of having an opaque
cairo_font_options_t. I'm open to making _cairo_surface_set_font_options()
public if that helps.
On the implementation level, it's just wrong. The scaled font glyph metrics
may depend on the antialias mode. In which case with your patch, apps
position glyphs with one mode, and render with another. It's broken.
I understand your frustration, but this approach doesn't work IMO.
> The attached patch (not properly formatted for the cairo git repository,
> sorry) implements proposed new APIs cairo_surface_set_subpixel_antialiasing
> and cairo_surface_get_subpixel_antialiasing. Comments welcome.
> "Now the Bereans were of more noble character than the Thessalonians, for they
> received the message with great eagerness and examined the Scriptures every
> day to see if what Paul said was true." [Acts 17:11]
> cairo mailing list
> cairo at cairographics.org
More information about the cairo