move rounding advance width to glyf

This commit is contained in:
Michiharu Ariza 2019-03-18 17:50:20 -07:00
parent 10f264da75
commit 84d0af456b
2 changed files with 18 additions and 14 deletions

View File

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

View File

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