-
Notifications
You must be signed in to change notification settings - Fork 820
/
theme.go
47 lines (43 loc) · 1.19 KB
/
theme.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
package xlsx
import (
"fmt"
"strconv"
)
type theme struct {
colors []string
}
func newTheme(themeXml xlsxTheme) *theme {
clrMap := map[string]string{}
clrSchemes := themeXml.ThemeElements.ClrScheme.Children
for _, scheme := range clrSchemes {
var rgbColor string
if scheme.SysClr != nil {
rgbColor = scheme.SysClr.LastClr
} else {
rgbColor = scheme.SrgbClr.Val
}
clrMap[scheme.XMLName.Local] = rgbColor
}
colors := []string{clrMap["lt1"], clrMap["dk1"], clrMap["lt2"], clrMap["dk2"], clrMap["accent1"],
clrMap["accent2"], clrMap["accent3"], clrMap["accent4"], clrMap["accent5"],
clrMap["accent6"], clrMap["hlink"], clrMap["folHlink"]}
return &theme{colors}
}
func (t *theme) themeColor(index int64, tint float64) string {
baseColor := t.colors[index]
if tint == 0 {
return "FF" + baseColor
} else {
r, _ := strconv.ParseInt(baseColor[0:2], 16, 64)
g, _ := strconv.ParseInt(baseColor[2:4], 16, 64)
b, _ := strconv.ParseInt(baseColor[4:6], 16, 64)
h, s, l := RGBToHSL(uint8(r), uint8(g), uint8(b))
if tint < 0 {
l *= (1 + tint)
} else {
l = l*(1-tint) + (1 - (1 - tint))
}
br, bg, bb := HSLToRGB(h, s, l)
return fmt.Sprintf("FF%02X%02X%02X", br, bg, bb)
}
}