From 2f0dbf7766d55cd924218b07ef611b6af0995a7f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 5 Feb 2025 09:15:49 +0530 Subject: [PATCH] Fix #8286 --- kitty/fonts.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/kitty/fonts.c b/kitty/fonts.c index 68ac167893..094594abde 100644 --- a/kitty/fonts.c +++ b/kitty/fonts.c @@ -845,25 +845,24 @@ apply_scale_to_font_group(FontGroup *fg, RunFont *rf) { float scale = rf ? scaled_cell_dimensions(*rf, &scaled_cell_width, &scaled_cell_height) : 1.f; scaled_font_map_t_itr i = vt_get(&fg->scaled_font_map, scale); ScaledFontData sfd; +#define apply_scaling(which_fg) if (!face_apply_scaling(medium_font->face, (FONTS_DATA_HANDLE)(which_fg))) { \ + if (PyErr_Occurred()) PyErr_Print(); \ + fatal("Could not apply scale of %f to font group at size: %f", scale, (which_fg)->font_sz_in_pts); \ + } + if (vt_is_end(i)) { Font *medium_font = &fg->fonts[fg->medium_font_idx]; FontGroup copy = {.fcm=fg->fcm, .logical_dpi_x=fg->logical_dpi_x, .logical_dpi_y=fg->logical_dpi_y}; copy.fcm.cell_width = scaled_cell_width; copy.fcm.cell_height = scaled_cell_height; copy.font_sz_in_pts = scale * fg->font_sz_in_pts; - if (!face_apply_scaling(medium_font->face, (FONTS_DATA_HANDLE)©)) { - if (PyErr_Occurred()) PyErr_Print(); - fatal("Could not apply scale of %f to font group at size: %f", scale, copy.font_sz_in_pts); - } + apply_scaling(©); calc_cell_metrics(©, medium_font->face); if (copy.fcm.cell_width > scaled_cell_width || copy.fcm.cell_height > scaled_cell_height) { float wfrac = (float)copy.fcm.cell_width / scaled_cell_width, hfrac = (float)copy.fcm.cell_height / scaled_cell_height; float frac = MIN(wfrac, hfrac); copy.font_sz_in_pts *= frac; while(true) { - if (!face_apply_scaling(medium_font->face, (FONTS_DATA_HANDLE)©)) { - if (PyErr_Occurred()) PyErr_Print(); - fatal("Could not apply scale of %f to font group at size: %f", scale, copy.font_sz_in_pts); - } + apply_scaling(©); calc_cell_metrics(©, medium_font->face); if (copy.fcm.cell_width <= scaled_cell_width && copy.fcm.cell_height <= scaled_cell_height) break; if (copy.font_sz_in_pts < 1) fatal("Could not apply scale of %f to font group as font size (%f) is less than minimum threshold", scale, copy.font_sz_in_pts); @@ -873,10 +872,12 @@ apply_scale_to_font_group(FontGroup *fg, RunFont *rf) { sfd.fcm = copy.fcm; sfd.font_sz_in_pts = copy.font_sz_in_pts; sfd.fcm.cell_width = scaled_cell_width; sfd.fcm.cell_height = scaled_cell_height; if (vt_is_end(vt_insert(&fg->scaled_font_map, scale, sfd))) fatal("Out of memory inserting scaled font data into map"); + apply_scaling(fg); } else sfd = i.data->val; fg->font_sz_in_pts = sfd.font_sz_in_pts; fg->fcm = sfd.fcm; return scale; +#undef apply_scaling } static pixel*