FontHelper.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Drawing.Text;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Optimizer
  9. {
  10. internal static class FontHelper
  11. {
  12. [System.Runtime.InteropServices.DllImport("gdi32.dll")]
  13. private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont,
  14. IntPtr pdv, [System.Runtime.InteropServices.In] ref uint pcFonts);
  15. static PrivateFontCollection fonts = new PrivateFontCollection();
  16. internal static Font Poppins15;
  17. internal static void LoadFont()
  18. {
  19. byte[] fontData = Properties.Resources.Poppins_Regular;
  20. IntPtr fontPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(fontData.Length);
  21. System.Runtime.InteropServices.Marshal.Copy(fontData, 0, fontPtr, fontData.Length);
  22. uint dummy = 0;
  23. fonts.AddMemoryFont(fontPtr, Properties.Resources.Poppins_Regular.Length);
  24. AddFontMemResourceEx(fontPtr, (uint)Properties.Resources.Poppins_Regular.Length, IntPtr.Zero, ref dummy);
  25. System.Runtime.InteropServices.Marshal.FreeCoTaskMem(fontPtr);
  26. Poppins15 = new Font(fonts.Families[0], 15f);
  27. }
  28. }
  29. }