Ability to set composer default font (#287)

* Added ability to set Composer font

* Added missing translations and refactoring

* Remove unused methods

* Small fixes
This commit is contained in:
Tiktack
2024-07-18 20:04:11 +02:00
committed by GitHub
parent 76375c9471
commit cf2f0ec936
30 changed files with 424 additions and 316 deletions

View File

@@ -1,50 +1,26 @@
using System.Collections.Generic;
using Serilog;
using Wino.Core.Domain.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using SkiaSharp;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Reader;
namespace Wino.Core.Services
namespace Wino.Core.Services;
public class FontService() : IFontService
{
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"];
private static List<string> InitializeFonts()
{
private readonly IPreferencesService _preferencesService;
private ILogger _logger = Log.ForContext<FontService>();
// 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;
private readonly List<ReaderFontModel> _availableFonts =
[
new ReaderFontModel(ReaderFont.Arial, "Arial"),
new ReaderFontModel(ReaderFont.Calibri, "Calibri"),
new ReaderFontModel(ReaderFont.TimesNewRoman, "Times New Roman"),
new ReaderFontModel(ReaderFont.TrebuchetMS, "Trebuchet MS"),
new ReaderFontModel(ReaderFont.Tahoma, "Tahoma"),
new ReaderFontModel(ReaderFont.Verdana, "Verdana"),
new ReaderFontModel(ReaderFont.Georgia, "Georgia"),
new ReaderFontModel(ReaderFont.CourierNew, "Courier New")
];
List<string> combinedFonts = [.. fontFamilies, .. _defaultFonts];
public FontService(IPreferencesService preferencesService)
{
_preferencesService = preferencesService;
}
public List<ReaderFontModel> GetReaderFonts() => _availableFonts;
public void ChangeReaderFont(ReaderFont font)
{
_preferencesService.ReaderFont = font;
_logger.Information("Default reader font is changed to {Font}", font);
}
public void ChangeReaderFontSize(int size)
{
_preferencesService.ReaderFontSize = size;
_logger.Information("Default reader font size is changed to {Size}", size);
}
public ReaderFontModel GetCurrentReaderFont() => _availableFonts.Find(f => f.Font == _preferencesService.ReaderFont);
public int GetCurrentReaderFontSize() => _preferencesService.ReaderFontSize;
return [.. combinedFonts.Distinct().OrderBy(x => x)];
}
public List<string> GetFonts() => _availableFonts.Value;
}