-
Notifications
You must be signed in to change notification settings - Fork 5
/
table_offset_test.go
77 lines (69 loc) · 1.6 KB
/
table_offset_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
/*
* 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 (
"bytes"
"testing"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// Test unmarshalling and marshalling offset table.
func TestOffsetTableReadWrite(t *testing.T) {
testcases := []struct {
fontPath string
// Expected offset table parameters.
expected offsetTable
}{
{
"./testdata/FreeSans.ttf",
offsetTable{
sfntVersion: 0x10000, // opentype
numTables: 16,
searchRange: 256,
entrySelector: 4,
rangeShift: 0,
},
},
{
"./testdata/wts11.ttf",
offsetTable{
sfntVersion: 0x10000, // opentype
numTables: 15,
searchRange: 128,
entrySelector: 3,
rangeShift: 112,
},
},
{
"./testdata/roboto/Roboto-BoldItalic.ttf",
offsetTable{
sfntVersion: 0x10000, // opentype
numTables: 18,
searchRange: 256,
entrySelector: 4,
rangeShift: 32,
},
},
}
for _, tcase := range testcases {
t.Logf("%s", tcase.fontPath)
fnt, err := ParseFile(tcase.fontPath)
require.NoError(t, err)
assert.Equal(t, tcase.expected, *fnt.ot)
logrus.Debug("Write offset table")
// Marshall to buffer.
var buf bytes.Buffer
bw := newByteWriter(&buf)
err = fnt.writeOffsetTable(bw)
require.NoError(t, err)
bw.flush()
// Reload from buffer.
br := newByteReader(bytes.NewReader(buf.Bytes()))
ot, err := fnt.parseOffsetTable(br)
require.NoError(t, err)
assert.Equal(t, fnt.ot, ot)
}
}