Skip to content

Commit 14837ef

Browse files
wieslawsoltesMrJul
andcommitted
Added guards in TryGetGlyphTypeface so the $Default placeholder stops… (#19891)
* Added guards in TryGetGlyphTypeface so the $Default placeholder stops recursing once the concrete default family cannot be resolved * Throw if $Default is used as the default family name * Stripped the redundant $Default guard/continue blocks --------- Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
1 parent 87d48e8 commit 14837ef

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Avalonia.Base/Media/FontManager.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public bool TryGetGlyphTypeface(Typeface typeface, [NotNullWhen(true)] out IGlyp
163163
}
164164

165165
//Nothing was found so use the default
166-
return TryGetGlyphTypeface(new Typeface(FontFamily.DefaultFontFamilyName, typeface.Style, typeface.Weight, typeface.Stretch), out glyphTypeface);
166+
return TryGetGlyphTypeface(new Typeface(DefaultFontFamily, typeface.Style, typeface.Weight, typeface.Stretch), out glyphTypeface);
167167

168168
FontFamily GetMappedFontFamily(FontFamily fontFamily)
169169
{
@@ -380,6 +380,12 @@ private string GetDefaultFontFamilyName(FontManagerOptions? options)
380380
"Default font family name can't be null or empty.");
381381
}
382382

383+
if (defaultFontFamilyName == FontFamily.DefaultFontFamilyName)
384+
{
385+
throw new InvalidOperationException(
386+
$"'{FontFamily.DefaultFontFamilyName}' is a placeholder and cannot be used as the default font family name. Provide a concrete font family name via {nameof(FontManagerOptions)} or the platform implementation.");
387+
}
388+
383389
return defaultFontFamilyName;
384390
}
385391

0 commit comments

Comments
 (0)