12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using Avalonia;
- using Avalonia.Media.Fonts;
- using Avalonia.Media;
- using System;
- namespace ShakerApp
- {
- internal class Program
- {
- // Initialization code. Don't use any Avalonia, third-party APIs or any
- // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
- // yet and stuff might break.
- [STAThread]
- public static void Main(string[] args) => BuildAvaloniaApp()
- .StartWithClassicDesktopLifetime(args);
- // Avalonia configuration, don't remove; also used by visual designer.
- public static AppBuilder BuildAvaloniaApp()
- => AppBuilder.Configure<App>()
- .UsePlatformDetect()
- .LogToTrace();
- }
- public static class FontExtensions
- {
- public static AppBuilder UseFontAlibaba(this AppBuilder appBuilder, Action<FontSettings>? configdelegate = default)
- {
- var setting = new FontSettings();
- configdelegate?.Invoke(setting);
- return appBuilder.With(new FontManagerOptions()
- {
- DefaultFamilyName = setting.DefaultFontFamily,
- FontFallbacks = new[]
- {
- new FontFallback()
- {
- FontFamily = setting.DefaultFontFamily,
- }
- }
- }).ConfigureFonts(manger => manger.AddFontCollection(new EmbeddedFontCollection(setting.Key, setting.Source)));
- }
- public class FontSettings
- {
- public string DefaultFontFamily = "fonts:ShakerAppFontFamilies#Alibaba PuHuiTi 3.0";
- public Uri Key { get; set; } = new Uri("fonts:ShakerAppFontFamilies", UriKind.Absolute);
- public Uri Source { get; set; } = new Uri("avares://ShakerApp/Fonts", UriKind.Absolute);
- }
- }
- }
|