-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
174 lines (163 loc) · 5.88 KB
/
types.go
File metadata and controls
174 lines (163 loc) · 5.88 KB
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
package bitmapfont
// http://www.angelcode.com/products/bmfont/doc/file_format.html
// This tag holds information on how the font was generated.
type Info struct {
Face string // This is the name of the true type font.
Size int // The size of the true type font.
Bld bool // The font is bold.
Italic bool // The font is italic.
Charset string // The name of the OEM charset used (when not unicode).
Unicode bool // Set to 1 if it is the unicode charset.
StretchH int // The font height stretch in percentage. 100% means no stretch.
Smooth bool // Set to 1 if smoothing was turned on.
AA int // The supersampling level used. 1 means no supersampling was used.
Padding []int // The padding for each character (up, right, down, left).
Spacing []int // The spacing for each character (horizontal, vertical).
Outline int // The outline thickness for the characters.
}
func buildInfo(kvs map[string]value) Info {
i := Info{}
for k, v := range kvs {
switch k {
case "face":
i.Face = v.stringValue
case "size":
i.Size = v.intValue
case "bld":
i.Bld = v.intValue > 0
case "italic":
i.Italic = v.intValue > 0
case "charset":
i.Charset = v.stringValue
case "unicode":
i.Unicode = v.intValue == 1
case "stretchH":
i.StretchH = v.intValue
case "smooth":
i.Smooth = v.intValue == 1
case "aa":
i.AA = v.intValue
case "padding":
i.Padding = v.intArray
case "spacing":
i.Spacing = v.intArray
case "outline":
i.Outline = v.intValue
}
}
return i
}
// This tag holds information common to all characters.
type Common struct {
LineHeight float32 // This is the distance in pixels between each line of text.
Base int // The number of pixels from the absolute top of the line to the base of the characters.
ScaleW float32 // The width of the texture, normally used to scale the x pos of the character image.
ScaleH float32 // The height of the texture, normally used to scale the y pos of the character image.
Pages int // The number of texture pages included in the font.
Packed int // Set to 1 if the monochrome characters have been packed into each of the texture channels. In this case alphaChnl describes what is stored in each channel.
AlphaChnl int // Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one.
RedChnl int // Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one.
GreenChnl int // Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one.
BlueChnl int // Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one.
}
func buildCommon(kvs map[string]value) Common {
c := Common{}
for k, v := range kvs {
switch k {
case "lineHeight":
c.LineHeight = v.f32()
case "base":
c.Base = v.intValue
case "scaleW":
c.ScaleW = v.f32()
case "scaleH":
c.ScaleH = v.f32()
case "pages":
c.Pages = v.intValue
case "packed":
c.Packed = v.intValue
}
}
return c
}
// This tag gives the name of a texture file. There is one for each page in the font.
type Page struct {
Id int // The page id.
File string // The texture file name.
}
func buildPage(kvs map[string]value) Page {
p := Page{}
for k, v := range kvs {
switch k {
case "id":
p.Id = v.intValue
case "file":
p.File = v.stringValue
}
}
return p
}
// This tag describes on character in the font. There is one for each included character in the font.
type Char struct {
Id uint8 // The character id.
X float32 // The left position of the character image in the texture.
Y float32 // The top position of the character image in the texture.
Width float32 // The width of the character image in the texture.
Height float32 // The height of the character image in the texture.
Xoffset float32 // How much the current position should be offset when copying the image from the texture to the screen.
Yoffset float32 // How much the current position should be offset when copying the image from the texture to the screen.
Xadvance float32 // How much the current position should be advanced after drawing the character.
Page int // The texture page where the character image is found.
Channel int // The texture channel where the character image is found (1 = blue, 2 = green, 4 = red, 8 = alpha, 15 = all channels).
Letter string // The letter is represents
}
func buildChar(kvs map[string]value) Char {
c := Char{}
for k, v := range kvs {
switch k {
case "id":
c.Id = uint8(v.intValue)
case "x":
c.X = v.f32()
case "y":
c.Y = v.f32()
case "width":
c.Width = v.f32()
case "height":
c.Height = v.f32()
case "xoffset":
c.Xoffset = v.f32()
case "yoffset":
c.Yoffset = v.f32()
case "xadvance":
c.Xadvance = v.f32()
case "page":
c.Page = v.intValue
case "chnl":
c.Channel = v.intValue
case "letter":
c.Letter = v.stringValue
}
}
return c
}
// The kerning information is used to adjust the distance between certain characters, e.g. some characters should be placed closer to each other than others.
type Kerning struct {
First uint8 // The first character id.
Second uint8 // The second character id.
Amount float32 // How much the x position should be adjusted when drawing the second character immediately following the first.
}
func buildKerning(kvs map[string]value) Kerning {
g := Kerning{}
for k, v := range kvs {
switch k {
case "first":
g.First = uint8(v.intValue)
case "second":
g.Second = uint8(v.intValue)
case "amount":
g.Amount = v.f32()
}
}
return g
}