aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2023-07-21 06:17:32 +0000
committerDaniel Eklöf <daniel@ekloef.se>2023-07-21 06:17:32 +0000
commitb3255465f1d4d5a96fbd7acee846db0e14026507 (patch)
treead1d707570654f125578087ded7bbd475d1e1ee8
parentMerge branch 'systemd-units-socket-activation' (diff)
render: change baseline calculation, to center it within the line
Before this patch, fonts were anchored to the top of the line. With this patch, it is instead centered. Closes #1302
-rw-r--r--CHANGELOG.md3
-rw-r--r--render.c7
2 files changed, 9 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 29380684..bda563dd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -59,10 +59,13 @@
`footclient` now tries `$XDG_RUNTIME_DIR/foot.sock`, then
`/tmp/foot.sock`, even if `$WAYLAND_DISPLAY` and/or
`$XDG_RUNTIME_DIR` are defined ([#1281][1281]).
+* Font baseline calculation: try to center the text within the line,
+ instead of anchoring it at the top ([#1302][1302]).
[starlight-v4]: https://github.com/CosmicToast/starlight/blob/v4/CHANGELOG.md#v4
[1416]: https://codeberg.org/dnkl/foot/issues/1416
[1281]: https://codeberg.org/dnkl/foot/pulls/1281
+[1302]: https://codeberg.org/dnkl/foot/issues/1302
### Deprecated
diff --git a/render.c b/render.c
index 11c2456a..48957a0a 100644
--- a/render.c
+++ b/render.c
@@ -305,7 +305,12 @@ color_brighten(const struct terminal *term, uint32_t color)
static inline int
font_baseline(const struct terminal *term)
{
- return term->font_y_ofs + term->fonts[0]->ascent;
+ const struct fcft_font *font = term->fonts[0];
+ const int line_height = term->cell_height;
+ const int font_height = font->ascent + font->descent;
+ const int glyph_top_y = round((line_height - font_height) / 2.);
+
+ return term->font_y_ofs + glyph_top_y + font->ascent;
}
static void