[cairo] [PATCH] Apply GASP parameters to TrueType fonts
Nicholas Miell
nmiell at gmail.com
Mon Jan 23 13:41:58 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.
FreeType's GASP support was introduced in 2.3.0 (released January 2007).
configure.ac has been updated to require at least this version.
Signed-off-by: Nicholas Miell <nmiell at gmail.com>
---
configure.ac | 4 ++--
src/cairo-ft-font.c | 18 ++++++++++++++++++
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac
index 3a438ee..498b6d1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -432,9 +432,9 @@ dnl ===========================================================================
# Set these as appropriate:
# release number - for information only
-FREETYPE_MIN_RELEASE=2.1.9
+FREETYPE_MIN_RELEASE=2.3.0
# libtool-specific version - this is what is checked
-FREETYPE_MIN_VERSION=9.7.3
+FREETYPE_MIN_VERSION=9.11.3
CAIRO_ENABLE_FONT_BACKEND(ft, FreeType, auto, [
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 5790395..cef4e27 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,20 @@ _cairo_ft_scaled_glyph_init (void *abstract_font,
vertical_layout = TRUE;
}
+ /*
+ * Apply GASP parameters. This overrides any settings from
+ * fontconfig or the cairo user entirely, otherwise fonts will
+ * render incorrectly.
+ */
+ 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