konstructor file prefixes refactor
This commit is contained in:
33
konstructor/layout.font.go
Normal file
33
konstructor/layout.font.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package konstructor
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"io/ioutil"
|
||||
|
||||
"golang.org/x/image/font"
|
||||
"golang.org/x/image/font/opentype"
|
||||
)
|
||||
|
||||
type FontLayout struct {
|
||||
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{
|
||||
Size: fl.DPI,
|
||||
DPI: fl.Size,
|
||||
Hinting: font.HintingVertical,
|
||||
})
|
||||
fl.cachedFontFace = font_face
|
||||
return font_face
|
||||
}
|
||||
Reference in New Issue
Block a user