Skip to content

Commit 30c4cd7

Browse files
committed
This close qax-os#1963, prevent the GetStyle function panic when theme without sysClr
1 parent d81b4c8 commit 30c4cd7

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

styles.go

+21-10
Original file line numberDiff line numberDiff line change
@@ -1376,22 +1376,33 @@ var (
13761376
}
13771377
)
13781378

1379+
// colorChoice returns a hex color code from the actual color values.
1380+
func (clr *decodeCTColor) colorChoice() *string {
1381+
if clr.SrgbClr != nil {
1382+
return clr.SrgbClr.Val
1383+
}
1384+
if clr.SysClr != nil {
1385+
return &clr.SysClr.LastClr
1386+
}
1387+
return nil
1388+
}
1389+
13791390
// GetBaseColor returns the preferred hex color code by giving hex color code,
13801391
// indexed color, and theme color.
13811392
func (f *File) GetBaseColor(hexColor string, indexedColor int, themeColor *int) string {
13821393
if f.Theme != nil && themeColor != nil {
13831394
clrScheme := f.Theme.ThemeElements.ClrScheme
13841395
if val, ok := map[int]*string{
1385-
0: &clrScheme.Lt1.SysClr.LastClr,
1386-
1: &clrScheme.Dk1.SysClr.LastClr,
1387-
2: clrScheme.Lt2.SrgbClr.Val,
1388-
3: clrScheme.Dk2.SrgbClr.Val,
1389-
4: clrScheme.Accent1.SrgbClr.Val,
1390-
5: clrScheme.Accent2.SrgbClr.Val,
1391-
6: clrScheme.Accent3.SrgbClr.Val,
1392-
7: clrScheme.Accent4.SrgbClr.Val,
1393-
8: clrScheme.Accent5.SrgbClr.Val,
1394-
9: clrScheme.Accent6.SrgbClr.Val,
1396+
0: clrScheme.Lt1.colorChoice(),
1397+
1: clrScheme.Dk1.colorChoice(),
1398+
2: clrScheme.Lt2.colorChoice(),
1399+
3: clrScheme.Dk2.colorChoice(),
1400+
4: clrScheme.Accent1.colorChoice(),
1401+
5: clrScheme.Accent2.colorChoice(),
1402+
6: clrScheme.Accent3.colorChoice(),
1403+
7: clrScheme.Accent4.colorChoice(),
1404+
8: clrScheme.Accent5.colorChoice(),
1405+
9: clrScheme.Accent6.colorChoice(),
13951406
}[*themeColor]; ok && val != nil {
13961407
return *val
13971408
}

styles_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,8 @@ func TestGetThemeColor(t *testing.T) {
613613
assert.Equal(t, "FFFFFF", f.getThemeColor(&xlsxColor{RGB: "FFFFFF"}))
614614
assert.Equal(t, "FF8080", f.getThemeColor(&xlsxColor{Indexed: 2, Tint: 0.5}))
615615
assert.Empty(t, f.getThemeColor(&xlsxColor{Indexed: len(IndexedColorMapping), Tint: 0.5}))
616+
clr := &decodeCTColor{}
617+
assert.Nil(t, clr.colorChoice())
616618
}
617619

618620
func TestGetStyle(t *testing.T) {

xmlTheme.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ type xlsxEffectStyleLst struct {
148148
EffectStyleLst string `xml:",innerxml"`
149149
}
150150

151-
// xlsxBgFillStyleLst element defines a list of background fills that are
151+
// xlsxBgFillStyleLst element defines a list of background fills that are
152152
// used within a theme. The background fills consist of three fills, arranged
153153
// in order from subtle to moderate to intense.
154154
type xlsxBgFillStyleLst struct {

0 commit comments

Comments
 (0)