Files
Wino-Mail/Wino.Core/Services/FontService.cs

27 lines
979 B
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using SkiaSharp;
2024-04-18 01:44:37 +02:00
using Wino.Core.Domain.Interfaces;
namespace Wino.Core.Services;
2024-04-18 01:44:37 +02:00
public class FontService() : IFontService
{
private static readonly Lazy<List<string>> _availableFonts = new(InitializeFonts);
private static readonly List<string> _defaultFonts = ["Arial", "Calibri", "Trebuchet MS", "Tahoma", "Verdana", "Courier New", "Georgia", "Times New Roman"];
2024-04-18 01:44:37 +02:00
private static List<string> InitializeFonts()
{
// TODO: Skia used to get system fonts. This is a temporary solution to support UWP and WinUI together.
// After migration to WinUI, this code should be replaced with lightweight solution.
var fontFamilies = SKFontManager.Default.FontFamilies;
2024-04-18 01:44:37 +02:00
List<string> combinedFonts = [.. fontFamilies, .. _defaultFonts];
2024-04-18 01:44:37 +02:00
return [.. combinedFonts.Distinct().OrderBy(x => x)];
2024-04-18 01:44:37 +02:00
}
public List<string> GetFonts() => _availableFonts.Value;
2024-04-18 01:44:37 +02:00
}