| 1 | #ifndef _GDIPLUSFONT_H
|
|---|
| 2 | #define _GDIPLUSFONT_H
|
|---|
| 3 |
|
|---|
| 4 | #require <GdiPlus.ab>
|
|---|
| 5 | #require <Classes/System/Drawing/Graphics.ab>
|
|---|
| 6 |
|
|---|
| 7 | Class FontFamily : End Class
|
|---|
| 8 | Class FontCollection : End Class
|
|---|
| 9 |
|
|---|
| 10 | Class Font
|
|---|
| 11 | Public
|
|---|
| 12 | ' friend class Graphics
|
|---|
| 13 |
|
|---|
| 14 | Sub Font(/*IN*/ hdc As HDC)
|
|---|
| 15 | Dim font = 0 As *GpFont
|
|---|
| 16 | lastResult = GdipCreateFontFromDC(hdc, font)
|
|---|
| 17 | SetNativeFont(font)
|
|---|
| 18 | End Sub
|
|---|
| 19 |
|
|---|
| 20 | Sub Font(/*IN*/ hdc As HDC, /*IN const*/ ByRef logfont As LOGFONTA)
|
|---|
| 21 | Dim font = 0 As *GpFont
|
|---|
| 22 | lastResult =GdipCreateFontFromLogfontA(hdc, logfont, font)
|
|---|
| 23 | SetNativeFont(font)
|
|---|
| 24 | End Sub
|
|---|
| 25 |
|
|---|
| 26 | Sub Font(/*IN*/ hdc As HDC, /*IN const*/ ByRef logfont As LOGFONTW)
|
|---|
| 27 | Dim font = 0 As *GpFont
|
|---|
| 28 | lastResult =GdipCreateFontFromLogfontW(hdc, logfont, font)
|
|---|
| 29 | SetNativeFont(font)
|
|---|
| 30 | End Sub
|
|---|
| 31 |
|
|---|
| 32 | Sub Font(/*IN*/ hdc As HDC, /*IN const*/ hfont As HFONT)
|
|---|
| 33 | Dim font = 0 As *GpFont
|
|---|
| 34 | If hfont <> 0 Then
|
|---|
| 35 | Dim lf As LOGFONTA
|
|---|
| 36 | If GetObjectA(hfont, sizeof (LOGFONTA), lf) <> 0 Then
|
|---|
| 37 | lastResult = GdipCreateFontFromLogfontA(hdc, lf, font)
|
|---|
| 38 | Else
|
|---|
| 39 | lastResult = GdipCreateFontFromDC(hdc, font)
|
|---|
| 40 | End If
|
|---|
| 41 | Else
|
|---|
| 42 | lastResult = GdipCreateFontFromDC(hdc, font)
|
|---|
| 43 | End If
|
|---|
| 44 | SetNativeFont(font)
|
|---|
| 45 | End Sub
|
|---|
| 46 |
|
|---|
| 47 | Sub Font(/*IN const*/ ByRef family As FontFamily, /*IN*/ emSize As Single)
|
|---|
| 48 | Font(family, emSize, FontStyleRegular, UnitPoint)
|
|---|
| 49 | End Sub
|
|---|
| 50 |
|
|---|
| 51 | Sub Font(/*IN const*/ ByRef family As FontFamily,
|
|---|
| 52 | /*IN*/ emSize As Single, /*IN*/ style As Long)
|
|---|
| 53 |
|
|---|
| 54 | Font(family, emSize, style, UnitPoint)
|
|---|
| 55 | End Sub
|
|---|
| 56 |
|
|---|
| 57 | Sub Font(/*IN const*/ ByRef family As FontFamily, /*IN*/ emSize As Single,
|
|---|
| 58 | /*IN*/ style As Long, /*IN*/ unit As GraphicsUnit)
|
|---|
| 59 |
|
|---|
| 60 | Dim font = 0 As *GpFont
|
|---|
| 61 | lastResult = GdipCreateFont(
|
|---|
| 62 | family.NativeFamily, emSize, style, unit, font)
|
|---|
| 63 | SetNativeFont(font)
|
|---|
| 64 | End Sub
|
|---|
| 65 |
|
|---|
| 66 | Sub Font(/*IN const*/ familyName As *WCHAR, /*IN*/ emSize As Single)
|
|---|
| 67 | Font(familyName, emSize, FontStyleRegular, UnitPoint, ByVal 0)
|
|---|
| 68 | End Sub
|
|---|
| 69 |
|
|---|
| 70 | Sub Font(/*IN const*/ familyName As *WCHAR, /*IN*/ emSize As Single,
|
|---|
| 71 | /*IN*/ style As Long)
|
|---|
| 72 | Font(familyName, emSize, style, UnitPoint, ByVal 0)
|
|---|
| 73 | End Sub
|
|---|
| 74 |
|
|---|
| 75 | Sub Font(/*IN const*/ familyName As *WCHAR, /*IN*/ emSize As Single,
|
|---|
| 76 | /*IN*/ style As Long, /*IN*/ unit As GraphicsUnit)
|
|---|
| 77 | Font(familyName, emSize, style, unit, ByVal 0)
|
|---|
| 78 | End Sub
|
|---|
| 79 |
|
|---|
| 80 | Sub Font(/*IN const*/ familyName As *WCHAR, /*IN*/ emSize As Single,
|
|---|
| 81 | /*IN*/ style As Long, /*IN*/ unit As GraphicsUnit,
|
|---|
| 82 | /*IN const*/ ByRef fontCollection As FontCollection)
|
|---|
| 83 |
|
|---|
| 84 | nativeFont = 0
|
|---|
| 85 |
|
|---|
| 86 | Dim family As FontFamily(familyName, fontCollection)
|
|---|
| 87 | Dim nativeFamily = family.NativeFamily As *GpFontFamily
|
|---|
| 88 |
|
|---|
| 89 | lastResult = family.GetLastStatus()
|
|---|
| 90 |
|
|---|
| 91 | If lastResult <> Ok Then
|
|---|
| 92 | nativeFamily = FontFamily.GenericSansSerif()->NativeFamily
|
|---|
| 93 | lastResult = FontFamily.GenericSansSerif()->lastResult
|
|---|
| 94 | If lastResult <> Ok Then
|
|---|
| 95 | Exit Sub
|
|---|
| 96 | End If
|
|---|
| 97 | End If
|
|---|
| 98 |
|
|---|
| 99 | lastResult = GdipCreateFont(
|
|---|
| 100 | nativeFamily, emSize, style, unit, nativeFont)
|
|---|
| 101 |
|
|---|
| 102 | If lastResult <> Ok Then
|
|---|
| 103 | nativeFamily = FontFamily.GenericSansSerif()->NativeFamily
|
|---|
| 104 | lastResult = FontFamily.GenericSansSerif()->lastResult
|
|---|
| 105 | If lastResult <> Ok Then
|
|---|
| 106 | Exit Sub
|
|---|
| 107 | End If
|
|---|
| 108 |
|
|---|
| 109 | lastResult = GdipCreateFont(
|
|---|
| 110 | nativeFamily, emSize, style, unit, nativeFont)
|
|---|
| 111 | End If
|
|---|
| 112 | End Sub
|
|---|
| 113 |
|
|---|
| 114 | Const Function GetLogFontA(/*IN const*/ ByRef g As Graphics, /*OUT*/ ByRef lf As LOGFONTA) As Status
|
|---|
| 115 | Dim nativeGraphics As *GpGraphics
|
|---|
| 116 | If VarPtr(g) <> 0 Then
|
|---|
| 117 | nativeGraphics = g.nativeGraphics
|
|---|
| 118 | End If
|
|---|
| 119 | Return SetStatus(GdipGetLogFontA(nativeFont, nativeGraphics, lf))
|
|---|
| 120 | End Function
|
|---|
| 121 |
|
|---|
| 122 | Const Function GetLogFontW(/*IN const*/ ByRef g As Graphics, /*OUT*/ ByRef lf As LOGFONTW) As Status
|
|---|
| 123 | Dim nativeGraphics As *GpGraphics
|
|---|
| 124 | If VarPtr(g) <> 0 Then
|
|---|
| 125 | nativeGraphics = g.nativeGraphics
|
|---|
| 126 | End If
|
|---|
| 127 | Return SetStatus(GdipGetLogFontW(nativeFont, nativeGraphics, lf))
|
|---|
| 128 | End Function
|
|---|
| 129 |
|
|---|
| 130 | Const Function Clone() As *Font
|
|---|
| 131 | Dim cloneFont = 0 As *GpFont
|
|---|
| 132 | SetStatus(GdipCloneFont(nativeFont, cloneFont))
|
|---|
| 133 | Return New Font(cloneFont, lastResult)
|
|---|
| 134 | End Function
|
|---|
| 135 |
|
|---|
| 136 | Sub ~Font()
|
|---|
| 137 | GdipDeleteFont(nativeFont)
|
|---|
| 138 | End Sub
|
|---|
| 139 |
|
|---|
| 140 | Const Function IsAvailable() As BOOL
|
|---|
| 141 | Return nativeFont <> 0
|
|---|
| 142 | End Function
|
|---|
| 143 |
|
|---|
| 144 | Const Function Style() As Long
|
|---|
| 145 | SetStatus(GdipGetFontStyle(nativeFont, Style))
|
|---|
| 146 | End Function
|
|---|
| 147 |
|
|---|
| 148 | Const Function Size() As Single
|
|---|
| 149 | SetStatus(GdipGetFontSize(nativeFont, Size))
|
|---|
| 150 | End Function
|
|---|
| 151 |
|
|---|
| 152 | Const Function Unit() As GraphicsUnit
|
|---|
| 153 | SetStatus(GdipGetFontUnit(nativeFont, Unit))
|
|---|
| 154 | End Function
|
|---|
| 155 |
|
|---|
| 156 | Const Function LastStatus() As Status
|
|---|
| 157 | Return lastResult
|
|---|
| 158 | End Function
|
|---|
| 159 |
|
|---|
| 160 | Const Function Height() As Single
|
|---|
| 161 | Return GetHeight()
|
|---|
| 162 | End Function
|
|---|
| 163 |
|
|---|
| 164 | Const Function GetHeight() As Single
|
|---|
| 165 | SetStatus(GdipGetFontHeight(nativeFont, 0, GetHeight))
|
|---|
| 166 | End Function
|
|---|
| 167 |
|
|---|
| 168 | Const Function GetHeight(/*IN const*/ ByRef g As Graphics) As Single
|
|---|
| 169 | Dim nativeGraphics As *GpGraphics
|
|---|
| 170 | If VarPtr(g) <> 0 Then
|
|---|
| 171 | nativeGraphics = g.NativeGraphics
|
|---|
| 172 | End If
|
|---|
| 173 | SetStatus(GdipGetFontHeight(nativeFont, nativeGraphics, GetHeight))
|
|---|
| 174 | End Function
|
|---|
| 175 |
|
|---|
| 176 | Const Function GetHeight(/*IN*/ dpi As Single) As Single
|
|---|
| 177 | SetStatus(GdipGetFontHeightGivenDPI(nativeFont, dpi, GetHeight))
|
|---|
| 178 | End Function
|
|---|
| 179 |
|
|---|
| 180 | ' Const Function FontFamily(/*OUT*/ ByRef family As FontFamily)
|
|---|
| 181 | ' If VarPtr(family) = 0 Then
|
|---|
| 182 | ' Return SetStatus(Status.InvalidParameter)
|
|---|
| 183 | ' End If
|
|---|
| 184 | ' Dim status = GdipGetFamily(nativeFont, family->nativeFamily)
|
|---|
| 185 | ' family->SetStatus(status)
|
|---|
| 186 | ' Return SetStatus(status)
|
|---|
| 187 | ' End Function
|
|---|
| 188 |
|
|---|
| 189 | Const Function NativeFont() As *GpFont
|
|---|
| 190 | Return nativeFont
|
|---|
| 191 | End Function
|
|---|
| 192 |
|
|---|
| 193 | Private
|
|---|
| 194 | ' Sub Font(ByRef f As Font)
|
|---|
| 195 | Sub Operator =(ByRef f As Font)
|
|---|
| 196 | Debug
|
|---|
| 197 | End Sub
|
|---|
| 198 |
|
|---|
| 199 | Protected
|
|---|
| 200 | Sub Font(f As *GpFont, status As Status)
|
|---|
| 201 | lastResult = status
|
|---|
| 202 | SetNativeFont(f)
|
|---|
| 203 | End Sub
|
|---|
| 204 |
|
|---|
| 205 | Sub SetNativeFont(f As *GpFont)
|
|---|
| 206 | nativeFont = f
|
|---|
| 207 | End Sub
|
|---|
| 208 |
|
|---|
| 209 | Const Function SetStatus(s As Status) As Status
|
|---|
| 210 | If s <> Status.Ok Then
|
|---|
| 211 | lastResult = s
|
|---|
| 212 | Return s
|
|---|
| 213 | Else
|
|---|
| 214 | Return s
|
|---|
| 215 | End If
|
|---|
| 216 | End Function
|
|---|
| 217 |
|
|---|
| 218 | Protected
|
|---|
| 219 | nativeFont As *GpFont
|
|---|
| 220 | /*mutable*/ lastResult As Status
|
|---|
| 221 | End Class
|
|---|
| 222 |
|
|---|
| 223 | #endif
|
|---|