From 14837efafaa88936ea048f51d8596b27760d51a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Thu, 23 Oct 2025 13:05:11 +0200 Subject: [PATCH] =?UTF-8?q?Added=20guards=20in=20TryGetGlyphTypeface=20so?= =?UTF-8?q?=20the=20$Default=20placeholder=20stops=E2=80=A6=20(#19891)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- src/Avalonia.Base/Media/FontManager.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Base/Media/FontManager.cs b/src/Avalonia.Base/Media/FontManager.cs index dfce362297..c8d8042e83 100644 --- a/src/Avalonia.Base/Media/FontManager.cs +++ b/src/Avalonia.Base/Media/FontManager.cs @@ -163,7 +163,7 @@ namespace Avalonia.Media } //Nothing was found so use the default - return TryGetGlyphTypeface(new Typeface(FontFamily.DefaultFontFamilyName, typeface.Style, typeface.Weight, typeface.Stretch), out glyphTypeface); + return TryGetGlyphTypeface(new Typeface(DefaultFontFamily, typeface.Style, typeface.Weight, typeface.Stretch), out glyphTypeface); FontFamily GetMappedFontFamily(FontFamily fontFamily) { @@ -380,6 +380,12 @@ namespace Avalonia.Media "Default font family name can't be null or empty."); } + if (defaultFontFamilyName == FontFamily.DefaultFontFamilyName) + { + throw new InvalidOperationException( + $"'{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."); + } + return defaultFontFamilyName; }