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>
fix/avnview-hittest
Jay Mao
5 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
16 additions and
1 deletions
src/Avalonia.Base/Media/Typeface.cs
tests/Avalonia.Skia.UnitTests/Media/FontManagerTests.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 )
{
{
}
}
@ -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 ) ;
}
}
}
}
}
}
}