-
Notifications
You must be signed in to change notification settings - Fork 0
/
font.go
47 lines (40 loc) · 853 Bytes
/
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
package main
import (
"io/ioutil"
"log"
"github.com/tkido/tendon/assets"
"github.com/tkido/tendon/ui"
"github.com/golang/freetype/truetype"
)
// Font const
const (
FontRegular ui.FontType = iota
FontBold
FontPixel
FontXS ui.FontSize = 12
FontSmall = 16
FontMedium = 24
FontLarge = 36
FontXL = 48
)
func init() {
registerFont(FontRegular, "mplus-1p-regular.ttf")
registerFont(FontBold, "mplus-1p-bold.ttf")
registerFont(FontPixel, "PixelMplus12-Regular.ttf")
}
func registerFont(fontType ui.FontType, path string) {
ttf, err := assets.Open(path)
if err != nil {
log.Fatal(err)
}
defer ttf.Close()
bs, err := ioutil.ReadAll(ttf)
if err != nil {
log.Fatal(err)
}
tt, err := truetype.Parse(bs)
if err != nil {
log.Fatal(err)
}
ui.RegisterFont(fontType, tt)
}