feat: support get and set default font
This commit is contained in:
parent
2ed86a81d0
commit
de4250f60b
6 changed files with 24 additions and 10 deletions
19
font.go
19
font.go
|
|
@ -32,9 +32,13 @@ import (
|
|||
|
||||
var fonts = sync.Map{}
|
||||
var ErrFontNotExists = errors.New("font is not exists")
|
||||
var defaultFontFamily = "defaultFontFamily"
|
||||
|
||||
func init() {
|
||||
_ = InstallFont("roboto", roboto.Roboto)
|
||||
name := "roboto"
|
||||
_ = InstallFont(name, roboto.Roboto)
|
||||
font, _ := GetFont(name)
|
||||
SetDefaultFont(font)
|
||||
}
|
||||
|
||||
// InstallFont installs the font for charts
|
||||
|
|
@ -47,6 +51,19 @@ func InstallFont(fontFamily string, data []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetDefaultFont get default font
|
||||
func GetDefaultFont() (*truetype.Font, error) {
|
||||
return GetFont(defaultFontFamily)
|
||||
}
|
||||
|
||||
// SetDefaultFont set default font
|
||||
func SetDefaultFont(font *truetype.Font) {
|
||||
if font == nil {
|
||||
return
|
||||
}
|
||||
fonts.Store(defaultFontFamily, font)
|
||||
}
|
||||
|
||||
// GetFont get the font by font family
|
||||
func GetFont(fontFamily string) (*truetype.Font, error) {
|
||||
value, ok := fonts.Load(fontFamily)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue