-
Notifications
You must be signed in to change notification settings - Fork 5
/
table_maxp.go
96 lines (80 loc) · 2.22 KB
/
table_maxp.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
/*
* This file is subject to the terms and conditions defined in
* file 'LICENSE.md', which is part of this source code package.
*/
package unitype
import (
"github.com/sirupsen/logrus"
)
// maxpTable represents the Maximum Profile (maxp) table.
// This table establishes the memory requirements for the font.
type maxpTable struct {
// Version 0.5 and above:
version fixed
numGlyphs uint16
// Version 1.0 and above:
maxPoints uint16
maxContours uint16
maxCompositePoints uint16
maxCompositeContours uint16
maxZones uint16
maxTwilightPoints uint16
maxStorage uint16
maxFunctionDefs uint16
maxInstructionDefs uint16
maxStackElements uint16
maxSizeOfInstructions uint16
maxComponentElements uint16
maxComponentDepth uint16
}
func (f *font) parseMaxp(r *byteReader) (*maxpTable, error) {
_, has, err := f.seekToTable(r, "maxp")
if err != nil {
return nil, err
}
if !has {
logrus.Debug("maxp table not present")
return nil, nil
}
t := &maxpTable{}
err = r.read(&t.version, &t.numGlyphs)
if err != nil {
return nil, err
}
if t.version < 0x00010000 {
logrus.Debug("Range check error")
return nil, errRangeCheck
}
err = r.read(&t.maxPoints, &t.maxContours, &t.maxCompositePoints, &t.maxCompositeContours)
if err != nil {
return nil, err
}
err = r.read(&t.maxZones, &t.maxTwilightPoints, &t.maxStorage, &t.maxFunctionDefs, &t.maxInstructionDefs)
if err != nil {
return nil, err
}
return t, r.read(&t.maxStackElements, &t.maxSizeOfInstructions, &t.maxComponentElements, &t.maxComponentDepth)
}
func (f *font) writeMaxp(w *byteWriter) error {
if f.maxp == nil {
return errRequiredField
}
t := f.maxp
err := w.write(t.version, t.numGlyphs)
if err != nil {
return err
}
if t.version < 0x00010000 {
logrus.Debug("Range check error")
return errRangeCheck
}
err = w.write(t.maxPoints, t.maxContours, t.maxCompositePoints, t.maxCompositeContours)
if err != nil {
return err
}
err = w.write(t.maxZones, t.maxTwilightPoints, t.maxStorage, t.maxFunctionDefs, t.maxInstructionDefs)
if err != nil {
return err
}
return w.write(t.maxStackElements, t.maxSizeOfInstructions, t.maxComponentElements, t.maxComponentDepth)
}