-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache.go
57 lines (41 loc) · 940 Bytes
/
cache.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"image"
"github.com/fogleman/gg"
"github.com/sirupsen/logrus"
)
var cacheImages = map[int]image.Image{}
func getBaseImage(week Days) image.Image {
img, ok := cacheImages[int(week)]
if !ok || refreshCache {
img = generateBaseImage(week)
logrus.Infof("miss cache")
cacheImages[int(week)] = img
}
return img
}
func generateBaseImage(week Days) image.Image {
dc := gg.NewContext(width, height)
dc.SetColor(backgroundColor)
dc.Clear()
drawDays(dc, week)
return dc.Image()
}
func drawDays(dc *gg.Context, week Days) {
for _, d := range days {
if week.HasFlag(d.Flag) {
loadDayOn(dc)
} else {
loadDayOff(dc)
}
dc.DrawStringAnchored(d.Letter, float64(d.PosX), float64(centerCaseDays), 0.5, 0.5)
}
}
func loadDayOn(dc *gg.Context) {
dc.SetFontFace(fontBold)
dc.SetColor(colorDayOn)
}
func loadDayOff(dc *gg.Context) {
dc.SetFontFace(fontRegular)
dc.SetColor(colorDayOff)
}