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.
This commit is contained in:
Daniel Eklöf 2022-11-24 14:34:31 +01:00
parent f31ea4f56d
commit 94bac0513a
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -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);
}