tangxu
2025-02-10 e40718947b5aa9205c87a7478aa86c37a82e0510
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
#region Imports
 
using System;
using System.Drawing;
using System.Drawing.Text;
using System.Runtime.InteropServices;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Extension.Metro
{
    #region MetroFontsExtension
 
    public class MetroFonts
    {
        public static Font SemiLight(float size)
        {
            return GetFont(Properties.Resources.SegoeWP_Semilight, size);
        }
 
        public static Font Light(float size)
        {
            return GetFont(Properties.Resources.SegoeWP_Light, size);
        }
        public static Font SemiBold(float size)
        {
            return GetFont(Properties.Resources.SegoeWP_Semibold, size);
        }
 
        public static Font Bold(float size)
        {
            return GetFont(Properties.Resources.SegoeWP_Bold, size);
        }
 
        public static Font Regular(float size)
        {
            return GetFont(Properties.Resources.SegoeWP, size);
        }
 
        public static Font UIRegular(float size)
        {
            return new Font("Segoe UI", size);
        }
 
        public static Font GetFont(byte[] fontbyte, float size)
        {
            using PrivateFontCollection privateFontCollection = new();
            byte[] fnt = fontbyte;
            IntPtr buffer = Marshal.AllocCoTaskMem(fnt.Length);
            Marshal.Copy(fnt, 0, buffer, fnt.Length);
            privateFontCollection.AddMemoryFont(buffer, fnt.Length);
            return new Font(privateFontCollection.Families[0].Name, size);
        }
    }
 
    #endregion
}