-
Notifications
You must be signed in to change notification settings - Fork 0
/
os2.go
64 lines (56 loc) · 1.95 KB
/
os2.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
package font
import (
"encoding/binary"
"errors"
"github.com/benoitkugler/go-opentype/tables"
)
type os2 struct {
version uint16
xAvgCharWidth uint16
useTypoMetrics bool // true if the field sTypoAscender, sTypoDescender and sTypoLineGap are valid.
ySubscriptXSize float32
ySubscriptYSize float32
ySubscriptXOffset float32
ySubscriptYOffset float32
ySuperscriptXSize float32
ySuperscriptYSize float32
ySuperscriptXOffset float32
yStrikeoutSize float32
yStrikeoutPosition float32
sTypoAscender float32
sTypoDescender float32
sTypoLineGap float32
sxHeigh float32
sCapHeight float32
}
func newOs2(os tables.Os2) (os2, error) {
out := os2{
version: os.Version,
xAvgCharWidth: os.XAvgCharWidth,
ySubscriptXSize: float32(os.YSubscriptXSize),
ySubscriptYSize: float32(os.YSubscriptYSize),
ySubscriptXOffset: float32(os.YSubscriptXOffset),
ySubscriptYOffset: float32(os.YSubscriptYOffset),
ySuperscriptXSize: float32(os.YSuperscriptXSize),
ySuperscriptYSize: float32(os.YSuperscriptYSize),
ySuperscriptXOffset: float32(os.YSuperscriptXOffset),
yStrikeoutSize: float32(os.YStrikeoutSize),
yStrikeoutPosition: float32(os.YStrikeoutPosition),
sTypoAscender: float32(os.STypoAscender),
sTypoDescender: float32(os.STypoDescender),
sTypoLineGap: float32(os.STypoLineGap),
}
// add addition info for version >= 2
if os.Version >= 2 {
if len(os.HigherVersionData) < 12 {
return os2{}, errors.New("invalid table os2")
}
out.sxHeigh = float32(binary.BigEndian.Uint16(os.HigherVersionData[8:]))
out.sCapHeight = float32(binary.BigEndian.Uint16(os.HigherVersionData[10:]))
}
const useTypoMetrics = 1 << 7
use := os.FsSelection&useTypoMetrics != 0
hasData := os.USWeightClass != 0 || os.USWidthClass != 0 || os.USFirstCharIndex != 0 || os.USLastCharIndex != 0
out.useTypoMetrics = use && hasData
return out, nil
}