From 5a54423000ad0cffec0178a6091c87d75110eee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 23 Nov 2022 16:15:32 +0100 Subject: [PATCH] term: adjust user-set line-height by the same percentage as the primary font MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this patch, a user-set line-height was increased/decreased by the exact same amount of pt’s as the font(s). This means, that when there’s a large discrepancy between the line-height and the font size, the proportion between the line’s height and the font size will change as we increase or decrease the font size. This patch changes how the line height is adjusted when the font size is incremented or decremented. We calculate the difference, in percent, between the primary font’s original (default) size, and its current size, and then apply that to the configured line-height. Closes #1218 --- terminal.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/terminal.c b/terminal.c index 6cb419be..ea934df9 100644 --- a/terminal.c +++ b/terminal.c @@ -2031,12 +2031,20 @@ term_font_size_adjust(struct terminal *term, double amount) } if (term->font_line_height.px >= 0) { - float old_pt_size = term->font_line_height.px > 0 - ? term->font_line_height.px * 72. / dpi - : term->font_line_height.pt; + const struct config *conf = term->conf; + + const float font_original_pt_size = + conf->fonts[0].arr[0].px_size > 0 + ? conf->fonts[0].arr[0].px_size * 72. / dpi + : conf->fonts[0].arr[0].pt_size; + + const float change = term->font_sizes[0][0].pt_size / font_original_pt_size; + const float line_original_pt_size = conf->line_height.px > 0 + ? conf->line_height.px * 72. / dpi + : conf->line_height.pt; term->font_line_height.px = 0; - term->font_line_height.pt = fmaxf(old_pt_size + amount, 0.); + term->font_line_height.pt = fmaxf(line_original_pt_size * change, 0.); } return reload_fonts(term);