Program.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Avalonia;
  2. using Avalonia.Media.Fonts;
  3. using Avalonia.Media;
  4. using System;
  5. namespace ShakerApp
  6. {
  7. internal class Program
  8. {
  9. // Initialization code. Don't use any Avalonia, third-party APIs or any
  10. // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
  11. // yet and stuff might break.
  12. [STAThread]
  13. public static void Main(string[] args) => BuildAvaloniaApp()
  14. .StartWithClassicDesktopLifetime(args);
  15. // Avalonia configuration, don't remove; also used by visual designer.
  16. public static AppBuilder BuildAvaloniaApp()
  17. => AppBuilder.Configure<App>()
  18. .UsePlatformDetect()
  19. .LogToTrace();
  20. }
  21. public static class FontExtensions
  22. {
  23. public static AppBuilder UseFontAlibaba(this AppBuilder appBuilder, Action<FontSettings>? configdelegate = default)
  24. {
  25. var setting = new FontSettings();
  26. configdelegate?.Invoke(setting);
  27. return appBuilder.With(new FontManagerOptions()
  28. {
  29. DefaultFamilyName = setting.DefaultFontFamily,
  30. FontFallbacks = new[]
  31. {
  32. new FontFallback()
  33. {
  34. FontFamily = setting.DefaultFontFamily,
  35. }
  36. }
  37. }).ConfigureFonts(manger => manger.AddFontCollection(new EmbeddedFontCollection(setting.Key, setting.Source)));
  38. }
  39. public class FontSettings
  40. {
  41. public string DefaultFontFamily = "fonts:ShakerAppFontFamilies#Alibaba PuHuiTi 3.0";
  42. public Uri Key { get; set; } = new Uri("fonts:ShakerAppFontFamilies", UriKind.Absolute);
  43. public Uri Source { get; set; } = new Uri("avares://ShakerApp/Fonts", UriKind.Absolute);
  44. }
  45. }
  46. }