1 | Namespace System
|
---|
2 | Namespace Drawing
|
---|
3 |
|
---|
4 | /**
|
---|
5 | @file Classes/System/Drawing/Font.ab
|
---|
6 | @brief Fontクラスなどの実装。
|
---|
7 | */
|
---|
8 |
|
---|
9 | Class FontCollection
|
---|
10 | Public
|
---|
11 | nativeCollection As *GpFontCollection
|
---|
12 | End Class
|
---|
13 |
|
---|
14 | Class Font
|
---|
15 | Implements System.IDisposable
|
---|
16 | Public
|
---|
17 | Static Function FromHDC(/*IN*/ hdc As HDC) As Font
|
---|
18 | Dim font = 0 As *GpFont
|
---|
19 | SetStatus(GdipCreateFontFromDC(hdc, font))
|
---|
20 | FromHDC = New Font(font)
|
---|
21 | End Function
|
---|
22 |
|
---|
23 | Static Function FromLogFont(/*IN*/ hdc As HDC, /*IN const*/ ByRef logfont As LOGFONTA) As Font
|
---|
24 | Dim font = 0 As *GpFont
|
---|
25 | SetStatus(GdipCreateFontFromLogfontA(hdc, logfont, font))
|
---|
26 | FromLogFont = New Font(font)
|
---|
27 | End Function
|
---|
28 |
|
---|
29 | Static Function FromLogFont(/*IN*/ hdc As HDC, /*IN const*/ ByRef logfont As LOGFONTW) As Font
|
---|
30 | Dim font = 0 As *GpFont
|
---|
31 | SetStatus(GdipCreateFontFromLogfontW(hdc, logfont, font))
|
---|
32 | FromLogFont = New Font(font)
|
---|
33 | End Function
|
---|
34 |
|
---|
35 | Static Function FromHFont(/*IN*/ hdc As HDC, /*IN const*/ hfont As HFONT) As Font
|
---|
36 | Dim font = 0 As *GpFont
|
---|
37 | If hfont <> 0 Then
|
---|
38 | Dim lf As LOGFONTA
|
---|
39 | If GetObjectA(hfont, Len(lf), lf) <> 0 Then
|
---|
40 | SetStatus(GdipCreateFontFromLogfontA(hdc, lf, font))
|
---|
41 | Else
|
---|
42 | SetStatus(GdipCreateFontFromDC(hdc, font))
|
---|
43 | End If
|
---|
44 | Else
|
---|
45 | SetStatus(GdipCreateFontFromDC(hdc, font))
|
---|
46 | End If
|
---|
47 | FromHFont = New Font(font)
|
---|
48 | End Function
|
---|
49 |
|
---|
50 | Sub Font(f As *GpFont)
|
---|
51 | nativeFont = f
|
---|
52 | End Sub
|
---|
53 |
|
---|
54 | Sub Font(/*IN const*/ family As FontFamily, /*IN*/ emSize As Single)
|
---|
55 | initFont(family, emSize, FontStyle.Regular, GraphicsUnit.Point)
|
---|
56 | End Sub
|
---|
57 |
|
---|
58 | Sub Font(/*IN const*/ family As FontFamily, /*IN*/ emSize As Single, /*IN*/ style As FontStyle)
|
---|
59 | initFont(family, emSize, style, GraphicsUnit.Point)
|
---|
60 | End Sub
|
---|
61 |
|
---|
62 | Sub Font(/*IN const*/ family As FontFamily, /*IN*/ emSize As Single, /*IN*/ unit As GraphicsUnit)
|
---|
63 | initFont(family, emSize, FontStyle.Regular, unit)
|
---|
64 | End Sub
|
---|
65 |
|
---|
66 | Sub Font(/*IN const*/ family As FontFamily, /*IN*/ emSize As Single,
|
---|
67 | /*IN*/ style As FontStyle, /*IN*/ unit As GraphicsUnit)
|
---|
68 |
|
---|
69 | initFont(family, emSize, style, unit)
|
---|
70 | End Sub
|
---|
71 |
|
---|
72 | Sub Font(/*IN const*/ familyName As PCWSTR, /*IN*/ emSize As Single)
|
---|
73 | initFromName(familyName, emSize, FontStyle.Regular, GraphicsUnit.Point, Nothing)
|
---|
74 | End Sub
|
---|
75 |
|
---|
76 | Sub Font(/*IN const*/ familyName As String, /*IN*/ emSize As Single)
|
---|
77 | initFromName(ToWCStr(familyName), emSize, FontStyle.Regular, GraphicsUnit.Point, Nothing)
|
---|
78 | End Sub
|
---|
79 |
|
---|
80 | Sub Font(/*IN const*/ familyName As PCWSTR, /*IN*/ emSize As Single, /*IN*/ style As FontStyle)
|
---|
81 | initFromName(familyName, emSize, style, GraphicsUnit.Point, Nothing)
|
---|
82 | End Sub
|
---|
83 |
|
---|
84 | Sub Font(/*IN const*/ familyName As String, /*IN*/ emSize As Single, /*IN*/ style As FontStyle)
|
---|
85 | initFromName(ToWCStr(familyName), emSize, style, GraphicsUnit.Point, Nothing)
|
---|
86 | End Sub
|
---|
87 |
|
---|
88 | Sub Font(/*IN const*/ familyName As PCWSTR, /*IN*/ emSize As Single, /*IN*/ unit As GraphicsUnit)
|
---|
89 | initFromName(familyName, emSize, FontStyle.Regular, unit, Nothing)
|
---|
90 | End Sub
|
---|
91 |
|
---|
92 | Sub Font(/*IN const*/ familyName As String, /*IN*/ emSize As Single, /*IN*/ unit As GraphicsUnit)
|
---|
93 | initFromName(ToWCStr(familyName), emSize, FontStyle.Regular, unit, Nothing)
|
---|
94 | End Sub
|
---|
95 |
|
---|
96 | Sub Font(/*IN const*/ familyName As PCWSTR, /*IN*/ emSize As Single,
|
---|
97 | /*IN*/ style As FontStyle, /*IN*/ unit As GraphicsUnit)
|
---|
98 |
|
---|
99 | initFromName(familyName, emSize, style, unit, Nothing)
|
---|
100 | End Sub
|
---|
101 |
|
---|
102 | Sub Font(/*IN const*/ familyName As String, /*IN*/ emSize As Single,
|
---|
103 | /*IN*/ style As FontStyle, /*IN*/ unit As GraphicsUnit)
|
---|
104 |
|
---|
105 | initFromName(ToWCStr(familyName), emSize, style, unit, Nothing)
|
---|
106 | End Sub
|
---|
107 |
|
---|
108 | Sub Font(/*IN const*/ familyName As PCWSTR, /*IN*/ emSize As Single,
|
---|
109 | /*IN*/ style As FontStyle, /*IN*/ unit As GraphicsUnit,
|
---|
110 | /*IN const*/ fontCollection As FontCollection)
|
---|
111 |
|
---|
112 | initFromName(familyName, emSize, style, unit, fontCollection)
|
---|
113 | End Sub
|
---|
114 |
|
---|
115 | Sub Font(/*IN const*/ familyName As String, /*IN*/ emSize As Single,
|
---|
116 | /*IN*/ style As FontStyle, /*IN*/ unit As GraphicsUnit,
|
---|
117 | /*IN const*/ fontCollection As FontCollection)
|
---|
118 |
|
---|
119 | initFromName(ToWCStr(familyName), emSize, style, unit, fontCollection)
|
---|
120 | End Sub
|
---|
121 |
|
---|
122 | Const Function Clone() As Font
|
---|
123 | Dim cloneFont = 0 As *GpFont
|
---|
124 | SetStatus(GdipCloneFont(nativeFont, cloneFont))
|
---|
125 | Clone = New Font(cloneFont)
|
---|
126 | End Function
|
---|
127 |
|
---|
128 | Sub Dispose()
|
---|
129 | If nativeFont <> 0 Then
|
---|
130 | GdipDeleteFont(nativeFont)
|
---|
131 | End If
|
---|
132 | nativeFont = 0
|
---|
133 | End Sub
|
---|
134 |
|
---|
135 | Sub ~Font()
|
---|
136 | Dispose()
|
---|
137 | End Sub
|
---|
138 |
|
---|
139 | ' Const Function Style() As FontStyle
|
---|
140 | ' SetStatus(GdipGetFontStyle(nativeFont, Style))
|
---|
141 | ' End Function
|
---|
142 |
|
---|
143 | Const Function Size() As Single
|
---|
144 | SetStatus(GdipGetFontSize(nativeFont, Size))
|
---|
145 | End Function
|
---|
146 |
|
---|
147 | ' Const Function SizeInPoints() As Single
|
---|
148 | ' End Function
|
---|
149 |
|
---|
150 | ' Const Function Unit() As GraphicsUnit
|
---|
151 | ' SetStatus(GdipGetFontUnit(nativeFont, Unit))
|
---|
152 | ' End Function
|
---|
153 |
|
---|
154 | Const Function Height() As Long
|
---|
155 | Height = GetHeight() As Long
|
---|
156 | End Function
|
---|
157 |
|
---|
158 | Const Function GetHeight() As Single
|
---|
159 | SetStatus(GdipGetFontHeight(nativeFont, 0, GetHeight))
|
---|
160 | End Function
|
---|
161 |
|
---|
162 | Const Function GetHeight(/*IN const*/ g As Graphics) As Single
|
---|
163 | Dim nativeGraphics = getNativeGraphics(g)
|
---|
164 | SetStatus(GdipGetFontHeight(nativeFont, nativeGraphics, GetHeight))
|
---|
165 | End Function
|
---|
166 |
|
---|
167 | Const Function GetHeight(/*IN*/ dpi As Single) As Single
|
---|
168 | SetStatus(GdipGetFontHeightGivenDPI(nativeFont, dpi, GetHeight))
|
---|
169 | End Function
|
---|
170 |
|
---|
171 | ' Const Function FontFamily() As FontFamily
|
---|
172 | ' Dim nativeFamily As *GpFamily
|
---|
173 | ' SetStatus(GdipGetFamily(nativeFont, nativeFamily))
|
---|
174 | ' FontFamily = New FontFamily(nativeFamily)
|
---|
175 | ' End Function
|
---|
176 |
|
---|
177 | Const Function Bold() As Boolean
|
---|
178 | Dim lf As LOGFONT
|
---|
179 | ToLogFont(lf)
|
---|
180 | Return lf.lfWeight > FW_BOLD
|
---|
181 | End Function
|
---|
182 |
|
---|
183 | Const Function GdiCharSet() As Byte
|
---|
184 | Dim lf As LOGFONT
|
---|
185 | ToLogFont(lf)
|
---|
186 | Return lf.lfCharSet
|
---|
187 | End Function
|
---|
188 |
|
---|
189 | 'Const Function GdiVerticalFont() As Boolean
|
---|
190 |
|
---|
191 | 'Const Function IsSystemFont() As Boolean
|
---|
192 |
|
---|
193 | Const Function Italic() As Boolean
|
---|
194 | Dim lf As LOGFONT
|
---|
195 | ToLogFont(lf)
|
---|
196 | Italic = lf.lfItalic <> FALSE
|
---|
197 | End Function
|
---|
198 |
|
---|
199 | Const Function Name() As String
|
---|
200 | Dim lf As LOGFONT
|
---|
201 | ToLogFont(lf)
|
---|
202 | Dim p = lf.lfFaceName As PCTSTR
|
---|
203 | Name = New String(p)
|
---|
204 | End Function
|
---|
205 |
|
---|
206 | Const Function StrikeOut() As Boolean
|
---|
207 | Dim lf As LOGFONT
|
---|
208 | ToLogFont(lf)
|
---|
209 | StrikeOut = lf.lfStrikeOut <> FALSE
|
---|
210 | End Function
|
---|
211 |
|
---|
212 | Const Function Style() As FontStyle
|
---|
213 | Dim lf As LOGFONT
|
---|
214 | ToLogFont(lf)
|
---|
215 | Style = FontStyle.Regular
|
---|
216 | If lf.lfWeight > FW_BOLD Then
|
---|
217 | Style Or= FontStyle.Bold
|
---|
218 | End If
|
---|
219 | If lf.lfItalic <> FALSE Then
|
---|
220 | Style Or= FontStyle.Italic
|
---|
221 | End If
|
---|
222 | If lf.lfStrikeOut <> FALSE Then
|
---|
223 | Style Or= FontStyle.Strikeout
|
---|
224 | End If
|
---|
225 | If lf.lfUnderline <> FALSE Then
|
---|
226 | Style Or= FontStyle.Underline
|
---|
227 | End If
|
---|
228 | End Function
|
---|
229 |
|
---|
230 | 'Const Function SystemFontName() As String
|
---|
231 |
|
---|
232 | Const Function Underline() As Boolean
|
---|
233 | Dim lf As LOGFONT
|
---|
234 | ToLogFont(lf)
|
---|
235 | Underline = lf.lfUnderline <> FALSE
|
---|
236 | End Function
|
---|
237 |
|
---|
238 | Override Function ToString() As String
|
---|
239 | ToString = Name
|
---|
240 | End Function
|
---|
241 |
|
---|
242 | Const Function ToHfont() As HFONT
|
---|
243 | Dim lf As LOGFONT
|
---|
244 | ToLogFont(lf)
|
---|
245 | ToHfont = CreateFontIndirect(lf)
|
---|
246 | End Function
|
---|
247 |
|
---|
248 | Const Sub ToLogFont(/*OUT*/ ByRef lf As LOGFONTA, /*IN const*/ g As Graphics)
|
---|
249 | Dim nativeGraphics = getNativeGraphics(g)
|
---|
250 | SetStatus(GdipGetLogFontA(nativeFont, nativeGraphics, lf))
|
---|
251 | End Sub
|
---|
252 |
|
---|
253 | Const Sub ToLogFont(/*OUT*/ ByRef lf As LOGFONTW, /*IN const*/ g As Graphics)
|
---|
254 | Dim nativeGraphics = getNativeGraphics(g)
|
---|
255 | SetStatus(GdipGetLogFontW(nativeFont, nativeGraphics, lf))
|
---|
256 | End Sub
|
---|
257 |
|
---|
258 | Const Sub ToLogFont(ByRef lf As LOGFONTA)
|
---|
259 | ToLogFont(lf, Nothing)
|
---|
260 | End Sub
|
---|
261 |
|
---|
262 | Const Sub ToLogFont(ByRef lf As LOGFONTW)
|
---|
263 | ToLogFont(lf, Nothing)
|
---|
264 | End Sub
|
---|
265 |
|
---|
266 | Function NativeFont() As *GpFont
|
---|
267 | NativeFont = nativeFont
|
---|
268 | End Function
|
---|
269 |
|
---|
270 | Private
|
---|
271 | Sub initFont(/*IN const*/ family As FontFamily, /*IN*/ emSize As Single,
|
---|
272 | /*IN*/ style As Long, /*IN*/ unit As GraphicsUnit)
|
---|
273 |
|
---|
274 | If ActiveBasic.IsNothing(family) Then
|
---|
275 | Throw New ArgumentNullException("family")
|
---|
276 | End If
|
---|
277 | SetStatus(GdipCreateFont(family.NativeFamily, emSize, style, unit, nativeFont))
|
---|
278 | End Sub
|
---|
279 |
|
---|
280 | Sub initFromName(/*IN const*/ familyName As PCWSTR, /*IN*/ emSize As Single,
|
---|
281 | /*IN*/ style As Long, /*IN*/ unit As GraphicsUnit, fontCollection As FontCollection)
|
---|
282 |
|
---|
283 | nativeFont = 0
|
---|
284 | Dim family = Nothing As FontFamily
|
---|
285 | Dim nativeFamily As *GpFontFamily
|
---|
286 |
|
---|
287 | Try
|
---|
288 | family = New FontFamily(familyName, fontCollection)
|
---|
289 | nativeFamily = family.NativeFamily
|
---|
290 | Catch e As Exception
|
---|
291 | nativeFamily = FontFamily.GenericSansSerif().NativeFamily
|
---|
292 | End Try
|
---|
293 |
|
---|
294 | Try
|
---|
295 | SetStatus(GdipCreateFont(nativeFamily, emSize, style, unit As Long, nativeFont))
|
---|
296 | Catch e As Exception
|
---|
297 | nativeFamily = FontFamily.GenericSansSerif().NativeFamily
|
---|
298 | SetStatus(GdipCreateFont(nativeFamily, emSize, style, unit, nativeFont))
|
---|
299 | End Try
|
---|
300 | End Sub
|
---|
301 |
|
---|
302 | Static Function getNativeGraphics(g As Graphics) As *GpGraphics
|
---|
303 | If ActiveBasic.IsNothing(g) Then
|
---|
304 | getNativeGraphics = 0
|
---|
305 | Else
|
---|
306 | getNativeGraphics = g.NativeGraphics
|
---|
307 | End If
|
---|
308 | End Function
|
---|
309 |
|
---|
310 | nativeFont As *GpFont
|
---|
311 | End Class
|
---|
312 |
|
---|
313 | End Namespace
|
---|
314 | End Namespace
|
---|