From 8a31e406291f4cb27480fc85049f08abd739cb59 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 30 Sep 2018 05:27:39 -0400 Subject: [PATCH] [font] Make *_advance() fallback to *_advances And remove redundant implementations. --- src/hb-font.cc | 12 ++++++++++++ src/hb-ft.cc | 19 ------------------- src/hb-ot-font.cc | 22 ---------------------- 3 files changed, 12 insertions(+), 41 deletions(-) diff --git a/src/hb-font.cc b/src/hb-font.cc index 77762f2d8..c0beea66e 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -141,6 +141,12 @@ hb_font_get_glyph_h_advance_default (hb_font_t *font, hb_codepoint_t glyph, void *user_data HB_UNUSED) { + if (font->has_glyph_h_advances_func ()) + { + hb_position_t ret; + font->get_glyph_h_advances (1, &glyph, 0, &ret, 0); + return ret; + } return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph)); } @@ -159,6 +165,12 @@ hb_font_get_glyph_v_advance_default (hb_font_t *font, hb_codepoint_t glyph, void *user_data HB_UNUSED) { + if (font->has_glyph_v_advances_func ()) + { + hb_position_t ret; + font->get_glyph_v_advances (1, &glyph, 0, &ret, 0); + return ret; + } return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph)); } diff --git a/src/hb-ft.cc b/src/hb-ft.cc index 50182f1b6..6da31fc29 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -218,24 +218,6 @@ hb_ft_get_variation_glyph (hb_font_t *font HB_UNUSED, return true; } -static hb_position_t -hb_ft_get_glyph_h_advance (hb_font_t *font, - void *font_data, - hb_codepoint_t glyph, - void *user_data HB_UNUSED) -{ - const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data; - FT_Fixed v; - - if (unlikely (FT_Get_Advance (ft_font->ft_face, glyph, ft_font->load_flags, &v))) - return 0; - - if (font->x_scale < 0) - v = -v; - - return (v + (1<<9)) >> 10; -} - static void hb_ft_get_glyph_h_advances (hb_font_t* font, void* font_data, unsigned count, @@ -480,7 +462,6 @@ static struct hb_ft_font_funcs_lazy_loader_t : hb_font_funcs_lazy_loader_tcmap.get_relaxed ()->get_variation_glyph (unicode, variation_selector, glyph); } -static hb_position_t -hb_ot_get_glyph_h_advance (hb_font_t *font, - void *font_data, - hb_codepoint_t glyph, - void *user_data HB_UNUSED) -{ - const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; - return font->em_scale_x (ot_face->hmtx.get_relaxed ()->get_advance (glyph, font)); -} - static void hb_ot_get_glyph_h_advances (hb_font_t* font, void* font_data, unsigned count, @@ -93,16 +83,6 @@ hb_ot_get_glyph_h_advances (hb_font_t* font, void* font_data, } } -static hb_position_t -hb_ot_get_glyph_v_advance (hb_font_t *font, - void *font_data, - hb_codepoint_t glyph, - void *user_data HB_UNUSED) -{ - const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; - return font->em_scale_y (-(int) ot_face->vmtx.get_relaxed ()->get_advance (glyph, font)); -} - static void hb_ot_get_glyph_v_advances (hb_font_t* font, void* font_data, unsigned count, @@ -217,9 +197,7 @@ static struct hb_ot_face_funcs_lazy_loader_t : hb_font_funcs_lazy_loader_t