[gimp] Issue #5530: do not fail font loading on broken user/GIMP fonts.conf.



commit c5f9b8e1901326b195e739349d4540620558982e
Author: Jehan <jehan girinstud io>
Date:   Sun Aug 16 17:21:12 2020 +0200

    Issue #5530: do not fail font loading on broken user/GIMP fonts.conf.
    
    Additionally to loading the default fontconfig configuration file, GIMP
    also looks up /etc/gimp/<version>/fonts.conf and
    $XDG_CONFIG_HOME/GIMP/<version>/fonts.conf (or equivalent in other
    OSes). If these don't exist (which is the most common case), this is not
    considered a bug. Fontconfig had a regression bug of
    FcConfigParseAndLoad() in 2.13.92, which was fixed in a later commit:
    https://gitlab.freedesktop.org/fontconfig/fontconfig/-/commit/fcada522913e5e07efa6367eff87ace9f06d24c8
    As a consequence of this bug, font loading failed in Windows when these
    non-mandatory files were absent.
    
    The current commit, originally proposed by Jacob Boerema (@Wormnest) and
    slightly reviewed works around the issue, because anyway there is never
    any reason why failing to load these files should break font loading as
    a general rule. Even if these files exist and are broken (wrong syntax
    or whatnot), we should just output some warning on stderr and continue
    loading without these additional confs.
    With fontconfig 2.13.92, warnings will be also outputted (wrongly), but
    at least it won't block loading anymore.
    
    Also let's unref() the `config` object even when the whole font loading
    succeeds. Man of FcConfigSetCurrent() clearly says that the reference
    count of config is incremented since 2.12.0 (our current minimum
    fontconfig is 2.12.4) so let's not leak one reference.

 app/text/gimpfontfactory.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
---
diff --git a/app/text/gimpfontfactory.c b/app/text/gimpfontfactory.c
index 625c7717a8..ead75d590f 100644
--- a/app/text/gimpfontfactory.c
+++ b/app/text/gimpfontfactory.c
@@ -273,6 +273,7 @@ gimp_font_factory_load_async_callback (GimpAsync       *async,
 
       gimp_font_factory_load_names (container, PANGO_FONT_MAP (fontmap), context);
       g_object_unref (context);
+      FcConfigDestroy (config);
     }
 
   gimp_container_thaw (container);
@@ -312,11 +313,15 @@ gimp_font_factory_load (GimpFontFactory  *factory,
 
   fonts_conf = gimp_directory_file (CONF_FNAME, NULL);
   if (! gimp_font_factory_load_fonts_conf (config, fonts_conf))
-    return;
+    g_printerr ("%s: failed to read '%s'.\n",
+                G_STRFUNC, g_file_peek_path (fonts_conf));
+  g_object_unref (fonts_conf);
 
   fonts_conf = gimp_sysconf_directory_file (CONF_FNAME, NULL);
   if (! gimp_font_factory_load_fonts_conf (config, fonts_conf))
-    return;
+    g_printerr ("%s: failed to read '%s'.\n",
+                G_STRFUNC, g_file_peek_path (fonts_conf));
+  g_object_unref (fonts_conf);
 
   path = gimp_data_factory_get_data_path (GIMP_DATA_FACTORY (factory));
   if (! path)
@@ -356,13 +361,9 @@ gimp_font_factory_load_fonts_conf (FcConfig *config,
   gboolean  ret  = TRUE;
 
   if (! FcConfigParseAndLoad (config, (const guchar *) path, FcFalse))
-    {
-      FcConfigDestroy (config);
-      ret = FALSE;
-    }
+    ret = FALSE;
 
   g_free (path);
-  g_object_unref (fonts_conf);
 
   return ret;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]