-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfonts.go
31 lines (23 loc) · 782 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
package ansitoimage
import _ "embed"
import (
"github.com/golang/freetype/truetype"
"github.com/pkg/errors"
"golang.org/x/image/font"
)
//go:embed fonts/DejaVuSansMono.ttf
var monoRegularFontData []byte
//go:embed fonts/DejaVuSansMono-Bold.ttf
var monoBoldFontData []byte
//go:embed fonts/DejaVuSansMono-Oblique.ttf
var monoObliqueFontData []byte
//go:embed fonts/DejaVuSansMono-BoldOblique.ttf
var monoBoldObliqueFontData []byte
// loadFontFace loads truetype font face from specified font data.
func loadFontFace(data []byte, points float64) (font.Face, error) {
trueTypeFont, err := truetype.Parse(data)
if err != nil {
return nil, errors.Wrap(err, "failed to parse truetype font")
}
return truetype.NewFace(trueTypeFont, &truetype.Options{Size: points}), nil
}