From 457d08080f5c3ce00ef1f2d39827b8cfe844fb3d Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Thu, 6 Jul 2023 23:51:35 +0200 Subject: [PATCH] cachedFont --- konstructor/entity.font.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/konstructor/entity.font.go b/konstructor/entity.font.go index ef1388c..7871c6c 100644 --- a/konstructor/entity.font.go +++ b/konstructor/entity.font.go @@ -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 }