-
Notifications
You must be signed in to change notification settings - Fork 0
/
font.go
76 lines (68 loc) · 1.72 KB
/
font.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
package banner
import (
"strings"
big "github.com/multiverse-os/banner/fonts/big"
giant "github.com/multiverse-os/banner/fonts/giant"
)
//type Character struct {
// Lines []string
// Height int
// Width int
//}
type Font struct {
Characters map[string][]string
characterSpacing int
//Characters map[string]Character
//paddingLeft int
//paddingRight int
}
func LoadFont(name string) *Font {
switch strings.ToLower(name) {
// TODO: Need to do analysis to see if this method will load every condition
// in the switch. If so, need to hand off this specific step to thing
// calling lib
case "giant":
return &Font{
characterSpacing: 1,
Characters: giant.Characters,
}
default:
return &Font{
characterSpacing: 1,
Characters: big.Characters,
}
}
//for _, character := range big.Characters {
// font.Characters = append(font.Characters, Character{
// Lines: character,
// Height: len(character),
// Width: len(character[0]),
// })
//}
}
//func (self *Font) PaddingLeft(whitespace int) *Font {
// self.paddingLeft = whitespace
// return self
//}
//
//func (self *Font) PaddingRight(whitespace int) *Font {
// self.paddingRight = whitespace
// return self
//}
func (self *Font) CharacterSpacing(whitespace int) *Font {
self.characterSpacing = whitespace
return self
}
func (self *Font) WriteString(text string) string {
outputLines := []string{}
for _, character := range text {
fontCharacter := self.Characters[string(character)]
for index, line := range fontCharacter {
if len(outputLines) <= index {
outputLines = append(outputLines, "")
}
outputLines[index] += line + strings.Repeat(" ", self.characterSpacing)
}
}
return strings.Join(outputLines, "\n")
}