From e989867f4871bba564cd5dcc0de64da8ead36058 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Thu, 28 Dec 2023 12:10:57 -0500 Subject: [PATCH 1/3] ply-utils: Use lstat instead of stat for ply_file_exists If a file is a symlink, we usually want to follow it, so testing the symlink itself, is less than optimal. This commit switches to lstat instead of stat. --- src/libply/ply-utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c index 95b505b1..a71d8de8 100644 --- a/src/libply/ply-utils.c +++ b/src/libply/ply-utils.c @@ -518,7 +518,7 @@ ply_file_exists (const char *file) { struct stat file_info; - if (stat (file, &file_info) < 0) + if (lstat (file, &file_info) < 0) return false; return S_ISREG (file_info.st_mode); From d8fd8e222c74d3a628b13e0dc2f99f3c9c765df3 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Thu, 28 Dec 2023 12:15:20 -0500 Subject: [PATCH 2/3] label-freetype: Don't bother loading fallback font if it doesn't exist If the fallback font doesn't exist, we shouldn't even try to load it, there's no point. Instead, put a nice error in the log. --- src/plugins/controls/label-freetype/plugin.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/plugins/controls/label-freetype/plugin.c b/src/plugins/controls/label-freetype/plugin.c index 403541f4..02b6f899 100644 --- a/src/plugins/controls/label-freetype/plugin.c +++ b/src/plugins/controls/label-freetype/plugin.c @@ -165,6 +165,11 @@ set_font_with_fallback (ply_label_plugin_control_t *label, if (fallback_font_path != NULL && error != 0) { ply_trace ("Could not load font '%s', trying fallback font '%s' (error %d)", primary_font_path?: "(unset)", fallback_font_path, (int) error); + + if (!ply_file_exists (fallback_font_path)) { + ply_trace ("Fallback font '%s' does not exist!", fallback_font_path); + return error; + } error = FT_New_Face (label->library, fallback_font_path, 0, &label->face); } From 8cd615f1882f6c4171d78debe772582bf032cd9e Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Thu, 28 Dec 2023 12:17:10 -0500 Subject: [PATCH 3/3] label-freetype: Log font loading error Right now if there's an error loading a font we quietly just proceed. This commit adds a debug log message saying what the error is. --- src/plugins/controls/label-freetype/plugin.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plugins/controls/label-freetype/plugin.c b/src/plugins/controls/label-freetype/plugin.c index 02b6f899..17cb134e 100644 --- a/src/plugins/controls/label-freetype/plugin.c +++ b/src/plugins/controls/label-freetype/plugin.c @@ -780,6 +780,8 @@ set_font_for_control (ply_label_plugin_control_t *label, if (error) { FT_Done_Face (label->face); label->face = NULL; + + ply_trace ("Could not load font, error %d", error); return; }