diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index 06a799d20..d4cae61b5 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -788,22 +788,24 @@ struct glyf return true; } - float get_advance_var (hb_codepoint_t glyph, - const int *coords, unsigned int coord_count, - bool vertical) const + unsigned int get_advance_var (hb_codepoint_t glyph, + const int *coords, unsigned int coord_count, + bool vertical) const { - float advance = 0.f; - if (coord_count != gvar_accel.get_axis_count ()) return advance; - + bool success = false; hb_vector_t phantoms; phantoms.resize (PHANTOM_COUNT); - if (unlikely (!get_var_metrics (glyph, coords, coord_count, phantoms.as_array ()))) return advance; + if (likely (coord_count == gvar_accel.get_axis_count ())) + success = get_var_metrics (glyph, coords, coord_count, phantoms.as_array ()); + + if (unlikely (!success)) + return vertical? vmtx_accel.get_advance (glyph): hmtx_accel.get_advance (glyph); if (vertical) - return -(phantoms[PHANTOM_BOTTOM].y - phantoms[PHANTOM_TOP].y); // is this sign correct? + return (unsigned int)roundf (phantoms[PHANTOM_TOP].y - phantoms[PHANTOM_BOTTOM].y); else - return phantoms[PHANTOM_RIGHT].x - phantoms[PHANTOM_LEFT].x; + return (unsigned int)roundf (phantoms[PHANTOM_RIGHT].x - phantoms[PHANTOM_LEFT].x); } int get_side_bearing_var (hb_codepoint_t glyph, const int *coords, unsigned int coord_count, bool vertical) const @@ -811,7 +813,9 @@ struct glyf hb_vector_t phantoms; phantoms.resize (PHANTOM_COUNT); - if (unlikely (!get_var_metrics (glyph, coords, coord_count, phantoms))) return 0; + if (unlikely (!get_var_metrics (glyph, coords, coord_count, phantoms))) + return vertical? vmtx_accel.get_side_bearing (glyph): hmtx_accel.get_side_bearing (glyph); + return (int)(vertical? -ceilf (phantoms[PHANTOM_TOP].y): floorf (phantoms[PHANTOM_LEFT].x)); } diff --git a/src/hb-ot-hmtx-table.cc b/src/hb-ot-hmtx-table.cc index 69b0f365f..012a9f2d9 100644 --- a/src/hb-ot-hmtx-table.cc +++ b/src/hb-ot-hmtx-table.cc @@ -34,10 +34,10 @@ int hmtxvmtx_accelerator_base_t::get_side_bearing_var_tt (hb_font_t *font, hb_co glyf::accelerator_t glyf_accel; glyf_accel.init (font->face); - float side_bearing = glyf_accel.get_side_bearing_var (glyph, font->coords, font->num_coords, vertical); + int side_bearing = glyf_accel.get_side_bearing_var (glyph, font->coords, font->num_coords, vertical); glyf_accel.fini (); - return (int)roundf (side_bearing); + return side_bearing; } unsigned int hmtxvmtx_accelerator_base_t::get_advance_var_tt (hb_font_t *font, hb_codepoint_t glyph, bool vertical) @@ -45,10 +45,10 @@ unsigned int hmtxvmtx_accelerator_base_t::get_advance_var_tt (hb_font_t *font, h glyf::accelerator_t glyf_accel; glyf_accel.init (font->face); - float advance = glyf_accel.get_advance_var (glyph, font->coords, font->num_coords, vertical); + unsigned int advance = glyf_accel.get_advance_var (glyph, font->coords, font->num_coords, vertical); glyf_accel.fini (); - return (unsigned int)roundf (advance); + return advance; } }