only warn if fontfile load fails

since it can fail for things like adding the same font twice from
different files

thanks molfar

see https://github.com/libvips/libvips/issues/2220
This commit is contained in:
John Cupitt 2021-04-22 15:27:18 +01:00
parent fa6e403d30
commit ee2255da00

View File

@ -126,12 +126,10 @@ static GMutex *vips_text_lock = NULL;
*/
static PangoFontMap *vips_text_fontmap = NULL;
#ifdef HAVE_FONTCONFIG
/* All the fontfiles we've loaded. fontconfig lets you add a fontfile
* repeatedly, and we obviously don't want that.
*/
static GHashTable *vips_text_fontfiles = NULL;
#endif
static void
vips_text_dispose( GObject *gobject )
@ -371,11 +369,9 @@ vips_text_build( VipsObject *object )
if( !vips_text_fontmap )
vips_text_fontmap = pango_cairo_font_map_new();
#ifdef HAVE_FONTCONFIG
if( !vips_text_fontfiles )
vips_text_fontfiles =
g_hash_table_new( g_str_hash, g_str_equal );
#endif
text->context = pango_font_map_create_context(
PANGO_FONT_MAP( vips_text_fontmap ) );
@ -383,23 +379,22 @@ vips_text_build( VipsObject *object )
#ifdef HAVE_FONTCONFIG
if( text->fontfile &&
!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.
*/
if( !FcConfigAppFontAddFile( NULL,
(const FcChar8 *) text->fontfile ) ) {
vips_error( class->nickname,
_( "unable to load font \"%s\"" ),
(const FcChar8 *) text->fontfile ) )
g_warning( _( "unable to load fontfile \"%s\"" ),
text->fontfile );
g_mutex_unlock( vips_text_lock );
return( -1 );
}
g_hash_table_insert( vips_text_fontfiles,
text->fontfile,
g_strdup( text->fontfile ) );
}
#else
#else /*!HAVE_FONTCONFIG*/
if( text->fontfile )
g_warning( "%s",
_( "ignoring fontfile (no fontconfig support)" ) );
#endif
#endif /*HAVE_FONTCONFIG*/
/* If our caller set height and not dpi, we adjust dpi until
* we get a fit.