2024-11-26 18:26:45 +01:00
|
|
|
package fonts
|
2024-09-15 09:01:13 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/golang/freetype/truetype"
|
|
|
|
"github.com/llgcode/draw2d"
|
|
|
|
)
|
|
|
|
|
2024-11-26 18:26:45 +01:00
|
|
|
type Cache map[string]*truetype.Font
|
2024-09-15 09:01:13 +02:00
|
|
|
|
2024-11-26 18:26:45 +01:00
|
|
|
func (fc Cache) Store(fd draw2d.FontData, font *truetype.Font) {
|
2024-09-15 09:01:13 +02:00
|
|
|
fc[fd.Name] = font
|
|
|
|
}
|
|
|
|
|
2024-11-26 18:26:45 +01:00
|
|
|
func (fc Cache) Load(fd draw2d.FontData) (*truetype.Font, error) {
|
2024-09-15 09:01:13 +02:00
|
|
|
font, stored := fc[fd.Name]
|
|
|
|
if !stored {
|
|
|
|
return nil, fmt.Errorf("font %s is not stored in font cache", fd.Name)
|
|
|
|
}
|
|
|
|
return font, nil
|
|
|
|
}
|