-
Notifications
You must be signed in to change notification settings - Fork 8
/
paragraph.go
86 lines (76 loc) · 1.82 KB
/
paragraph.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
package rtfdoc
import (
"fmt"
"strings"
)
// AddParagraph return new instance of Paragraph.
func (doc *Document) AddParagraph() *Paragraph {
p := Paragraph{
align: AlignCenter,
indent: "\\fl360",
content: nil,
generalSettings: generalSettings{
colorTable: doc.colorTable,
fontColor: doc.fontColor,
},
allowedWidth: doc.maxWidth,
}
p.updateMaxWidth()
doc.content = append(doc.content, &p)
return &p
}
func (par *Paragraph) updateMaxWidth() *Paragraph {
par.maxWidth = par.allowedWidth
return par
}
func (par Paragraph) compose() string {
var res strings.Builder
indentStr := fmt.Sprintf("\\fi%d \\li%d \\ri%d",
par.indentFirstLine,
par.indentLeftIndent,
par.indentRightIndent)
res.WriteString(fmt.Sprintf("\n\\pard \\q%s %s {", par.align, indentStr))
if par.isTable {
res.WriteString("\\intbl")
}
// res += fmt.Sprintf(" \\q%s", par.align)
for _, c := range par.content {
res.WriteString(c.compose())
}
// res += "\n\\par}"
res.WriteString("}")
if !par.isTable {
res.WriteString("\\par")
}
return res.String()
}
// SetIndentFirstLine function sets first line indent in twips.
func (par *Paragraph) SetIndentFirstLine(value int) *Paragraph {
par.indentFirstLine = value
return par
}
// SetIndentRight function sets right indent in twips.
func (par *Paragraph) SetIndentRight(value int) *Paragraph {
par.indentRightIndent = value
return par
}
// SetIndentLeft function sets left indent in twips.
func (par *Paragraph) SetIndentLeft(value int) *Paragraph {
par.indentLeftIndent = value
return par
}
// SetAlign sets Paragraph align (c/center, l/left, r/right, j/justify).
func (par *Paragraph) SetAlign(align string) *Paragraph {
for _, i := range []string{
AlignCenter,
AlignLeft,
AlignRight,
AlignJustify,
AlignDistribute,
} {
if i == align {
par.align = i
}
}
return par
}