From db137ef7180636fd2a1f335a76834ddc6e5b6384 Mon Sep 17 00:00:00 2001 From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com> Date: Thu, 11 Jul 2024 03:17:15 +0800 Subject: [PATCH] feat: web demo font. --- .../AvaloniaAppBuilderExtensions.cs | 16 ++++++++++++++++ demo/Semi.Avalonia.Demo.Web/Program.cs | 1 + .../{linker.xml => Roots.xml} | 0 .../Semi.Avalonia.Demo.Web.csproj | 7 ++++--- 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 demo/Semi.Avalonia.Demo.Web/AvaloniaAppBuilderExtensions.cs rename demo/Semi.Avalonia.Demo.Web/{linker.xml => Roots.xml} (100%) diff --git a/demo/Semi.Avalonia.Demo.Web/AvaloniaAppBuilderExtensions.cs b/demo/Semi.Avalonia.Demo.Web/AvaloniaAppBuilderExtensions.cs new file mode 100644 index 00000000..2d5a50f1 --- /dev/null +++ b/demo/Semi.Avalonia.Demo.Web/AvaloniaAppBuilderExtensions.cs @@ -0,0 +1,16 @@ +using Avalonia; +using Avalonia.Media; + +namespace Semi.Avalonia.Demo.Web; + +public static class AvaloniaAppBuilderExtensions +{ + private static string DefaultFontFamily => "avares://Semi.Avalonia.Demo.Web/Assets#Source Han Sans CN"; + + public static AppBuilder WithSourceHanSansCNFont(this AppBuilder builder) => + builder.With(new FontManagerOptions + { + DefaultFamilyName = DefaultFontFamily, + FontFallbacks = new[] { new FontFallback { FontFamily = new FontFamily(DefaultFontFamily) } } + }); +} \ No newline at end of file diff --git a/demo/Semi.Avalonia.Demo.Web/Program.cs b/demo/Semi.Avalonia.Demo.Web/Program.cs index 41a1c77e..62d4e940 100644 --- a/demo/Semi.Avalonia.Demo.Web/Program.cs +++ b/demo/Semi.Avalonia.Demo.Web/Program.cs @@ -10,6 +10,7 @@ namespace Semi.Avalonia.Demo.Web; internal sealed partial class Program { private static Task Main(string[] args) => BuildAvaloniaApp() + .WithSourceHanSansCNFont() .StartBrowserAppAsync("out"); public static AppBuilder BuildAvaloniaApp() diff --git a/demo/Semi.Avalonia.Demo.Web/linker.xml b/demo/Semi.Avalonia.Demo.Web/Roots.xml similarity index 100% rename from demo/Semi.Avalonia.Demo.Web/linker.xml rename to demo/Semi.Avalonia.Demo.Web/Roots.xml diff --git a/demo/Semi.Avalonia.Demo.Web/Semi.Avalonia.Demo.Web.csproj b/demo/Semi.Avalonia.Demo.Web/Semi.Avalonia.Demo.Web.csproj index 4f674d84..96e64dc7 100644 --- a/demo/Semi.Avalonia.Demo.Web/Semi.Avalonia.Demo.Web.csproj +++ b/demo/Semi.Avalonia.Demo.Web/Semi.Avalonia.Demo.Web.csproj @@ -5,14 +5,15 @@ - + + - + - +