From c19cbaad24655d618c8f40e5fa743a910f3a0747 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 20 Feb 2019 06:19:54 +0530 Subject: [PATCH] Handle wrap around when using negative values for adjust cell sizes --- kitty/fonts.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/kitty/fonts.c b/kitty/fonts.c index 0ad9b33ca..e2ef5f171 100644 --- a/kitty/fonts.c +++ b/kitty/fonts.c @@ -393,11 +393,15 @@ calc_cell_metrics(FontGroup *fg) { cell_metrics(fg->fonts[fg->medium_font_idx].face, &cell_width, &cell_height, &baseline, &underline_position, &underline_thickness); if (!cell_width) fatal("Failed to calculate cell width for the specified font"); unsigned int before_cell_height = cell_height; - if (OPT(adjust_line_height_px) != 0) cell_height += OPT(adjust_line_height_px); - if (OPT(adjust_line_height_frac) != 0.f) cell_height *= OPT(adjust_line_height_frac); - if (OPT(adjust_column_width_px != 0)) cell_width += OPT(adjust_column_width_px); - if (OPT(adjust_column_width_frac) != 0.f) cell_width *= OPT(adjust_column_width_frac); - cell_width = MAX(2, cell_width); + int cw = cell_width, ch = cell_height; + if (OPT(adjust_line_height_px) != 0) ch += OPT(adjust_line_height_px); + if (OPT(adjust_line_height_frac) != 0.f) ch *= OPT(adjust_line_height_frac); + if (OPT(adjust_column_width_px != 0)) cw += OPT(adjust_column_width_px); + if (OPT(adjust_column_width_frac) != 0.f) cw *= OPT(adjust_column_width_frac); + if (cw >= 2 && cw < 1000) cell_width = cw; + else log_error("Cell width invalid after adjustment, ignoring adjust_column_width"); + if (ch >= 4 && ch < 1000) cell_height = ch; + else log_error("Cell height invalid after adjustment, ignoring adjust_line_height"); int line_height_adjustment = cell_height - before_cell_height; if (cell_height < 4) fatal("Line height too small after adjustment"); if (cell_height > 1000) fatal("Line height too large after adjustment");