[ft] FT_Get_Advance() for advance-width callbacks
Using graphite2's comparerenderer suggests that this makes hb-ft 15
times faster. No caching layer needed anymore.
diff --git a/configure.ac b/configure.ac
index 6cd1018..f42fb3c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -134,7 +134,7 @@
dnl ==========================================================================
-PKG_CHECK_MODULES(FREETYPE, freetype2, have_freetype=true, have_freetype=false)
+PKG_CHECK_MODULES(FREETYPE, freetype2 >= 2.3.8, have_freetype=true, have_freetype=false)
if $have_freetype; then
AC_DEFINE(HAVE_FREETYPE, 1, [Have FreeType 2 library])
_save_libs="$LIBS"
diff --git a/src/hb-ft.cc b/src/hb-ft.cc
index 25368f1..23c2cc0 100644
--- a/src/hb-ft.cc
+++ b/src/hb-ft.cc
@@ -31,6 +31,7 @@
#include "hb-font-private.hh"
+#include FT_ADVANCES_H
#include FT_TRUETYPE_TABLES_H
@@ -47,9 +48,13 @@
*
* - We don't handle any load_flags. That definitely has API implications. :(
* I believe hb_ft_font_create() should take load_flags input.
+ * In particular, FT_Get_Advance() without the NO_HINTING flag seems to be
+ * buggy.
*
* - We don't handle / allow for emboldening / obliqueing.
*
+ * - Rounding, etc?
+ *
* - In the future, we should add constructors to create fonts in font space.
*
* - I believe transforms are not correctly implemented. FreeType does not
@@ -89,12 +94,13 @@
void *user_data HB_UNUSED)
{
FT_Face ft_face = (FT_Face) font_data;
- int load_flags = FT_LOAD_DEFAULT;
+ int load_flags = FT_LOAD_DEFAULT | FT_LOAD_NO_HINTING;
+ FT_Fixed v;
- if (unlikely (FT_Load_Glyph (ft_face, glyph, load_flags)))
+ if (unlikely (FT_Get_Advance (ft_face, glyph, load_flags, &v)))
return 0;
- return ft_face->glyph->metrics.horiAdvance;
+ return v >> 10;
}
static hb_position_t
@@ -104,14 +110,15 @@
void *user_data HB_UNUSED)
{
FT_Face ft_face = (FT_Face) font_data;
- int load_flags = FT_LOAD_DEFAULT;
+ int load_flags = FT_LOAD_DEFAULT | FT_LOAD_NO_HINTING | FT_LOAD_VERTICAL_LAYOUT;
+ FT_Fixed v;
- if (unlikely (FT_Load_Glyph (ft_face, glyph, load_flags)))
+ if (unlikely (FT_Get_Advance (ft_face, glyph, load_flags, &v)))
return 0;
/* Note: FreeType's vertical metrics grows downward while other FreeType coordinates
* have a Y growing upward. Hence the extra negation. */
- return -ft_face->glyph->metrics.vertAdvance;
+ return -v >> 10;
}
static hb_bool_t
diff --git a/util/common.hh b/util/common.hh
index 5c8baab..58dec6f 100644
--- a/util/common.hh
+++ b/util/common.hh
@@ -44,6 +44,8 @@
#include <glib.h>
#include <glib/gprintf.h>
-void fail (const char *format, ...);
+
+void fail (const char *format, ...) G_GNUC_NORETURN;
+
#endif