2017-04-14 20:43:52 -04:00
|
|
|
package chart
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/golang/freetype/truetype"
|
2020-11-22 19:45:10 -05:00
|
|
|
"github.com/wcharczuk/go-chart/v2/roboto"
|
2017-04-14 20:43:52 -04: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 {
|
2017-05-12 20:12:23 -04:00
|
|
|
font, err := truetype.Parse(roboto.Roboto)
|
2017-04-14 20:43:52 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
_defaultFont = font
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _defaultFont, nil
|
|
|
|
}
|