Browse Source

Fix some tests

pull/10455/head
Benedikt Stebner 4 years ago
parent
commit
5b2a6368c9
  1. 5
      src/Avalonia.Base/Media/Fonts/EmbeddedFontCollection.cs
  2. 16
      src/Avalonia.Base/Media/Fonts/FontFamilyLoader.cs
  3. 2
      src/Avalonia.Themes.Simple/Accents/Base.xaml
  4. 22
      tests/Avalonia.Skia.UnitTests/Media/EmbeddedFontCollectionTests.cs

5
src/Avalonia.Base/Media/Fonts/EmbeddedFontCollection.cs

@ -23,11 +23,6 @@ namespace Avalonia.Media.Fonts
{
_key = key;
if(!source.IsAvares() && !source.IsAbsoluteResm())
{
throw new ArgumentOutOfRangeException(nameof(source), "Specified source uri does not follow the resm: or avares: scheme.");
}
_source = source;
}

16
src/Avalonia.Base/Media/Fonts/FontFamilyLoader.cs

@ -13,10 +13,18 @@ namespace Avalonia.Media.Fonts
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static IEnumerable<Uri> LoadFontAssets(Uri source) =>
IsFontTtfOrOtf(source) ?
GetFontAssetsByExpression(source) :
GetFontAssetsBySource(source);
public static IEnumerable<Uri> LoadFontAssets(Uri source)
{
if (source.IsAvares() || source.IsAbsoluteResm())
{
return IsFontTtfOrOtf(source) ?
GetFontAssetsByExpression(source) :
GetFontAssetsBySource(source);
}
return Enumerable.Empty<Uri>();
}
/// <summary>
/// Searches for font assets at a given location and returns a quantity of found assets

2
src/Avalonia.Themes.Simple/Accents/Base.xaml

@ -76,7 +76,7 @@
<SolidColorBrush x:Key="RefreshVisualizerBackground" Color="Transparent" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<FontFamily x:Key="ContentControlThemeFontFamily">avares://Avalonia.Fonts.Inter/Assets#Inter, $Default</FontFamily>
<FontFamily x:Key="ContentControlThemeFontFamily">fonts://Inter#Inter, $Default</FontFamily>
<Color x:Key="ThemeAccentColor">#CC119EDA</Color>
<Color x:Key="ThemeAccentColor2">#99119EDA</Color>
<Color x:Key="ThemeAccentColor3">#66119EDA</Color>

22
tests/Avalonia.Skia.UnitTests/Media/EmbeddedFontCollectionTests.cs

@ -17,9 +17,13 @@ namespace Avalonia.Skia.UnitTests.Media
[Theory]
public void Should_Get_Near_Matching_Typeface(FontWeight fontWeight, FontStyle fontStyle)
{
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface.With(fontManagerImpl: new CustomFontManagerImpl())))
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
{
var fontCollection = new EmbeddedFontCollection(FontManager.Current, new Uri(s_notoMono));
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));
@ -32,9 +36,13 @@ namespace Avalonia.Skia.UnitTests.Media
[Fact]
public void Should_Not_Get_Typeface_For_Invalid_FamilyName()
{
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface.With(fontManagerImpl: new CustomFontManagerImpl())))
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
{
var fontCollection = new EmbeddedFontCollection(FontManager.Current, new Uri(s_notoMono));
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));
}
@ -43,11 +51,13 @@ namespace Avalonia.Skia.UnitTests.Media
[Fact]
public void Should_Get_Typeface_For_Partial_FamilyName()
{
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface.With(fontManagerImpl: new CustomFontManagerImpl())))
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(FontManager.Current, source);
var fontCollection = new EmbeddedFontCollection(source, source);
fontCollection.Initialize(new CustomFontManagerImpl());
Assert.True(fontCollection.TryGetGlyphTypeface("T", FontStyle.Normal, FontWeight.Normal, FontStretch.Normal, out var glyphTypeface));

Loading…
Cancel
Save