[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.
This commit is contained in:
Behdad Esfahbod 2011-05-25 11:27:33 -04:00
parent d31691296f
commit 2d8ebcb9d0
5 changed files with 91 additions and 140 deletions

View File

@ -56,40 +56,28 @@ hb_font_get_glyph_nil (hb_font_t *font HB_UNUSED,
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));
return font->x_scale;
}
*advance = 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 @@ hb_font_get_glyph_v_origin_nil (hb_font_t *font HB_UNUSED,
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));
return 0;
}
*kerning = 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,25 +316,21 @@ hb_font_get_glyph (hb_font_t *font,
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,
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,
return font->klass->get.glyph_v_advance (font, font->user_data,
glyph,
font->klass->user_data.glyph_v_advance);
}
@ -384,27 +356,21 @@ hb_font_get_glyph_v_origin (hb_font_t *font,
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_font_get_glyph_advance_for_direction (hb_font_t *font,
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 @@ guess_v_origin_minus_h_origin (hb_font_t *font,
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_font_get_glyph_kerning_for_direction (hb_font_t *font,
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);
}
}

View File

@ -142,9 +142,8 @@ typedef hb_bool_t (*hb_font_get_glyph_func_t) (hb_font_t *font, void *font_data,
void *user_data);
typedef void (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, void *font_data,
typedef hb_position_t (*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_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,9 +155,8 @@ typedef hb_bool_t (*hb_font_get_glyph_origin_func_t) (hb_font_t *font, void *fon
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,
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,
hb_position_t *kerning,
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 @@ hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,
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_font_get_glyph (hb_font_t *font,
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_font_get_glyph_v_origin (hb_font_t *font,
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,

View File

@ -78,38 +78,36 @@ hb_ft_get_glyph (hb_font_t *font HB_UNUSED,
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 @@ hb_ft_get_glyph_v_origin (hb_font_t *font HB_UNUSED,
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

View File

@ -121,8 +121,7 @@ _test_font_nil_funcs (hb_font_t *font)
g_assert_cmpint (x, ==, 0);
g_assert_cmpint (y, ==, 0);
x = 13;
hb_font_get_glyph_h_advance (font, 17, &x);
x = hb_font_get_glyph_h_advance (font, 17);
g_assert_cmpint (x, ==, 0);
extents.x_bearing = extents.y_bearing = 13;
@ -138,7 +137,7 @@ _test_font_nil_funcs (hb_font_t *font)
g_assert_cmpint (glyph, ==, 0);
x = 13;
hb_font_get_glyph_h_kerning (font, 17, 19, &x);
x = hb_font_get_glyph_h_kerning (font, 17, 19);
g_assert_cmpint (x, ==, 0);
}
@ -236,15 +235,15 @@ contour_point_func2 (hb_font_t *font, void *font_data,
glyph, point_index, x, y);
}
static void
static hb_position_t
glyph_h_advance_func1 (hb_font_t *font, void *font_data,
hb_codepoint_t glyph,
hb_position_t *advance,
void *user_data)
{
if (glyph == 1) {
*advance = 8;
}
if (glyph == 1)
return 8;
return 0;
}
static void
@ -287,9 +286,9 @@ test_fontfuncs_subclassing (void)
g_assert (!hb_font_get_glyph_contour_point_for_origin (font1, 3, 7, HB_DIRECTION_RTL, &x, &y));
g_assert_cmpint (x, ==, 0);
g_assert_cmpint (y, ==, 0);
hb_font_get_glyph_h_advance (font1, 1, &x);
x = hb_font_get_glyph_h_advance (font1, 1);
g_assert_cmpint (x, ==, 8);
hb_font_get_glyph_h_advance (font1, 2, &x);
x = hb_font_get_glyph_h_advance (font1, 2);
g_assert_cmpint (x, ==, 0);
@ -313,9 +312,9 @@ test_fontfuncs_subclassing (void)
g_assert (!hb_font_get_glyph_contour_point_for_origin (font2, 3, 7, HB_DIRECTION_LTR, &x, &y));
g_assert_cmpint (x, ==, 0);
g_assert_cmpint (y, ==, 0);
hb_font_get_glyph_h_advance (font2, 1, &x);
x = hb_font_get_glyph_h_advance (font2, 1);
g_assert_cmpint (x, ==, 8);
hb_font_get_glyph_h_advance (font2, 2, &x);
x = hb_font_get_glyph_h_advance (font2, 2);
g_assert_cmpint (x, ==, 0);
@ -336,9 +335,9 @@ test_fontfuncs_subclassing (void)
g_assert (!hb_font_get_glyph_contour_point_for_origin (font3, 3, 7, HB_DIRECTION_LTR, &x, &y));
g_assert_cmpint (x, ==, 0*2);
g_assert_cmpint (y, ==, 0*3);
hb_font_get_glyph_h_advance (font3, 1, &x);
x = hb_font_get_glyph_h_advance (font3, 1);
g_assert_cmpint (x, ==, 8*2);
hb_font_get_glyph_h_advance (font3, 2, &x);
x = hb_font_get_glyph_h_advance (font3, 2);
g_assert_cmpint (x, ==, 0*2);

View File

@ -37,17 +37,17 @@
static const char test_data[] = "test\0data";
static void
static hb_position_t
glyph_h_advance_func (hb_font_t *font, void *font_data,
hb_codepoint_t glyph,
hb_position_t *advance,
void *user_data)
{
switch (glyph) {
case 1: *advance = 10; return;
case 2: *advance = 6; return;
case 3: *advance = 5; return;
case 1: return 10;
case 2: return 6;
case 3: return 5;
}
return 0;
}
static hb_bool_t
@ -61,19 +61,18 @@ glyph_func (hb_font_t *font, void *font_data,
case 'e': *glyph = 2; return TRUE;
case 's': *glyph = 3; return TRUE;
}
return FALSE;
}
static void
static hb_position_t
glyph_h_kerning_func (hb_font_t *font, void *font_data,
hb_codepoint_t left, hb_codepoint_t right,
hb_position_t *kerning,
void *user_data)
{
if (left == 1 && right == 2) {
*kerning = -2;
}
if (left == 1 && right == 2)
return -2;
return 0;
}
static const char TesT[] = "TesT";