aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-02-08 17:23:08 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-02-08 17:23:08 +0000
commit1dfd121c449d9c9bba9c520885e517afdc80b795 (patch)
tree27278f5d9acc01e8fcda3fa759b3ca7fd36fdc51
parentrender: resize: reset scroll damage (diff)
term: factor out common font changing code
-rw-r--r--terminal.c42
1 files changed, 20 insertions, 22 deletions
diff --git a/terminal.c b/terminal.c
index 72d98104..a07b1912 100644
--- a/terminal.c
+++ b/terminal.c
@@ -1112,6 +1112,24 @@ term_reset(struct terminal *term, bool hard)
}
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)
{
struct font *fonts[4] = {
@@ -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