cachedFont

This commit is contained in:
2023-07-06 23:51:35 +02:00
parent a4e7eedb39
commit 457d08080f

View File

@@ -9,14 +9,18 @@ import (
)
type FontLayout struct {
Path string
DPI float64
Size float64
Color color.Color
SelectedColor color.Color
Path string
DPI float64
Size float64
Color color.Color
SelectedColor color.Color
cachedFontFace font.Face
}
func (fl *FontLayout) GetFontFace() 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{
@@ -24,5 +28,6 @@ func (fl *FontLayout) GetFontFace() font.Face {
DPI: fl.Size,
Hinting: font.HintingVertical,
})
fl.cachedFontFace = font_face
return font_face
}