aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2022-11-24 18:17:09 +0000
committerDaniel Eklöf <daniel@ekloef.se>2022-11-24 18:17:09 +0000
commit4d03b6c611523412590398072dce7b439c5597eb (patch)
tree7a7c044952876b045058f1d11d418189f013ff71
parentreadme/foot.1: mention that we now need “-d info” to get log output (diff)
parentchangelog: scaling factor not being applied when converting px-to-pt (diff)
Merge branch 'line-height-adjust'
Closes #1218
-rw-r--r--CHANGELOG.md5
-rw-r--r--terminal.c46
2 files changed, 39 insertions, 12 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ba339100..c5584b45 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -98,11 +98,16 @@
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]).
+* 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
[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
diff --git a/terminal.c b/terminal.c
index 6cb419be..1914a229 100644
--- a/terminal.c
+++ b/terminal.c
@@ -704,6 +704,37 @@ 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) {
+ 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.;
+
+ 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 +761,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);
@@ -913,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 {
@@ -1078,7 +1111,6 @@ load_fonts_from_conf(struct terminal *term)
}
}
- term->font_line_height = term->conf->line_height;
return reload_fonts(term);
}
@@ -1298,7 +1330,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,15 +2061,6 @@ 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;
-
- term->font_line_height.px = 0;
- term->font_line_height.pt = fmaxf(old_pt_size + amount, 0.);
- }
-
return reload_fonts(term);
}