From 73b4d5d05ab3d3059017a0d3e2a5c798a241da87 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 30 Jul 2019 18:04:28 +0200 Subject: font: add support for fallback fonts A top-level font now has a list of fallback fonts. When a glyph cannot be found, we try each fallback font in turn, until we either find one that has the glyph, or until we've exhausted the list. To make this actually work in practise (read: to make performance acceptable), the cache is re-worked and is now populated on demand. It also supports non-ASCII characters, by using the 4-byte unicode character as index instead. Since having an array that can be indexed by a 4-byte value isn't really viable, we now have a simple hash table instead of an array. --- config.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index dda3c635..08156d16 100644 --- a/config.c +++ b/config.c @@ -147,8 +147,12 @@ parse_section_main(const char *key, const char *value, struct config *conf, } else if (strcmp(key, "font") == 0) { - free(conf->font); - conf->font = strdup(value); + //free(conf->font); + //conf->font = strdup(value); + char *copy = strdup(value); + for (const char *font = strtok(copy, ","); font != NULL; font = strtok(NULL, ",")) + tll_push_back(conf->fonts, strdup(font)); + free(copy); } else if (strcmp(key, "workers") == 0) { @@ -404,7 +408,7 @@ config_load(struct config *conf) *conf = (struct config) { .term = strdup("foot"), .shell = get_shell(), - .font = strdup("monospace"), + .fonts = tll_init(), .colors = { .fg = default_foreground, @@ -462,6 +466,7 @@ config_load(struct config *conf) fclose(f); out: + tll_push_back(conf->fonts, strdup("monospace")); free(path); return ret; } @@ -471,5 +476,6 @@ config_free(struct config conf) { free(conf.term); free(conf.shell); - free(conf.font); + //free(conf.font); + tll_free_and_free(conf.fonts, free); } -- cgit v1.3