From a46daccc110b6a43bf1dba928d7f1f1e72a14d81 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Thu, 20 Apr 2023 21:55:47 +0200 Subject: fix missing font crash and use color index as rgb if not found --- drw.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'drw.c') diff --git a/drw.c b/drw.c index ff30811..3e8fed5 100644 --- a/drw.c +++ b/drw.c @@ -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); -- cgit v1.2.3-70-g09d2