source: branch/egtra-gdiplus/Classes/System/Drawing/Font.ab

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

GDI+に対して名前空間で囲ったものの、現在コンパイルできないため分岐させておく

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