-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglyphs_bitmap_gen.go
executable file
·361 lines (313 loc) · 9.89 KB
/
glyphs_bitmap_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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
package tables
import (
"encoding/binary"
"fmt"
)
// Code generated by binarygen from glyphs_bitmap_src.go. DO NOT EDIT
func (item *BigGlyphMetrics) mustParse(src []byte) {
_ = src[7] // early bound checking
item.SmallGlyphMetrics.mustParse(src[0:])
item.vertBearingX = int8(src[5])
item.vertBearingY = int8(src[6])
item.vertAdvance = src[7]
}
func (item *BitmapSize) mustParse(src []byte) {
_ = src[47] // early bound checking
item.indexSubTableArrayOffset = Offset32(binary.BigEndian.Uint32(src[0:]))
item.indexTablesSize = binary.BigEndian.Uint32(src[4:])
item.numberOfIndexSubTables = binary.BigEndian.Uint32(src[8:])
item.colorRef = binary.BigEndian.Uint32(src[12:])
item.Hori.mustParse(src[16:])
item.Vert.mustParse(src[28:])
item.startGlyphIndex = binary.BigEndian.Uint16(src[40:])
item.endGlyphIndex = binary.BigEndian.Uint16(src[42:])
item.PpemX = src[44]
item.PpemY = src[45]
item.bitDepth = src[46]
item.flags = int8(src[47])
}
func (item *GlyphIdOffsetPair) mustParse(src []byte) {
_ = src[3] // early bound checking
item.GlyphID = binary.BigEndian.Uint16(src[0:])
item.SbitOffset = Offset16(binary.BigEndian.Uint16(src[2:]))
}
func (item *IndexData2) mustParse(src []byte) {
_ = src[11] // early bound checking
item.ImageSize = binary.BigEndian.Uint32(src[0:])
item.BigMetrics.mustParse(src[4:])
}
func (item *IndexSubTableHeader) mustParse(src []byte) {
_ = src[7] // early bound checking
item.FirstGlyph = binary.BigEndian.Uint16(src[0:])
item.LastGlyph = binary.BigEndian.Uint16(src[2:])
item.additionalOffsetToIndexSubtable = Offset32(binary.BigEndian.Uint32(src[4:]))
}
func ParseBitmapData17(src []byte) (BitmapData17, int, error) {
var item BitmapData17
n := 0
if L := len(src); L < 9 {
return item, 0, fmt.Errorf("reading BitmapData17: "+"EOF: expected length: 9, got %d", L)
}
_ = src[8] // early bound checking
item.SmallGlyphMetrics.mustParse(src[0:])
arrayLengthImage := int(binary.BigEndian.Uint32(src[5:]))
n += 9
{
L := int(9 + arrayLengthImage)
if len(src) < L {
return item, 0, fmt.Errorf("reading BitmapData17: "+"EOF: expected length: %d, got %d", L, len(src))
}
item.Image = src[9:L]
n = L
}
return item, n, nil
}
func ParseBitmapData18(src []byte) (BitmapData18, int, error) {
var item BitmapData18
n := 0
if L := len(src); L < 12 {
return item, 0, fmt.Errorf("reading BitmapData18: "+"EOF: expected length: 12, got %d", L)
}
_ = src[11] // early bound checking
item.BigGlyphMetrics.mustParse(src[0:])
arrayLengthImage := int(binary.BigEndian.Uint32(src[8:]))
n += 12
{
L := int(12 + arrayLengthImage)
if len(src) < L {
return item, 0, fmt.Errorf("reading BitmapData18: "+"EOF: expected length: %d, got %d", L, len(src))
}
item.Image = src[12:L]
n = L
}
return item, n, nil
}
func ParseBitmapData19(src []byte) (BitmapData19, int, error) {
var item BitmapData19
n := 0
if L := len(src); L < 4 {
return item, 0, fmt.Errorf("reading BitmapData19: "+"EOF: expected length: 4, got %d", L)
}
arrayLengthImage := int(binary.BigEndian.Uint32(src[0:]))
n += 4
{
L := int(4 + arrayLengthImage)
if len(src) < L {
return item, 0, fmt.Errorf("reading BitmapData19: "+"EOF: expected length: %d, got %d", L, len(src))
}
item.Image = src[4:L]
n = L
}
return item, n, nil
}
func ParseBitmapData2(src []byte) (BitmapData2, int, error) {
var item BitmapData2
n := 0
if L := len(src); L < 5 {
return item, 0, fmt.Errorf("reading BitmapData2: "+"EOF: expected length: 5, got %d", L)
}
item.SmallGlyphMetrics.mustParse(src[0:])
n += 5
{
item.Image = src[5:]
n = len(src)
}
return item, n, nil
}
func ParseBitmapData5(src []byte) (BitmapData5, int, error) {
var item BitmapData5
n := 0
{
item.Image = src[0:]
n = len(src)
}
return item, n, nil
}
func ParseCBLC(src []byte) (CBLC, int, error) {
var item CBLC
n := 0
if L := len(src); L < 8 {
return item, 0, fmt.Errorf("reading CBLC: "+"EOF: expected length: 8, got %d", L)
}
_ = src[7] // early bound checking
item.majorVersion = binary.BigEndian.Uint16(src[0:])
item.minorVersion = binary.BigEndian.Uint16(src[2:])
arrayLengthBitmapSizes := int(binary.BigEndian.Uint32(src[4:]))
n += 8
{
if L := len(src); L < 8+arrayLengthBitmapSizes*48 {
return item, 0, fmt.Errorf("reading CBLC: "+"EOF: expected length: %d, got %d", 8+arrayLengthBitmapSizes*48, L)
}
item.BitmapSizes = make([]BitmapSize, arrayLengthBitmapSizes) // allocation guarded by the previous check
for i := range item.BitmapSizes {
item.BitmapSizes[i].mustParse(src[8+i*48:])
}
n += arrayLengthBitmapSizes * 48
}
{
err := item.parseIndexSubTables(src[:])
if err != nil {
return item, 0, fmt.Errorf("reading CBLC: %s", err)
}
}
return item, n, nil
}
func ParseIndexData1(src []byte, sbitOffsetsCount int) (IndexData1, int, error) {
var item IndexData1
n := 0
{
if L := len(src); L < sbitOffsetsCount*4 {
return item, 0, fmt.Errorf("reading IndexData1: "+"EOF: expected length: %d, got %d", sbitOffsetsCount*4, L)
}
item.SbitOffsets = make([]Offset32, sbitOffsetsCount) // allocation guarded by the previous check
for i := range item.SbitOffsets {
item.SbitOffsets[i] = Offset32(binary.BigEndian.Uint32(src[i*4:]))
}
n += sbitOffsetsCount * 4
}
return item, n, nil
}
func ParseIndexData2(src []byte) (IndexData2, int, error) {
var item IndexData2
n := 0
if L := len(src); L < 12 {
return item, 0, fmt.Errorf("reading IndexData2: "+"EOF: expected length: 12, got %d", L)
}
item.mustParse(src)
n += 12
return item, n, nil
}
func ParseIndexData3(src []byte, sbitOffsetsCount int) (IndexData3, int, error) {
var item IndexData3
n := 0
{
if L := len(src); L < sbitOffsetsCount*2 {
return item, 0, fmt.Errorf("reading IndexData3: "+"EOF: expected length: %d, got %d", sbitOffsetsCount*2, L)
}
item.SbitOffsets = make([]Offset16, sbitOffsetsCount) // allocation guarded by the previous check
for i := range item.SbitOffsets {
item.SbitOffsets[i] = Offset16(binary.BigEndian.Uint16(src[i*2:]))
}
n += sbitOffsetsCount * 2
}
return item, n, nil
}
func ParseIndexData4(src []byte) (IndexData4, int, error) {
var item IndexData4
n := 0
if L := len(src); L < 4 {
return item, 0, fmt.Errorf("reading IndexData4: "+"EOF: expected length: 4, got %d", L)
}
item.numGlyphs = binary.BigEndian.Uint32(src[0:])
n += 4
{
arrayLength := int(item.numGlyphs + 1)
if L := len(src); L < 4+arrayLength*4 {
return item, 0, fmt.Errorf("reading IndexData4: "+"EOF: expected length: %d, got %d", 4+arrayLength*4, L)
}
item.GlyphArray = make([]GlyphIdOffsetPair, arrayLength) // allocation guarded by the previous check
for i := range item.GlyphArray {
item.GlyphArray[i].mustParse(src[4+i*4:])
}
n += arrayLength * 4
}
return item, n, nil
}
func ParseIndexData5(src []byte) (IndexData5, int, error) {
var item IndexData5
n := 0
if L := len(src); L < 16 {
return item, 0, fmt.Errorf("reading IndexData5: "+"EOF: expected length: 16, got %d", L)
}
_ = src[15] // early bound checking
item.ImageSize = binary.BigEndian.Uint32(src[0:])
item.BigMetrics.mustParse(src[4:])
arrayLengthGlyphIdArray := int(binary.BigEndian.Uint32(src[12:]))
n += 16
{
if L := len(src); L < 16+arrayLengthGlyphIdArray*2 {
return item, 0, fmt.Errorf("reading IndexData5: "+"EOF: expected length: %d, got %d", 16+arrayLengthGlyphIdArray*2, L)
}
item.GlyphIdArray = make([]uint16, arrayLengthGlyphIdArray) // allocation guarded by the previous check
for i := range item.GlyphIdArray {
item.GlyphIdArray[i] = binary.BigEndian.Uint16(src[16+i*2:])
}
n += arrayLengthGlyphIdArray * 2
}
return item, n, nil
}
func ParseIndexSubHeader(src []byte, sbitOffsetsCount int) (IndexSubHeader, int, error) {
var item IndexSubHeader
n := 0
if L := len(src); L < 8 {
return item, 0, fmt.Errorf("reading IndexSubHeader: "+"EOF: expected length: 8, got %d", L)
}
_ = src[7] // early bound checking
item.indexFormat = indexVersion(binary.BigEndian.Uint16(src[0:]))
item.ImageFormat = binary.BigEndian.Uint16(src[2:])
item.ImageDataOffset = Offset32(binary.BigEndian.Uint32(src[4:]))
n += 8
{
var (
read int
err error
)
switch item.indexFormat {
case indexVersion1:
item.IndexData, read, err = ParseIndexData1(src[8:], sbitOffsetsCount)
case indexVersion2:
item.IndexData, read, err = ParseIndexData2(src[8:])
case indexVersion3:
item.IndexData, read, err = ParseIndexData3(src[8:], sbitOffsetsCount)
case indexVersion4:
item.IndexData, read, err = ParseIndexData4(src[8:])
case indexVersion5:
item.IndexData, read, err = ParseIndexData5(src[8:])
default:
err = fmt.Errorf("unsupported IndexDataVersion %d", item.indexFormat)
}
if err != nil {
return item, 0, fmt.Errorf("reading IndexSubHeader: %s", err)
}
n += read
}
return item, n, nil
}
func ParseIndexSubTableArray(src []byte, subtablesCount int) (IndexSubTableArray, int, error) {
var item IndexSubTableArray
n := 0
{
if L := len(src); L < subtablesCount*8 {
return item, 0, fmt.Errorf("reading IndexSubTableArray: "+"EOF: expected length: %d, got %d", subtablesCount*8, L)
}
item.Subtables = make([]IndexSubTableHeader, subtablesCount) // allocation guarded by the previous check
for i := range item.Subtables {
item.Subtables[i].mustParse(src[i*8:])
}
n += subtablesCount * 8
}
return item, n, nil
}
func (item *SbitLineMetrics) mustParse(src []byte) {
_ = src[11] // early bound checking
item.Ascender = int8(src[0])
item.Descender = int8(src[1])
item.widthMax = src[2]
item.caretSlopeNumerator = int8(src[3])
item.caretSlopeDenominator = int8(src[4])
item.caretOffset = int8(src[5])
item.minOriginSB = int8(src[6])
item.minAdvanceSB = int8(src[7])
item.MaxBeforeBL = int8(src[8])
item.MinAfterBL = int8(src[9])
item.pad1 = int8(src[10])
item.pad2 = int8(src[11])
}
func (item *SmallGlyphMetrics) mustParse(src []byte) {
_ = src[4] // early bound checking
item.Height = src[0]
item.Width = src[1]
item.BearingX = int8(src[2])
item.BearingY = int8(src[3])
item.Advance = src[4]
}