From 1dfd121c449d9c9bba9c520885e517afdc80b795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 8 Feb 2020 18:23:08 +0100 Subject: [PATCH] term: factor out common font changing code --- terminal.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/terminal.c b/terminal.c index 72d98104..a07b1912 100644 --- a/terminal.c +++ b/terminal.c @@ -1111,6 +1111,24 @@ term_reset(struct terminal *term, bool hard) term_damage_all(term); } +static void +term_set_fonts(struct terminal *term, struct font *fonts[static 4]) +{ + for (size_t i = 0; i < 4; i++) { + assert(fonts[i] != NULL); + + font_destroy(term->fonts[i]); + term->fonts[i] = fonts[i]; + } + + term->cell_width = term->fonts[0]->space_x_advance > 0 + ? term->fonts[0]->space_x_advance : term->fonts[0]->max_x_advance; + term->cell_height = term->fonts[0]->height; + LOG_INFO("cell width=%d, height=%d", term->cell_width, term->cell_height); + + render_resize_force(term, term->width, term->height); +} + static void term_font_size_adjust(struct terminal *term, double amount) { @@ -1129,17 +1147,7 @@ term_font_size_adjust(struct terminal *term, double amount) return; } - for (size_t i = 0; i < 4; i++) { - font_destroy(term->fonts[i]); - term->fonts[i] = fonts[i]; - } - - term->cell_width = term->fonts[0]->space_x_advance > 0 - ? term->fonts[0]->space_x_advance : term->fonts[0]->max_x_advance; - term->cell_height = term->fonts[0]->height; - LOG_INFO("cell width=%d, height=%d", term->cell_width, term->cell_height); - - render_resize_force(term, term->width, term->height); + term_set_fonts(term, fonts); } void @@ -1161,17 +1169,7 @@ term_font_size_reset(struct terminal *term) if (!initialize_fonts(term, term->conf, fonts)) return; - for (size_t i = 0; i < 4; i++) { - font_destroy(term->fonts[i]); - term->fonts[i] = fonts[i]; - } - - term->cell_width = term->fonts[0]->space_x_advance > 0 - ? term->fonts[0]->space_x_advance : term->fonts[0]->max_x_advance; - term->cell_height = term->fonts[0]->height; - LOG_INFO("cell width=%d, height=%d", term->cell_width, term->cell_height); - - render_resize_force(term, term->width, term->height); + term_set_fonts(term, fonts); } void