[glyf] Fix confusion between scaled vs unscaled lsb

Was always broken.
This commit is contained in:
Behdad Esfahbod 2022-07-02 16:37:26 -06:00
parent 6665881c7d
commit 78b4f39821
1 changed files with 20 additions and 8 deletions

View File

@ -194,6 +194,7 @@ struct glyf_accelerator_t
hb_font_t *font; hb_font_t *font;
hb_glyph_extents_t *extents; hb_glyph_extents_t *extents;
contour_point_t *phantoms; contour_point_t *phantoms;
bool unscaled;
struct contour_bounds_t struct contour_bounds_t
{ {
@ -209,7 +210,7 @@ struct glyf_accelerator_t
bool empty () const { return (min_x >= max_x) || (min_y >= max_y); } bool empty () const { return (min_x >= max_x) || (min_y >= max_y); }
void get_extents (hb_font_t *font, hb_glyph_extents_t *extents) void get_extents (hb_font_t *font, hb_glyph_extents_t *extents, bool unscaled = false)
{ {
if (unlikely (empty ())) if (unlikely (empty ()))
{ {
@ -219,26 +220,37 @@ struct glyf_accelerator_t
extents->y_bearing = 0; extents->y_bearing = 0;
return; return;
} }
if (unscaled)
{
extents->x_bearing = roundf (min_x);
extents->width = roundf (max_x - extents->x_bearing);
extents->y_bearing = roundf (max_y);
extents->height = roundf (min_y - extents->y_bearing);
}
else
{
extents->x_bearing = font->em_scalef_x (min_x); extents->x_bearing = font->em_scalef_x (min_x);
extents->width = font->em_scalef_x (max_x) - extents->x_bearing; extents->width = font->em_scalef_x (max_x) - extents->x_bearing;
extents->y_bearing = font->em_scalef_y (max_y); extents->y_bearing = font->em_scalef_y (max_y);
extents->height = font->em_scalef_y (min_y) - extents->y_bearing; extents->height = font->em_scalef_y (min_y) - extents->y_bearing;
} }
}
protected: protected:
float min_x, min_y, max_x, max_y; float min_x, min_y, max_x, max_y;
} bounds; } bounds;
points_aggregator_t (hb_font_t *font_, hb_glyph_extents_t *extents_, contour_point_t *phantoms_) points_aggregator_t (hb_font_t *font_, hb_glyph_extents_t *extents_, contour_point_t *phantoms_, bool unscaled_ = false)
{ {
font = font_; font = font_;
extents = extents_; extents = extents_;
phantoms = phantoms_; phantoms = phantoms_;
unscaled = unscaled_;
if (extents) bounds = contour_bounds_t (); if (extents) bounds = contour_bounds_t ();
} }
void consume_point (const contour_point_t &point) { bounds.add (point); } void consume_point (const contour_point_t &point) { bounds.add (point); }
void points_end () { bounds.get_extents (font, extents); } void points_end () { bounds.get_extents (font, extents, unscaled); }
bool is_consuming_contour_points () { return extents; } bool is_consuming_contour_points () { return extents; }
contour_point_t *get_phantoms_sink () { return phantoms; } contour_point_t *get_phantoms_sink () { return phantoms; }
@ -276,7 +288,7 @@ struct glyf_accelerator_t
hb_glyph_extents_t extents; hb_glyph_extents_t extents;
contour_point_t phantoms[glyf_impl::PHANTOM_COUNT]; contour_point_t phantoms[glyf_impl::PHANTOM_COUNT];
if (unlikely (!get_points (font, gid, points_aggregator_t (font, &extents, phantoms)))) if (unlikely (!get_points (font, gid, points_aggregator_t (font, &extents, phantoms, true))))
return return
#ifndef HB_NO_VERTICAL #ifndef HB_NO_VERTICAL
is_vertical ? vmtx->get_side_bearing (gid) : is_vertical ? vmtx->get_side_bearing (gid) :