diff --git a/src/hb-font.cc b/src/hb-font.cc index 955ff6869..2760b09a4 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -1649,8 +1649,8 @@ DEFINE_NULL_INSTANCE (hb_font_t) = 1000, /* y_scale */ 0., /* slant */ 0., /* slant_xy; */ - 1000, /* upem */ - 0.001f, /* upem_inv */ + 1.f, /* x_multf */ + 1.f, /* y_multf */ 1<<16, /* x_mult */ 1<<16, /* y_mult */ @@ -1683,9 +1683,8 @@ _hb_font_create (hb_face_t *face) font->face = hb_face_reference (face); font->klass = hb_font_funcs_get_empty (); font->data.init0 (font); - font->x_scale = font->y_scale = hb_face_get_upem (face); - font->upem = face->get_upem (); - font->upem_inv = 1.f / font->upem; + font->x_scale = font->y_scale = face->get_upem (); + font->x_multf = font->y_multf = 1.f; font->x_mult = font->y_mult = 1 << 16; return font; diff --git a/src/hb-font.hh b/src/hb-font.hh index 9e3365ab5..452927ef6 100644 --- a/src/hb-font.hh +++ b/src/hb-font.hh @@ -114,8 +114,8 @@ struct hb_font_t int32_t y_scale; float slant; float slant_xy; - unsigned upem; - float upem_inv; + float x_multf; + float y_multf; int64_t x_mult; int64_t y_mult; @@ -141,12 +141,12 @@ struct hb_font_t { return HB_DIRECTION_IS_VERTICAL(direction) ? y_mult : x_mult; } hb_position_t em_scale_x (int16_t v) { return em_mult (v, x_mult); } hb_position_t em_scale_y (int16_t v) { return em_mult (v, y_mult); } - hb_position_t em_scalef_x (float v) { return em_scalef (v, x_scale); } - hb_position_t em_scalef_y (float v) { return em_scalef (v, y_scale); } - float em_fscale_x (int16_t v) { return em_fscale (v, x_scale); } - float em_fscale_y (int16_t v) { return em_fscale (v, y_scale); } - float em_fscalef_x (float v) { return em_fscalef (v, x_scale); } - float em_fscalef_y (float v) { return em_fscalef (v, y_scale); } + hb_position_t em_scalef_x (float v) { return em_multf (v, x_multf); } + hb_position_t em_scalef_y (float v) { return em_multf (v, y_multf); } + float em_fscale_x (int16_t v) { return em_fmult (v, x_multf); } + float em_fscale_y (int16_t v) { return em_fmult (v, y_multf); } + float em_fscalef_x (float v) { return em_fmultf (v, x_multf); } + float em_fscalef_y (float v) { return em_fmultf (v, y_multf); } hb_position_t em_scale_dir (int16_t v, hb_direction_t direction) { return em_mult (v, dir_mult (direction)); } @@ -631,23 +631,24 @@ struct hb_font_t void mults_changed () { - upem = face->get_upem (); - upem_inv = 1.f / upem; + float upem = face->get_upem (); + x_multf = x_scale / upem; + y_multf = y_scale / upem; bool x_neg = x_scale < 0; - x_mult = (x_neg ? -((int64_t) -x_scale << 16) : ((int64_t) x_scale << 16)) * upem_inv; + x_mult = (x_neg ? -((int64_t) -x_scale << 16) : ((int64_t) x_scale << 16)) / upem; bool y_neg = y_scale < 0; - y_mult = (y_neg ? -((int64_t) -y_scale << 16) : ((int64_t) y_scale << 16)) * upem_inv; + y_mult = (y_neg ? -((int64_t) -y_scale << 16) : ((int64_t) y_scale << 16)) / upem; slant_xy = y_scale ? slant * x_scale / y_scale : 0.f; } hb_position_t em_mult (int16_t v, int64_t mult) { return (hb_position_t) ((v * mult + 32768) >> 16); } - hb_position_t em_scalef (float v, int scale) - { return (hb_position_t) roundf (em_fscalef (v, scale)); } - float em_fscalef (float v, int scale) - { return v * scale * upem_inv; } - float em_fscale (int16_t v, int scale) - { return (float) v * scale * upem_inv; } + hb_position_t em_multf (float v, float mult) + { return (hb_position_t) roundf (em_fmultf (v, mult)); } + float em_fmultf (float v, float mult) + { return v * mult; } + float em_fmult (int16_t v, float mult) + { return (float) v * mult; } }; DECLARE_NULL_INSTANCE (hb_font_t); diff --git a/test/api/test-draw.c b/test/api/test-draw.c index 2211fae19..32c8e5618 100644 --- a/test/api/test-draw.c +++ b/test/api/test-draw.c @@ -479,7 +479,7 @@ test_hb_draw_font_kit_glyphs_tests (void) char expected[] = "M581,274L443,274Q409,274 384,259Q359,243 348,219Q336,194 340,166" "Q343,138 365,111L468,-13Q470,-10 473,-6Q475,-3 477,0L253,0Q225,0 203,8" "Q180,15 168,32Q155,48 155,73L155,269L50,269L50,73Q50,24 69,-10" - "Q88,-44 118,-65Q147,-85 181,-95Q214,-104 243,-104L473,-104" + "Q88,-44 118,-64Q147,-85 181,-94Q214,-104 243,-104L473,-104" "Q501,-104 525,-91Q549,-78 564,-56Q578,-34 578,-8Q578,18 557,43" "L442,182Q439,179 437,176Q435,173 432,170L581,170L581,274ZM184,-194" "Q184,-216 199,-231Q214,-246 236,-246Q258,-246 273,-231Q288,-216 288,-194"