forked from unidoc/unioffice
/
style.go
150 lines (131 loc) · 3.59 KB
/
style.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Copyright 2017 Baliance. All rights reserved.
//
// Use of this source code is governed by the terms of the Affero GNU General
// Public License version 3.0 as published by the Free Software Foundation and
// appearing in the file LICENSE included in the packaging of this file. A
// commercial license can be purchased by contacting sales@baliance.com.
package document
import (
"baliance.com/gooxml/schema/soo/wml"
)
// Style is a style within the styles.xml file.
type Style struct {
x *wml.CT_Style
}
// X returns the inner wrapped XML type.
func (s Style) X() *wml.CT_Style {
return s.x
}
// Type returns the type of the style.
func (s Style) Type() wml.ST_StyleType {
return s.x.TypeAttr
}
// StyleID returns the style ID.
func (s Style) StyleID() string {
if s.x.StyleIdAttr == nil {
return ""
}
return *s.x.StyleIdAttr
}
// Name returns the name of the style if set.
func (s Style) Name() string {
if s.x.Name == nil {
return ""
}
return s.x.Name.ValAttr
}
// SetName sets the name of the style.
func (s Style) SetName(name string) {
s.x.Name = wml.NewCT_String()
s.x.Name.ValAttr = name
}
// SetPrimaryStyle marks the style as a primary style.
func (s Style) SetPrimaryStyle(b bool) {
if b {
s.x.QFormat = wml.NewCT_OnOff()
} else {
s.x.QFormat = nil
}
}
// SetUISortOrder controls the order the style is displayed in the UI.
func (s Style) SetUISortOrder(order int) {
s.x.UiPriority = wml.NewCT_DecimalNumber()
s.x.UiPriority.ValAttr = int64(order)
}
// SetSemiHidden controls if the style is hidden in the UI.
func (s Style) SetSemiHidden(b bool) {
if b {
s.x.SemiHidden = wml.NewCT_OnOff()
} else {
s.x.SemiHidden = nil
}
}
// SetUnhideWhenUsed controls if a semi hidden style becomes visible when used.
func (s Style) SetUnhideWhenUsed(b bool) {
if b {
s.x.UnhideWhenUsed = wml.NewCT_OnOff()
} else {
s.x.UnhideWhenUsed = nil
}
}
// SetBasedOn sets the style that this style is based on.
func (s Style) SetBasedOn(name string) {
if name == "" {
s.x.BasedOn = nil
} else {
s.x.BasedOn = wml.NewCT_String()
s.x.BasedOn.ValAttr = name
}
}
// SetLinkedStyle sets the style that this style is linked to.
func (s Style) SetLinkedStyle(name string) {
if name == "" {
s.x.Link = nil
} else {
s.x.Link = wml.NewCT_String()
s.x.Link.ValAttr = name
}
}
// SetNextStyle sets the style that the next paragraph will use.
func (s Style) SetNextStyle(name string) {
if name == "" {
s.x.Next = nil
} else {
s.x.Next = wml.NewCT_String()
s.x.Next.ValAttr = name
}
}
// ParagraphProperties returns the paragraph style properties.
func (s Style) ParagraphProperties() ParagraphStyleProperties {
if s.x.PPr == nil {
s.x.PPr = wml.NewCT_PPrGeneral()
}
return ParagraphStyleProperties{s.x.PPr}
}
// RunProperties returns the run style properties.
func (s Style) RunProperties() RunProperties {
if s.x.RPr == nil {
s.x.RPr = wml.NewCT_RPr()
}
return RunProperties{s.x.RPr}
}
// TableProperties returns the table style properties.
func (s Style) TableProperties() TableStyleProperties {
if s.x.TblPr == nil {
s.x.TblPr = wml.NewCT_TblPrBase()
}
return TableStyleProperties{s.x.TblPr}
}
// TableConditionalFormatting returns a conditional formatting object of a given
// type. Calling this method repeatedly will return the same object.
func (s Style) TableConditionalFormatting(typ wml.ST_TblStyleOverrideType) TableConditionalFormatting {
for _, pr := range s.x.TblStylePr {
if pr.TypeAttr == typ {
return TableConditionalFormatting{pr}
}
}
pr := wml.NewCT_TblStylePr()
pr.TypeAttr = typ
s.x.TblStylePr = append(s.x.TblStylePr, pr)
return TableConditionalFormatting{pr}
}