summaryrefslogtreecommitdiff
path: root/styles.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2018-07-07 15:59:48 +0800
committerxuri <xuri.me@gmail.com>2018-07-07 15:59:48 +0800
commitd6468fc114217678e8bc8b4324fd6185794e0182 (patch)
tree92e193d6a5c38c754c7719161af0062b46f58492 /styles.go
parent9cb0e9308b7e65d5a277b0c6af9fa0e8680b3658 (diff)
- Initialize theme support;
- RGBA, HSL color convert has been added; - go test updated
Diffstat (limited to 'styles.go')
-rw-r--r--styles.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/styles.go b/styles.go
index 32350ca..e2a1ae6 100644
--- a/styles.go
+++ b/styles.go
@@ -2723,3 +2723,29 @@ func drawConfFmtExp(p int, ct string, format *formatConditional) *xlsxCfRule {
func getPaletteColor(color string) string {
return "FF" + strings.Replace(strings.ToUpper(color), "#", "", -1)
}
+
+// themeReader provides function to get the pointer to the xl/theme/theme1.xml
+// structure after deserialization.
+func (f *File) themeReader() *xlsxTheme {
+ var theme xlsxTheme
+ _ = xml.Unmarshal([]byte(f.readXML("xl/theme/theme1.xml")), &theme)
+ return &theme
+}
+
+// ThemeColor applied the color with tint value.
+func ThemeColor(baseColor string, tint float64) string {
+ if tint == 0 {
+ return "FF" + baseColor
+ }
+ 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)
+}