SKTypefaceCollectionCacheTests.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Avalonia.Media;
  2. using Avalonia.UnitTests;
  3. using Xunit;
  4. namespace Avalonia.Skia.UnitTests.Media
  5. {
  6. public class SKTypefaceCollectionCacheTests
  7. {
  8. private const string s_notoMono =
  9. "resm:Avalonia.Skia.UnitTests.Assets?assembly=Avalonia.Skia.UnitTests#Noto Mono";
  10. [InlineData(s_notoMono, FontWeight.SemiLight, FontStyle.Normal)]
  11. [InlineData(s_notoMono, FontWeight.Bold, FontStyle.Italic)]
  12. [InlineData(s_notoMono, FontWeight.Heavy, FontStyle.Oblique)]
  13. [Theory]
  14. public void Should_Get_Near_Matching_Typeface(string familyName, FontWeight fontWeight, FontStyle fontStyle)
  15. {
  16. using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
  17. {
  18. var fontFamily = new FontFamily(familyName);
  19. var typefaceCollection = SKTypefaceCollectionCache.GetOrAddTypefaceCollection(fontFamily);
  20. var actual = typefaceCollection.Get(new Typeface(fontFamily, fontStyle, fontWeight))?.FamilyName;
  21. Assert.Equal("Noto Mono", actual);
  22. }
  23. }
  24. [Fact]
  25. public void Should_Get_Typeface_For_Invalid_FamilyName()
  26. {
  27. using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
  28. {
  29. var notoMono =
  30. new FontFamily("resm:Avalonia.Skia.UnitTests.Assets?assembly=Avalonia.Skia.UnitTests#Noto Mono");
  31. var notoMonoCollection = SKTypefaceCollectionCache.GetOrAddTypefaceCollection(notoMono);
  32. var typeface = notoMonoCollection.Get(new Typeface("ABC"));
  33. Assert.NotNull(typeface);
  34. }
  35. }
  36. [Fact]
  37. public void Should_Get_Typeface_For_Partial_FamilyName()
  38. {
  39. using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
  40. {
  41. var fontFamily = new FontFamily("resm:Avalonia.Skia.UnitTests.Assets?assembly=Avalonia.Skia.UnitTests#T");
  42. var fontCollection = SKTypefaceCollectionCache.GetOrAddTypefaceCollection(fontFamily);
  43. var typeface = fontCollection.Get(new Typeface(fontFamily));
  44. Assert.NotNull(typeface);
  45. Assert.Equal("Twitter Color Emoji", typeface.FamilyName);
  46. }
  47. }
  48. }
  49. }