Browse Source

Fix typeface exception when created with empty font family name (#19654)

* add unit test case to check typeface creation with empty font family.

* fallback to default font family when the font family name is empty.

---------

Co-authored-by: jay.mao <jay.mao@ringcentral.com>
release/11.3.7
Jay Mao 5 months ago
committed by Julien Lebosquain
parent
commit
d7ad0bfcbc
  1. 3
      src/Avalonia.Base/Media/Typeface.cs
  2. 14
      tests/Avalonia.Skia.UnitTests/Media/FontManagerTests.cs

3
src/Avalonia.Base/Media/Typeface.cs

@ -48,7 +48,8 @@ namespace Avalonia.Media
FontStyle style = FontStyle.Normal, FontStyle style = FontStyle.Normal,
FontWeight weight = FontWeight.Normal, FontWeight weight = FontWeight.Normal,
FontStretch stretch = FontStretch.Normal) FontStretch stretch = FontStretch.Normal)
: this(fontFamilyName == null ? FontFamily.Default : new FontFamily(fontFamilyName), style, weight, stretch) : this(string.IsNullOrEmpty(fontFamilyName) ? FontFamily.Default : new FontFamily(fontFamilyName),
style, weight, stretch)
{ {
} }

14
tests/Avalonia.Skia.UnitTests/Media/FontManagerTests.cs

@ -427,5 +427,19 @@ namespace Avalonia.Skia.UnitTests.Media
} }
} }
} }
[Fact]
public void Should_Fallback_When_Font_Family_Is_Empty()
{
using (UnitTestApplication.Start(
TestServices.MockPlatformRenderInterface.With(fontManagerImpl: new FontManagerImpl())))
{
using (AvaloniaLocator.EnterScope())
{
var typeface = new Typeface(string.Empty);
Assert.NotNull(typeface.FontFamily);
}
}
}
} }
} }

Loading…
Cancel
Save