From e294200dac3d7cd41a02e0753f63acfbb5e24820 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Fri, 15 Jul 2022 21:36:50 +0200 Subject: [PATCH] [ft] Check for FT_Get_Transform at build time --- configure.ac | 2 +- meson.build | 1 + src/hb-ft.cc | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 8873907de..aec960090 100644 --- a/configure.ac +++ b/configure.ac @@ -308,7 +308,7 @@ if $have_freetype; then AC_DEFINE(HAVE_FREETYPE, 1, [Have FreeType 2 library]) save_libs=$LIBS LIBS="$LIBS $FREETYPE_LIBS" - AC_CHECK_FUNCS(FT_Get_Var_Blend_Coordinates FT_Set_Var_Blend_Coordinates FT_Done_MM_Var) + AC_CHECK_FUNCS(FT_Get_Var_Blend_Coordinates FT_Set_Var_Blend_Coordinates FT_Done_MM_Var FT_Get_Transform) LIBS=$save_libs fi AM_CONDITIONAL(HAVE_FREETYPE, $have_freetype) diff --git a/meson.build b/meson.build index 8039efdc2..d6a206e25 100644 --- a/meson.build +++ b/meson.build @@ -198,6 +198,7 @@ if freetype_dep.found() ['FT_Get_Var_Blend_Coordinates', {'deps': freetype_dep}], ['FT_Set_Var_Blend_Coordinates', {'deps': freetype_dep}], ['FT_Done_MM_Var', {'deps': freetype_dep}], + ['FT_Get_Transform', {'deps': freetype_dep}], ] if freetype_dep.type_name() == 'internal' diff --git a/src/hb-ft.cc b/src/hb-ft.cc index 8b1128bea..dd2cbbc44 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -422,9 +422,13 @@ hb_ft_get_glyph_h_advances (hb_font_t* font, void* font_data, hb_lock_t lock (ft_font->lock); FT_Face ft_face = ft_font->ft_face; int load_flags = ft_font->load_flags; +#ifdef HAVE_FT_GET_TRANSFORM FT_Matrix matrix; FT_Get_Transform (ft_face, &matrix, nullptr); float mult = matrix.xx / 65536.f; +#else + float mult = font->x_scale < 0 ? -1 : +1; +#endif for (unsigned int i = 0; i < count; i++) { @@ -456,9 +460,13 @@ hb_ft_get_glyph_v_advance (hb_font_t *font, const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data; hb_lock_t lock (ft_font->lock); FT_Fixed v; +#ifdef HAVE_FT_GET_TRANSFORM FT_Matrix matrix; FT_Get_Transform (ft_font->ft_face, &matrix, nullptr); float y_mult = matrix.yy / 65536.f; +#else + float y_mult = font->y_scale < 0 ? -1 : +1; +#endif if (unlikely (FT_Get_Advance (ft_font->ft_face, glyph, ft_font->load_flags | FT_LOAD_VERTICAL_LAYOUT, &v))) return 0; @@ -484,10 +492,15 @@ hb_ft_get_glyph_v_origin (hb_font_t *font, const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data; hb_lock_t lock (ft_font->lock); FT_Face ft_face = ft_font->ft_face; +#ifdef HAVE_FT_GET_TRANSFORM FT_Matrix matrix; FT_Get_Transform (ft_face, &matrix, nullptr); float x_mult = matrix.xx / 65536.f; float y_mult = matrix.yy / 65536.f; +#else + float x_mult = font->x_scale < 0 ? -1 : +1; + float y_mult = font->y_scale < 0 ? -1 : +1; +#endif if (unlikely (FT_Load_Glyph (ft_face, glyph, ft_font->load_flags))) return false; @@ -534,10 +547,15 @@ hb_ft_get_glyph_extents (hb_font_t *font, const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data; hb_lock_t lock (ft_font->lock); FT_Face ft_face = ft_font->ft_face; +#ifdef HAVE_FT_GET_TRANSFORM FT_Matrix matrix; FT_Get_Transform (ft_face, &matrix, nullptr); float x_mult = matrix.xx / 65536.f; float y_mult = matrix.yy / 65536.f; +#else + float x_mult = font->x_scale < 0 ? -1 : +1; + float y_mult = font->y_scale < 0 ? -1 : +1; +#endif if (unlikely (FT_Load_Glyph (ft_face, glyph, ft_font->load_flags))) return false; @@ -639,9 +657,13 @@ hb_ft_get_font_h_extents (hb_font_t *font HB_UNUSED, const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data; hb_lock_t lock (ft_font->lock); FT_Face ft_face = ft_font->ft_face; +#ifdef HAVE_FT_GET_TRANSFORM FT_Matrix matrix; FT_Get_Transform (ft_face, &matrix, nullptr); float y_mult = matrix.yy / 65536.f; +#else + float y_mult = font->y_scale < 0 ? -1 : +1; +#endif metrics->ascender = FT_MulFix(ft_face->ascender, ft_face->size->metrics.y_scale); metrics->descender = FT_MulFix(ft_face->descender, ft_face->size->metrics.y_scale);