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