1 | #ifndef _GDIPLUSFONT_H
|
---|
2 | #define _GDIPLUSFONT_H
|
---|
3 |
|
---|
4 | #require <GdiPlus.ab>
|
---|
5 | #require <Classes/System/Drawing/misc.ab>
|
---|
6 | #require <Classes/System/Drawing/Graphics.ab>
|
---|
7 |
|
---|
8 | Class FontFamily : End Class
|
---|
9 | Class FontCollection : End Class
|
---|
10 |
|
---|
11 | Class Font
|
---|
12 | Public
|
---|
13 | ' friend class Graphics
|
---|
14 |
|
---|
15 | Sub Font(/*IN*/ hdc As HDC)
|
---|
16 | Dim font = 0 As *GpFont
|
---|
17 | lastResult = GdipCreateFontFromDC(hdc, font)
|
---|
18 | SetNativeFont(font)
|
---|
19 | End Sub
|
---|
20 |
|
---|
21 | Sub Font(/*IN*/ hdc As HDC, /*IN const*/ ByRef logfont As LOGFONTA)
|
---|
22 | Dim font = 0 As *GpFont
|
---|
23 | lastResult =GdipCreateFontFromLogfontA(hdc, logfont, font)
|
---|
24 | SetNativeFont(font)
|
---|
25 | End Sub
|
---|
26 |
|
---|
27 | Sub Font(/*IN*/ hdc As HDC, /*IN const*/ ByRef logfont As LOGFONTW)
|
---|
28 | Dim font = 0 As *GpFont
|
---|
29 | lastResult =GdipCreateFontFromLogfontW(hdc, logfont, font)
|
---|
30 | SetNativeFont(font)
|
---|
31 | End Sub
|
---|
32 |
|
---|
33 | Sub Font(/*IN*/ hdc As HDC, /*IN const*/ hfont As HFONT)
|
---|
34 | Dim font = 0 As *GpFont
|
---|
35 | If hfont <> 0 Then
|
---|
36 | Dim lf As LOGFONTA
|
---|
37 | If GetObjectA(hfont, sizeof (LOGFONTA), lf) <> 0 Then
|
---|
38 | lastResult = GdipCreateFontFromLogfontA(hdc, lf, font)
|
---|
39 | Else
|
---|
40 | lastResult = GdipCreateFontFromDC(hdc, font)
|
---|
41 | End If
|
---|
42 | Else
|
---|
43 | lastResult = GdipCreateFontFromDC(hdc, font)
|
---|
44 | End If
|
---|
45 | SetNativeFont(font)
|
---|
46 | End Sub
|
---|
47 |
|
---|
48 | Sub Font(/*IN const*/ ByRef family As FontFamily, /*IN*/ emSize As Single)
|
---|
49 | Font(family, emSize, FontStyleRegular, UnitPoint)
|
---|
50 | End Sub
|
---|
51 |
|
---|
52 | Sub Font(/*IN const*/ ByRef family As FontFamily,
|
---|
53 | /*IN*/ emSize As Single, /*IN*/ style As Long)
|
---|
54 |
|
---|
55 | Font(family, emSize, style, UnitPoint)
|
---|
56 | End Sub
|
---|
57 |
|
---|
58 | Sub Font(/*IN const*/ ByRef family As FontFamily, /*IN*/ emSize As Single,
|
---|
59 | /*IN*/ style As Long, /*IN*/ unit As GraphicsUnit)
|
---|
60 |
|
---|
61 | Dim font = 0 As *GpFont
|
---|
62 | lastResult = GdipCreateFont(
|
---|
63 | family.NativeFamily, emSize, style, unit, font)
|
---|
64 | SetNativeFont(font)
|
---|
65 | End Sub
|
---|
66 |
|
---|
67 | Sub Font(/*IN const*/ familyName As PCWSTR, /*IN*/ emSize As Single)
|
---|
68 | Font(familyName, emSize, FontStyleRegular, Unit.Point, ByVal 0)
|
---|
69 | End Sub
|
---|
70 |
|
---|
71 | Sub Font(/*IN const*/ familyName As String, /*IN*/ emSize As Single)
|
---|
72 | Font(familyName, emSize, FontStyleRegular, Unit.Point, ByVal 0)
|
---|
73 | End Sub
|
---|
74 |
|
---|
75 | Sub Font(/*IN const*/ familyName As PCWSTR, /*IN*/ emSize As Single,
|
---|
76 | /*IN*/ style As Long)
|
---|
77 | Font(familyName, emSize, style, Unit.Point, ByVal 0)
|
---|
78 | End Sub
|
---|
79 |
|
---|
80 | Sub Font(/*IN const*/ familyName As String, /*IN*/ emSize As Single,
|
---|
81 | /*IN*/ style As Long)
|
---|
82 | Font(familyName, emSize, style, Unit.Point, ByVal 0)
|
---|
83 | End Sub
|
---|
84 |
|
---|
85 | Sub Font(/*IN const*/ familyName As PCWSTR, /*IN*/ emSize As Single,
|
---|
86 | /*IN*/ style As Long, /*IN*/ unit As GraphicsUnit)
|
---|
87 | Font(familyName, emSize, style, unit, ByVal 0)
|
---|
88 | End Sub
|
---|
89 |
|
---|
90 | Sub Font(/*IN const*/ familyName As String, /*IN*/ emSize As Single,
|
---|
91 | /*IN*/ style As Long, /*IN*/ unit As GraphicsUnit)
|
---|
92 | Font(familyName, emSize, style, unit, ByVal 0)
|
---|
93 | End Sub
|
---|
94 |
|
---|
95 | Sub Font(/*IN const*/ familyName As PCWSTR, /*IN*/ emSize As Single,
|
---|
96 | /*IN*/ style As Long, /*IN*/ unit As GraphicsUnit,
|
---|
97 | /*IN const*/ ByRef fontCollection As FontCollection)
|
---|
98 |
|
---|
99 | nativeFont = 0
|
---|
100 |
|
---|
101 | Dim family As FontFamily(familyName, fontCollection)
|
---|
102 | Dim nativeFamily = family.NativeFamily As *GpFontFamily
|
---|
103 |
|
---|
104 | lastResult = family.GetLastStatus()
|
---|
105 |
|
---|
106 | If lastResult <> Ok Then
|
---|
107 | nativeFamily = FontFamily.GenericSansSerif()->NativeFamily
|
---|
108 | lastResult = FontFamily.GenericSansSerif()->lastResult
|
---|
109 | If lastResult <> Ok Then
|
---|
110 | Exit Sub
|
---|
111 | End If
|
---|
112 | End If
|
---|
113 |
|
---|
114 | lastResult = GdipCreateFont(
|
---|
115 | nativeFamily, emSize, style, unit, nativeFont)
|
---|
116 |
|
---|
117 | If lastResult <> Ok Then
|
---|
118 | nativeFamily = FontFamily.GenericSansSerif()->NativeFamily
|
---|
119 | lastResult = FontFamily.GenericSansSerif()->lastResult
|
---|
120 | If lastResult <> Ok Then
|
---|
121 | Exit Sub
|
---|
122 | End If
|
---|
123 |
|
---|
124 | lastResult = GdipCreateFont(
|
---|
125 | nativeFamily, emSize, style, unit, nativeFont)
|
---|
126 | End If
|
---|
127 | End Sub
|
---|
128 |
|
---|
129 | Sub Font(/*IN const*/ familyName As String, /*IN*/ emSize As Single,
|
---|
130 | /*IN*/ style As Long, /*IN*/ unit As GraphicsUnit,
|
---|
131 | /*IN const*/ ByRef fontCollection As FontCollection)
|
---|
132 | #ifdef __STRING_IS_NOT_UNICODE
|
---|
133 | Dim name = _System_MultiByteToWideChar(familyName)
|
---|
134 | Font(name, emSize, style, unit, fontCollection)
|
---|
135 | _System_free(name)
|
---|
136 | #else
|
---|
137 | Font(familyName.Chars, emSize, style, unit, fontCollection)
|
---|
138 | #endif
|
---|
139 | End Sub
|
---|
140 |
|
---|
141 | Const Function GetLogFontA(/*IN const*/ ByRef g As Graphics, /*OUT*/ ByRef lf As LOGFONTA) As Status
|
---|
142 | Dim nativeGraphics As *GpGraphics
|
---|
143 | If VarPtr(g) <> 0 Then
|
---|
144 | nativeGraphics = g.nativeGraphics
|
---|
145 | End If
|
---|
146 | Return SetStatus(GdipGetLogFontA(nativeFont, nativeGraphics, lf))
|
---|
147 | End Function
|
---|
148 |
|
---|
149 | Const Function GetLogFontW(/*IN const*/ ByRef g As Graphics, /*OUT*/ ByRef lf As LOGFONTW) As Status
|
---|
150 | Dim nativeGraphics As *GpGraphics
|
---|
151 | If VarPtr(g) <> 0 Then
|
---|
152 | nativeGraphics = g.nativeGraphics
|
---|
153 | End If
|
---|
154 | Return SetStatus(GdipGetLogFontW(nativeFont, nativeGraphics, lf))
|
---|
155 | End Function
|
---|
156 |
|
---|
157 | Const Function GetLogFont(/*IN const*/ ByRef g As Graphics, /*OUT*/ ByRef lf As LOGFONTA) As Status
|
---|
158 | Dim nativeGraphics As *GpGraphics
|
---|
159 | If VarPtr(g) <> 0 Then
|
---|
160 | nativeGraphics = g.nativeGraphics
|
---|
161 | End If
|
---|
162 | #ifdef UNICODE
|
---|
163 | Return SetStatus(GdipGetLogFontW(nativeFont, nativeGraphics, lf))
|
---|
164 | #else
|
---|
165 | Return SetStatus(GdipGetLogFontA(nativeFont, nativeGraphics, lf))
|
---|
166 | #endif
|
---|
167 | End Function
|
---|
168 |
|
---|
169 | Const Function Clone() As *Font
|
---|
170 | Dim cloneFont = 0 As *GpFont
|
---|
171 | SetStatus(GdipCloneFont(nativeFont, cloneFont))
|
---|
172 | Return New Font(cloneFont, lastResult)
|
---|
173 | End Function
|
---|
174 |
|
---|
175 | Sub ~Font()
|
---|
176 | GdipDeleteFont(nativeFont)
|
---|
177 | End Sub
|
---|
178 |
|
---|
179 | Const Function IsAvailable() As Boolean
|
---|
180 | Return nativeFont <> 0
|
---|
181 | End Function
|
---|
182 |
|
---|
183 | Const Function Style() As Long
|
---|
184 | SetStatus(GdipGetFontStyle(nativeFont, Style))
|
---|
185 | End Function
|
---|
186 |
|
---|
187 | Const Function Size() As Single
|
---|
188 | SetStatus(GdipGetFontSize(nativeFont, Size))
|
---|
189 | End Function
|
---|
190 |
|
---|
191 | Const Function SizeInPoints() As Single
|
---|
192 |
|
---|
193 | Const Function Unit() As GraphicsUnit
|
---|
194 | SetStatus(GdipGetFontUnit(nativeFont, Unit))
|
---|
195 | End Function
|
---|
196 |
|
---|
197 | Const Function LastStatus() As Status
|
---|
198 | Return lastResult
|
---|
199 | End Function
|
---|
200 |
|
---|
201 | Const Function Height() As Long
|
---|
202 | Return GetHeight() As Long
|
---|
203 | End Function
|
---|
204 |
|
---|
205 | Const Function GetHeight() As Single
|
---|
206 | SetStatus(GdipGetFontHeight(nativeFont, 0, GetHeight))
|
---|
207 | End Function
|
---|
208 |
|
---|
209 | Const Function GetHeight(/*IN const*/ ByRef g As Graphics) As Single
|
---|
210 | Dim nativeGraphics As *GpGraphics
|
---|
211 | If VarPtr(g) <> 0 Then
|
---|
212 | nativeGraphics = g.NativeGraphics
|
---|
213 | End If
|
---|
214 | SetStatus(GdipGetFontHeight(nativeFont, nativeGraphics, GetHeight))
|
---|
215 | End Function
|
---|
216 |
|
---|
217 | Const Function GetHeight(/*IN*/ dpi As Single) As Single
|
---|
218 | SetStatus(GdipGetFontHeightGivenDPI(nativeFont, dpi, GetHeight))
|
---|
219 | End Function
|
---|
220 |
|
---|
221 | ' Const Function FontFamily(/*OUT*/ ByRef family As FontFamily)
|
---|
222 | ' If VarPtr(family) = 0 Then
|
---|
223 | ' Return SetStatus(Status.InvalidParameter)
|
---|
224 | ' End If
|
---|
225 | ' Dim status = GdipGetFamily(nativeFont, family->nativeFamily)
|
---|
226 | ' family->SetStatus(status)
|
---|
227 | ' Return SetStatus(status)
|
---|
228 | ' End Function
|
---|
229 |
|
---|
230 | Const Function Bold() As Boolean
|
---|
231 | Dim lf As LOGFONT
|
---|
232 | GetLogFont(0, lf)
|
---|
233 | Return lf.lfWeight > FW_BOLD
|
---|
234 | End Function
|
---|
235 |
|
---|
236 | Const Function GdiCharSet() As Byte
|
---|
237 | Dim lf As LOGFONT
|
---|
238 | GetLogFont(0, lf)
|
---|
239 | Return lf.lfCharSet
|
---|
240 | End Function
|
---|
241 |
|
---|
242 | 'Const Function GdiVerticalFont() As Boolean
|
---|
243 |
|
---|
244 | Const Function NativeFont() As *GpFont
|
---|
245 | Return nativeFont
|
---|
246 | End Function
|
---|
247 |
|
---|
248 | 'Const Function IsSystemFont() As Boolean
|
---|
249 |
|
---|
250 | Const Function Italic() As Boolean
|
---|
251 | Dim lf As LOGFONT
|
---|
252 | GetLogFont(0, lf)
|
---|
253 | Return lf.lfItalic <> FALSE
|
---|
254 | End Function
|
---|
255 |
|
---|
256 | Const Function Name() As String
|
---|
257 | #ifdef __STRING_IS_NOT_UNICODE
|
---|
258 | Dim lf As LOGFONTA
|
---|
259 | GetLogFontA(0, lf)
|
---|
260 | #else
|
---|
261 | Dim lf As LOGFONTW
|
---|
262 | GetLogFontW(0, lf)
|
---|
263 | #endif
|
---|
264 | Return lf.lfFaceName
|
---|
265 | End Function
|
---|
266 |
|
---|
267 | 'Const Function SizeInPoint() As Boolean
|
---|
268 |
|
---|
269 | Const Function NativeFont() As *GpFont
|
---|
270 | Return nativeFont
|
---|
271 | End Function
|
---|
272 |
|
---|
273 | Const Function StrikeOut() As Boolean
|
---|
274 | Dim lf As LOGFONT
|
---|
275 | GetLogFont(0, lf)
|
---|
276 | Return lf.fdwStrikeOut <> FALSE
|
---|
277 | End Function
|
---|
278 |
|
---|
279 | Const Function Style() As FontStyle
|
---|
280 | Dim lf As LOGFONT
|
---|
281 | GetLogFont(0, lf)
|
---|
282 | Return (((lf.lfWeight > FW_BOLD) And FontStyle.Bold) Or _
|
---|
283 | ((lf.lfItatlic <> FALSE) And FontStyle.Italic) Or _
|
---|
284 | ((lf.fdwStrikeOut <> FALSE) And FontStyle.Strickeout) Or _
|
---|
285 | ((lf.fdwUnderline <> FALSE) And FontStyle.Underline)) As FontStyle
|
---|
286 | End Function
|
---|
287 |
|
---|
288 | 'Const Function SystemFontName() As String
|
---|
289 |
|
---|
290 | Const Function Underline() As Boolean
|
---|
291 | Dim lf As LOGFONT
|
---|
292 | GetLogFont(0, lf)
|
---|
293 | Return lf.fdwUnderline <> FALSE
|
---|
294 | End Function
|
---|
295 |
|
---|
296 | Override Function ToString() As String
|
---|
297 | Return Name
|
---|
298 | End Function
|
---|
299 |
|
---|
300 | Const Function ToHfont() As HFONT
|
---|
301 | Dim lf As LOGFONT
|
---|
302 | GetLogFont(ByVal 0, lf)
|
---|
303 | Return CreateFontIndirect(lf)
|
---|
304 | End Function
|
---|
305 |
|
---|
306 | Const Sub ToLogFont(ByRef lf As LOGFONT)
|
---|
307 | GetLogFont(ByVal 0, lf)
|
---|
308 | End Sub
|
---|
309 |
|
---|
310 | Const Sub ToLogFont(ByRef lf As LOGFONT, ByRef g As Graphics)
|
---|
311 | GetLogFont(g, lf)
|
---|
312 | End Sub
|
---|
313 |
|
---|
314 |
|
---|
315 | Private
|
---|
316 | ' Sub Font(ByRef f As Font)
|
---|
317 | Sub Operator =(ByRef f As Font)
|
---|
318 | Debug
|
---|
319 | End Sub
|
---|
320 |
|
---|
321 | Protected
|
---|
322 | Sub Font(f As *GpFont, status As Status)
|
---|
323 | lastResult = status
|
---|
324 | SetNativeFont(f)
|
---|
325 | End Sub
|
---|
326 |
|
---|
327 | Sub SetNativeFont(f As *GpFont)
|
---|
328 | nativeFont = f
|
---|
329 | End Sub
|
---|
330 |
|
---|
331 | Const Function SetStatus(s As Status) As Status
|
---|
332 | If s <> Status.Ok Then
|
---|
333 | lastResult = s
|
---|
334 | Return s
|
---|
335 | Else
|
---|
336 | Return s
|
---|
337 | End If
|
---|
338 | End Function
|
---|
339 |
|
---|
340 | Protected
|
---|
341 | nativeFont As *GpFont
|
---|
342 | /*mutable*/ lastResult As Status
|
---|
343 | End Class
|
---|
344 |
|
---|
345 | #endif
|
---|