2017-01-08 07:54:09 +00:00
|
|
|
|
using System;
|
2017-07-02 02:43:51 +00:00
|
|
|
|
using System.Diagnostics;
|
2017-01-08 07:54:09 +00:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Text;
|
|
|
|
|
using System.Runtime.InteropServices;
|
2017-05-12 04:34:18 +00:00
|
|
|
|
using PKHeX.WinForms.Properties;
|
2017-01-08 07:54:09 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.WinForms
|
|
|
|
|
{
|
|
|
|
|
public static class FontUtil
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// Font Related
|
|
|
|
|
#if WINDOWS
|
|
|
|
|
[DllImport("gdi32.dll")]
|
|
|
|
|
private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [In] ref uint pcFonts);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
private static readonly PrivateFontCollection s_FontCollection = new PrivateFontCollection();
|
|
|
|
|
private static FontFamily[] FontFamilies
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (s_FontCollection.Families.Length == 0) SetPKXFont();
|
2017-01-08 07:54:09 +00:00
|
|
|
|
return s_FontCollection.Families;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static Font GetPKXFont(float size)
|
2017-01-08 07:54:09 +00:00
|
|
|
|
{
|
|
|
|
|
return new Font(FontFamilies[0], size);
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static void SetPKXFont()
|
2017-01-08 07:54:09 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
byte[] fontData = Resources.pgldings_normalregular;
|
|
|
|
|
#if WINDOWS
|
|
|
|
|
IntPtr fontPtr = Marshal.AllocCoTaskMem(fontData.Length);
|
|
|
|
|
Marshal.Copy(fontData, 0, fontPtr, fontData.Length);
|
|
|
|
|
s_FontCollection.AddMemoryFont(fontPtr, Resources.pgldings_normalregular.Length); uint dummy = 0;
|
|
|
|
|
AddFontMemResourceEx(fontPtr, (uint)Resources.pgldings_normalregular.Length, IntPtr.Zero, ref dummy);
|
|
|
|
|
Marshal.FreeCoTaskMem(fontPtr);
|
|
|
|
|
#else
|
|
|
|
|
GCHandle fontHandle = GCHandle.Alloc(fontData, GCHandleType.Pinned);
|
|
|
|
|
s_FontCollection.AddMemoryFont(fontHandle.AddrOfPinnedObject(), fontData.Length);
|
|
|
|
|
fontHandle.Free();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
}
|
2017-07-02 02:43:51 +00:00
|
|
|
|
catch (Exception ex) { Debug.WriteLine("Unable to add ingame font: " + ex.Message); }
|
2017-01-08 07:54:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|