mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-05-06 22:44:25 -05:00
Don't care about operating system; use the AddFontFile method instead. Add fallback for font load failure. This should be easier to maintain in the future, if multiple char->glyph mappings are to be supported (gen6 is already different from gen7 with some swapped glyphs).
38 lines
1.0 KiB
C#
38 lines
1.0 KiB
C#
using System;
|
|
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();
|
|
|
|
static FontUtil()
|
|
{
|
|
string g6path = Path.Combine(Path.GetTempPath(), "pgldings6.ttf");
|
|
try
|
|
{
|
|
if (!File.Exists(g6path))
|
|
File.WriteAllBytes(g6path, Resources.pgldings_normalregular);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Debug.WriteLine($"Unable to add in-game font: {ex.Message}");
|
|
return;
|
|
}
|
|
|
|
CustomFonts.AddFontFile(g6path);
|
|
}
|
|
|
|
public static Font GetPKXFont(float size)
|
|
{
|
|
var family = CustomFonts.Families.Length == 0 ? FontFamily.GenericSansSerif : CustomFonts.Families[0];
|
|
return new Font(family, size);
|
|
}
|
|
}
|
|
}
|