cachedFont
This commit is contained in:
@@ -9,14 +9,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type FontLayout struct {
|
type FontLayout struct {
|
||||||
Path string
|
Path string
|
||||||
DPI float64
|
DPI float64
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user