From 8b38faeede41e64eb0f6ac2e12ce51dd7138d50a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 19 May 2011 13:08:00 -0400 Subject: [PATCH] More vertical Starting to get there, but not without yet another round of changes. I think I know wheere to go now. --- src/hb-font.cc | 44 ++++++++++++++++++++++++++++++++------------ src/hb-font.h | 10 ++++++++++ src/hb-ft.cc | 14 ++++++++++++-- src/hb-ot-shape.cc | 4 ++++ 4 files changed, 58 insertions(+), 14 deletions(-) diff --git a/src/hb-font.cc b/src/hb-font.cc index c2fbb94..e223a68 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -472,6 +472,34 @@ hb_font_get_glyph_origin_for_direction (hb_font_t *font, } void +hb_font_add_glyph_origin_for_direction (hb_font_t *font, + hb_codepoint_t glyph, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y) +{ + hb_position_t origin_x, origin_y; + + hb_font_get_glyph_origin_for_direction (font, glyph, direction, &origin_x, &origin_y); + + *x += origin_x; + *y += origin_y; +} + +void +hb_font_subtract_glyph_origin_for_direction (hb_font_t *font, + hb_codepoint_t glyph, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y) +{ + hb_position_t origin_x, origin_y; + + hb_font_get_glyph_origin_for_direction (font, glyph, direction, &origin_x, &origin_y); + + *x -= origin_x; + *y -= origin_y; +} + +void hb_font_get_glyph_kerning_for_direction (hb_font_t *font, hb_codepoint_t first_glyph, hb_codepoint_t second_glyph, hb_direction_t direction, @@ -502,12 +530,8 @@ hb_font_get_glyph_extents_for_direction (hb_font_t *font, { hb_bool_t ret = hb_font_get_glyph_extents (font, glyph, extents); - if (ret) { - hb_position_t origin_x, origin_y; - hb_font_get_glyph_origin_for_direction (font, glyph, direction, &origin_x, &origin_y); - extents->x_bearing += origin_x; - extents->y_bearing += origin_y; - } + if (ret) + hb_font_subtract_glyph_origin_for_direction (font, glyph, direction, &extents->x_bearing, &extents->y_bearing); } hb_bool_t @@ -518,12 +542,8 @@ hb_font_get_glyph_contour_point_for_direction (hb_font_t *font, { hb_bool_t ret = hb_font_get_glyph_contour_point (font, glyph, point_index, x, y); - if (ret) { - hb_position_t origin_x, origin_y; - hb_font_get_glyph_origin_for_direction (font, glyph, direction, &origin_x, &origin_y); - *x += origin_x; - *y += origin_y; - } + if (ret) + hb_font_subtract_glyph_origin_for_direction (font, glyph, direction, x, y); return ret; } diff --git a/src/hb-font.h b/src/hb-font.h index a73b8d1..3c181f0 100644 --- a/src/hb-font.h +++ b/src/hb-font.h @@ -275,6 +275,16 @@ hb_font_get_glyph_origin_for_direction (hb_font_t *font, hb_codepoint_t glyph, hb_direction_t direction, hb_position_t *x, hb_position_t *y); +void +hb_font_add_glyph_origin_for_direction (hb_font_t *font, + hb_codepoint_t glyph, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y); +void +hb_font_subtract_glyph_origin_for_direction (hb_font_t *font, + hb_codepoint_t glyph, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y); void hb_font_get_glyph_kerning_for_direction (hb_font_t *font, diff --git a/src/hb-ft.cc b/src/hb-ft.cc index c545d24..f6a62cf 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -110,6 +110,8 @@ hb_ft_get_glyph_v_advance (hb_font_t *font HB_UNUSED, if (unlikely (FT_Load_Glyph (ft_face, glyph, load_flags))) return FALSE; + /* Note: FreeType's vertical metrics grows downward while other FreeType coordinates + * have a Y growing upward. Hence the extra negation. */ *y = -ft_face->glyph->metrics.vertAdvance; return TRUE; } @@ -140,7 +142,16 @@ hb_ft_get_glyph_v_origin (hb_font_t *font HB_UNUSED, if (unlikely (FT_Load_Glyph (ft_face, glyph, load_flags))) return FALSE; - /* XXX */*y = ft_face->glyph->metrics.vertAdvance; + /* Note: FreeType's vertical metrics grows downward while other FreeType coordinates + * have a Y growing upward. Hence the extra negation. */ + *x = ft_face->glyph->metrics.horiBearingX - ft_face->glyph->metrics.vertBearingX; + *y = ft_face->glyph->metrics.horiBearingY - (-ft_face->glyph->metrics.vertBearingY); + + /* TODO ?? + if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) + FT_Vector_Transform (&vector, &scaled_font->unscaled->Current_Shape); + */ + return TRUE; } @@ -190,7 +201,6 @@ hb_ft_get_glyph_extents (hb_font_t *font HB_UNUSED, if (unlikely (FT_Load_Glyph (ft_face, glyph, load_flags))) return FALSE; - /* XXX: A few negations should be in order here, not sure. */ extents->x_bearing = ft_face->glyph->metrics.horiBearingX; extents->y_bearing = ft_face->glyph->metrics.horiBearingY; extents->width = ft_face->glyph->metrics.width; diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 8823f5a..f9c05ec 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -262,6 +262,10 @@ hb_position_default (hb_ot_shape_context_t *c) c->buffer->props.direction, &c->buffer->pos[i].x_advance, &c->buffer->pos[i].y_advance); + hb_font_subtract_glyph_origin_for_direction (c->font, c->buffer->info[i].codepoint, + c->buffer->props.direction, + &c->buffer->pos[i].x_offset, + &c->buffer->pos[i].y_offset); } } -- 2.7.4