From f65eab255cb8cd41ccf72f2496d441a799765775 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 12 Aug 2026 18:16:08 -0600 Subject: [PATCH] [cairo] Widen glyph position accumulation The Cairo adapter accumulated full-range glyph positions in signed HarfBuzz positions before converting them to doubles. Accumulate and negate in double precision instead, and clamp the scale passed back to the HarfBuzz font. This is part of the complete position-overflow fix for issue #6151. Testing: meson test -C build --print-errorlogs Assisted-by: Codex --- src/hb-cairo.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/hb-cairo.cc b/src/hb-cairo.cc index add26bea7..04440c19a 100644 --- a/src/hb-cairo.cc +++ b/src/hb-cairo.cc @@ -549,8 +549,8 @@ hb_cairo_init_scaled_font (cairo_scaled_font_t *scaled_font, cairo_matrix_t font_matrix; cairo_scaled_font_get_scale_matrix (scaled_font, &font_matrix); hb_font_set_scale (font, - round (font_matrix.xx * scale_factor), - round (font_matrix.yy * scale_factor)); + hb_clamp_to (round (font_matrix.xx * scale_factor)), + hb_clamp_to (round (font_matrix.yy * scale_factor))); } auto *init_func = (hb_cairo_font_init_func_t) @@ -578,7 +578,7 @@ hb_cairo_init_scaled_font (cairo_scaled_font_t *scaled_font, hb_font_get_h_extents (font, &hb_extents); extents->ascent = (double) hb_extents.ascender / y_scale; - extents->descent = (double) -hb_extents.descender / y_scale; + extents->descent = -(double) hb_extents.descender / y_scale; extents->height = extents->ascent + extents->descent; #ifdef HAVE_CAIRO_USER_FONT_FACE_SET_RENDER_COLOR_GLYPH_FUNC @@ -1014,15 +1014,15 @@ hb_cairo_glyphs_from_buffer (hb_buffer_t *buffer, double x_scale = x_scale_factor ? 1. / x_scale_factor : 0.; double y_scale = y_scale_factor ? 1. / y_scale_factor : 0.; - hb_position_t hx = 0, hy = 0; + double hx = 0, hy = 0; int i; for (i = 0; i < (int) *num_glyphs; i++) { (*glyphs)[i].index = hb_glyph[i].codepoint; - (*glyphs)[i].x = x + (+hb_position->x_offset + hx) * x_scale; - (*glyphs)[i].y = y + (-hb_position->y_offset + hy) * y_scale; + (*glyphs)[i].x = x + ((double) hb_position->x_offset + hx) * x_scale; + (*glyphs)[i].y = y + (-(double) hb_position->y_offset + hy) * y_scale; hx += hb_position->x_advance; - hy += -hb_position->y_advance; + hy -= hb_position->y_advance; hb_position++; }