-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglyphs_sbix_gen.go
executable file
·90 lines (76 loc) · 2.27 KB
/
glyphs_sbix_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
package tables
import (
"encoding/binary"
"fmt"
)
// Code generated by binarygen from glyphs_sbix_src.go. DO NOT EDIT
func ParseBitmapGlyphData(src []byte) (BitmapGlyphData, int, error) {
var item BitmapGlyphData
n := 0
if L := len(src); L < 8 {
return item, 0, fmt.Errorf("reading BitmapGlyphData: "+"EOF: expected length: 8, got %d", L)
}
_ = src[7] // early bound checking
item.OriginOffsetX = int16(binary.BigEndian.Uint16(src[0:]))
item.OriginOffsetY = int16(binary.BigEndian.Uint16(src[2:]))
item.GraphicType = Tag(binary.BigEndian.Uint32(src[4:]))
n += 8
{
item.Data = src[8:]
n = len(src)
}
return item, n, nil
}
func ParseSbix(src []byte, numGlyphs int) (Sbix, int, error) {
var item Sbix
n := 0
if L := len(src); L < 8 {
return item, 0, fmt.Errorf("reading Sbix: "+"EOF: expected length: 8, got %d", L)
}
_ = src[7] // early bound checking
item.version = binary.BigEndian.Uint16(src[0:])
item.Flags = binary.BigEndian.Uint16(src[2:])
arrayLengthStrikes := int(binary.BigEndian.Uint32(src[4:]))
n += 8
{
if L := len(src); L < 8+arrayLengthStrikes*4 {
return item, 0, fmt.Errorf("reading Sbix: "+"EOF: expected length: %d, got %d", 8+arrayLengthStrikes*4, L)
}
item.Strikes = make([]Strike, arrayLengthStrikes) // allocation guarded by the previous check
for i := range item.Strikes {
offset := int(binary.BigEndian.Uint32(src[8+i*4:]))
// ignore null offsets
if offset == 0 {
continue
}
if L := len(src); L < offset {
return item, 0, fmt.Errorf("reading Sbix: "+"EOF: expected length: %d, got %d", offset, L)
}
var err error
item.Strikes[i], _, err = ParseStrike(src[offset:], numGlyphs)
if err != nil {
return item, 0, fmt.Errorf("reading Sbix: %s", err)
}
}
n += arrayLengthStrikes * 4
}
return item, n, nil
}
func ParseStrike(src []byte, numGlyphs int) (Strike, int, error) {
var item Strike
n := 0
if L := len(src); L < 4 {
return item, 0, fmt.Errorf("reading Strike: "+"EOF: expected length: 4, got %d", L)
}
_ = src[3] // early bound checking
item.Ppem = binary.BigEndian.Uint16(src[0:])
item.Ppi = binary.BigEndian.Uint16(src[2:])
n += 4
{
err := item.parseGlyphDatas(src[:], numGlyphs)
if err != nil {
return item, 0, fmt.Errorf("reading Strike: %s", err)
}
}
return item, n, nil
}