-
Notifications
You must be signed in to change notification settings - Fork 2
/
FontManager.cs
62 lines (57 loc) · 1.62 KB
/
FontManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Drawing;
namespace AdvancedWindowsAppearence
{
static class FontManager
{
public static double DPI = -1.0;
static bool _loaded = false;
static bool _loading = true;
static List<Font> _fonts = new List<Font>();
public static void GetDPI()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop\WindowMetrics");
if (key == null)
{
DPI = 1d;
return;
}
DPI = (int)key.GetValue("AppliedDPI") / 96d;
}
public static List<Font> GetSystemFonts()
{
if (!_loaded)
{
_loaded = true;
foreach (FontFamily fontfamily in FontFamily.Families)
{
try
{
Font f = new Font(fontfamily, 9);
_fonts.Add(f);
}
catch { }
}
_loading = false;
}
while (_loading) { }
return _fonts;
}
public static Font FindFontFromString(string stringname)
{
List<Font> fonts = GetSystemFonts();
foreach (var f in fonts)
{
if (f is null) continue;
if (stringname.Contains(f.Name))
{
return f;
}
}
Console.WriteLine("Font not found!");
return null;
}
}
}