aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2023-04-20 21:55:47 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2023-04-20 21:55:47 +0200
commita46daccc110b6a43bf1dba928d7f1f1e72a14d81 (patch)
treeef66aacc32657452b8b435a2f5e732b49b08f41f
parenta4a86549a939dee9da41f28efe7435ba4884f1a6 (diff)
fix missing font crash and use color index as rgb if not found
-rw-r--r--drw.c28
-rw-r--r--swt.c9
2 files changed, 23 insertions, 14 deletions
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);
diff --git a/swt.c b/swt.c
index 446267a..b16447d 100644
--- a/swt.c
+++ b/swt.c
@@ -72,7 +72,7 @@ static int execshortcut();
static char *kmap();
static void buffer_release(void *data, struct wl_buffer *buffer);
static void draw_frame();
-static uint32_t get_color(int i);
+static uint32_t get_color(uint32_t i);
static void draw_glyph(Glyph g, int x, int y);
static void commit_surface();
static void surface_configure(void *data, struct xdg_surface *surface, uint32_t serial);
@@ -216,10 +216,11 @@ paste()
uint32_t
-get_color(int i)
+get_color(uint32_t i)
{
- if (!BETWEEN(i, 0, sizeof(colors) / sizeof(uint32_t)))
- return colors[defaultbg];
+ if (!BETWEEN(i, 0, sizeof(colors) / sizeof(uint32_t))) {
+ return i;
+ }
return colors[i];
}