[font] Clamp scaled glyph extents

Glyph extents can span the full position range supplied by a callback.
Scale widened rectangle endpoints and clamp the rounded result instead
of narrowing inputs and relying on overflowing position arithmetic.

This is part of the complete position-overflow fix for issue #6151.

Testing: meson test -C build --print-errorlogs

Assisted-by: Codex <codex@openai.com>
This commit is contained in:
Behdad Esfahbod committed 2026-08-12 17:58:38 -06:00
1 parent 160179e64f
commit 2a2a3792a5
1 file changed
+13 -8
+13 -8
View File
@@ -200,15 +200,20 @@ struct hb_font_t
void scale_glyph_extents (hb_glyph_extents_t *extents)
{
float x1 = em_fscale_x (extents->x_bearing);
float y1 = em_fscale_y (extents->y_bearing);
float x2 = em_fscale_x (extents->x_bearing + extents->width);
float y2 = em_fscale_y (extents->y_bearing + extents->height);
float x1 = em_fscalef_x ((float) extents->x_bearing);
float y1 = em_fscalef_y ((float) extents->y_bearing);
float x2 = em_fscalef_x ((float) ((int64_t) extents->x_bearing + extents->width));
float y2 = em_fscalef_y ((float) ((int64_t) extents->y_bearing + extents->height));
extents->x_bearing = floorf (x1);
extents->y_bearing = floorf (y1);
extents->width = ceilf (x2) - extents->x_bearing;
extents->height = ceilf (y2) - extents->y_bearing;
double rx1 = floorf (x1);
double ry1 = floorf (y1);
double rx2 = ceilf (x2);
double ry2 = ceilf (y2);
extents->x_bearing = hb_clamp_to<hb_position_t> (rx1);
extents->y_bearing = hb_clamp_to<hb_position_t> (ry1);
extents->width = hb_clamp_to<hb_position_t> (rx2 - rx1);
extents->height = hb_clamp_to<hb_position_t> (ry2 - ry1);
}
void synthetic_glyph_extents (hb_glyph_extents_t *extents)