cachedFont

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

View File

@@ -14,9 +14,13 @@ type FontLayout struct {
Size float64 Size float64
Color color.Color Color color.Color
SelectedColor color.Color SelectedColor color.Color
cachedFontFace font.Face
} }
func (fl *FontLayout) GetFontFace() font.Face { func (fl *FontLayout) GetFontFace() font.Face {
if fl.cachedFontFace != nil {
return fl.cachedFontFace
}
file, _ := ioutil.ReadFile(fl.Path) file, _ := ioutil.ReadFile(fl.Path)
true_type, _ := opentype.Parse(file) true_type, _ := opentype.Parse(file)
font_face, _ := opentype.NewFace(true_type, &opentype.FaceOptions{ font_face, _ := opentype.NewFace(true_type, &opentype.FaceOptions{
@@ -24,5 +28,6 @@ func (fl *FontLayout) GetFontFace() font.Face {
DPI: fl.Size, DPI: fl.Size,
Hinting: font.HintingVertical, Hinting: font.HintingVertical,
}) })
fl.cachedFontFace = font_face
return font_face return font_face
} }