forked from unidoc/unitype
-
Notifications
You must be signed in to change notification settings - Fork 0
/
table_hmtx_test.go
130 lines (126 loc) · 3.05 KB
/
table_hmtx_test.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
package unitype
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestOptimizeHmtxTable(t *testing.T) {
testcases := []struct {
fnt *font
expNumGlyphs int
expNumHMetrics int
expLSB []int16
exphMetrics []longHorMetric
}{
{
fnt: &font{
maxp: &maxpTable{
numGlyphs: 5,
},
hhea: &hheaTable{
numberOfHMetrics: 3,
},
hmtx: &hmtxTable{
hMetrics: []longHorMetric{
{advanceWidth: 10, lsb: 1},
{advanceWidth: 20, lsb: 2},
{advanceWidth: 30, lsb: 3},
},
leftSideBearings: []int16{
4,
5,
},
},
},
expNumGlyphs: 5,
expNumHMetrics: 3,
exphMetrics: []longHorMetric{
{advanceWidth: 10, lsb: 1},
{advanceWidth: 20, lsb: 2},
{advanceWidth: 30, lsb: 3},
},
expLSB: []int16{4, 5},
},
{
fnt: &font{
maxp: &maxpTable{
numGlyphs: 7,
},
hhea: &hheaTable{
numberOfHMetrics: 7,
},
hmtx: &hmtxTable{
hMetrics: []longHorMetric{
{advanceWidth: 10, lsb: 1},
{advanceWidth: 20, lsb: 2},
{advanceWidth: 30, lsb: 3},
{advanceWidth: 40, lsb: 4},
{advanceWidth: 50, lsb: 5},
{advanceWidth: 60, lsb: 6}, // should include this once optimized.
{advanceWidth: 60, lsb: 7},
},
leftSideBearings: []int16{},
},
},
expNumGlyphs: 7,
expNumHMetrics: 6,
exphMetrics: []longHorMetric{
{advanceWidth: 10, lsb: 1},
{advanceWidth: 20, lsb: 2},
{advanceWidth: 30, lsb: 3},
{advanceWidth: 40, lsb: 4},
{advanceWidth: 50, lsb: 5},
{advanceWidth: 60, lsb: 6},
},
expLSB: []int16{7},
},
{
fnt: &font{
maxp: &maxpTable{
numGlyphs: 13,
},
hhea: &hheaTable{
numberOfHMetrics: 10,
},
hmtx: &hmtxTable{
hMetrics: []longHorMetric{
{advanceWidth: 10, lsb: 1},
{advanceWidth: 20, lsb: 2},
{advanceWidth: 30, lsb: 3},
{advanceWidth: 40, lsb: 4},
{advanceWidth: 50, lsb: 5},
{advanceWidth: 60, lsb: 6}, // should include this once optimized.
{advanceWidth: 60, lsb: 7},
{advanceWidth: 60, lsb: 8},
{advanceWidth: 60, lsb: 9},
{advanceWidth: 60, lsb: 10},
},
leftSideBearings: []int16{
11,
12,
13,
},
},
},
expNumGlyphs: 13,
expNumHMetrics: 6,
exphMetrics: []longHorMetric{
{advanceWidth: 10, lsb: 1},
{advanceWidth: 20, lsb: 2},
{advanceWidth: 30, lsb: 3},
{advanceWidth: 40, lsb: 4},
{advanceWidth: 50, lsb: 5},
{advanceWidth: 60, lsb: 6},
},
expLSB: []int16{7, 8, 9, 10, 11, 12, 13},
},
}
for _, tcase := range testcases {
tcase.fnt.optimizeHmtx()
assert.EqualValues(t, tcase.expNumGlyphs, tcase.fnt.maxp.numGlyphs)
assert.EqualValues(t, tcase.expNumHMetrics, tcase.fnt.hhea.numberOfHMetrics)
assert.Len(t, tcase.fnt.hmtx.hMetrics, tcase.expNumHMetrics)
assert.Len(t, tcase.fnt.hmtx.leftSideBearings, tcase.expNumGlyphs-tcase.expNumHMetrics)
assert.Equal(t, tcase.expLSB, tcase.fnt.hmtx.leftSideBearings)
assert.Equal(t, tcase.exphMetrics, tcase.fnt.hmtx.hMetrics)
}
}