@ -1,5 +1,8 @@
using Avalonia.Media ;
using System.Collections.Concurrent ;
using System.Collections.Generic ;
using Avalonia.Media ;
using Avalonia.Media.Fonts ;
using Avalonia.UnitTests ;
using Xunit ;
namespace Avalonia.Skia.UnitTests.Media
@ -24,5 +27,40 @@ namespace Avalonia.Skia.UnitTests.Media
Assert . Equal ( weight , result . Weight ) ;
Assert . Equal ( FontStretch . Normal , result . Stretch ) ;
}
[Win32Fact("Relies on some installed font family")]
public void Should_Cache_Nearest_Match ( )
{
using ( UnitTestApplication . Start ( TestServices . MockPlatformRenderInterface . With ( fontManagerImpl : new FontManagerImpl ( ) ) ) )
{
var fontManager = FontManager . Current ;
var fontCollection = new TestSystemFontCollection ( FontManager . Current ) ;
Assert . True ( fontCollection . TryGetGlyphTypeface ( "Arial" , FontStyle . Normal , FontWeight . ExtraBlack , FontStretch . Normal , out var glyphTypeface ) ) ;
Assert . True ( glyphTypeface . FontSimulations = = FontSimulations . Bold ) ;
Assert . True ( fontCollection . GlyphTypfaceCache . TryGetValue ( "Arial" , out var glyphTypefaces ) ) ;
Assert . Equal ( 2 , glyphTypefaces . Count ) ;
Assert . True ( glyphTypefaces . ContainsKey ( new FontCollectionKey ( FontStyle . Normal , FontWeight . Black , FontStretch . Normal ) ) ) ;
fontCollection . TryGetGlyphTypeface ( "Arial" , FontStyle . Normal , FontWeight . ExtraBlack , FontStretch . Normal , out var otherGlyphTypeface ) ;
Assert . Equal ( glyphTypeface , otherGlyphTypeface ) ;
}
}
private class TestSystemFontCollection : SystemFontCollection
{
public TestSystemFontCollection ( FontManager fontManager ) : base ( fontManager )
{
}
public IDictionary < string , ConcurrentDictionary < FontCollectionKey , IGlyphTypeface ? > > GlyphTypfaceCache = > _ glyphTypefaceCache ;
}
}
}