/
aat_ankr_gen.go
executable file
·343 lines (296 loc) · 9.49 KB
/
aat_ankr_gen.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
package tables
import (
"encoding/binary"
"fmt"
)
// Code generated by binarygen from aat_ankr_src.go. DO NOT EDIT
func (item *AnkrAnchor) mustParse(src []byte) {
_ = src[3] // early bound checking
item.X = int16(binary.BigEndian.Uint16(src[0:]))
item.Y = int16(binary.BigEndian.Uint16(src[2:]))
}
func (item *LookupRecord2) mustParse(src []byte) {
_ = src[5] // early bound checking
item.LastGlyph = binary.BigEndian.Uint16(src[0:])
item.FirstGlyph = binary.BigEndian.Uint16(src[2:])
item.Value = binary.BigEndian.Uint16(src[4:])
}
func ParseAATLookup(src []byte, valuesCount int) (AATLookup, int, error) {
var item AATLookup
if L := len(src); L < 2 {
return item, 0, fmt.Errorf("reading AATLookup: "+"EOF: expected length: 2, got %d", L)
}
format := uint16(binary.BigEndian.Uint16(src[0:]))
var (
read int
err error
)
switch format {
case 0:
item, read, err = ParseAATLoopkup0(src[0:], valuesCount)
case 10:
item, read, err = ParseAATLoopkup10(src[0:])
case 2:
item, read, err = ParseAATLoopkup2(src[0:])
case 4:
item, read, err = ParseAATLoopkup4(src[0:])
case 6:
item, read, err = ParseAATLoopkup6(src[0:])
case 8:
item, read, err = ParseAATLoopkup8(src[0:])
default:
err = fmt.Errorf("unsupported AATLookup format %d", format)
}
if err != nil {
return item, 0, fmt.Errorf("reading AATLookup: %s", err)
}
return item, read, nil
}
func ParseAATLookupRecord4(src []byte, parentSrc []byte) (AATLookupRecord4, int, error) {
var item AATLookupRecord4
n := 0
if L := len(src); L < 6 {
return item, 0, fmt.Errorf("reading AATLookupRecord4: "+"EOF: expected length: 6, got %d", L)
}
_ = src[5] // early bound checking
item.LastGlyph = binary.BigEndian.Uint16(src[0:])
item.FirstGlyph = binary.BigEndian.Uint16(src[2:])
offsetValues := int(binary.BigEndian.Uint16(src[4:]))
n += 6
{
if offsetValues != 0 { // ignore null offset
if L := len(parentSrc); L < offsetValues {
return item, 0, fmt.Errorf("reading AATLookupRecord4: "+"EOF: expected length: %d, got %d", offsetValues, L)
}
arrayLength := int(item.nValues())
if L := len(parentSrc); L < offsetValues+arrayLength*2 {
return item, 0, fmt.Errorf("reading AATLookupRecord4: "+"EOF: expected length: %d, got %d", offsetValues+arrayLength*2, L)
}
item.Values = make([]uint16, arrayLength) // allocation guarded by the previous check
for i := range item.Values {
item.Values[i] = binary.BigEndian.Uint16(parentSrc[offsetValues+i*2:])
}
offsetValues += arrayLength * 2
}
}
return item, n, nil
}
func ParseAATLoopkup0(src []byte, valuesCount int) (AATLoopkup0, int, error) {
var item AATLoopkup0
n := 0
if L := len(src); L < 2 {
return item, 0, fmt.Errorf("reading AATLoopkup0: "+"EOF: expected length: 2, got %d", L)
}
item.version = binary.BigEndian.Uint16(src[0:])
n += 2
{
if L := len(src); L < 2+valuesCount*2 {
return item, 0, fmt.Errorf("reading AATLoopkup0: "+"EOF: expected length: %d, got %d", 2+valuesCount*2, L)
}
item.Values = make([]uint16, valuesCount) // allocation guarded by the previous check
for i := range item.Values {
item.Values[i] = binary.BigEndian.Uint16(src[2+i*2:])
}
n += valuesCount * 2
}
return item, n, nil
}
func ParseAATLoopkup10(src []byte) (AATLoopkup10, int, error) {
var item AATLoopkup10
n := 0
if L := len(src); L < 8 {
return item, 0, fmt.Errorf("reading AATLoopkup10: "+"EOF: expected length: 8, got %d", L)
}
_ = src[7] // early bound checking
item.version = binary.BigEndian.Uint16(src[0:])
item.unitSize = binary.BigEndian.Uint16(src[2:])
item.FirstGlyph = binary.BigEndian.Uint16(src[4:])
arrayLengthValues := int(binary.BigEndian.Uint16(src[6:]))
n += 8
{
if L := len(src); L < 8+arrayLengthValues*2 {
return item, 0, fmt.Errorf("reading AATLoopkup10: "+"EOF: expected length: %d, got %d", 8+arrayLengthValues*2, L)
}
item.Values = make([]uint16, arrayLengthValues) // allocation guarded by the previous check
for i := range item.Values {
item.Values[i] = binary.BigEndian.Uint16(src[8+i*2:])
}
n += arrayLengthValues * 2
}
return item, n, nil
}
func ParseAATLoopkup2(src []byte) (AATLoopkup2, int, error) {
var item AATLoopkup2
n := 0
if L := len(src); L < 12 {
return item, 0, fmt.Errorf("reading AATLoopkup2: "+"EOF: expected length: 12, got %d", L)
}
_ = src[11] // early bound checking
item.version = binary.BigEndian.Uint16(src[0:])
item.binSearchHeader.mustParse(src[2:])
n += 12
{
arrayLength := int(item.nUnits)
if L := len(src); L < 12+arrayLength*6 {
return item, 0, fmt.Errorf("reading AATLoopkup2: "+"EOF: expected length: %d, got %d", 12+arrayLength*6, L)
}
item.Records = make([]LookupRecord2, arrayLength) // allocation guarded by the previous check
for i := range item.Records {
item.Records[i].mustParse(src[12+i*6:])
}
n += arrayLength * 6
}
return item, n, nil
}
func ParseAATLoopkup4(src []byte) (AATLoopkup4, int, error) {
var item AATLoopkup4
n := 0
if L := len(src); L < 12 {
return item, 0, fmt.Errorf("reading AATLoopkup4: "+"EOF: expected length: 12, got %d", L)
}
_ = src[11] // early bound checking
item.version = binary.BigEndian.Uint16(src[0:])
item.binSearchHeader.mustParse(src[2:])
n += 12
{
arrayLength := int(item.nUnits - 1)
offset := 12
for i := 0; i < arrayLength; i++ {
elem, read, err := ParseAATLookupRecord4(src[offset:], src)
if err != nil {
return item, 0, fmt.Errorf("reading AATLoopkup4: %s", err)
}
item.Records = append(item.Records, elem)
offset += read
}
n = offset
}
return item, n, nil
}
func ParseAATLoopkup6(src []byte) (AATLoopkup6, int, error) {
var item AATLoopkup6
n := 0
if L := len(src); L < 12 {
return item, 0, fmt.Errorf("reading AATLoopkup6: "+"EOF: expected length: 12, got %d", L)
}
_ = src[11] // early bound checking
item.version = binary.BigEndian.Uint16(src[0:])
item.binSearchHeader.mustParse(src[2:])
n += 12
{
arrayLength := int(item.nUnits)
if L := len(src); L < 12+arrayLength*4 {
return item, 0, fmt.Errorf("reading AATLoopkup6: "+"EOF: expected length: %d, got %d", 12+arrayLength*4, L)
}
item.Records = make([]loopkupRecord6, arrayLength) // allocation guarded by the previous check
for i := range item.Records {
item.Records[i].mustParse(src[12+i*4:])
}
n += arrayLength * 4
}
return item, n, nil
}
func ParseAATLoopkup8(src []byte) (AATLoopkup8, int, error) {
var item AATLoopkup8
n := 0
if L := len(src); L < 2 {
return item, 0, fmt.Errorf("reading AATLoopkup8: "+"EOF: expected length: 2, got %d", L)
}
item.version = binary.BigEndian.Uint16(src[0:])
n += 2
{
var (
err error
read int
)
item.AATLoopkup8Data, read, err = ParseAATLoopkup8Data(src[2:])
if err != nil {
return item, 0, fmt.Errorf("reading AATLoopkup8: %s", err)
}
n += read
}
return item, n, nil
}
func ParseAATLoopkup8Data(src []byte) (AATLoopkup8Data, int, error) {
var item AATLoopkup8Data
n := 0
if L := len(src); L < 4 {
return item, 0, fmt.Errorf("reading AATLoopkup8Data: "+"EOF: expected length: 4, got %d", L)
}
_ = src[3] // early bound checking
item.FirstGlyph = binary.BigEndian.Uint16(src[0:])
arrayLengthValues := int(binary.BigEndian.Uint16(src[2:]))
n += 4
{
if L := len(src); L < 4+arrayLengthValues*2 {
return item, 0, fmt.Errorf("reading AATLoopkup8Data: "+"EOF: expected length: %d, got %d", 4+arrayLengthValues*2, L)
}
item.Values = make([]uint16, arrayLengthValues) // allocation guarded by the previous check
for i := range item.Values {
item.Values[i] = binary.BigEndian.Uint16(src[4+i*2:])
}
n += arrayLengthValues * 2
}
return item, n, nil
}
func ParseAnkr(src []byte, valuesCount int) (Ankr, int, error) {
var item Ankr
n := 0
if L := len(src); L < 12 {
return item, 0, fmt.Errorf("reading Ankr: "+"EOF: expected length: 12, got %d", L)
}
_ = src[11] // early bound checking
item.version = binary.BigEndian.Uint16(src[0:])
item.flags = binary.BigEndian.Uint16(src[2:])
offsetLookupTable := int(binary.BigEndian.Uint32(src[4:]))
offsetGlyphDataTable := int(binary.BigEndian.Uint32(src[8:]))
n += 12
{
if offsetLookupTable != 0 { // ignore null offset
if L := len(src); L < offsetLookupTable {
return item, 0, fmt.Errorf("reading Ankr: "+"EOF: expected length: %d, got %d", offsetLookupTable, L)
}
var (
err error
read int
)
item.lookupTable, read, err = ParseAATLookup(src[offsetLookupTable:], valuesCount)
if err != nil {
return item, 0, fmt.Errorf("reading Ankr: %s", err)
}
offsetLookupTable += read
}
}
{
if offsetGlyphDataTable != 0 { // ignore null offset
if L := len(src); L < offsetGlyphDataTable {
return item, 0, fmt.Errorf("reading Ankr: "+"EOF: expected length: %d, got %d", offsetGlyphDataTable, L)
}
item.glyphDataTable = src[offsetGlyphDataTable:]
}
}
return item, n, nil
}
func ParseAnkrAnchor(src []byte) (AnkrAnchor, int, error) {
var item AnkrAnchor
n := 0
if L := len(src); L < 4 {
return item, 0, fmt.Errorf("reading AnkrAnchor: "+"EOF: expected length: 4, got %d", L)
}
item.mustParse(src)
n += 4
return item, n, nil
}
func (item *binSearchHeader) mustParse(src []byte) {
_ = src[9] // early bound checking
item.unitSize = binary.BigEndian.Uint16(src[0:])
item.nUnits = binary.BigEndian.Uint16(src[2:])
item.searchRange = binary.BigEndian.Uint16(src[4:])
item.entrySelector = binary.BigEndian.Uint16(src[6:])
item.rangeShift = binary.BigEndian.Uint16(src[8:])
}
func (item *loopkupRecord6) mustParse(src []byte) {
_ = src[3] // early bound checking
item.Glyph = binary.BigEndian.Uint16(src[0:])
item.Value = binary.BigEndian.Uint16(src[2:])
}