-
Notifications
You must be signed in to change notification settings - Fork 2
/
embed.go
47 lines (38 loc) · 1.07 KB
/
embed.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 (
_ "embed"
"fmt"
"sync"
"gioui.org/font"
"gioui.org/font/opentype"
"gioui.org/text"
)
//go:embed fonts/AlbertSans-Regular.ttf
var AlbertSansRegular []byte
//go:embed fonts/AlbertSans-Medium.ttf
var AlbertSansMedium []byte
//go:embed fonts/AlbertSans-Light.ttf
var AlbertSansLight []byte
//go:embed fonts/AlbertSans-SemiBold.ttf
var AlbertSansSemiBold []byte
var (
once sync.Once
collection []text.FontFace
)
func Collection() []text.FontFace {
once.Do(func() {
register("AlbertSans", font.Font{}, AlbertSansRegular)
register("AlbertSans", font.Font{Weight: font.Light}, AlbertSansLight)
register("AlbertSans", font.Font{Weight: font.Medium}, AlbertSansMedium)
register("AlbertSans", font.Font{Weight: font.SemiBold}, AlbertSansSemiBold)
})
return collection
}
func register(typeface string, fnt font.Font, ttf []byte) {
face, err := opentype.Parse(ttf)
if err != nil {
panic(fmt.Errorf("failed to parse font: %v", err))
}
fnt.Typeface = font.Typeface(typeface)
collection = append(collection, font.FontFace{Font: fnt, Face: face})
}