csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.5 KiB
68 lines
2.5 KiB
using System;
|
|
using Avalonia.Media;
|
|
using Avalonia.Media.Fonts;
|
|
using Avalonia.UnitTests;
|
|
using Xunit;
|
|
|
|
namespace Avalonia.Skia.UnitTests.Media
|
|
{
|
|
public class EmbeddedFontCollectionTests
|
|
{
|
|
private const string s_notoMono =
|
|
"resm:Avalonia.Skia.UnitTests.Assets?assembly=Avalonia.Skia.UnitTests#Noto Mono";
|
|
|
|
[InlineData(FontWeight.SemiLight, FontStyle.Normal)]
|
|
[InlineData(FontWeight.Bold, FontStyle.Italic)]
|
|
[InlineData(FontWeight.Heavy, FontStyle.Oblique)]
|
|
[Theory]
|
|
public void Should_Get_Near_Matching_Typeface(FontWeight fontWeight, FontStyle fontStyle)
|
|
{
|
|
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
|
|
{
|
|
var source = new Uri(s_notoMono, UriKind.Absolute);
|
|
|
|
var fontCollection = new EmbeddedFontCollection(source, source);
|
|
|
|
fontCollection.Initialize(new CustomFontManagerImpl());
|
|
|
|
Assert.True(fontCollection.TryGetGlyphTypeface("Noto Mono", fontStyle, fontWeight, FontStretch.Normal, out var glyphTypeface));
|
|
|
|
var actual = glyphTypeface?.FamilyName;
|
|
|
|
Assert.Equal("Noto Mono", actual);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_Not_Get_Typeface_For_Invalid_FamilyName()
|
|
{
|
|
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
|
|
{
|
|
var source = new Uri(s_notoMono, UriKind.Absolute);
|
|
|
|
var fontCollection = new EmbeddedFontCollection(source, source);
|
|
|
|
fontCollection.Initialize(new CustomFontManagerImpl());
|
|
|
|
Assert.False(fontCollection.TryGetGlyphTypeface("ABC", FontStyle.Normal, FontWeight.Normal, FontStretch.Normal, out var glyphTypeface));
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_Get_Typeface_For_Partial_FamilyName()
|
|
{
|
|
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
|
|
{
|
|
var source = new Uri("resm:Avalonia.Skia.UnitTests.Assets?assembly=Avalonia.Skia.UnitTests#T", UriKind.Absolute);
|
|
|
|
var fontCollection = new EmbeddedFontCollection(source, source);
|
|
|
|
fontCollection.Initialize(new CustomFontManagerImpl());
|
|
|
|
Assert.True(fontCollection.TryGetGlyphTypeface("T", FontStyle.Normal, FontWeight.Normal, FontStretch.Normal, out var glyphTypeface));
|
|
|
|
Assert.Equal("Twitter Color Emoji", glyphTypeface.FamilyName);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|