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

Nicholas Miell nmiell at gmail.com
Mon Jan 23 11:40:19 PST 2012


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.

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



More information about the cairo mailing list