Browse Source

Include System.Drawing fonts in picker

Not all are necessarily compatible

Closes #54
Daniel Chalmers 1 year ago
parent
commit
235c4c0ad0
1 changed files with 18 additions and 1 deletions
  1. 18 1
      DesktopClock/SettingsWindow.xaml.cs

+ 18 - 1
DesktopClock/SettingsWindow.xaml.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Generic;
 using System.Diagnostics;
+using System.Drawing.Text;
 using System.Linq;
 using System.Windows;
 using System.Windows.Controls;
@@ -79,7 +80,7 @@ public partial class SettingsWindowViewModel : ObservableObject
     public SettingsWindowViewModel(Settings settings)
     {
         Settings = settings;
-        FontFamilies = Fonts.SystemFontFamilies.Select(ff => ff.Source).ToList();
+        FontFamilies = GetAllSystemFonts().Distinct().OrderBy(f => f).ToList();
         FontStyles = ["Normal", "Italic", "Oblique"];
         TimeZones = TimeZoneInfo.GetSystemTimeZones().Select(tz => tz.Id).ToList();
     }
@@ -116,4 +117,20 @@ public partial class SettingsWindowViewModel : ObservableObject
     {
         Settings.CountdownTo = default;
     }
+
+    private IEnumerable<string> GetAllSystemFonts()
+    {
+        // Get fonts from WPF.
+        foreach (var fontFamily in Fonts.SystemFontFamilies)
+        {
+            yield return fontFamily.Source;
+        }
+
+        // Get fonts from System.Drawing.
+        var installedFontCollection = new InstalledFontCollection();
+        foreach (var fontFamily in installedFontCollection.Families)
+        {
+            yield return fontFamily.Name;
+        }
+    }
 }