@ -47,18 +47,46 @@ namespace Avalonia.Media.Fonts
var key = new FontCollectionKey ( style , weight , stretch ) ;
var key = new FontCollectionKey ( style , weight , stretch ) ;
var glyphTypefaces = _ glyphTypefaceCache . GetOrAdd ( familyName , ( key ) = > new ConcurrentDictionary < FontCollectionKey , IGlyphTypeface ? > ( ) ) ;
var glyphTypefaces = _ glyphTypefaceCache . GetOrAdd ( familyName ,
( _ ) = > new ConcurrentDictionary < FontCollectionKey , IGlyphTypeface ? > ( ) ) ;
if ( ! glyphTypefaces . TryGetValue ( key , out glyphTypeface ) )
if ( glyphTypefaces . TryGetValue ( key , out glyphTypeface ) )
{
{
_f ontManager . PlatformImpl . TryCreateGlyphTypeface ( familyName , style , weight , stretch , out glyphTypeface ) ;
return glyphTypeface ! = null ;
}
if ( ! _f ontManager . PlatformImpl . TryCreateGlyphTypeface ( familyName , style , weight , stretch , out glyphTypeface ) | |
! glyphTypeface . FamilyName . Contains ( familyName ) )
{
//Try to find nearest match if possible
TryGetNearestMatch ( glyphTypefaces , key , out glyphTypeface ) ;
}
if ( ! glyphTypefaces . TryAdd ( key , glyphTypeface ) )
if ( glyphTypeface is IGlyphTypeface2 glyphTypeface2 )
{
var fontSimulations = FontSimulations . None ;
if ( style ! = FontStyle . Normal & & glyphTypeface2 . Style ! = style )
{
{
return false ;
fontSimulations | = FontSimulations . Oblique ;
}
if ( ( int ) weight > = 6 0 0 & & glyphTypeface2 . Weight ! = weight )
{
fontSimulations | = FontSimulations . Bold ;
}
if ( fontSimulations ! = FontSimulations . None & & glyphTypeface2 . TryGetStream ( out var stream ) )
{
using ( stream )
{
_f ontManager . PlatformImpl . TryCreateGlyphTypeface ( stream , fontSimulations , out glyphTypeface ) ;
}
}
}
}
}
glyphTypefaces . TryAdd ( key , glyphTypeface ) ;
return glyphTypeface ! = null ;
return glyphTypeface ! = null ;
}
}
@ -87,7 +115,7 @@ namespace Avalonia.Media.Fonts
{
{
var stream = assetLoader . Open ( fontAsset ) ;
var stream = assetLoader . Open ( fontAsset ) ;
if ( fontManager . TryCreateGlyphTypeface ( stream , out var glyphTypeface ) )
if ( fontManager . TryCreateGlyphTypeface ( stream , FontSimulations . None , out var glyphTypeface ) )
{
{
if ( ! _ glyphTypefaceCache . TryGetValue ( glyphTypeface . FamilyName , out var glyphTypefaces ) )
if ( ! _ glyphTypefaceCache . TryGetValue ( glyphTypeface . FamilyName , out var glyphTypefaces ) )
{
{
@ -101,9 +129,9 @@ namespace Avalonia.Media.Fonts
}
}
var key = new FontCollectionKey (
var key = new FontCollectionKey (
glyphTypeface . Style ,
glyphTypeface . Style ,
glyphTypeface . Weight ,
glyphTypeface . Weight ,
glyphTypeface . Stretch ) ;
glyphTypeface . Stretch ) ;
glyphTypefaces . TryAdd ( key , glyphTypeface ) ;
glyphTypefaces . TryAdd ( key , glyphTypeface ) ;
}
}