/
config.go
72 lines (50 loc) · 1.04 KB
/
config.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
package font
type Directional interface {
Direction() Direction
}
type TTFConfig interface {
FontSize() int
Runes() []rune
}
// TTF config based on range
type rangeTTFConfig struct {
Low, High uint32
Size int
}
func (fc rangeTTFConfig) FontSize() int {
return fc.Size
}
func (fc rangeTTFConfig) Runes() (runes []rune) {
if fc.Low == fc.High && fc.Low == 0{
fc.Low = 32
fc.High = 127
}
runes = make([]rune, fc.High-fc.Low+1)
for i,j := fc.Low, fc.High; i <= j; i++ {
runes[i-fc.Low] = rune(i)
}
return
}
func (rangeTTFConfig) Direction() Direction {
return LeftToRight
}
// TTF config based on runes collection
type ttfConfig struct {
size int
runes []rune
}
func (ttf ttfConfig) FontSize() int {
return ttf.size
}
func (ttf ttfConfig) Runes() []rune {
return ttf.runes
}
func (ttfConfig) Direction() Direction {
return LeftToRight
}
func NewTTFConfig(size int, runes []rune) TTFConfig {
return ttfConfig{size:size, runes:runes}
}
func ASCII(size int) TTFConfig {
return rangeTTFConfig{Size:size, Low:32, High:127}
}