diff --git a/doc/articles/features/custom-fonts.md b/doc/articles/features/custom-fonts.md index 4389de569bce..15f7effdfcc0 100644 --- a/doc/articles/features/custom-fonts.md +++ b/doc/articles/features/custom-fonts.md @@ -155,9 +155,11 @@ public static void main(string[] orgs) // You can add more than one, but preload too many fonts could hurt user experience. // IMPORTANT: The string parameter should be exactly the same string (including casing) // used as FontFamily in the application. - Windows.UI.Xaml.Media.FontFamilyHelper.PreloadAsync("ms-appx:///Assets/Fonts/yourfont01.ttf#ApplicationFont01"); - Windows.UI.Xaml.Media.FontFamilyHelper.PreloadAsync("https://fonts.cdnfonts.com/s/71084/antikythera.woff#Antikythera"); - Windows.UI.Xaml.Media.FontFamilyHelper.PreloadAsync("Roboto"); + Uno.UI.Xaml.Media.FontFamilyHelper.PreloadAsync("ms-appx:///Assets/Fonts/yourfont01.ttf#ApplicationFont01"); + Uno.UI.Xaml.Media.FontFamilyHelper.PreloadAsync("https://fonts.cdnfonts.com/s/71084/antikythera.woff#Antikythera"); + + // Preloads a font which has been specified as a CSS font, either with a data uri or a remote resource. + Uno.UI.Xaml.Media.FontFamilyHelper.PreloadAsync("Roboto"); Windows.UI.Xaml.Application.Start(_ => _app = new App()); ``` diff --git a/src/Uno.UI.Runtime.WebAssembly/Xaml/Media/FontFamilyHelper.cs b/src/Uno.UI.Runtime.WebAssembly/Xaml/Media/FontFamilyHelper.cs new file mode 100644 index 000000000000..9da760259f22 --- /dev/null +++ b/src/Uno.UI.Runtime.WebAssembly/Xaml/Media/FontFamilyHelper.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Windows.UI.Xaml.Media; + +namespace Uno.UI.Xaml.Media; + +/// +/// WebAssembly specific helper +/// +public partial class FontFamilyHelper +{ + /// + /// Pre-loads a font to minimize loading time and prevent potential text re-layouts. + /// + /// True is the font loaded successfuly, otherwise false. + public static Task PreloadAsync(FontFamily family) + => FontFamily.PreloadAsync(family); + + /// + /// Pre-loads a font to minimize loading time and prevent potential text re-layouts. + /// + /// True is the font loaded successfuly, otherwise false. + public static Task PreloadAsync(string familyName) + => PreloadAsync(new FontFamily(familyName)); +}