diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh index 4950e0bbe..81ae41118 100644 --- a/src/hb-font-private.hh +++ b/src/hb-font-private.hh @@ -54,6 +54,7 @@ HB_FONT_FUNC_IMPLEMENT (glyph_contour_point) \ HB_FONT_FUNC_IMPLEMENT (glyph_name) \ HB_FONT_FUNC_IMPLEMENT (glyph_from_name) \ + HB_FONT_FUNC_IMPLEMENT (glyph_h_advances) \ /* ^--- Add new callbacks here */ struct hb_font_funcs_t @@ -227,6 +228,18 @@ struct hb_font_t klass->user_data.glyph_h_advance); } + inline void get_glyph_h_advances(unsigned count, + hb_codepoint_t* glyphs, + unsigned glyph_struct_size, + hb_position_t* advances, + unsigned advance_struct_size) { + return klass->get.f.glyph_h_advances (this, user_data, + count, + glyphs, glyph_struct_size, + advances, advance_struct_size, + klass->user_data.glyph_h_advances); + } + inline hb_position_t get_glyph_v_advance (hb_codepoint_t glyph) { return klass->get.f.glyph_v_advance (this, user_data, diff --git a/src/hb-font.cc b/src/hb-font.cc index 7d8de6d0c..a3f4d1a42 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -143,6 +143,43 @@ hb_font_get_glyph_h_advance_parent (hb_font_t *font, return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph)); } +template +T* advance_by_byte_size(T* p, unsigned byte_size) { + return reinterpret_cast(reinterpret_cast(p) + byte_size); +} + +static void +hb_font_get_glyph_h_advances_nil(hb_font_t *font, + void *font_data HB_UNUSED, + unsigned count, + hb_codepoint_t* glyphs, + unsigned glyph_struct_size, + hb_position_t* advances, + unsigned advance_struct_size, + void *user_data HB_UNUSED) { + for (; count--; + glyphs = advance_by_byte_size(glyphs, glyph_struct_size), + advances = advance_by_byte_size(advances, advance_struct_size)) { + *advances = hb_font_get_glyph_h_advance_nil(font, font_data, *glyphs, user_data); + } +} + +static void +hb_font_get_glyph_h_advances_parent(hb_font_t* font, + void* font_data HB_UNUSED, + unsigned count, + hb_codepoint_t* glyphs, + unsigned glyph_struct_size, + hb_position_t* advances, + unsigned advance_struct_size, + void* user_data HB_UNUSED) { + for (; count--; + glyphs = advance_by_byte_size(glyphs, glyph_struct_size), + advances = advance_by_byte_size(advances, advance_struct_size)) { + *advances = hb_font_get_glyph_h_advance_parent(font, font_data, *glyphs, user_data); + } +} + static hb_position_t hb_font_get_glyph_v_advance_nil (hb_font_t *font, void *font_data HB_UNUSED, diff --git a/src/hb-font.h b/src/hb-font.h index c95b61d2d..41e9b0b1f 100644 --- a/src/hb-font.h +++ b/src/hb-font.h @@ -132,6 +132,16 @@ typedef hb_position_t (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, void typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_h_advance_func_t; typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_v_advance_func_t; +typedef void (*hb_font_get_glyph_h_advances_func_t)( + hb_font_t* font, + void* font_data, + unsigned count, + hb_codepoint_t* glyphs, + unsigned glyph_struct_size, + hb_position_t* advances, + unsigned advance_struct_size, + void* user_data); + typedef hb_bool_t (*hb_font_get_glyph_origin_func_t) (hb_font_t *font, void *font_data, hb_codepoint_t glyph, hb_position_t *x, hb_position_t *y, @@ -248,6 +258,11 @@ hb_font_funcs_set_glyph_h_advance_func (hb_font_funcs_t *ffuncs, hb_font_get_glyph_h_advance_func_t func, void *user_data, hb_destroy_func_t destroy); +HB_EXTERN void +hb_font_funcs_set_glyph_h_advances_func (hb_font_funcs_t *ffuncs, + hb_font_get_glyph_h_advances_func_t func, + void *user_data, hb_destroy_func_t destroy); + /** * hb_font_funcs_set_glyph_v_advance_func: * @ffuncs: font functions. diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index d7f4afeab..71b448c19 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -680,8 +680,8 @@ hb_ot_position_default (hb_ot_shape_context_t *c) if (HB_DIRECTION_IS_HORIZONTAL (direction)) { - for (unsigned int i = 0; i < count; i++) - pos[i].x_advance = c->font->get_glyph_h_advance (info[i].codepoint); + c->font->get_glyph_h_advances (count, &info[0].codepoint, sizeof(info[0]), + &pos[0].x_advance, sizeof(pos[0])); /* The nil glyph_h_origin() func returns 0, so no need to apply it. */ if (c->font->has_glyph_h_origin_func ()) for (unsigned int i = 0; i < count; i++)