-
Notifications
You must be signed in to change notification settings - Fork 4
/
run_rpr_background.go
97 lines (72 loc) · 1.73 KB
/
run_rpr_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
package run
import (
"bytes"
"fmt"
"github.com/Luna-CY/go-office/docx/template"
)
type Background struct {
// isSet 是否设置背景
isSet bool
// fill 16进制颜色值,指定背景色
fill *string
// color 16进制颜色值,指定前景色(文字颜色)
// 可选值: auto
color *string
// mask 前景色蒙版的值
// 参考文档 http://officeopenxml.com/WPtextShading.php
mask string
}
// GetBackgroundColor 获取背景色
func (b *Background) GetBackgroundColor() string {
if nil == b.fill {
return ""
}
return *b.fill
}
// SetBackgroundColor 设置背景色,不包含#号
func (b *Background) SetBackgroundColor(color string) *Background {
b.isSet = true
b.fill = &color
return b
}
// GetColor 获取前景色
func (b *Background) GetColor() string {
if nil == b.color {
return "auto"
}
return *b.color
}
// SetColor 设置前景色,不包含#号
func (b *Background) SetColor(color string) *Background {
b.isSet = true
b.color = &color
return b
}
// SetMask 设置背景模式
func (b *Background) SetMask(val string) *Background {
b.isSet = true
b.mask = val
return b
}
func (b *Background) GetXmlBytes() ([]byte, error) {
if !b.isSet {
return []byte{}, nil
}
buffer := new(bytes.Buffer)
buffer.WriteByte('<')
buffer.WriteString(template.RunPPrBackgroundTag)
if nil != b.fill {
buffer.WriteString(fmt.Sprintf(` %v="%v"`, template.RunPPrBackgroundFill, *b.fill))
if nil == b.color {
color := "auto"
b.color = &color
}
buffer.WriteString(fmt.Sprintf(` %v="%v"`, template.RunPPrBackgroundColor, *b.color))
}
if "" == b.mask {
b.mask = "clear"
}
buffer.WriteString(fmt.Sprintf(` %v="%v"`, template.RunRPrVal, b.mask))
buffer.WriteString("/>")
return buffer.Bytes(), nil
}