src/font.c

changeset 253
6ab35fcb8676
parent 214
9d460888a83e
equal deleted inserted replaced
252:42e8695372f7 253:6ab35fcb8676
31 #include "ascension/font.h" 31 #include "ascension/font.h"
32 32
33 #include <assert.h> 33 #include <assert.h>
34 #include <math.h> 34 #include <math.h>
35 #include <cx/array_list.h> 35 #include <cx/array_list.h>
36
37 #include <SDL3_ttf/SDL_ttf.h>
36 38
37 static const char *asc_font_filename(enum AscFontStyle style) { 39 static const char *asc_font_filename(enum AscFontStyle style) {
38 switch (style) { 40 switch (style) {
39 case ASC_FONT_REGULAR: 41 case ASC_FONT_REGULAR:
40 return "OpenSans-Regular.ttf"; 42 return "OpenSans-Regular.ttf";
95 cxmutstr fpath = asc_filesystem_combine_paths(cx_strcast(asc_context.font_path), cx_str(font_name)); 97 cxmutstr fpath = asc_filesystem_combine_paths(cx_strcast(asc_context.font_path), cx_str(font_name));
96 asc_dprintf("Load font from %" CX_PRIstr, CX_SFMT(fpath)); 98 asc_dprintf("Load font from %" CX_PRIstr, CX_SFMT(fpath));
97 entry.ttf = TTF_OpenFont(fpath.ptr, font.size); 99 entry.ttf = TTF_OpenFont(fpath.ptr, font.size);
98 cx_strfree(&fpath); 100 cx_strfree(&fpath);
99 if (entry.ttf == NULL) { 101 if (entry.ttf == NULL) {
100 asc_error("Failed to load font %s: %s", font_name, TTF_GetError()); 102 asc_error("Failed to load font %s: %s", font_name, SDL_GetError());
101 return NULL; 103 return NULL;
102 } else { 104 } else {
103 cxListAdd(asc_font_cache, &entry); 105 cxListAdd(asc_font_cache, &entry);
104 asc_dprintf("Loaded font size %d, style %d from %s", font.size, font.style, font_name); 106 asc_dprintf("Loaded font size %d, style %d from %s", font.size, font.style, font_name);
105 return entry.ttf; 107 return entry.ttf;

mercurial