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 1/6] 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); From f31ea4f56d6ff560ad16f9c18528881ee8077dba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 23 Nov 2022 16:23:01 +0100 Subject: [PATCH 2/6] changelog: line-height adjustment with user-set line-height --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba339100..499b4275 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -98,11 +98,14 @@ cursor. Only applies to block cursor using inversed fg/bg colors. ([#1205][1205]). * Crash when monitor’s physical size is "too small" ([#1209][1209]). +* Line-height adjustment when incrementing/decrementing the font size + with a user-set line-height ([#1218][1218]). [1173]: https://codeberg.org/dnkl/foot/issues/1173 [1190]: https://codeberg.org/dnkl/foot/issues/1190 [1205]: https://codeberg.org/dnkl/foot/issues/1205 [1209]: https://codeberg.org/dnkl/foot/issues/1209 +[1218]: https://codeberg.org/dnkl/foot/issues/1218 ### Security From 94bac0513ab3ca78464d8e79c153c8ee4bac835f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 24 Nov 2022 14:34:31 +0100 Subject: [PATCH 3/6] term: update user-set line-height just before calculating the cell dimensions This ensures *all* font-size affecting changes (DPI, output scaling, font size increment/decrement) also updates the line-height. --- terminal.c | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/terminal.c b/terminal.c index ea934df9..3af436a4 100644 --- a/terminal.c +++ b/terminal.c @@ -704,6 +704,34 @@ free_custom_glyphs(struct fcft_glyph ***glyphs, size_t count) *glyphs = NULL; } +static void +term_line_height_update(struct terminal *term) +{ + const struct config *conf = term->conf; + + if (term->conf->line_height.px < 0) + return; + + const float dpi = term->font_is_sized_by_dpi ? term->font_dpi : 96.; + + 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 font_current_pt_size = + term->font_sizes[0][0].px_size > 0 + ? term->font_sizes[0][0].px_size * 72. / dpi + : term->font_sizes[0][0].pt_size; + + const float change = font_current_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(line_original_pt_size * change, 0.); +} + static bool term_set_fonts(struct terminal *term, struct fcft_font *fonts[static 4]) { @@ -730,6 +758,8 @@ term_set_fonts(struct terminal *term, struct fcft_font *fonts[static 4]) fonts[0], U'M', term->font_subpixel); int advance = M != NULL ? M->advance.x : term->fonts[0]->max_advance.x; + term_line_height_update(term); + term->cell_width = advance + term_pt_or_px_as_pixels(term, &conf->letter_spacing); @@ -1078,7 +1108,6 @@ load_fonts_from_conf(struct terminal *term) } } - term->font_line_height = term->conf->line_height; return reload_fonts(term); } @@ -1298,7 +1327,6 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, .pt_size = font->pt_size, .px_size = font->px_size}; } } - term->font_line_height = conf->line_height; add_utmp_record(conf, reaper, ptmx); @@ -2030,23 +2058,6 @@ term_font_size_adjust(struct terminal *term, double amount) } } - if (term->font_line_height.px >= 0) { - 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(line_original_pt_size * change, 0.); - } - return reload_fonts(term); } From e85257bcae116f5e6148e38690e2ec95b586d451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 24 Nov 2022 17:09:31 +0100 Subject: [PATCH 4/6] =?UTF-8?q?term:=20initialize=20term->font=5Fline=5Fhe?= =?UTF-8?q?ight=20when=20there=E2=80=99s=20no=20user-set=20line-height?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- terminal.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/terminal.c b/terminal.c index 3af436a4..429a4cc3 100644 --- a/terminal.c +++ b/terminal.c @@ -709,8 +709,11 @@ term_line_height_update(struct terminal *term) { const struct config *conf = term->conf; - if (term->conf->line_height.px < 0) + if (term->conf->line_height.px < 0) { + term->font_line_height.pt = 0; + term->font_line_height.px = -1; return; + } const float dpi = term->font_is_sized_by_dpi ? term->font_dpi : 96.; From fa6b07abeacfb5b8a70bc762e9c8ff64470c4d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 24 Nov 2022 17:20:05 +0100 Subject: [PATCH 5/6] term: apply scale factor when converting a px value to pt --- terminal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terminal.c b/terminal.c index 429a4cc3..1914a229 100644 --- a/terminal.c +++ b/terminal.c @@ -946,7 +946,7 @@ term_pt_or_px_as_pixels(const struct terminal *term, return pt_or_px->px == 0 ? round(pt_or_px->pt * scale * dpi / 72) - : pt_or_px->px; + : pt_or_px->px * scale; } struct font_load_data { From db2627ea26564fc1b8bfc890e42c90a2cde48a6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 24 Nov 2022 17:21:53 +0100 Subject: [PATCH 6/6] changelog: scaling factor not being applied when converting px-to-pt --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 499b4275..c5584b45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,6 +100,8 @@ * Crash when monitor’s physical size is "too small" ([#1209][1209]). * Line-height adjustment when incrementing/decrementing the font size with a user-set line-height ([#1218][1218]). +* Scaling factor not being correctly applied when converting pt-or-px + config values (e.g. letter offsets, line height etc). [1173]: https://codeberg.org/dnkl/foot/issues/1173 [1190]: https://codeberg.org/dnkl/foot/issues/1190