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. --- main.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index bdb1de3e..cc2fd054 100644 --- a/main.c +++ b/main.c @@ -291,8 +291,8 @@ main(int argc, char *const *argv) break; case 'f': - free(conf.font); - conf.font = strdup(optarg); + tll_free_and_free(conf.fonts, free); + tll_push_back(conf.fonts, strdup(optarg)); break; case 'h': @@ -431,20 +431,20 @@ main(int argc, char *const *argv) thrd_create(&term.render.workers.threads[i], &render_worker_thread, &worker_context[i]); } - if (!font_from_name(conf.font, &term.fonts[0])) - goto out; + font_list_t font_names = tll_init(); + tll_foreach(conf.fonts, it) + tll_push_back(font_names, it->item); - { - char fname[1024]; - snprintf(fname, sizeof(fname), "%s:style=bold", conf.font); - font_from_name(fname, &term.fonts[1]); + if (!font_from_name(font_names, "", &term.fonts[0])) { + tll_free(font_names); + goto out; + } - snprintf(fname, sizeof(fname), "%s:style=italic", conf.font); - font_from_name(fname, &term.fonts[2]); + font_from_name(font_names, "style=bold", &term.fonts[1]); + font_from_name(font_names, "style=italic", &term.fonts[2]); + font_from_name(font_names, "style=bold italic", &term.fonts[3]); - snprintf(fname, sizeof(fname), "%s:style=bold italic", conf.font); - font_from_name(fname, &term.fonts[3]); - } + tll_free(font_names); /* Underline position and size */ for (size_t i = 0; i < sizeof(term.fonts) / sizeof(term.fonts[0]); i++) { -- cgit v1.3