1 |
#Region "Microsoft.VisualBasic::5339d805de5b6c894834cd6d8d99b07b, Microsoft.VisualBasic.Core\Extensions\Image\GDI+\FontFace.vb"
|
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 |
#End Region
|
56 |
|
57 |
Imports System.Drawing
|
58 |
Imports System.Drawing.Text
|
59 |
Imports System.Runtime.CompilerServices
|
60 |
Imports DefaultFont = Microsoft.VisualBasic.Language.Default.DefaultValue(Of System.Drawing.Font)
|
61 |
|
62 |
Namespace Imaging
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
Public NotInheritable Class FontFace
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
Public Const MicrosoftYaHei As String = "Microsoft YaHei"
|
73 |
Public Const MicrosoftYaHeiUI As String = "Microsoft YaHei UI"
|
74 |
Public Const Ubuntu As String = "Ubuntu"
|
75 |
Public Const SegoeUI As String = "Segoe UI"
|
76 |
Public Const Arial As String = "Arial"
|
77 |
Public Const BookmanOldStyle As String = "Bookman Old Style"
|
78 |
Public Const Calibri As String = "Calibri"
|
79 |
Public Const Cambria As String = "Cambria"
|
80 |
Public Const CambriaMath As String = "Cambria Math"
|
81 |
Public Const Consolas As String = "Consolas"
|
82 |
Public Const CourierNew As String = "Courier New"
|
83 |
Public Const NSimSun As String = "NSimSun"
|
84 |
Public Const SimSun As String = "SimSun"
|
85 |
Public Const Verdana As String = "Verdana"
|
86 |
Public Const Tahoma As String = "Tahoma"
|
87 |
Public Const TimesNewRoman As String = "Times New Roman"
|
88 |
|
89 |
Public Shared ReadOnly Property InstalledFontFamilies As IReadOnlyCollection(Of String)
|
90 |
|
91 |
Shared ReadOnly fontFamilies As Dictionary(Of String, String)
|
92 |
|
93 |
Shared Sub New()
|
94 |
Dim fontFamilies() As FontFamily
|
95 |
Dim installedFontCollection As New InstalledFontCollection()
|
96 |
|
97 |
|
98 |
fontFamilies = installedFontCollection.Families
|
99 |
InstalledFontFamilies = fontFamilies.Select(Function(f) f.Name).ToArray
|
100 |
FontFace.fontFamilies = New Dictionary(Of String, String)
|
101 |
|
102 |
For Each family$ In InstalledFontFamilies
|
103 |
FontFace.fontFamilies(LCase(family)) = family
|
104 |
Next
|
105 |
End Sub
|
106 |
|
107 |
Private Sub New()
|
108 |
End Sub
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
116 |
Public Shared Function IsInstalled(name As String) As Boolean
|
117 |
Return fontFamilies.ContainsKey(name) OrElse fontFamilies.ContainsKey(LCase(name))
|
118 |
End Function
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
Public Shared Function GetFontName(name$, Optional default$ = FontFace.SegoeUI) As String
|
128 |
If fontFamilies.ContainsKey(name) Then
|
129 |
Return fontFamilies(name)
|
130 |
Else
|
131 |
name = LCase(name)
|
132 |
|
133 |
If fontFamilies.ContainsKey(name) Then
|
134 |
Return fontFamilies(name)
|
135 |
Else
|
136 |
Return [default]
|
137 |
End If
|
138 |
End If
|
139 |
End Function
|
140 |
|
141 |
Public Shared Function MeasureString(text As String, font As Font) As SizeF
|
142 |
Static dummy_img As Image = New Bitmap(1, 1)
|
143 |
Static dummy_drawing As Graphics = Graphics.FromImage(dummy_img)
|
144 |
|
145 |
Return dummy_drawing.MeasureString(text, font)
|
146 |
End Function
|
147 |
End Class
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
Public Module DefaultFontValues
|
153 |
|
154 |
Public NotInheritable Class MicrosoftYaHei
|
155 |
|
156 |
Public Shared ReadOnly Property Normal As DefaultFont = New Font(FontFace.MicrosoftYaHei, 12, FontStyle.Regular)
|
157 |
Public Shared ReadOnly Property Large As DefaultFont = New Font(FontFace.MicrosoftYaHei, 30, FontStyle.Regular)
|
158 |
Public Shared ReadOnly Property Bold As DefaultFont = New Font(FontFace.MicrosoftYaHei, 12, FontStyle.Bold)
|
159 |
|
160 |
Private Sub New()
|
161 |
End Sub
|
162 |
End Class
|
163 |
End Module
|
164 |
End Namespace
|