package tins2020 import ( "github.com/veandco/go-sdl2/ttf" "opslag.de/schobers/fs/vfs" ) type Fonts struct { dir vfs.CopyDir fonts map[string]*ttf.Font } func (f *Fonts) Init(dir vfs.CopyDir) { f.dir = dir f.fonts = map[string]*ttf.Font{} } func (f *Fonts) Load(name, path string, size int) error { fontPath, err := f.dir.Retrieve(path) if err != nil { return err } font, err := ttf.OpenFont(fontPath, size) if err != nil { return err } if font, ok := f.fonts[name]; ok { font.Close() } f.fonts[name] = font return nil } func (f *Fonts) Destroy() { if f.fonts == nil { return } for _, f := range f.fonts { f.Close() } }