Skip to content

Commit

Permalink
fix(wasm): Expose FontFamilyHelper through Uno.UI.Runtime.WebAssembly
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Sep 6, 2022
1 parent f49af2a commit 7ed2ae9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
8 changes: 5 additions & 3 deletions doc/articles/features/custom-fonts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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());
```
Expand Down
27 changes: 27 additions & 0 deletions src/Uno.UI.Runtime.WebAssembly/Xaml/Media/FontFamilyHelper.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// WebAssembly specific <see cref="FontFamily"/> helper
/// </summary>
public partial class FontFamilyHelper
{
/// <summary>
/// Pre-loads a font to minimize loading time and prevent potential text re-layouts.
/// </summary>
/// <returns>True is the font loaded successfuly, otherwise false.</returns>
public static Task<bool> PreloadAsync(FontFamily family)
=> FontFamily.PreloadAsync(family);

/// <summary>
/// Pre-loads a font to minimize loading time and prevent potential text re-layouts.
/// </summary>
/// <returns>True is the font loaded successfuly, otherwise false.</returns>
public static Task<bool> PreloadAsync(string familyName)
=> PreloadAsync(new FontFamily(familyName));
}

0 comments on commit 7ed2ae9

Please sign in to comment.