Bug 23981

Summary: cairo doesn't respect TrueType gasp tables (and fonts look ugly as a result)
Product: cairo Reporter: Nicholas Miell <nmiell>
Component: freetype font backendAssignee: David Turner <david>
Status: RESOLVED MOVED QA Contact: cairo-bugs mailing list <cairo-bugs>
Severity: normal    
Priority: medium CC: bugs.freedesktop, fonts-bugs, freedesktop
Version: 1.9.3   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: Verdana Bold 15 pt, rendered correctly
Verdana Bold 15 pt, rendered incorrectly

Description Nicholas Miell 2009-09-16 20:07:52 UTC
TrueType fonts have a table called 'gasp' (Grid-fitting And Scan-conversion Procedure) which contains a list of font size ranges and some attributes that control how they should be rendered.

One such attribute is whether or not glyphs at specific sizes should be antialiased.

FreeType does not automatically apply the settings from the gasp table, instead the FreeType user must query the gasp table using FT_Get_Gasp() and then alter their behavior based on that result.

If this is not done, some fonts will be misrendered.

One such font is Verdana Bold. The hinting programs in Verdana Bold assume that sizes 9-16 will not be antialiased (as specified in the gasp table), thus when they query the global antialiasing boolean while being run on size 9-16 glyphs, the resulting hinting is incorrect and the K, N, V and W glyphs (among others) are misrendered.

See http://www.freetype.org/freetype2/docs/reference/ft2-gasp_table.html for more information. (Note that the gasp table also controls whether or not the bytecode should be interpreted at all, which probably also results in rendering errors, but I haven't noticed any.)
Comment 1 James Cloos 2009-09-17 06:47:13 UTC
Whether to honour the gasp suggestion and disable either antialiasing or
the bytecode interpreter at any given sizes should not be cairo's choice
but rather should be specified in the fontconfig settings, so that users
can choose for themselves what they prefer.

OTOH, on doze this suggestion makes some sense.
Comment 2 Behdad Esfahbod 2009-09-17 08:46:31 UTC
I'd rather FreeType do these by default, unless overriden by the user...
Comment 3 Nicholas Miell 2009-09-17 12:57:07 UTC
(In reply to comment #1)
> Whether to honour the gasp suggestion and disable either antialiasing or
> the bytecode interpreter at any given sizes should not be cairo's choice
> but rather should be specified in the fontconfig settings, so that users
> can choose for themselves what they prefer.
> 
> OTOH, on doze this suggestion makes some sense.
> 

The gasp table isn't a suggestion, it's a requirement. Fonts render incorrectly if the gasp table isn't followed.

As an end user, I would prefer my fonts to render correctly instead of incorrectly.

If you're suggesting that I should configure this manually in some fontconfig XML file for each font individually, I'm going to state right here that you are completely wrong.
Comment 4 Ben Laenen 2009-12-05 03:56:46 UTC
(In reply to comment #3)
> As an end user, I would prefer my fonts to render correctly instead of
> incorrectly.

In any case there should be a way to override the font's gasp table. I personally favour seeing the few badly antialiased glyphs than seeing them all as bitmapped.
Comment 5 Nicholas Miell 2009-12-05 10:38:53 UTC
(In reply to comment #4)
> (In reply to comment #3)
> > As an end user, I would prefer my fonts to render correctly instead of
> > incorrectly.
> 
> In any case there should be a way to override the font's gasp table. I
> personally favour seeing the few badly antialiased glyphs than seeing them all
> as bitmapped.
> 

Antialiasing the font anyway but lying to the bytecode about whether the AA is being performed might be an interesting exercise. That can't be done at the cairo level, though.
Comment 6 Nicholas Miell 2011-06-25 10:27:52 UTC
Created attachment 48403 [details]
Verdana Bold 15 pt, rendered correctly
Comment 7 Nicholas Miell 2011-06-25 10:32:02 UTC
Created attachment 48404 [details]
Verdana Bold 15 pt, rendered incorrectly

Pay attention to the extra-fat N, V and W glyphs, as well as the subtle changes to the K, %, and many others.
Comment 8 GitLab Migration User 2018-08-25 13:54:55 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/cairo/cairo/issues/262.

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.