Browse Source
Merge pull request #11775 from Gillibald/fixes/fontManagerInfiniteLoop
Prevent an infinite loop if the default FontFamily lookup fails
pull/11809/head
Max Katz
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
22 additions and
1 deletions
-
src/Avalonia.Base/Media/FontManager.cs
-
tests/Avalonia.Skia.UnitTests/Media/FontManagerTests.cs
|
|
|
@ -151,8 +151,13 @@ namespace Avalonia.Media |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(typeface.FontFamily == DefaultFontFamily) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
//Nothing was found so use the default
|
|
|
|
return TryGetGlyphTypeface(new Typeface(DefaultFontFamily, typeface.Style, typeface.Weight, typeface.Stretch), out glyphTypeface); |
|
|
|
return TryGetGlyphTypeface(new Typeface(FontFamily.DefaultFontFamilyName, typeface.Style, typeface.Weight, typeface.Stretch), out glyphTypeface); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
@ -123,5 +123,21 @@ namespace Avalonia.Skia.UnitTests.Media |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_Return_False_For_Invalid_DefaultFontFamily() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface.With(fontManagerImpl: new FontManagerImpl()))) |
|
|
|
{ |
|
|
|
using (AvaloniaLocator.EnterScope()) |
|
|
|
{ |
|
|
|
AvaloniaLocator.CurrentMutable.BindToSelf(new FontManagerOptions { DefaultFamilyName = "avares://resm:Avalonia.Skia.UnitTests.Assets?assembly=Avalonia.Skia.UnitTests#Unknown" }); |
|
|
|
|
|
|
|
var result = FontManager.Current.TryGetGlyphTypeface(Typeface.Default, out _); |
|
|
|
|
|
|
|
Assert.False(result); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|