-
Notifications
You must be signed in to change notification settings - Fork 3
/
gdiplusfont.go
195 lines (168 loc) · 4.7 KB
/
gdiplusfont.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package gdiplus
import (
"unsafe"
. "github.com/tryor/winapi"
. "github.com/tryor/winapi/gdi"
)
type Font struct {
GdiplusBase
nativeFont *GpFont
}
func (this *Font) Release() {
if this.nativeFont != nil {
this.setStatus(GdipDeleteFont(this.nativeFont))
this.nativeFont = nil
}
}
func NewFont(family *FontFamily, emSize REAL, style FontStyle, unit Unit) (*Font, error) {
var nativeFamily *GpFontFamily
if family != nil {
nativeFamily = family.nativeFamily
}
font := &Font{}
var nativeFont *GpFont
font.setStatus(GdipCreateFont(nativeFamily, emSize, style, unit, &nativeFont))
font.nativeFont = nativeFont
return font, font.LastError
}
func NewFont2(familyName string, emSize REAL, style FontStyle, unit Unit, fontCollection IFontCollection) (*Font, error) {
font := &Font{}
family, _ := NewFontFamily(familyName, fontCollection)
defer family.Release()
//nativeFamily := family.nativeFamily
var nativeFamily *GpFontFamily
if family != nil {
nativeFamily = family.nativeFamily
font.setStatus((family.GetLastStatus()), nil)
}
if font.LastResult != Ok {
genericSansSerif := GenericSansSerif()
nativeFamily = genericSansSerif.nativeFamily
font.setStatus((genericSansSerif.LastResult), nil)
if font.LastResult != Ok {
return font, font.LastError
}
}
font.setStatus(GdipCreateFont(nativeFamily,
emSize,
style,
unit,
&font.nativeFont))
if font.LastResult != Ok {
genericSansSerif := GenericSansSerif()
nativeFamily = genericSansSerif.nativeFamily
//lastResult = genericSansSerif.LastResult;
if genericSansSerif.LastResult != Ok {
return font, font.LastError
}
font.setStatus(GdipCreateFont(nativeFamily,
emSize,
style,
unit,
&font.nativeFont))
}
return font, font.LastError
}
//TODO 测试时报参数错误
func NewFont3(hdc HDC) (*Font, error) {
font := &Font{}
var nativeFont *GpFont
font.setStatus(GdipCreateFontFromDC(hdc, &nativeFont))
font.nativeFont = nativeFont
return font, font.LastError
}
//TODO 测试时报参数错误
func NewFont4(hdc HDC, hfont HFONT) (*Font, error) {
font := &Font{}
if hfont != 0 {
var lf LOGFONTA
if GetObjectA(HANDLE(hfont), uintptr(LOGFONTA_SIZE), uintptr(unsafe.Pointer(&lf))) != 0 {
font.setStatus(GdipCreateFontFromLogfontA(hdc, &lf, &font.nativeFont))
} else {
font.setStatus(GdipCreateFontFromDC(hdc, &font.nativeFont))
}
} else {
font.setStatus(GdipCreateFontFromDC(hdc, &font.nativeFont))
}
return font, font.LastError
}
func NewFont5(hdc HDC, logfont *LOGFONTW) (*Font, error) {
font := &Font{}
if logfont != nil {
font.setStatus(GdipCreateFontFromLogfontW(hdc, logfont, &font.nativeFont))
} else {
font.setStatus(GdipCreateFontFromDC(hdc, &font.nativeFont))
}
return font, font.LastError
}
func NewFont6(hdc HDC, logfont *LOGFONTA) (*Font, error) {
font := &Font{}
if logfont != nil {
font.setStatus(GdipCreateFontFromLogfontA(hdc, logfont, &font.nativeFont))
} else {
font.setStatus(GdipCreateFontFromDC(hdc, &font.nativeFont))
}
return font, font.LastError
}
func (this *Font) GetLogFontA(g *Graphics) (logfontA *LOGFONTA, status Status) {
var nativeGraphics *GpGraphics
if g != nil {
nativeGraphics = g.nativeGraphics
}
logfontA = &LOGFONTA{}
status = this.setStatus(GdipGetLogFontA(this.nativeFont, nativeGraphics, logfontA))
return
}
func (this *Font) GetLogFontW(g *Graphics) (logfontW *LOGFONTW, status Status) {
var nativeGraphics *GpGraphics
if g != nil {
nativeGraphics = g.nativeGraphics
}
logfontW = &LOGFONTW{}
status = this.setStatus(GdipGetLogFontW(this.nativeFont, nativeGraphics, logfontW))
return
}
func (this *Font) Clone() (*Font, error) {
cloneFont := &Font{}
this.setStatus(GdipCloneFont(this.nativeFont, &cloneFont.nativeFont))
return cloneFont, this.LastError
}
func (this *Font) IsAvailable() BOOL {
return this.nativeFont != nil
}
func (this *Font) GetFamily() (family *FontFamily, status Status) {
family = &FontFamily{}
s, err := GdipGetFamily(this.nativeFont, &family.nativeFamily)
this.setStatus(s, err)
return family, family.setStatus(s, err)
}
func (this *Font) GetStyle() (style INT) {
this.setStatus(GdipGetFontStyle(this.nativeFont, &style))
return
}
func (this *Font) GetSize() (size REAL) {
this.setStatus(GdipGetFontSize(this.nativeFont, &size))
return
}
func (this *Font) GetUnit() (unit Unit) {
this.setStatus(GdipGetFontUnit(this.nativeFont, &unit))
return
}
func (this *Font) GetHeight(g *Graphics) (height REAL) {
var nativeGraphics *GpGraphics
if g != nil {
nativeGraphics = g.nativeGraphics
}
this.setStatus(GdipGetFontHeight(
this.nativeFont,
nativeGraphics,
&height))
return
}
func (this *Font) GetHeigh2(dpi REAL) (height REAL) {
this.setStatus(GdipGetFontHeightGivenDPI(
this.nativeFont,
dpi,
&height))
return
}