aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-02-08 16:57:50 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-02-08 16:57:50 +0000
commit6c0d00fcee760be86d13366cf5d1fbf9a78a34b2 (patch)
treeead3800da9afc0be5861181be1fa369ecd7065c6
parentmeson/PKGBUILD: bump fcft required version to 1.2.0 (diff)
term: add term_font_size_reset()
-rw-r--r--terminal.c45
-rw-r--r--terminal.h1
2 files changed, 39 insertions, 7 deletions
diff --git a/terminal.c b/terminal.c
index 75b400d3..72d98104 100644
--- a/terminal.c
+++ b/terminal.c
@@ -507,7 +507,8 @@ initialize_render_workers(struct terminal *term)
}
static bool
-initialize_fonts(struct terminal *term, const struct config *conf)
+initialize_fonts(const struct terminal *term, const struct config *conf,
+ struct font *fonts[static 4])
{
const size_t count = tll_length(conf->fonts);
const char *names[count];
@@ -529,11 +530,21 @@ initialize_fonts(struct terminal *term, const struct config *conf)
snprintf(attrs2, sizeof(attrs2), "dpi=%u:slant=italic", dpi);
snprintf(attrs3, sizeof(attrs3), "dpi=%u:weight=bold:slant=italic", dpi);
- return (
- (term->fonts[0] = font_from_name(count, names, attrs0)) != NULL &&
- (term->fonts[1] = font_from_name(count, names, attrs1)) != NULL &&
- (term->fonts[2] = font_from_name(count, names, attrs2)) != NULL &&
- (term->fonts[3] = font_from_name(count, names, attrs3)) != NULL);
+ fonts[0] = fonts[1] = fonts[2] = fonts[3] = NULL;
+ bool ret =
+ (fonts[0] = font_from_name(count, names, attrs0)) != NULL &&
+ (fonts[1] = font_from_name(count, names, attrs1)) != NULL &&
+ (fonts[2] = font_from_name(count, names, attrs2)) != NULL &&
+ (fonts[3] = font_from_name(count, names, attrs3)) != NULL;
+
+ if (!ret) {
+ for (size_t i = 0; i < 4; i++) {
+ font_destroy(fonts[i]);
+ fonts[i] = NULL;
+ }
+ }
+
+ return ret;
}
struct terminal *
@@ -697,7 +708,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl,
initialize_color_cube(term);
if (!initialize_render_workers(term))
goto err;
- if (!initialize_fonts(term, conf))
+ if (!initialize_fonts(term, conf, term->fonts))
goto err;
/* Cell dimensions are based on the font metrics. Obviously */
@@ -1144,6 +1155,26 @@ term_font_size_decrease(struct terminal *term)
}
void
+term_font_size_reset(struct terminal *term)
+{
+ struct font *fonts[4];
+ 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);
+}
+
+void
term_damage_rows(struct terminal *term, int start, int end)
{
assert(start <= end);
diff --git a/terminal.h b/terminal.h
index e98b14c1..b4ce1212 100644
--- a/terminal.h
+++ b/terminal.h
@@ -365,6 +365,7 @@ bool term_to_slave(struct terminal *term, const void *data, size_t len);
void term_font_size_increase(struct terminal *term);
void term_font_size_decrease(struct terminal *term);
+void term_font_size_reset(struct terminal *term);
void term_damage_rows(struct terminal *term, int start, int end);
void term_damage_rows_in_view(struct terminal *term, int start, int end);