59 lines
2.2 KiB
C#
59 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows.Media;
|
|
|
|
namespace QuickClaude
|
|
{
|
|
// The same font choices as wIRC. Saved in settings.json by Name.
|
|
// - Windows fonts (Segoe UI, Tahoma, Tw Cen MT) aren't bundled; they're listed only when
|
|
// installed (Tw Cen MT only comes with Office).
|
|
// - The rounded fonts (Nunito, Quicksand, Varela Round) are SIL OFL licensed and built into
|
|
// the exe from the fonts folder, with their license files.
|
|
// An unknown or missing font falls back to Consolas.
|
|
public static class Fonts
|
|
{
|
|
public const string Default = "Consolas";
|
|
|
|
static readonly Uri PackRoot = new Uri("pack://application:,,,/");
|
|
|
|
public class Choice
|
|
{
|
|
public string Name;
|
|
public FontFamily Family;
|
|
}
|
|
|
|
static List<Choice> choices;
|
|
|
|
public static List<Choice> All
|
|
{
|
|
get
|
|
{
|
|
if (choices != null) return choices;
|
|
var installed = new HashSet<string>(
|
|
System.Windows.Media.Fonts.SystemFontFamilies.Select(f => f.Source),
|
|
StringComparer.OrdinalIgnoreCase);
|
|
|
|
choices = new List<Choice>
|
|
{
|
|
new Choice { Name = "Consolas", Family = new FontFamily("Consolas, Courier New") }
|
|
};
|
|
foreach (var sys in new[] { "Segoe UI", "Tahoma", "Tw Cen MT" })
|
|
if (installed.Contains(sys))
|
|
choices.Add(new Choice { Name = sys, Family = new FontFamily(sys) });
|
|
|
|
choices.Add(Bundled("Nunito (rounded)", "Nunito"));
|
|
choices.Add(Bundled("Quicksand (rounded)", "Quicksand"));
|
|
choices.Add(Bundled("Varela Round (rounded)", "Varela Round"));
|
|
return choices;
|
|
}
|
|
}
|
|
|
|
static Choice Bundled(string name, string family) =>
|
|
new Choice { Name = name, Family = new FontFamily(PackRoot, "./fonts/#" + family + ", Consolas") };
|
|
|
|
public static Choice Find(string name) =>
|
|
All.FirstOrDefault(c => string.Equals(c.Name, name, StringComparison.OrdinalIgnoreCase)) ?? All[0];
|
|
}
|
|
}
|