[API] One last font-funcs API change Now that vertical text works correctly, I'm doing a last round modification of the font-funcs API to simplify. Expect no more changes around here.
diff --git a/src/hb-font.cc b/src/hb-font.cc index ae2910c..27ec005 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc
@@ -56,40 +56,28 @@ return FALSE; } -static void +static hb_position_t hb_font_get_glyph_h_advance_nil (hb_font_t *font HB_UNUSED, void *font_data HB_UNUSED, hb_codepoint_t glyph, - hb_position_t *advance, void *user_data HB_UNUSED) { - if (font->parent) { - hb_font_get_glyph_h_advance (font->parent, - glyph, - advance); - *advance = font->parent_scale_x_distance (*advance); - return; - } + if (font->parent) + return font->parent_scale_x_distance (hb_font_get_glyph_h_advance (font->parent, glyph)); - *advance = font->x_scale; + return font->x_scale; } -static void +static hb_position_t hb_font_get_glyph_v_advance_nil (hb_font_t *font HB_UNUSED, void *font_data HB_UNUSED, hb_codepoint_t glyph, - hb_position_t *advance, void *user_data HB_UNUSED) { - if (font->parent) { - hb_font_get_glyph_v_advance (font->parent, - glyph, - advance); - *advance = font->parent_scale_y_distance (*advance); - return; - } + if (font->parent) + return font->parent_scale_y_distance (hb_font_get_glyph_v_advance (font->parent, glyph)); - *advance = font->y_scale; + return font->y_scale; } static hb_bool_t @@ -134,42 +122,30 @@ return FALSE; } -static void +static hb_position_t hb_font_get_glyph_h_kerning_nil (hb_font_t *font HB_UNUSED, void *font_data HB_UNUSED, hb_codepoint_t left_glyph, hb_codepoint_t right_glyph, - hb_position_t *kerning, void *user_data HB_UNUSED) { - if (font->parent) { - hb_font_get_glyph_h_kerning (font->parent, - left_glyph, right_glyph, - kerning); - *kerning = font->parent_scale_x_distance (*kerning); - return; - } + if (font->parent) + return font->parent_scale_x_distance (hb_font_get_glyph_h_kerning (font->parent, left_glyph, right_glyph)); - *kerning = 0; + return 0; } -static void +static hb_position_t hb_font_get_glyph_v_kerning_nil (hb_font_t *font HB_UNUSED, void *font_data HB_UNUSED, hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph, - hb_position_t *kerning, void *user_data HB_UNUSED) { - if (font->parent) { - hb_font_get_glyph_v_kerning (font->parent, - top_glyph, bottom_glyph, - kerning); - *kerning = font->parent_scale_y_distance (*kerning); - return; - } + if (font->parent) + return font->parent_scale_y_distance (hb_font_get_glyph_v_kerning (font->parent, top_glyph, bottom_glyph)); - *kerning = 0; + return 0; } static hb_bool_t @@ -340,26 +316,22 @@ font->klass->user_data.glyph); } -void +hb_position_t hb_font_get_glyph_h_advance (hb_font_t *font, - hb_codepoint_t glyph, - hb_position_t *advance) + hb_codepoint_t glyph) { - *advance = 0; - font->klass->get.glyph_h_advance (font, font->user_data, - glyph, advance, - font->klass->user_data.glyph_h_advance); + return font->klass->get.glyph_h_advance (font, font->user_data, + glyph, + font->klass->user_data.glyph_h_advance); } -void +hb_position_t hb_font_get_glyph_v_advance (hb_font_t *font, - hb_codepoint_t glyph, - hb_position_t *advance) + hb_codepoint_t glyph) { - *advance = 0; - font->klass->get.glyph_v_advance (font, font->user_data, - glyph, advance, - font->klass->user_data.glyph_v_advance); + return font->klass->get.glyph_v_advance (font, font->user_data, + glyph, + font->klass->user_data.glyph_v_advance); } hb_bool_t @@ -384,27 +356,21 @@ font->klass->user_data.glyph_v_origin); } -void +hb_position_t hb_font_get_glyph_h_kerning (hb_font_t *font, - hb_codepoint_t left_glyph, hb_codepoint_t right_glyph, - hb_position_t *kerning) + hb_codepoint_t left_glyph, hb_codepoint_t right_glyph) { - *kerning = 0; return font->klass->get.glyph_h_kerning (font, font->user_data, left_glyph, right_glyph, - kerning, font->klass->user_data.glyph_h_kerning); } -void +hb_position_t hb_font_get_glyph_v_kerning (hb_font_t *font, - hb_codepoint_t left_glyph, hb_codepoint_t right_glyph, - hb_position_t *kerning) + hb_codepoint_t left_glyph, hb_codepoint_t right_glyph) { - *kerning = 0; return font->klass->get.glyph_v_kerning (font, font->user_data, left_glyph, right_glyph, - kerning, font->klass->user_data.glyph_v_kerning); } @@ -442,11 +408,11 @@ hb_position_t *x, hb_position_t *y) { if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) { + *x = hb_font_get_glyph_h_advance (font, glyph); *y = 0; - hb_font_get_glyph_h_advance (font, glyph, x); } else { *x = 0; - hb_font_get_glyph_v_advance (font, glyph, y); + *y = hb_font_get_glyph_v_advance (font, glyph); } } @@ -455,10 +421,7 @@ hb_codepoint_t glyph, hb_position_t *x, hb_position_t *y) { - *x = *y = 0; - - hb_font_get_glyph_h_advance (font, glyph, x); - *x /= 2; + *x = hb_font_get_glyph_h_advance (font, glyph) / 2; /* TODO use font_metics.ascent */ *y = font->y_scale; @@ -523,11 +486,11 @@ hb_position_t *x, hb_position_t *y) { if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) { + *x = hb_font_get_glyph_h_kerning (font, first_glyph, second_glyph); *y = 0; - hb_font_get_glyph_h_kerning (font, first_glyph, second_glyph, x); } else { *x = 0; - hb_font_get_glyph_v_kerning (font, first_glyph, second_glyph, y); + *y = hb_font_get_glyph_v_kerning (font, first_glyph, second_glyph); } }
diff --git a/src/hb-font.h b/src/hb-font.h index 22384ac..37d36b4 100644 --- a/src/hb-font.h +++ b/src/hb-font.h
@@ -142,10 +142,9 @@ void *user_data); -typedef void (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, void *font_data, - hb_codepoint_t glyph, - hb_position_t *advance, - void *user_data); +typedef hb_position_t (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, void *font_data, + hb_codepoint_t glyph, + void *user_data); 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; @@ -156,10 +155,9 @@ typedef hb_font_get_glyph_origin_func_t hb_font_get_glyph_h_origin_func_t; typedef hb_font_get_glyph_origin_func_t hb_font_get_glyph_v_origin_func_t; -typedef void (*hb_font_get_glyph_kerning_func_t) (hb_font_t *font, void *font_data, - hb_codepoint_t first_glyph, hb_codepoint_t second_glyph, - hb_position_t *kerning, - void *user_data); +typedef hb_position_t (*hb_font_get_glyph_kerning_func_t) (hb_font_t *font, void *font_data, + hb_codepoint_t first_glyph, hb_codepoint_t second_glyph, + void *user_data); typedef hb_font_get_glyph_kerning_func_t hb_font_get_glyph_h_kerning_func_t; typedef hb_font_get_glyph_kerning_func_t hb_font_get_glyph_v_kerning_func_t; @@ -183,38 +181,38 @@ void hb_font_funcs_set_glyph_h_advance_func (hb_font_funcs_t *ffuncs, - hb_font_get_glyph_h_advance_func_t glyph_advance_func, + hb_font_get_glyph_h_advance_func_t func, void *user_data, hb_destroy_func_t destroy); void hb_font_funcs_set_glyph_v_advance_func (hb_font_funcs_t *ffuncs, - hb_font_get_glyph_v_advance_func_t glyph_advance_func, + hb_font_get_glyph_v_advance_func_t func, void *user_data, hb_destroy_func_t destroy); void hb_font_funcs_set_glyph_h_origin_func (hb_font_funcs_t *ffuncs, - hb_font_get_glyph_h_origin_func_t glyph_advance_func, + hb_font_get_glyph_h_origin_func_t func, void *user_data, hb_destroy_func_t destroy); void hb_font_funcs_set_glyph_v_origin_func (hb_font_funcs_t *ffuncs, - hb_font_get_glyph_v_origin_func_t glyph_advance_func, + hb_font_get_glyph_v_origin_func_t func, void *user_data, hb_destroy_func_t destroy); void hb_font_funcs_set_glyph_h_kerning_func (hb_font_funcs_t *ffuncs, - hb_font_get_glyph_h_kerning_func_t kerning_func, + hb_font_get_glyph_h_kerning_func_t func, void *user_data, hb_destroy_func_t destroy); void hb_font_funcs_set_glyph_v_kerning_func (hb_font_funcs_t *ffuncs, - hb_font_get_glyph_v_kerning_func_t kerning_func, + hb_font_get_glyph_v_kerning_func_t func, void *user_data, hb_destroy_func_t destroy); void hb_font_funcs_set_glyph_extents_func (hb_font_funcs_t *ffuncs, - hb_font_get_glyph_extents_func_t glyph_extents_func, + hb_font_get_glyph_extents_func_t func, void *user_data, hb_destroy_func_t destroy); void hb_font_funcs_set_glyph_contour_point_func (hb_font_funcs_t *ffuncs, - hb_font_get_glyph_contour_point_func_t glyph_contour_point_func, + hb_font_get_glyph_contour_point_func_t func, void *user_data, hb_destroy_func_t destroy); @@ -225,14 +223,12 @@ hb_codepoint_t unicode, hb_codepoint_t variation_selector, hb_codepoint_t *glyph); -void +hb_position_t hb_font_get_glyph_h_advance (hb_font_t *font, - hb_codepoint_t glyph, - hb_position_t *advance); -void + hb_codepoint_t glyph); +hb_position_t hb_font_get_glyph_v_advance (hb_font_t *font, - hb_codepoint_t glyph, - hb_position_t *advance); + hb_codepoint_t glyph); hb_bool_t hb_font_get_glyph_h_origin (hb_font_t *font, @@ -243,14 +239,12 @@ hb_codepoint_t glyph, hb_position_t *x, hb_position_t *y); -void +hb_position_t hb_font_get_glyph_h_kerning (hb_font_t *font, - hb_codepoint_t left_glyph, hb_codepoint_t right_glyph, - hb_position_t *kerning); -void + hb_codepoint_t left_glyph, hb_codepoint_t right_glyph); +hb_position_t hb_font_get_glyph_v_kerning (hb_font_t *font, - hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph, - hb_position_t *kerning); + hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph); hb_bool_t hb_font_get_glyph_extents (hb_font_t *font,
diff --git a/src/hb-ft.cc b/src/hb-ft.cc index feaf9aa..4a180ee 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc
@@ -78,38 +78,36 @@ return *glyph != 0; } -static void +static hb_position_t hb_ft_get_glyph_h_advance (hb_font_t *font HB_UNUSED, void *font_data, hb_codepoint_t glyph, - hb_position_t *advance, void *user_data HB_UNUSED) { FT_Face ft_face = (FT_Face) font_data; int load_flags = FT_LOAD_DEFAULT; if (unlikely (FT_Load_Glyph (ft_face, glyph, load_flags))) - return; + return 0; - *advance = ft_face->glyph->metrics.horiAdvance; + return ft_face->glyph->metrics.horiAdvance; } -static void +static hb_position_t hb_ft_get_glyph_v_advance (hb_font_t *font HB_UNUSED, void *font_data, hb_codepoint_t glyph, - hb_position_t *advance, void *user_data HB_UNUSED) { FT_Face ft_face = (FT_Face) font_data; int load_flags = FT_LOAD_DEFAULT; if (unlikely (FT_Load_Glyph (ft_face, glyph, load_flags))) - return; + return 0; /* Note: FreeType's vertical metrics grows downward while other FreeType coordinates * have a Y growing upward. Hence the extra negation. */ - *advance = -ft_face->glyph->metrics.vertAdvance; + return -ft_face->glyph->metrics.vertAdvance; } static hb_bool_t @@ -146,33 +144,31 @@ return TRUE; } -static void +static hb_position_t hb_ft_get_glyph_h_kerning (hb_font_t *font HB_UNUSED, void *font_data, hb_codepoint_t left_glyph, hb_codepoint_t right_glyph, - hb_position_t *kerning, void *user_data HB_UNUSED) { FT_Face ft_face = (FT_Face) font_data; FT_Vector kerningv; if (FT_Get_Kerning (ft_face, left_glyph, right_glyph, FT_KERNING_DEFAULT, &kerningv)) - return; + return 0; - *kerning = kerningv.x; + return kerningv.x; } -static void +static hb_position_t hb_ft_get_glyph_v_kerning (hb_font_t *font HB_UNUSED, void *font_data HB_UNUSED, hb_codepoint_t top_glyph HB_UNUSED, hb_codepoint_t bottom_glyph HB_UNUSED, - hb_position_t *kerning HB_UNUSED, void *user_data HB_UNUSED) { /* FreeType API doesn't support vertical kerning */ - return; + return 0; } static hb_bool_t