diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-04-20 21:55:47 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-04-20 21:55:47 +0200 |
| commit | a46daccc110b6a43bf1dba928d7f1f1e72a14d81 (patch) | |
| tree | ef66aacc32657452b8b435a2f5e732b49b08f41f /drw.c | |
| parent | a4a86549a939dee9da41f28efe7435ba4884f1a6 (diff) | |
fix missing font crash and use color index as rgb if not found
Diffstat (limited to 'drw.c')
| -rw-r--r-- | drw.c | 28 |
1 files changed, 18 insertions, 10 deletions
@@ -202,9 +202,14 @@ create_font_family(FontPath fontpath) FontFamily *fontfamily = malloc(sizeof(FontFamily)); for (i = 0; i < FONT_TYPE_SIZE; ++i) { + (*fontfamily)[i].path = 0; + (*fontfamily)[i].loaded = 0; + (*fontfamily)[i].face = 0; + (*fontfamily)[i].library = 0; + (*fontfamily)[i].stroke = 0; + if (fontpath[i]) { (*fontfamily)[i].path = fontpath[i]; - (*fontfamily)[i].loaded = 0; } } @@ -232,17 +237,19 @@ init_font(Font *font) error = FT_Init_FreeType(&font->library); if (error) - die("cannot init library"); + die("cannot init library:"); error = FT_New_Face(font->library, font->path, 0, &font->face); if (error) - die("cannot open face"); + die("cannot open face:"); error = FT_Select_Charmap(font->face, ft_encoding_unicode); if (error) - die("cannot set unicode"); + die("cannot set unicode:"); FT_Stroker_New(font->library, &font->stroke); + + font->loaded = 1; } @@ -306,10 +313,8 @@ get_font_with_charcode(FontCache *fontcache, uint_least32_t charcode) if (!font->path) continue; - if (!font->loaded) { + if (!font->loaded) init_font(font); - font->loaded = 1; - } glyph_index = FT_Get_Char_Index(font->face, charcode); @@ -317,9 +322,10 @@ get_font_with_charcode(FontCache *fontcache, uint_least32_t charcode) return font; } - font = fontcache->first->family[fontcache->fonttype]; - init_font(font); - font->loaded = 1; + font = &(*fontcache->first->family)[fontcache->fonttype]; + if (!font->loaded) + init_font(font); + return font; } @@ -337,9 +343,11 @@ draw_char(Canvas *canvas, FontCache *fontcache, uint_least32_t charcode, unsigne FT_BitmapGlyph bg; FT_Glyph glyph; + font = get_font_with_charcode(fontcache, charcode); FT_Set_Pixel_Sizes(font->face, 0, fontcache->fontsize); + if (boldstokemode && fontcache->fonttype == FONT_BOLD) { FT_Stroker_Set(font->stroke, fontcache->fontsize * 2, FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, fontcache->fontsize * 2); |