source: trunk/Include/Classes/System/Drawing/Font.ab@ 384

Last change on this file since 384 was 212, checked in by イグトランス (egtra), 18 years ago

Object.ReferenceEqualsを追加

File size: 9.1 KB
Line 
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
8Class FontFamily : End Class
9Class FontCollection : End Class
10
11Class Font
12Public
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*/ family As FontFamily, /*IN*/ emSize As Single)
49 Font(family, emSize, FontStyleRegular, UnitPoint)
50 End Sub
51
52 Sub Font(/*IN const*/ 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*/ 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*/ 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*/ 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*/ 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*/ g As Graphics, /*OUT*/ ByRef lf As LOGFONT) 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*/ 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, g As Graphics)
314 GetLogFont(g, lf)
315 End Sub
316
317Private
318' Sub Font(ByRef f As Font)
319
320Protected
321 Sub Font(f As *GpFont, status As Status)
322 lastResult = status
323 SetNativeFont(f)
324 End Sub
325
326 Sub SetNativeFont(f As *GpFont)
327 nativeFont = f
328 End Sub
329
330 Const Function SetStatus(s As Status) As Status
331 If s <> Status.Ok Then
332 lastResult = s
333 Return s
334 Else
335 Return s
336 End If
337 End Function
338
339Protected
340 nativeFont As *GpFont
341 /*mutable*/ lastResult As Status
342End Class
343
344#endif
Note: See TracBrowser for help on using the repository browser.