-
Notifications
You must be signed in to change notification settings - Fork 3
/
gdiplusfontfamily.go
125 lines (101 loc) · 3.48 KB
/
gdiplusfontfamily.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
package gdiplus
import (
"syscall"
"unsafe"
. "github.com/tryor/winapi"
. "github.com/tryor/winapi/gdi"
)
var GenericSansSerifFontFamily *FontFamily
var GenericSerifFontFamily *FontFamily
var GenericMonospaceFontFamily *FontFamily
var GenericSansSerifFontFamilyBuffer [unsafe.Sizeof(FontFamily{})]BYTE
var GenericSerifFontFamilyBuffer [unsafe.Sizeof(FontFamily{})]BYTE
var GenericMonospaceFontFamilyBuffer [unsafe.Sizeof(FontFamily{})]BYTE
type FontFamily struct {
GdiplusBase
nativeFamily *GpFontFamily
}
func NewFontFamily(name string, fontCollection IFontCollection) (*FontFamily, error) {
var nativeFontCollection *GpFontCollection
if fontCollection != nil {
nativeFontCollection = fontCollection.GetNativeFontCollection()
}
family := &FontFamily{}
var nativeFamily *GpFontFamily
family.setStatus(GdipCreateFontFamilyFromName(name, nativeFontCollection, &nativeFamily))
family.nativeFamily = nativeFamily
return family, family.LastError
}
func (this *FontFamily) Release() {
if this.nativeFamily != nil {
this.setStatus(GdipDeleteFontFamily(this.nativeFamily))
this.nativeFamily = nil
}
}
func (this *FontFamily) Clone() *FontFamily {
family := &FontFamily{}
this.setStatus(GdipCloneFontFamily(this.nativeFamily, &family.nativeFamily))
family.setStatus(this.LastResult, this.LastError)
return family
}
func (this *FontFamily) GetFamilyName(language LANGID) (name string, status Status) {
namebuf := make([]uint16, LF_FACESIZE)
status = this.setStatus(GdipGetFamilyName(this.nativeFamily,
&namebuf[0],
language))
name = syscall.UTF16ToString(namebuf)
return
}
func (this *FontFamily) IsStyleAvailable(style INT) BOOL {
var styleAvailable BOOL
this.setStatus(GdipIsStyleAvailable(this.nativeFamily, style, &styleAvailable))
if this.LastResult != Ok {
styleAvailable = FALSE
}
return styleAvailable
}
func (this *FontFamily) GetEmHeight(style INT) (emHeight UINT16) {
this.setStatus(GdipGetEmHeight(this.nativeFamily, style, &emHeight))
return
}
func (this *FontFamily) GetCellAscent(style INT) (cellAscent UINT16) {
this.setStatus(GdipGetCellAscent(this.nativeFamily, style, &cellAscent))
return
}
func (this *FontFamily) GetCellDescent(style INT) (cellDescent UINT16) {
this.setStatus(GdipGetCellDescent(this.nativeFamily, style, &cellDescent))
return
}
func (this *FontFamily) GetLineSpacing(style INT) (lineSpacing UINT16) {
this.setStatus(GdipGetLineSpacing(this.nativeFamily, style, &lineSpacing))
return
}
func GenericSansSerif() *FontFamily {
if GenericSansSerifFontFamily != nil {
return GenericSansSerifFontFamily
}
GenericSansSerifFontFamily =
(*FontFamily)(unsafe.Pointer(&GenericSansSerifFontFamilyBuffer[0]))
GenericSansSerifFontFamily.setStatus(GdipGetGenericFontFamilySansSerif(&GenericSansSerifFontFamily.nativeFamily))
return GenericSansSerifFontFamily
}
func GenericSerif() *FontFamily {
if GenericSerifFontFamily != nil {
return GenericSerifFontFamily
}
GenericSerifFontFamily =
(*FontFamily)(unsafe.Pointer(&GenericSerifFontFamilyBuffer[0]))
GenericSerifFontFamily.setStatus(GdipGetGenericFontFamilySerif(
&(GenericSerifFontFamily.nativeFamily)))
return GenericSerifFontFamily
}
func GenericMonospace() *FontFamily {
if GenericMonospaceFontFamily != nil {
return GenericMonospaceFontFamily
}
GenericMonospaceFontFamily =
(*FontFamily)(unsafe.Pointer(&GenericMonospaceFontFamilyBuffer[0]))
GenericMonospaceFontFamily.setStatus(GdipGetGenericFontFamilyMonospace(
&(GenericMonospaceFontFamily.nativeFamily)))
return GenericMonospaceFontFamily
}