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 oldAlloc = _System_AllocForConvertedString
|
---|
134 | _System_AllocForConvertedString = AddressOf (_System_malloc)
|
---|
135 | Dim name = ToWCStr(familyName)
|
---|
136 | Font(name, emSize, style, unit, fontCollection)
|
---|
137 | _System_free(name)
|
---|
138 | _System_AllocForConvertedString = oldAlloc
|
---|
139 | #else
|
---|
140 | Font(familyName.Chars, emSize, style, unit, fontCollection)
|
---|
141 | #endif
|
---|
142 | End Sub
|
---|
143 |
|
---|
144 | Const Function GetLogFontA(/*IN const*/ ByRef g As Graphics, /*OUT*/ ByRef lf As LOGFONTA) As Status
|
---|
145 | Dim nativeGraphics As *GpGraphics
|
---|
146 | If VarPtr(g) <> 0 Then
|
---|
147 | nativeGraphics = g.nativeGraphics
|
---|
148 | End If
|
---|
149 | Return SetStatus(GdipGetLogFontA(nativeFont, nativeGraphics, lf))
|
---|
150 | End Function
|
---|
151 |
|
---|
152 | Const Function GetLogFontW(/*IN const*/ ByRef g As Graphics, /*OUT*/ ByRef lf As LOGFONTW) As Status
|
---|
153 | Dim nativeGraphics As *GpGraphics
|
---|
154 | If VarPtr(g) <> 0 Then
|
---|
155 | nativeGraphics = g.nativeGraphics
|
---|
156 | End If
|
---|
157 | Return SetStatus(GdipGetLogFontW(nativeFont, nativeGraphics, lf))
|
---|
158 | End Function
|
---|
159 |
|
---|
160 | Const Function GetLogFont(/*IN const*/ ByRef g As Graphics, /*OUT*/ ByRef lf As LOGFONTA) As Status
|
---|
161 | Dim nativeGraphics As *GpGraphics
|
---|
162 | If VarPtr(g) <> 0 Then
|
---|
163 | nativeGraphics = g.nativeGraphics
|
---|
164 | End If
|
---|
165 | #ifdef UNICODE
|
---|
166 | Return SetStatus(GdipGetLogFontW(nativeFont, nativeGraphics, lf))
|
---|
167 | #else
|
---|
168 | Return SetStatus(GdipGetLogFontA(nativeFont, nativeGraphics, lf))
|
---|
169 | #endif
|
---|
170 | End Function
|
---|
171 |
|
---|
172 | Const Function Clone() As *Font
|
---|
173 | Dim cloneFont = 0 As *GpFont
|
---|
174 | SetStatus(GdipCloneFont(nativeFont, cloneFont))
|
---|
175 | Return New Font(cloneFont, lastResult)
|
---|
176 | End Function
|
---|
177 |
|
---|
178 | Sub ~Font()
|
---|
179 | GdipDeleteFont(nativeFont)
|
---|
180 | End Sub
|
---|
181 |
|
---|
182 | Const Function IsAvailable() As Boolean
|
---|
183 | Return nativeFont <> 0
|
---|
184 | End Function
|
---|
185 |
|
---|
186 | Const Function Style() As Long
|
---|
187 | SetStatus(GdipGetFontStyle(nativeFont, Style))
|
---|
188 | End Function
|
---|
189 |
|
---|
190 | Const Function Size() As Single
|
---|
191 | SetStatus(GdipGetFontSize(nativeFont, Size))
|
---|
192 | End Function
|
---|
193 |
|
---|
194 | Const Function SizeInPoints() As Single
|
---|
195 |
|
---|
196 | Const Function Unit() As GraphicsUnit
|
---|
197 | SetStatus(GdipGetFontUnit(nativeFont, Unit))
|
---|
198 | End Function
|
---|
199 |
|
---|
200 | Const Function LastStatus() As Status
|
---|
201 | Return lastResult
|
---|
202 | End Function
|
---|
203 |
|
---|
204 | Const Function Height() As Long
|
---|
205 | Return GetHeight() As Long
|
---|
206 | End Function
|
---|
207 |
|
---|
208 | Const Function GetHeight() As Single
|
---|
209 | SetStatus(GdipGetFontHeight(nativeFont, 0, GetHeight))
|
---|
210 | End Function
|
---|
211 |
|
---|
212 | Const Function GetHeight(/*IN const*/ ByRef g As Graphics) As Single
|
---|
213 | Dim nativeGraphics As *GpGraphics
|
---|
214 | If VarPtr(g) <> 0 Then
|
---|
215 | nativeGraphics = g.NativeGraphics
|
---|
216 | End If
|
---|
217 | SetStatus(GdipGetFontHeight(nativeFont, nativeGraphics, GetHeight))
|
---|
218 | End Function
|
---|
219 |
|
---|
220 | Const Function GetHeight(/*IN*/ dpi As Single) As Single
|
---|
221 | SetStatus(GdipGetFontHeightGivenDPI(nativeFont, dpi, GetHeight))
|
---|
222 | End Function
|
---|
223 |
|
---|
224 | ' Const Function FontFamily(/*OUT*/ ByRef family As FontFamily)
|
---|
225 | ' If VarPtr(family) = 0 Then
|
---|
226 | ' Return SetStatus(Status.InvalidParameter)
|
---|
227 | ' End If
|
---|
228 | ' Dim status = GdipGetFamily(nativeFont, family->nativeFamily)
|
---|
229 | ' family->SetStatus(status)
|
---|
230 | ' Return SetStatus(status)
|
---|
231 | ' End Function
|
---|
232 |
|
---|
233 | Const Function Bold() As Boolean
|
---|
234 | Dim lf As LOGFONT
|
---|
235 | GetLogFont(0, lf)
|
---|
236 | Return lf.lfWeight > FW_BOLD
|
---|
237 | End Function
|
---|
238 |
|
---|
239 | Const Function GdiCharSet() As Byte
|
---|
240 | Dim lf As LOGFONT
|
---|
241 | GetLogFont(0, lf)
|
---|
242 | Return lf.lfCharSet
|
---|
243 | End Function
|
---|
244 |
|
---|
245 | 'Const Function GdiVerticalFont() As Boolean
|
---|
246 |
|
---|
247 | Const Function NativeFont() As *GpFont
|
---|
248 | Return nativeFont
|
---|
249 | End Function
|
---|
250 |
|
---|
251 | 'Const Function IsSystemFont() As Boolean
|
---|
252 |
|
---|
253 | Const Function Italic() As Boolean
|
---|
254 | Dim lf As LOGFONT
|
---|
255 | GetLogFont(0, lf)
|
---|
256 | Return lf.lfItalic <> FALSE
|
---|
257 | End Function
|
---|
258 |
|
---|
259 | Const Function Name() As String
|
---|
260 | #ifdef __STRING_IS_NOT_UNICODE
|
---|
261 | Dim lf As LOGFONTA
|
---|
262 | GetLogFontA(0, lf)
|
---|
263 | #else
|
---|
264 | Dim lf As LOGFONTW
|
---|
265 | GetLogFontW(0, lf)
|
---|
266 | #endif
|
---|
267 | Return lf.lfFaceName
|
---|
268 | End Function
|
---|
269 |
|
---|
270 | 'Const Function SizeInPoint() As Boolean
|
---|
271 |
|
---|
272 | Const Function NativeFont() As *GpFont
|
---|
273 | Return nativeFont
|
---|
274 | End Function
|
---|
275 |
|
---|
276 | Const Function StrikeOut() As Boolean
|
---|
277 | Dim lf As LOGFONT
|
---|
278 | GetLogFont(0, lf)
|
---|
279 | Return lf.fdwStrikeOut <> FALSE
|
---|
280 | End Function
|
---|
281 |
|
---|
282 | Const Function Style() As FontStyle
|
---|
283 | Dim lf As LOGFONT
|
---|
284 | GetLogFont(0, lf)
|
---|
285 | Return (((lf.lfWeight > FW_BOLD) And FontStyle.Bold) Or _
|
---|
286 | ((lf.lfItatlic <> FALSE) And FontStyle.Italic) Or _
|
---|
287 | ((lf.fdwStrikeOut <> FALSE) And FontStyle.Strickeout) Or _
|
---|
288 | ((lf.fdwUnderline <> FALSE) And FontStyle.Underline)) As FontStyle
|
---|
289 | End Function
|
---|
290 |
|
---|
291 | 'Const Function SystemFontName() As String
|
---|
292 |
|
---|
293 | Const Function Underline() As Boolean
|
---|
294 | Dim lf As LOGFONT
|
---|
295 | GetLogFont(0, lf)
|
---|
296 | Return lf.fdwUnderline <> FALSE
|
---|
297 | End Function
|
---|
298 |
|
---|
299 | Override Function ToString() As String
|
---|
300 | Return Name
|
---|
301 | End Function
|
---|
302 |
|
---|
303 | Const Function ToHfont() As HFONT
|
---|
304 | Dim lf As LOGFONT
|
---|
305 | GetLogFont(ByVal 0, lf)
|
---|
306 | Return CreateFontIndirect(lf)
|
---|
307 | End Function
|
---|
308 |
|
---|
309 | Const Sub ToLogFont(ByRef lf As LOGFONT)
|
---|
310 | GetLogFont(ByVal 0, lf)
|
---|
311 | End Sub
|
---|
312 |
|
---|
313 | Const Sub ToLogFont(ByRef lf As LOGFONT, ByRef g As Graphics)
|
---|
314 | GetLogFont(g, lf)
|
---|
315 | End Sub
|
---|
316 |
|
---|
317 |
|
---|
318 | Private
|
---|
319 | ' Sub Font(ByRef f As Font)
|
---|
320 | Sub Operator =(ByRef f As Font)
|
---|
321 | Debug
|
---|
322 | End Sub
|
---|
323 |
|
---|
324 | Protected
|
---|
325 | Sub Font(f As *GpFont, status As Status)
|
---|
326 | lastResult = status
|
---|
327 | SetNativeFont(f)
|
---|
328 | End Sub
|
---|
329 |
|
---|
330 | Sub SetNativeFont(f As *GpFont)
|
---|
331 | nativeFont = f
|
---|
332 | End Sub
|
---|
333 |
|
---|
334 | Const Function SetStatus(s As Status) As Status
|
---|
335 | If s <> Status.Ok Then
|
---|
336 | lastResult = s
|
---|
337 | Return s
|
---|
338 | Else
|
---|
339 | Return s
|
---|
340 | End If
|
---|
341 | End Function
|
---|
342 |
|
---|
343 | Protected
|
---|
344 | nativeFont As *GpFont
|
---|
345 | /*mutable*/ lastResult As Status
|
---|
346 | End Class
|
---|
347 |
|
---|
348 | #endif
|
---|