Skip to content

Commit

Permalink
text: use a private FcConfig
Browse files Browse the repository at this point in the history
We were adding fonts to Fontconfig's global "current config",
instead prefer using a private config instead.

Requires Pango 1.38.
  • Loading branch information
kleisauke committed Aug 19, 2024
1 parent 65a1371 commit 0f8a60a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
30 changes: 19 additions & 11 deletions libvips/create/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,14 @@ vips_text_init_once(void *client)
{
vips_text_lock = vips_g_mutex_new();
vips_text_fontmap = pango_cairo_font_map_new();
#ifdef HAVE_FONTCONFIG
if (PANGO_IS_FC_FONT_MAP(vips_text_fontmap)) {
FcConfig *config = FcInitLoadConfigAndFonts();
pango_fc_font_map_set_config(PANGO_FC_FONT_MAP(vips_text_fontmap),
config);
FcConfigDestroy(config);
}
#endif /*HAVE_FONTCONFIG*/
vips_text_fontfiles = g_hash_table_new(g_str_hash, g_str_equal);

return NULL;
Expand Down Expand Up @@ -420,24 +428,24 @@ vips_text_build(VipsObject *object)

#ifdef HAVE_FONTCONFIG
if (text->fontfile &&
PANGO_IS_FC_FONT_MAP(vips_text_fontmap) &&
!g_hash_table_lookup(vips_text_fontfiles, text->fontfile)) {
/* This can fail if you eg. add the same font from two
* different files. Just warn.
FcConfig *config =
pango_fc_font_map_get_config(PANGO_FC_FONT_MAP(vips_text_fontmap));

/* This can fail if you eg. add the same font from two different
* files. Just warn.
*/
if (!FcConfigAppFontAddFile(NULL,
(const FcChar8 *) text->fontfile))
g_warning(_("unable to load fontfile \"%s\""),
text->fontfile);
g_hash_table_insert(vips_text_fontfiles,
text->fontfile,
if (!FcConfigAppFontAddFile(config, (const FcChar8 *) text->fontfile))
g_warning(_("unable to load fontfile \"%s\""), text->fontfile);

g_hash_table_insert(vips_text_fontfiles, text->fontfile,
g_strdup(text->fontfile));

/* We need to inform that pango should invalidate its
* fontconfig cache whenever any changes are made.
*/
if (PANGO_IS_FC_FONT_MAP(vips_text_fontmap))
pango_fc_font_map_cache_clear(
PANGO_FC_FONT_MAP(vips_text_fontmap));
pango_fc_font_map_config_changed(PANGO_FC_FONT_MAP(vips_text_fontmap));
}
#else /*!HAVE_FONTCONFIG*/
if (text->fontfile)
Expand Down
4 changes: 2 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -387,14 +387,14 @@ if libwebp_dep.found()
cfg_var.set('HAVE_LIBWEBP', '1')
endif

pangocairo_dep = dependency('pangocairo', version: '>=1.32.6', required: get_option('pangocairo'))
pangocairo_dep = dependency('pangocairo', version: '>=1.38.0', required: get_option('pangocairo'))
if pangocairo_dep.found()
external_deps += pangocairo_dep
cfg_var.set('HAVE_PANGOCAIRO', '1')
endif

# text rendering with fontconfig requires pangoft2
pangoft2_dep = dependency('pangoft2', version: '>=1.32.6', required: get_option('fontconfig'))
pangoft2_dep = dependency('pangoft2', version: '>=1.38.0', required: get_option('fontconfig'))
fontconfig_dep = dependency('fontconfig', required: get_option('fontconfig'))
fontconfig_found = pangoft2_dep.found() and fontconfig_dep.found() and pangocairo_dep.found()
if fontconfig_found
Expand Down

0 comments on commit 0f8a60a

Please sign in to comment.