summaryrefslogtreecommitdiff
path: root/ted.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-07-18 16:32:29 -0400
committerpommicket <pommicket@gmail.com>2023-07-18 16:32:29 -0400
commit8f2258fcce0d3bd5e6cf1364bd58669391fbab7c (patch)
treee8bdc9ea407237beabd8f1c5b9b5307cc14beb6c /ted.c
parent2d2f0a09b180cf3bd6a2bc0ad3d21ea956398822 (diff)
start "multifonts"
Diffstat (limited to 'ted.c')
-rw-r--r--ted.c40
1 files changed, 34 insertions, 6 deletions
diff --git a/ted.c b/ted.c
index 73a5969..19d360c 100644
--- a/ted.c
+++ b/ted.c
@@ -287,12 +287,13 @@ Status ted_get_file(Ted const *ted, const char *name, char *out, size_t outsz) {
return false;
}
-static Font *ted_load_font(Ted *ted, const char *filename) {
+static Font *ted_load_single_font(Ted *ted, const char *filename) {
char path[TED_PATH_MAX];
if (!ted_get_file(ted, filename, path, sizeof path)) {
- die("Couldn't find font file %s", filename);
+ ted_error(ted, "Couldn't find font file '%s'", filename);
+ return NULL;
}
-
+
arr_foreach_ptr(ted->all_fonts, LoadedFont, f) {
if (paths_eq(path, f->path))
return f->font;
@@ -300,20 +301,47 @@ static Font *ted_load_font(Ted *ted, const char *filename) {
Font *font = text_font_load(path, ted_active_settings(ted)->text_size);
if (!font) {
- die("Couldn't load font %s: %s\n", path, text_get_err());
+ ted_error(ted, "Couldn't load font '%s': %s\n", path, text_get_err());
+ return NULL;
}
LoadedFont *f = arr_addp(ted->all_fonts);
f->path = str_dup(path);
f->font = font;
+ return font;
+}
+
+static Font *ted_load_multifont(Ted *ted, const char *filenames) {
+ char filename[TED_PATH_MAX];
+ Font *font = NULL;
+
+ while (*filenames) {
+ while (*filenames == ',') ++filenames;
+ size_t len = strcspn(filenames, ",");
+ strn_cpy(filename, sizeof filename, filenames, len);
+ str_trim(filename);
+ if (*filename) {
+ font = ted_load_single_font(ted, filename);
+ }
+ filenames += len;
+ }
return font;
}
void ted_load_fonts(Ted *ted) {
ted_free_fonts(ted);
- ted->font = ted_load_font(ted, "assets/font.ttf");
- ted->font_bold = ted_load_font(ted, "assets/font-bold.ttf");
+ Settings *settings = ted_active_settings(ted);
+ ted->font = ted_load_multifont(ted, settings->font);
+ if (!ted->font) {
+ ted->font = ted_load_multifont(ted, "assets/font.ttf");
+ if (!ted->font)
+ die("Couldn't load default font: %s.", ted->message);
+ }
+ ted->font_bold = ted_load_multifont(ted, settings->font_bold);
+ if (!ted->font_bold) {
+ ted->font_bold = ted->font;
+ }
}
void ted_change_text_size(Ted *ted, float new_size) {