Skip to content

Commit 7ed2ae9

Browse files
committed
fix(wasm): Expose FontFamilyHelper through Uno.UI.Runtime.WebAssembly
1 parent f49af2a commit 7ed2ae9

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

doc/articles/features/custom-fonts.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,11 @@ public static void main(string[] orgs)
155155
// You can add more than one, but preload too many fonts could hurt user experience.
156156
// IMPORTANT: The string parameter should be exactly the same string (including casing)
157157
// used as FontFamily in the application.
158-
Windows.UI.Xaml.Media.FontFamilyHelper.PreloadAsync("ms-appx:///Assets/Fonts/yourfont01.ttf#ApplicationFont01");
159-
Windows.UI.Xaml.Media.FontFamilyHelper.PreloadAsync("https://fonts.cdnfonts.com/s/71084/antikythera.woff#Antikythera");
160-
Windows.UI.Xaml.Media.FontFamilyHelper.PreloadAsync("Roboto");
158+
Uno.UI.Xaml.Media.FontFamilyHelper.PreloadAsync("ms-appx:///Assets/Fonts/yourfont01.ttf#ApplicationFont01");
159+
Uno.UI.Xaml.Media.FontFamilyHelper.PreloadAsync("https://fonts.cdnfonts.com/s/71084/antikythera.woff#Antikythera");
160+
161+
// Preloads a font which has been specified as a CSS font, either with a data uri or a remote resource.
162+
Uno.UI.Xaml.Media.FontFamilyHelper.PreloadAsync("Roboto");
161163

162164
Windows.UI.Xaml.Application.Start(_ => _app = new App());
163165
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
using Windows.UI.Xaml.Media;
6+
7+
namespace Uno.UI.Xaml.Media;
8+
9+
/// <summary>
10+
/// WebAssembly specific <see cref="FontFamily"/> helper
11+
/// </summary>
12+
public partial class FontFamilyHelper
13+
{
14+
/// <summary>
15+
/// Pre-loads a font to minimize loading time and prevent potential text re-layouts.
16+
/// </summary>
17+
/// <returns>True is the font loaded successfuly, otherwise false.</returns>
18+
public static Task<bool> PreloadAsync(FontFamily family)
19+
=> FontFamily.PreloadAsync(family);
20+
21+
/// <summary>
22+
/// Pre-loads a font to minimize loading time and prevent potential text re-layouts.
23+
/// </summary>
24+
/// <returns>True is the font loaded successfuly, otherwise false.</returns>
25+
public static Task<bool> PreloadAsync(string familyName)
26+
=> PreloadAsync(new FontFamily(familyName));
27+
}

0 commit comments

Comments
 (0)