[font] Do user-space conversion when chaining up to parent font

This commit is contained in:
Behdad Esfahbod 2011-05-11 00:15:37 -04:00
parent b6f902a1a9
commit 63d646fb29
2 changed files with 45 additions and 6 deletions

View File

@ -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; }
};

View File

@ -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;
}