[cairo] [PATCH] Apply GASP parmeters to TrueType fonts

Andrea Canciani ranma42 at gmail.com
Mon Jan 23 13:06:27 PST 2012


On Mon, Jan 23, 2012 at 8:40 PM, Nicholas Miell <nmiell at gmail.com> wrote:
> TrueType/OpenType fonts can have a GASP table, which controls whether
> or not a font is rendered with hinting or antialiasing at a specific ppem.
>
> For some unknown reason, this table isn't automatically applied by
> FreeType. If the FreeType clients don't do this themselves, fonts will
> render incorrectly.

The FT_Get_Gasp() function is only available since FreeType 2.3.0, so
to use it you should bump the version requirement in configure.ac (or
call it conditionally depending on its availability).

Would it be possible to create a small test that checks if GASP values
are respected?

How do these flags interact with FontConfig and with the user
hinting/antialiasing settings?
I hope somebody more knowledgeable about fonts than me will comment.
In any case, I think we should add a comment explaining the issue.

Andrea

>
> So whenever a font's scale is set, cache away the GASP value for that ppem
> and whenever a glyph is loaded, apply the GASP value as necessary.
>
> GASP tables also have flags that apply to ClearType rendering. These flags
> should be used instead of the above mentioned hinting and antialising
> flags if the font is being subpixel rendered. However, there doesn't appear
> to be any way to pass these flags on to FreeType, so they're ignored
> completely.
>
> Signed-off-by: Nicholas Miell <nmiell at gmail.com>
> ---
>  src/cairo-ft-font.c |   13 +++++++++++++
>  1 files changed, 13 insertions(+), 0 deletions(-)
>
> diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
> index 5790395..4ae5db5 100644
> --- a/src/cairo-ft-font.c
> +++ b/src/cairo-ft-font.c
> @@ -56,6 +56,7 @@
>  #include FT_IMAGE_H
>  #include FT_TRUETYPE_TABLES_H
>  #include FT_XFREE86_H
> +#include FT_GASP_H
>  #if HAVE_FT_GLYPHSLOT_EMBOLDEN
>  #include FT_SYNTHESIS_H
>  #endif
> @@ -152,6 +153,7 @@ struct _cairo_ft_unscaled_font {
>     cairo_matrix_t current_scale;
>     double x_scale;            /* Extracted X scale factor */
>     double y_scale;             /* Extracted Y scale factor */
> +    FT_Int gasp;               /* Cached GASP value for current scale */
>     cairo_bool_t have_shape;   /* true if the current scale has a non-scale component*/
>     cairo_matrix_t current_shape;
>     FT_Matrix Current_Shape;
> @@ -829,6 +831,8 @@ _cairo_ft_unscaled_font_set_scale (cairo_ft_unscaled_font_t *unscaled,
>            return _cairo_error (CAIRO_STATUS_NO_MEMORY);
>     }
>
> +    unscaled->gasp = FT_Get_Gasp(unscaled->face, unscaled->face->size->metrics.y_ppem);
> +
>     return CAIRO_STATUS_SUCCESS;
>  }
>
> @@ -2157,6 +2161,15 @@ _cairo_ft_scaled_glyph_init (void                        *abstract_font,
>        vertical_layout = TRUE;
>     }
>
> +    if (unscaled->gasp != FT_GASP_NO_TABLE) {
> +       if (!(unscaled->gasp & FT_GASP_DO_GRIDFIT))
> +           load_flags |= FT_LOAD_NO_HINTING;
> +       if (!(unscaled->gasp & FT_GASP_DO_GRAY)) {
> +           load_flags &= ~FT_LOAD_TARGET_(0);
> +           load_flags |= FT_LOAD_TARGET_MONO;
> +       }
> +    }
> +
>     error = FT_Load_Glyph (face,
>                           _cairo_scaled_glyph_index(scaled_glyph),
>                           load_flags);
> --
> 1.7.7.5
>
> --
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo


More information about the cairo mailing list