feature<Preference>: add custom font settings

This commit is contained in:
Jai 2021-08-10 16:55:01 +08:00
parent 0643f5803c
commit 0c7f217106
29 changed files with 202 additions and 70 deletions

View file

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows.Markup;
using System.Windows.Media;
namespace SourceGit.Models {
public class InstalledFont {
public string Name { get; set; }
public int FamilyIndex { get; set; }
public static List<InstalledFont> GetFonts {
get {
var fontList = new List<InstalledFont>();
var fontCollection = Fonts.SystemFontFamilies;
var familyCount = fontCollection.Count;
for (int i = 0; i < familyCount; i++) {
var fontFamily = fontCollection.ElementAt(i);
var familyNames = fontFamily.FamilyNames;
if (!familyNames.TryGetValue(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.Name), out var name)) {
if (!familyNames.TryGetValue(XmlLanguage.GetLanguage("en-us"), out name)) {
name = familyNames.FirstOrDefault().Value;
}
}
fontList.Add(new InstalledFont() {
Name = name,
FamilyIndex = i
});
}
fontList.Sort((p, n) => string.Compare(p.Name, n.Name, StringComparison.Ordinal));
return fontList;
}
}
}
}