playground header, font scaling
This commit is contained in:
@@ -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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user