-
Notifications
You must be signed in to change notification settings - Fork 0
/
fonts.go
46 lines (34 loc) · 786 Bytes
/
fonts.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
package main
import (
"io/ioutil"
"log"
"path/filepath"
"golang.org/x/image/font"
"golang.org/x/image/font/opentype"
)
const dpi = 72
func LoadTtfFont(path string, size int) font.Face {
fops := &opentype.FaceOptions{
Size: float64(size),
DPI: dpi,
Hinting: font.HintingNone,
}
data, err := ioutil.ReadFile(path)
if err != nil {
log.Fatal(err)
}
ttf, err := opentype.Parse(data)
if err != nil {
log.Fatal(err)
}
font, err := opentype.NewFace(ttf, fops)
if err != nil {
log.Fatal(err)
}
return font
}
func LoadFonts() {
fontTitle = LoadTtfFont(filepath.Join("font", "alagard.ttf"), 16)
fontDetail = LoadTtfFont(filepath.Join("font", "Volter__28Goldfish_29.ttf"), 9)
fontSmall = LoadTtfFont(filepath.Join("font", "small_pixel.ttf"), 8)
}