/
background.go
101 lines (75 loc) · 2.05 KB
/
background.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package docx
import (
"bytes"
"fmt"
"github.com/Luna-CY/go-office/docx/template"
)
// themeTint 文档的背景配置
type Background struct {
// isSet 是否设置了背景
isSet bool
// color 背景色,16进制颜色值
color string
// themeColor 主题颜色的id,其指向的id在主题中定义
themeColor string
// themeShade 主题阴影颜色,0-255的16进制值
themeShade string
// themeTint 主题色调值,0-255的16进制值
themeTint string
}
// SetBackground 设置文档背景
func (b *Background) SetBackground(color, themeColor, themeShade, themeTint string) *Background {
b.isSet = true
b.color = color
b.themeColor = themeColor
b.themeShade = themeShade
b.themeTint = themeTint
return b
}
// SetColor 设置颜色
func (b *Background) SetColor(color string) *Background {
b.isSet = true
b.color = color
return b
}
// SetThemeColor 设置主题颜色
func (b *Background) SetThemeColor(themeColor string) *Background {
b.isSet = true
b.themeColor = themeColor
return b
}
// SetThemeShade 设置主题阴影
func (b *Background) SetThemeShade(themeShade string) *Background {
b.isSet = true
b.themeShade = themeShade
return b
}
// SetThemeTint 设置主题的色调值
// 0-255的16进制字符串
func (b *Background) SetThemeTint(themeTint string) *Background {
b.isSet = true
b.themeTint = themeTint
return b
}
func (b *Background) GetXmlBytes() ([]byte, error) {
if !b.isSet {
return []byte{}, nil
}
buffer := new(bytes.Buffer)
buffer.WriteByte('<')
buffer.WriteString(template.BackgroundTag)
if "" != b.color {
buffer.WriteString(fmt.Sprintf(` %v="%v"`, template.BackgroundColor, b.color))
}
if "" != b.themeColor {
buffer.WriteString(fmt.Sprintf(` %v="%v"`, template.BackgroundThemeColor, b.themeColor))
}
if "" != b.themeShade {
buffer.WriteString(fmt.Sprintf(` %v="%v"`, template.BackgroundThemeShade, b.themeShade))
}
if "" != b.themeTint {
buffer.WriteString(fmt.Sprintf(` %v="%v"`, template.BackgroundThemeTint, b.themeTint))
}
buffer.WriteString("/>")
return buffer.Bytes(), nil
}