[font] Remove division when scaling

Yoohoo.  This seems to be precise enough!  Let's see if it sticks.
I'm asking Dominik to run this in Chrome test suite and report.

Fixes https://github.com/harfbuzz/harfbuzz/issues/1801
This commit is contained in:
Behdad Esfahbod 2019-07-05 13:56:45 -07:00
parent b847769292
commit f18ea1dd3a
2 changed files with 17 additions and 22 deletions

View File

@ -129,16 +129,16 @@ struct hb_font_t
/* Convert from font-space to user-space */ /* Convert from font-space to user-space */
int dir_scale (hb_direction_t direction) int64_t dir_mult (hb_direction_t direction)
{ return HB_DIRECTION_IS_VERTICAL(direction) ? y_scale : x_scale; } { return HB_DIRECTION_IS_VERTICAL(direction) ? y_mult : x_mult; }
hb_position_t em_scale_x (int16_t v) { return em_scale (v, x_scale); } 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_scale (v, y_scale); } 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, this->x_scale); } 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, this->y_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_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_fscale_y (int16_t v) { return em_fscale (v, y_scale); }
hb_position_t em_scale_dir (int16_t v, hb_direction_t direction) hb_position_t em_scale_dir (int16_t v, hb_direction_t direction)
{ return em_scale (v, dir_scale (direction)); } { return em_mult (v, dir_mult (direction)); }
/* Convert from parent-font user-space to our user-space */ /* Convert from parent-font user-space to our user-space */
hb_position_t parent_scale_x_distance (hb_position_t v) hb_position_t parent_scale_x_distance (hb_position_t v)
@ -616,14 +616,9 @@ struct hb_font_t
y_mult = ((int64_t) y_scale << 16) / upem; y_mult = ((int64_t) y_scale << 16) / upem;
} }
hb_position_t em_scale (int16_t v, int scale) hb_position_t em_mult (int16_t v, int64_t mult)
{ {
signed upem = face->get_upem (); return (hb_position_t) ((v * mult) >> 16);
signed upem2 = upem >> 1;
int64_t scaled = v * (int64_t) scale;
scaled += scaled >= 0 ? upem2 : -upem2; /* Round. */
return (hb_position_t) (scaled / upem);
} }
hb_position_t em_scalef (float v, int scale) hb_position_t em_scalef (float v, int scale)
{ return (hb_position_t) roundf (v * scale / face->get_upem ()); } { return (hb_position_t) roundf (v * scale / face->get_upem ()); }

View File

@ -453,14 +453,14 @@ struct MathGlyphPartRecord
} }
void extract (hb_ot_math_glyph_part_t &out, void extract (hb_ot_math_glyph_part_t &out,
int scale, int64_t mult,
hb_font_t *font) const hb_font_t *font) const
{ {
out.glyph = glyph; out.glyph = glyph;
out.start_connector_length = font->em_scale (startConnectorLength, scale); out.start_connector_length = font->em_mult (startConnectorLength, mult);
out.end_connector_length = font->em_scale (endConnectorLength, scale); out.end_connector_length = font->em_mult (endConnectorLength, mult);
out.full_advance = font->em_scale (fullAdvance, scale); out.full_advance = font->em_mult (fullAdvance, mult);
static_assert ((unsigned int) HB_OT_MATH_GLYPH_PART_FLAG_EXTENDER == static_assert ((unsigned int) HB_OT_MATH_GLYPH_PART_FLAG_EXTENDER ==
(unsigned int) PartFlags::Extender, ""); (unsigned int) PartFlags::Extender, "");
@ -508,11 +508,11 @@ struct MathGlyphAssembly
{ {
if (parts_count) if (parts_count)
{ {
int scale = font->dir_scale (direction); int64_t mult = font->dir_mult (direction);
hb_array_t<const MathGlyphPartRecord> arr = partRecords.sub_array (start_offset, parts_count); hb_array_t<const MathGlyphPartRecord> arr = partRecords.sub_array (start_offset, parts_count);
unsigned int count = arr.length; unsigned int count = arr.length;
for (unsigned int i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
arr[i].extract (parts[i], scale, font); arr[i].extract (parts[i], mult, font);
} }
if (italics_correction) if (italics_correction)
@ -553,13 +553,13 @@ struct MathGlyphConstruction
{ {
if (variants_count) if (variants_count)
{ {
int scale = font->dir_scale (direction); int64_t mult = font->dir_mult (direction);
hb_array_t<const MathGlyphVariantRecord> arr = mathGlyphVariantRecord.sub_array (start_offset, variants_count); hb_array_t<const MathGlyphVariantRecord> arr = mathGlyphVariantRecord.sub_array (start_offset, variants_count);
unsigned int count = arr.length; unsigned int count = arr.length;
for (unsigned int i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
{ {
variants[i].glyph = arr[i].variantGlyph; variants[i].glyph = arr[i].variantGlyph;
variants[i].advance = font->em_scale (arr[i].advanceMeasurement, scale); variants[i].advance = font->em_mult (arr[i].advanceMeasurement, mult);
} }
} }
return mathGlyphVariantRecord.len; return mathGlyphVariantRecord.len;