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.
This commit is contained in:
Daniel Eklöf 2019-07-30 18:04:28 +02:00
parent 85ef9df586
commit 73b4d5d05a
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
7 changed files with 280 additions and 127 deletions

28
main.c
View file

@ -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,21 +431,21 @@ 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]))
font_list_t font_names = tll_init();
tll_foreach(conf.fonts, it)
tll_push_back(font_names, it->item);
if (!font_from_name(font_names, "", &term.fonts[0])) {
tll_free(font_names);
goto out;
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s:style=bold", conf.font);
font_from_name(fname, &term.fonts[1]);
snprintf(fname, sizeof(fname), "%s:style=italic", conf.font);
font_from_name(fname, &term.fonts[2]);
snprintf(fname, sizeof(fname), "%s:style=bold italic", conf.font);
font_from_name(fname, &term.fonts[3]);
}
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]);
tll_free(font_names);
/* Underline position and size */
for (size_t i = 0; i < sizeof(term.fonts) / sizeof(term.fonts[0]); i++) {
struct font *f = &term.fonts[i];