aboutsummaryrefslogtreecommitdiff
path: root/terminal.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2023-10-11 14:31:53 +0000
committerDaniel Eklöf <daniel@ekloef.se>2023-10-11 14:31:53 +0000
commit6e58bd835126c90d1bbd38edad3ef769068ca368 (patch)
tree16ca700c8bb42ab78f141467c811fdf24107e0b5 /terminal.c
parentrender: better description of why we disable transparency in fullscreen (diff)
parentterm: cache font baseline (diff)
Merge branch 'fix-font-baseline-calculation'
Closes #1511 Closes #1463
Diffstat (limited to 'terminal.c')
-rw-r--r--terminal.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/terminal.c b/terminal.c
index 9a76488e..efbbded1 100644
--- a/terminal.c
+++ b/terminal.c
@@ -774,6 +774,8 @@ term_set_fonts(struct terminal *term, struct fcft_font *fonts[static 4],
term->font_x_ofs = term_pt_or_px_as_pixels(term, &conf->horizontal_letter_offset);
term->font_y_ofs = term_pt_or_px_as_pixels(term, &conf->vertical_letter_offset);
+ term->font_baseline = term_font_baseline(term);
+
LOG_INFO("cell width=%d, height=%d", term->cell_width, term->cell_height);
sixel_cell_size_changed(term);
@@ -2189,10 +2191,18 @@ term_font_baseline(const struct terminal *term)
{
const struct fcft_font *font = term->fonts[0];
const int line_height = term->cell_height;
- const int font_height = max(font->height, font->ascent + font->descent);
- const int glyph_top_y = round((line_height - font_height) / 2.);
+ const int font_height = font->ascent + font->descent;
+
+ /*
+ * Center glyph on the line *if* using a custom line height,
+ * otherwise the baseline is simply 'descent' pixels above the
+ * bottom of the cell
+ */
+ const int glyph_top_y = term->font_line_height.px >= 0
+ ? round((line_height - font_height) / 2.)
+ : 0;
- return term->font_y_ofs + glyph_top_y + font->ascent;
+ return term->font_y_ofs + line_height - glyph_top_y - font->descent;
}
void