mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-27 22:40:22 +00:00
01fb233e48
Extract some interfaces Suppress some warning messages with commented reasons if appropriate
46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.Drawing.Text;
|
|
using System.IO;
|
|
using PKHeX.WinForms.Properties;
|
|
|
|
namespace PKHeX.WinForms
|
|
{
|
|
public static class FontUtil
|
|
{
|
|
private static readonly PrivateFontCollection CustomFonts = new PrivateFontCollection();
|
|
private static readonly Dictionary<float, Font> GeneratedFonts = new Dictionary<float, Font>();
|
|
|
|
static FontUtil()
|
|
{
|
|
string g6path = Path.Combine(Path.GetTempPath(), "pgldings6.ttf");
|
|
try
|
|
{
|
|
if (!File.Exists(g6path))
|
|
File.WriteAllBytes(g6path, Resources.pgldings_normalregular);
|
|
CustomFonts.AddFontFile(g6path);
|
|
}
|
|
catch (FileNotFoundException ex){
|
|
Debug.WriteLine($"Unable to read font file: {ex.Message}");
|
|
}
|
|
#pragma warning disable CA1031 // Do not catch general exception types
|
|
catch (Exception ex)
|
|
#pragma warning restore CA1031 // Do not catch general exception types
|
|
{
|
|
Debug.WriteLine($"Unable to add in-game font: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
public static Font GetPKXFont(float size = 11f)
|
|
{
|
|
if (GeneratedFonts.TryGetValue(size, out var f))
|
|
return f;
|
|
var family = CustomFonts.Families.Length == 0 ? FontFamily.GenericSansSerif : CustomFonts.Families[0];
|
|
var font = new Font(family, size);
|
|
GeneratedFonts.Add(size, font);
|
|
return font;
|
|
}
|
|
}
|
|
}
|