From d6468fc114217678e8bc8b4324fd6185794e0182 Mon Sep 17 00:00:00 2001 From: xuri Date: Sat, 7 Jul 2018 15:59:48 +0800 Subject: - Initialize theme support; - RGBA, HSL color convert has been added; - go test updated --- styles.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'styles.go') 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) +} -- cgit v1.2.1