playground header, font scaling

This commit is contained in:
2023-07-08 10:59:46 +02:00
parent 09959a8932
commit 3947c34b4c
9 changed files with 78 additions and 32 deletions

View File

@@ -8,6 +8,8 @@ import (
"golang.org/x/image/font/opentype"
)
type FontName string
type FontLayout struct {
Path string
DPI float64
@@ -17,17 +19,21 @@ type FontLayout struct {
cachedFontFace font.Face
}
func (fl *FontLayout) GetFontFace() font.Face {
func (fl *FontLayout) GetFontFace(scale int) font.Face {
if fl.cachedFontFace != nil {
return fl.cachedFontFace
}
file, _ := ioutil.ReadFile(fl.Path)
true_type, _ := opentype.Parse(file)
font_face, _ := opentype.NewFace(true_type, &opentype.FaceOptions{
Size: fl.DPI,
DPI: fl.Size,
Size: fl.Size * float64(scale),
DPI: fl.DPI,
Hinting: font.HintingVertical,
})
fl.cachedFontFace = font_face
return font_face
}
func GetFontPath(name FontName) string {
return "assets/fonts/" + string(name) + ".ttf"
}