Skip to content

Commit

Permalink
perf: Add ForceFontUsage binding
Browse files Browse the repository at this point in the history
  • Loading branch information
ebariche committed Apr 4, 2023
1 parent 57f4ce7 commit 2f3a3e8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Uno.UI/UI/Xaml/FontFamilyLoader.Interop.wasm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NET7_0_OR_GREATER
#if NET7_0_OR_GREATER
using System.Runtime.InteropServices.JavaScript;

namespace __Windows.UI.Xaml.Media
Expand All @@ -7,6 +7,9 @@ internal partial class FontFamilyLoader
{
internal static partial class NativeMethods
{
[JSImport("globalThis.Windows.UI.Xaml.Media.FontFamily.forceFontUsage")]
internal static partial void ForceFontUsage(string cssFontName);

[JSImport("globalThis.Windows.UI.Xaml.Media.FontFamily.loadFont")]
internal static partial void LoadFont(string cssFontName, string externalSource);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Uno.UI/UI/Xaml/FontFamilyLoader.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ internal async Task<bool> LoadFontAsync()
}
else
{
#if NET7_0_OR_GREATER
NativeMethods.ForceFontUsage(_fontFamily.CssFontName);
#else
WebAssemblyRuntime.InvokeJS($"Windows.UI.Xaml.Media.FontFamily.forceFontUsage(\"{_fontFamily.CssFontName}\")");
#endif
}

_loadOperation = new TaskCompletionSource<bool>();
Expand Down

0 comments on commit 2f3a3e8

Please sign in to comment.