gdi32: Lazily create and cache fontconfig patterns.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2020-11-20 10:40:42 +00:00 committed by Alexandre Julliard
parent a51d68e35c
commit f7e646ccb7
1 changed files with 11 additions and 13 deletions

View File

@ -1343,21 +1343,22 @@ static UINT parse_aa_pattern( FcPattern *pattern )
return aa_flags; return aa_flags;
} }
static FcPattern *create_family_pattern( const char *name ) static FcPattern *create_family_pattern( const char *name, FcPattern **cached )
{ {
FcPattern *ret, *pattern = pFcPatternCreate(); FcPattern *ret = NULL, *tmp, *pattern = pFcPatternCreate();
FcResult result; FcResult result;
if (*cached) return *cached;
pFcPatternAddString( pattern, FC_FAMILY, (const FcChar8 *)name ); pFcPatternAddString( pattern, FC_FAMILY, (const FcChar8 *)name );
pFcPatternAddString( pattern, FC_NAMELANG, (const FcChar8 *)"en-us" ); pFcPatternAddString( pattern, FC_NAMELANG, (const FcChar8 *)"en-us" );
pFcPatternAddString( pattern, FC_PRGNAME, (const FcChar8 *)"wine" ); pFcPatternAddString( pattern, FC_PRGNAME, (const FcChar8 *)"wine" );
pFcConfigSubstitute( NULL, pattern, FcMatchPattern ); pFcConfigSubstitute( NULL, pattern, FcMatchPattern );
pFcDefaultSubstitute( pattern ); pFcDefaultSubstitute( pattern );
ret = pFcFontMatch( NULL, pattern, &result ); tmp = pFcFontMatch( NULL, pattern, &result );
pFcPatternDestroy( pattern ); pFcPatternDestroy( pattern );
if (ret && result == FcResultMatch) return ret; if (result != FcResultMatch) pFcPatternDestroy( tmp );
pFcPatternDestroy( ret ); else if ((ret = InterlockedCompareExchangePointer( (void **)cached, tmp, NULL ))) pFcPatternDestroy( tmp );
return NULL; else ret = tmp;
return ret;
} }
static void fontconfig_add_font( FcPattern *pattern, DWORD flags ) static void fontconfig_add_font( FcPattern *pattern, DWORD flags )
@ -1458,9 +1459,6 @@ static void init_fontconfig(void)
default_aa_flags = parse_aa_pattern( pattern ); default_aa_flags = parse_aa_pattern( pattern );
pFcPatternDestroy( pattern ); pFcPatternDestroy( pattern );
} }
pattern_serif = create_family_pattern( "serif" );
pattern_fixed = create_family_pattern( "monospace" );
pattern_sans = create_family_pattern( "sans" );
TRACE( "enabled, default flags = %x\n", default_aa_flags ); TRACE( "enabled, default flags = %x\n", default_aa_flags );
fontconfig_enabled = TRUE; fontconfig_enabled = TRUE;
@ -2213,9 +2211,9 @@ static BOOL CDECL fontconfig_enum_family_fallbacks( DWORD pitch_and_family, int
char *str; char *str;
DWORD len; DWORD len;
if ((pitch_and_family & FIXED_PITCH) || (pitch_and_family & 0xf0) == FF_MODERN) pat = pattern_fixed; if ((pitch_and_family & FIXED_PITCH) || (pitch_and_family & 0xf0) == FF_MODERN) pat = create_family_pattern( "monospace", &pattern_fixed );
else if ((pitch_and_family & 0xf0) == FF_ROMAN) pat = pattern_serif; else if ((pitch_and_family & 0xf0) == FF_ROMAN) pat = create_family_pattern( "serif", &pattern_serif );
else pat = pattern_sans; else pat = create_family_pattern( "sans", &pattern_sans );
if (!pat) return FALSE; if (!pat) return FALSE;
if (pFcPatternGetString( pat, FC_FAMILY, index, (FcChar8 **)&str ) != FcResultMatch) return FALSE; if (pFcPatternGetString( pat, FC_FAMILY, index, (FcChar8 **)&str ) != FcResultMatch) return FALSE;