everything I got
This commit is contained in:
37
assets/fonts.go
Normal file
37
assets/fonts.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package assets
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"log"
|
||||
|
||||
"golang.org/x/image/font"
|
||||
"golang.org/x/image/font/opentype"
|
||||
)
|
||||
|
||||
//go:embed *
|
||||
var FontFiles embed.FS
|
||||
var fontFace font.Face
|
||||
|
||||
func LoadFontFace(fileName string, size float64) font.Face {
|
||||
fontBytes, err := FontFiles.ReadFile(fileName)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
tt, err := opentype.Parse(fontBytes)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
const dpi = 144
|
||||
fontFace, err = opentype.NewFace(tt, &opentype.FaceOptions{
|
||||
Size: size,
|
||||
DPI: dpi,
|
||||
Hinting: font.HintingNone,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return fontFace
|
||||
}
|
||||
Reference in New Issue
Block a user