-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtruetype_test.go
121 lines (103 loc) · 2.32 KB
/
truetype_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
package gltext
import (
"golang.org/x/image/math/fixed"
"os"
"testing"
)
func TestRuneRangesSort(t *testing.T) {
rr := make(RuneRanges, 0)
r := RuneRange{Low: 400, High: 500}
rr = append(rr, r)
r = RuneRange{Low: 32, High: 127}
rr = append(rr, r)
if !rr.Validate() {
t.Error("Not validating.")
}
previousMax := rune(0)
for _, r := range rr {
if r.Low < previousMax {
t.Error("Unsorted")
}
if r.Low == previousMax {
t.Error("Overlap")
}
previousMax = r.High
}
}
func TestRuneRangesOverlap(t *testing.T) {
rr := make(RuneRanges, 0)
r := RuneRange{Low: 40, High: 50}
rr = append(rr, r)
r = RuneRange{Low: 30, High: 40}
rr = append(rr, r)
if rr.Validate() {
t.Error("Expecting invalidity due to overlap.")
}
}
func TestRuneRangesLowHigh(t *testing.T) {
rr := make(RuneRanges, 0)
r := RuneRange{Low: 40, High: 39}
rr = append(rr, r)
if rr.Validate() {
t.Error("Expecting invalidity.")
}
}
func TestGetGlyphIndex(t *testing.T) {
runeRanges := make(RuneRanges, 0)
r := RuneRange{Low: 30, High: 40}
runeRanges = append(runeRanges, r)
r = RuneRange{Low: 100, High: 400}
runeRanges = append(runeRanges, r)
if !runeRanges.Validate() {
t.Error("Not validating properly.")
}
index := runeRanges.GetGlyphIndex(30)
if index != 0 {
t.Error("Bad index", index)
}
index = runeRanges.GetGlyphIndex(40)
if index != 10 {
t.Error("Bad index", index)
}
index = runeRanges.GetGlyphIndex(100)
if index != 11 {
t.Error("Bad index", index)
}
index = runeRanges.GetGlyphIndex(390)
if index != 301 {
t.Error("Bad index", index)
}
}
func TestGetGlyphIndexEdge(t *testing.T) {
IsDebug = true
runeRanges := RuneRanges{{Low: 32, High: 128}}
if !runeRanges.Validate() {
t.Error("Not validating properly.")
}
char := ' '
index := runeRanges.GetGlyphIndex(char)
if index != 0 {
t.Error("Bad index", index)
}
char = '('
index = runeRanges.GetGlyphIndex(char)
if index != 8 {
t.Error("Bad index", index)
}
fd, err := os.Open("font/font_1_honokamin.ttf")
if err != nil {
panic(err)
}
defer fd.Close()
scale := fixed.Int26_6(24)
runesPerRow := fixed.Int26_6(3)
config, err := NewTruetypeFontConfig(fd, scale, runeRanges, runesPerRow, 0)
if err != nil {
panic(err)
}
// save png for manual inspection
err = config.Save("fontconfigs", "font_1_honokamin")
if err != nil {
panic(err)
}
}