theme_test.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package xlsx
  2. import (
  3. "bytes"
  4. "encoding/xml"
  5. . "gopkg.in/check.v1"
  6. )
  7. type ThemeSuite struct{}
  8. var _ = Suite(&ThemeSuite{})
  9. func (s *ThemeSuite) TestThemeColors(c *C) {
  10. themeXmlBytes := bytes.NewBufferString(`
  11. <?xml version="1.0"?>
  12. <a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office Theme">
  13. <a:themeElements>
  14. <a:clrScheme name="Office">
  15. <a:dk1>
  16. <a:sysClr val="windowText" lastClr="000000"/>
  17. </a:dk1>
  18. <a:lt1>
  19. <a:sysClr val="window" lastClr="FFFFFF"/>
  20. </a:lt1>
  21. <a:dk2>
  22. <a:srgbClr val="1F497D"/>
  23. </a:dk2>
  24. <a:lt2>
  25. <a:srgbClr val="EEECE1"/>
  26. </a:lt2>
  27. <a:accent1>
  28. <a:srgbClr val="4F81BD"/>
  29. </a:accent1>
  30. <a:accent2>
  31. <a:srgbClr val="C0504D"/>
  32. </a:accent2>
  33. <a:accent3>
  34. <a:srgbClr val="9BBB59"/>
  35. </a:accent3>
  36. <a:accent4>
  37. <a:srgbClr val="8064A2"/>
  38. </a:accent4>
  39. <a:accent5>
  40. <a:srgbClr val="4BACC6"/>
  41. </a:accent5>
  42. <a:accent6>
  43. <a:srgbClr val="F79646"/>
  44. </a:accent6>
  45. <a:hlink>
  46. <a:srgbClr val="0000FF"/>
  47. </a:hlink>
  48. <a:folHlink>
  49. <a:srgbClr val="800080"/>
  50. </a:folHlink>
  51. </a:clrScheme>
  52. </a:themeElements>
  53. </a:theme>
  54. `)
  55. var themeXml xlsxTheme
  56. err := xml.NewDecoder(themeXmlBytes).Decode(&themeXml)
  57. c.Assert(err, IsNil)
  58. clrSchemes := themeXml.ThemeElements.ClrScheme.Children
  59. c.Assert(len(clrSchemes), Equals, 12)
  60. dk1Scheme := clrSchemes[0]
  61. c.Assert(dk1Scheme.XMLName.Local, Equals, "dk1")
  62. c.Assert(dk1Scheme.SrgbClr, IsNil)
  63. c.Assert(dk1Scheme.SysClr, NotNil)
  64. c.Assert(dk1Scheme.SysClr.Val, Equals, "windowText")
  65. c.Assert(dk1Scheme.SysClr.LastClr, Equals, "000000")
  66. dk2Scheme := clrSchemes[2]
  67. c.Assert(dk2Scheme.XMLName.Local, Equals, "dk2")
  68. c.Assert(dk2Scheme.SysClr, IsNil)
  69. c.Assert(dk2Scheme.SrgbClr, NotNil)
  70. c.Assert(dk2Scheme.SrgbClr.Val, Equals, "1F497D")
  71. theme := newTheme(themeXml)
  72. c.Assert(theme.themeColor(0, 0), Equals, "FFFFFFFF")
  73. c.Assert(theme.themeColor(2, 0), Equals, "FFEEECE1")
  74. }