go-chart/font.go
Jaroslavs Samcuks 2b12f707da font: add test
2021-06-08 19:53:31 +02:00

31 lines
569 B
Go

package chart
import (
"sync"
"github.com/golang/freetype/truetype"
"github.com/wcharczuk/go-chart/v2/roboto"
)
var _defaultFont defaultFont
// GetDefaultFont returns the default font (Roboto-Medium).
func GetDefaultFont() (*truetype.Font, error) {
return _defaultFont.Font()
}
type defaultFont struct {
font *truetype.Font
err error
once sync.Once
}
var _testingHook = func() {}
func (df *defaultFont) Font() (*truetype.Font, error) {
df.once.Do(func() {
df.font, df.err = truetype.Parse(roboto.Roboto)
_testingHook()
})
return df.font, df.err
}