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:
fcada52291
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.
This commit is contained in:
Jehan 2020-08-16 17:21:12 +02:00
parent 1e94bd3f83
commit c5f9b8e190
1 changed files with 8 additions and 7 deletions

View File

@ -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;
}