forked from unidoc/unioffice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumbering.go
128 lines (107 loc) · 3.52 KB
/
numbering.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
// Copyright 2017 FoxyUtils ehf. All rights reserved.
//
// Use of this software package and source code is governed by the terms of the
// UniDoc End User License Agreement (EULA) that is available at:
// https://unidoc.io/eula/
// A trial license code for evaluation can be obtained at https://unidoc.io.
package document
import (
"github.com/unidoc/unioffice"
"github.com/unidoc/unioffice/schema/soo/ofc/sharedTypes"
"github.com/unidoc/unioffice/schema/soo/wml"
)
// Numbering is the document wide numbering styles contained in numbering.xml.
type Numbering struct {
x *wml.Numbering
}
// NewNumbering constructs a new numbering.
func NewNumbering() Numbering {
n := wml.NewNumbering()
return Numbering{n}
}
// X returns the inner wrapped XML type.
func (n Numbering) X() *wml.Numbering {
return n.x
}
// Clear resets the numbering.
func (n Numbering) Clear() {
n.x.AbstractNum = nil
n.x.Num = nil
n.x.NumIdMacAtCleanup = nil
n.x.NumPicBullet = nil
}
// InitializeDefault constructs a default numbering.
func (n Numbering) InitializeDefault() {
abs := wml.NewCT_AbstractNum()
abs.MultiLevelType = wml.NewCT_MultiLevelType()
abs.MultiLevelType.ValAttr = wml.ST_MultiLevelTypeHybridMultilevel
n.x.AbstractNum = append(n.x.AbstractNum, abs)
abs.AbstractNumIdAttr = 1
const indentStart = 720
const indentDelta = 720
const hangingIndent = 360
for i := 0; i < 9; i++ {
lvl := wml.NewCT_Lvl()
lvl.IlvlAttr = int64(i)
lvl.Start = wml.NewCT_DecimalNumber()
lvl.Start.ValAttr = 1
lvl.NumFmt = wml.NewCT_NumFmt()
lvl.NumFmt.ValAttr = wml.ST_NumberFormatBullet
lvl.Suff = wml.NewCT_LevelSuffix()
lvl.Suff.ValAttr = wml.ST_LevelSuffixNothing
lvl.LvlText = wml.NewCT_LevelText()
lvl.LvlText.ValAttr = unioffice.String("")
lvl.LvlJc = wml.NewCT_Jc()
lvl.LvlJc.ValAttr = wml.ST_JcLeft
lvl.RPr = wml.NewCT_RPr()
lvl.RPr.RFonts = wml.NewCT_Fonts()
lvl.RPr.RFonts.AsciiAttr = unioffice.String("Symbol")
lvl.RPr.RFonts.HAnsiAttr = unioffice.String("Symbol")
lvl.RPr.RFonts.HintAttr = wml.ST_HintDefault
lvl.PPr = wml.NewCT_PPrGeneral()
indent := int64(i*indentDelta + indentStart)
lvl.PPr.Ind = wml.NewCT_Ind()
lvl.PPr.Ind.LeftAttr = &wml.ST_SignedTwipsMeasure{}
lvl.PPr.Ind.LeftAttr.Int64 = unioffice.Int64(indent)
lvl.PPr.Ind.HangingAttr = &sharedTypes.ST_TwipsMeasure{}
lvl.PPr.Ind.HangingAttr.ST_UnsignedDecimalNumber = unioffice.Uint64(uint64(hangingIndent))
abs.Lvl = append(abs.Lvl, lvl)
}
num := wml.NewCT_Num()
num.NumIdAttr = 1
num.AbstractNumId = wml.NewCT_DecimalNumber()
num.AbstractNumId.ValAttr = 1
n.x.Num = append(n.x.Num, num)
}
// Definitions returns the defined numbering definitions.
func (n Numbering) Definitions() []NumberingDefinition {
ret := []NumberingDefinition{}
for _, n := range n.x.AbstractNum {
ret = append(ret, NumberingDefinition{n})
}
return ret
}
// AddDefinition adds a new numbering definition.
func (n Numbering) AddDefinition() NumberingDefinition {
nx := wml.NewCT_Num()
nextAbstractNumID := int64(1)
for _, nd := range n.Definitions() {
if nd.AbstractNumberID() >= nextAbstractNumID {
nextAbstractNumID = nd.AbstractNumberID() + 1
}
}
nextNumID := int64(1)
for _, n := range n.X().Num {
if n.NumIdAttr >= nextNumID {
nextNumID = n.NumIdAttr + 1
}
}
nx.NumIdAttr = nextNumID
nx.AbstractNumId = wml.NewCT_DecimalNumber()
nx.AbstractNumId.ValAttr = nextAbstractNumID
an := wml.NewCT_AbstractNum()
an.AbstractNumIdAttr = nextAbstractNumID
n.x.AbstractNum = append(n.x.AbstractNum, an)
n.x.Num = append(n.x.Num, nx)
return NumberingDefinition{an}
}