From 63d646fb2933c2765ce526d321a498d0f7fae2f5 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 11 May 2011 00:15:37 -0400 Subject: [PATCH] [font] Do user-space conversion when chaining up to parent font --- src/hb-font-private.hh | 28 ++++++++++++++++++++++++++++ src/hb-font.cc | 23 +++++++++++++++++------ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh index 203cd238e..f60ce975b 100644 --- a/src/hb-font-private.hh +++ b/src/hb-font-private.hh @@ -118,6 +118,34 @@ struct _hb_font_t { inline hb_position_t em_scale_x (int16_t v) { return em_scale (v, this->x_scale); } inline hb_position_t em_scale_y (int16_t v) { return em_scale (v, this->y_scale); } + /* Convert from parent-font user-space to our user-space */ + inline hb_position_t parent_scale_x_distance (hb_position_t v) { + if (unlikely (parent && parent->x_scale != x_scale)) + return v * (int64_t) this->x_scale / this->parent->x_scale; + return v; + } + inline hb_position_t parent_scale_y_distance (hb_position_t v) { + if (unlikely (parent && parent->y_scale != y_scale)) + return v * (int64_t) this->y_scale / this->parent->y_scale; + return v; + } + inline hb_position_t parent_scale_x_position (hb_position_t v) { + return parent_scale_x_distance (v); /* We don't have translation right now */ + } + inline hb_position_t parent_scale_y_position (hb_position_t v) { + return parent_scale_y_distance (v); /* We don't have translation right now */ + } + + inline void parent_scale_distance (hb_position_t *x, hb_position_t *y) { + *x = parent_scale_x_distance (*x); + *y = parent_scale_y_distance (*y); + } + inline void parent_scale_position (hb_position_t *x, hb_position_t *y) { + *x = parent_scale_x_position (*x); + *y = parent_scale_y_position (*y); + } + + private: inline hb_position_t em_scale (int16_t v, int scale) { return v * (int64_t) scale / this->face->upem; } }; diff --git a/src/hb-font.cc b/src/hb-font.cc index 3dcc4178d..280b27a5e 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -50,10 +50,14 @@ hb_font_get_contour_point_nil (hb_font_t *font HB_UNUSED, hb_position_t *y HB_UNUSED, const void *user_data HB_UNUSED) { - if (font->parent) - return hb_font_get_contour_point (font->parent, - point_index, glyph, - x, y); + if (font->parent) { + hb_bool_t ret; + ret = hb_font_get_contour_point (font->parent, + point_index, glyph, + x, y); + font->parent_scale_position (x, y); + return ret; + } *x = *y = 0; @@ -70,6 +74,7 @@ hb_font_get_glyph_advance_nil (hb_font_t *font HB_UNUSED, { if (font->parent) { hb_font_get_glyph_advance (font->parent, glyph, x_advance, y_advance); + font->parent_scale_distance (x_advance, y_advance); return; } @@ -85,6 +90,8 @@ hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED, { if (font->parent) { hb_font_get_glyph_extents (font->parent, glyph, extents); + font->parent_scale_position (&extents->x_bearing, &extents->y_bearing); + font->parent_scale_distance (&extents->width, &extents->height); return; } @@ -112,8 +119,12 @@ hb_font_get_kerning_nil (hb_font_t *font HB_UNUSED, hb_codepoint_t second_glyph HB_UNUSED, const void *user_data HB_UNUSED) { - if (font->parent) - return hb_font_get_kerning (font->parent, first_glyph, second_glyph); + if (font->parent) { + hb_position_t ret; + ret = hb_font_get_kerning (font->parent, first_glyph, second_glyph); + ret = font->parent_scale_x_distance (ret); + return ret; + } return 0; }