go-chart/font.go

30 lines
561 B
Go
Raw Normal View History

2017-04-15 02:43:52 +02:00
package chart
import (
"sync"
2018-12-06 16:38:58 +01:00
"git.gutmet.org/golang-freetype.git/truetype"
"git.gutmet.org/go-chart.git/roboto"
2017-04-15 02:43:52 +02:00
)
var (
_defaultFontLock sync.Mutex
_defaultFont *truetype.Font
)
// GetDefaultFont returns the default font (Roboto-Medium).
func GetDefaultFont() (*truetype.Font, error) {
if _defaultFont == nil {
_defaultFontLock.Lock()
defer _defaultFontLock.Unlock()
if _defaultFont == nil {
font, err := truetype.Parse(roboto.Roboto)
2017-04-15 02:43:52 +02:00
if err != nil {
return nil, err
}
_defaultFont = font
}
}
return _defaultFont, nil
}