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

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

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

File size: 9.7 KB
RevLine 
[104]1#ifndef _GDIPLUSFONT_H
2#define _GDIPLUSFONT_H
3
[241]4#require <GdiPlusTypes.ab>
5#require <GdiPlusGpStubs.ab>
6#require <GdiPlusFlat.ab>
[137]7#require <Classes/System/Drawing/misc.ab>
[104]8#require <Classes/System/Drawing/Graphics.ab>
9
[241]10Namespace System
11Namespace Drawing
12
[104]13Class FontFamily : End Class
[241]14
15Namespace Text
[104]16Class FontCollection : End Class
[241]17End Namespace
[104]18
[241]19'Todo: コンストラクタ内での別コンストラクタ呼出を修正せよ
20
[104]21Class Font
22Public
23' friend class Graphics
24
25 Sub Font(/*IN*/ hdc As HDC)
[241]26 Dim font = 0 As *Gdiplus.GpFont
27 lastResult = Gdiplus.DllExports.GdipCreateFontFromDC(hdc, font)
[104]28 SetNativeFont(font)
29 End Sub
30
31 Sub Font(/*IN*/ hdc As HDC, /*IN const*/ ByRef logfont As LOGFONTA)
[241]32 Dim font = 0 As *Gdiplus.GpFont
33 lastResult = Gdiplus.DllExports.GdipCreateFontFromLogfontA(hdc, logfont, font)
[104]34 SetNativeFont(font)
35 End Sub
36
37 Sub Font(/*IN*/ hdc As HDC, /*IN const*/ ByRef logfont As LOGFONTW)
[241]38 Dim font = 0 As *Gdiplus.GpFont
39 lastResult = Gdiplus.DllExports.GdipCreateFontFromLogfontW(hdc, logfont, font)
[104]40 SetNativeFont(font)
41 End Sub
42
43 Sub Font(/*IN*/ hdc As HDC, /*IN const*/ hfont As HFONT)
[241]44 Dim font = 0 As *Gdiplus.GpFont
[104]45 If hfont <> 0 Then
46 Dim lf As LOGFONTA
[241]47 If GetObjectA(hfont, SizeOf (LOGFONTA), lf) <> 0 Then
48 lastResult = Gdiplus.DllExports.GdipCreateFontFromLogfontA(hdc, lf, font)
[104]49 Else
[241]50 lastResult = Gdiplus.DllExports.GdipCreateFontFromDC(hdc, font)
[104]51 End If
52 Else
[241]53 lastResult = Gdiplus.DllExports.GdipCreateFontFromDC(hdc, font)
[104]54 End If
55 SetNativeFont(font)
56 End Sub
57
[212]58 Sub Font(/*IN const*/ family As FontFamily, /*IN*/ emSize As Single)
[104]59 Font(family, emSize, FontStyleRegular, UnitPoint)
60 End Sub
61
[212]62 Sub Font(/*IN const*/ family As FontFamily,
[104]63 /*IN*/ emSize As Single, /*IN*/ style As Long)
64
65 Font(family, emSize, style, UnitPoint)
66 End Sub
67
[212]68 Sub Font(/*IN const*/ family As FontFamily, /*IN*/ emSize As Single,
[104]69 /*IN*/ style As Long, /*IN*/ unit As GraphicsUnit)
70
[241]71 Dim font = 0 As *Gdiplus.GpFont
72 lastResult = Gdiplus.DllExports.GdipCreateFont(family.NativeFamily, emSize, style, unit, font)
[104]73 SetNativeFont(font)
74 End Sub
75
[137]76 Sub Font(/*IN const*/ familyName As PCWSTR, /*IN*/ emSize As Single)
77 Font(familyName, emSize, FontStyleRegular, Unit.Point, ByVal 0)
[104]78 End Sub
79
[137]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,
[104]85 /*IN*/ style As Long)
[137]86 Font(familyName, emSize, style, Unit.Point, ByVal 0)
[104]87 End Sub
88
[137]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,
[104]95 /*IN*/ style As Long, /*IN*/ unit As GraphicsUnit)
96 Font(familyName, emSize, style, unit, ByVal 0)
97 End Sub
98
[137]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,
[104]105 /*IN*/ style As Long, /*IN*/ unit As GraphicsUnit,
[241]106 /*IN const*/ ByRef fontCollection As Text.FontCollection)
[104]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
[241]115 If lastResult <> Gdiplus.Status.Ok Then
116 nativeFamily = FontFamily.GenericSansSerif().NativeFamily
117 lastResult = FontFamily.GenericSansSerif().lastResult
118 If lastResult <> Gdiplus.Status.Ok Then
[104]119 Exit Sub
120 End If
121 End If
122
[241]123 lastResult = Gdiplus.DllExports.GdipCreateFont(
[104]124 nativeFamily, emSize, style, unit, nativeFont)
125
[241]126 If lastResult <> Gdiplus.Status.Ok Then
127 nativeFamily = FontFamily.GenericSansSerif().NativeFamily
128 lastResult = FontFamily.GenericSansSerif().lastResult
129 If lastResult <> Gdiplus.Status.Ok Then
[104]130 Exit Sub
131 End If
132
[241]133 lastResult = Gdiplus.DllExports.GdipCreateFont(nativeFamily, emSize, style, unit, nativeFont)
[104]134 End If
135 End Sub
136
[137]137 Sub Font(/*IN const*/ familyName As String, /*IN*/ emSize As Single,
138 /*IN*/ style As Long, /*IN*/ unit As GraphicsUnit,
[241]139 /*IN const*/ fontCollection As Text.FontCollection)
140 Font(ToWCStr(familyName), emSize, style, unit, fontCollection)
[137]141 End Sub
142
[241]143 Const Function GetLogFontA(/*IN const*/ g As Graphics, /*OUT*/ ByRef lf As LOGFONTA) As Gdiplus.Status
[104]144 Dim nativeGraphics As *GpGraphics
145 If VarPtr(g) <> 0 Then
146 nativeGraphics = g.nativeGraphics
147 End If
[241]148 Return SetStatus(Gdiplus.DllExports.GdipGetLogFontA(nativeFont, nativeGraphics, lf))
[104]149 End Function
150
[241]151 Const Function GetLogFontW(/*IN const*/ g As Graphics, /*OUT*/ ByRef lf As LOGFONTW) As Gdiplus.Status
[104]152 Dim nativeGraphics As *GpGraphics
153 If VarPtr(g) <> 0 Then
154 nativeGraphics = g.nativeGraphics
155 End If
[241]156 Return SetStatus(Gdiplus.DllExports.GdipGetLogFontW(nativeFont, nativeGraphics, lf))
[104]157 End Function
158
[241]159 Const Function GetLogFont(/*IN const*/ g As Graphics, /*OUT*/ ByRef lf As LOGFONT) As Gdiplus.Status
[137]160 Dim nativeGraphics As *GpGraphics
161 If VarPtr(g) <> 0 Then
162 nativeGraphics = g.nativeGraphics
163 End If
164#ifdef UNICODE
[241]165 Return SetStatus(Gdiplus.DllExports.GdipGetLogFontW(nativeFont, nativeGraphics, lf))
[137]166#else
[241]167 Return SetStatus(Gdiplus.DllExports.GdipGetLogFontA(nativeFont, nativeGraphics, lf))
[137]168#endif
169 End Function
170
[212]171 Const Function Clone() As Font
[241]172 Dim cloneFont = 0 As *Gdiplus.GpFont
173 SetStatus(Gdiplus.DllExports.GdipCloneFont(nativeFont, cloneFont))
[104]174 Return New Font(cloneFont, lastResult)
175 End Function
176
[241]177 Sub Dispose()
178 Gdiplus.DllExports.GdipDeleteFont(nativeFont)
179 nativeFont = 0
180 End Sub
181
[104]182 Sub ~Font()
[241]183 If nativeFont <> 0 Then
184 Dispose()
185 End If
[104]186 End Sub
187
[137]188 Const Function IsAvailable() As Boolean
[104]189 Return nativeFont <> 0
190 End Function
191
192 Const Function Style() As Long
[241]193 SetStatus(Gdiplus.DllExports.GdipGetFontStyle(nativeFont, Style))
[104]194 End Function
195
196 Const Function Size() As Single
[241]197 SetStatus(Gdiplus.DllExports.GdipGetFontSize(nativeFont, Size))
[104]198 End Function
199
[241]200' Const Function SizeInPoints() As Single
[137]201
[104]202 Const Function Unit() As GraphicsUnit
[241]203 SetStatus(Gdiplus.DllExports.GdipGetFontUnit(nativeFont, Unit))
[104]204 End Function
205
[241]206 Const Function LastStatus() As Gdiplus.Status
[104]207 Return lastResult
208 End Function
209
[137]210 Const Function Height() As Long
211 Return GetHeight() As Long
[104]212 End Function
213
214 Const Function GetHeight() As Single
[241]215 SetStatus(Gdiplus.DllExports.GdipGetFontHeight(nativeFont, 0, GetHeight))
[104]216 End Function
217
[212]218 Const Function GetHeight(/*IN const*/ g As Graphics) As Single
[241]219 Dim nativeGraphics As *Gdiplus.GpGraphics
[104]220 If VarPtr(g) <> 0 Then
221 nativeGraphics = g.NativeGraphics
222 End If
[241]223 SetStatus(Gdiplus.DllExports.GdipGetFontHeight(nativeFont, nativeGraphics, GetHeight))
[104]224 End Function
225
226 Const Function GetHeight(/*IN*/ dpi As Single) As Single
[241]227 SetStatus(Gdiplus.DllExports.GdipGetFontHeightGivenDPI(nativeFont, dpi, GetHeight))
[104]228 End Function
229
230' Const Function FontFamily(/*OUT*/ ByRef family As FontFamily)
[241]231' family = New FontFamily
232' Dim status = GdipGetFamily(nativeFont, family.nativeFamily)
233' family.SetStatus(status)
[104]234' Return SetStatus(status)
235' End Function
236
[137]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
[241]251 Const Function NativeFont() As *Gdiplus.GpFont
[104]252 Return nativeFont
253 End Function
254
[137]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
[241]276 Const Function NativeFont() As *Gdiplus.GpFont
[137]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
[142]294
[137]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
[212]317 Const Sub ToLogFont(ByRef lf As LOGFONT, g As Graphics)
[137]318 GetLogFont(g, lf)
319 End Sub
320
[241]321'Protected
322 Sub Font(f As *Gdiplus.GpFont, status As Gdiplus.Status)
[104]323 lastResult = status
324 SetNativeFont(f)
325 End Sub
[241]326Protected
327 Sub SetNativeFont(f As *Gdiplus.GpFont)
[104]328 nativeFont = f
329 End Sub
330
[241]331 Const Function SetStatus(s As Gdiplus.Status) As Gdiplus.Status
332 If s <> Gdiplus.Status.Ok Then
[104]333 lastResult = s
334 Return s
335 Else
336 Return s
337 End If
338 End Function
339
340Protected
[241]341 nativeFont As *Gdiplus.GpFont
342 /*mutable*/ lastResult As Gdiplus.Status
[104]343End Class
344
[241]345End Namespace 'Drawing
346End Namespace 'System
347
[104]348#endif
Note: See TracBrowser for help on using the repository browser.