forked from liamg/darktile
/
fonts.go
49 lines (37 loc) · 1.08 KB
/
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
47
48
49
package gui
import (
"bytes"
"fmt"
"github.com/gobuffalo/packr"
"github.com/liamg/aminal/glfont"
)
func (gui *GUI) getPackedFont(name string) (*glfont.Font, error) {
box := packr.NewBox("./packed-fonts")
fontBytes, err := box.Find(name)
if err != nil {
return nil, fmt.Errorf("packaged font '%s' could not be read: %s", name, err)
}
font, err := glfont.LoadFont(bytes.NewReader(fontBytes), gui.fontScale*gui.dpiScale/gui.scale(), gui.width, gui.height)
if err != nil {
return nil, fmt.Errorf("font '%s' failed to load: %v", name, err)
}
return font, nil
}
func (gui *GUI) loadFonts() error {
// from https://github.com/ryanoasis/nerd-fonts/tree/master/patched-fonts/Hack
defaultFont, err := gui.getPackedFont("Hack Regular Nerd Font Complete.ttf")
if err != nil {
return err
}
boldFont, err := gui.getPackedFont("Hack Bold Nerd Font Complete.ttf")
if err != nil {
return err
}
if gui.fontMap == nil {
gui.fontMap = NewFontMap(defaultFont, boldFont)
} else {
gui.fontMap.AssignFonts(defaultFont, boldFont)
}
// add special non-ascii fonts here
return nil
}