-
Notifications
You must be signed in to change notification settings - Fork 0
/
Textspan.go
89 lines (78 loc) · 3.73 KB
/
Textspan.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
package odf
import (
//"fmt"
"math/rand"
"strconv"
"strings"
"github.com/LIJUCHACKO/XmlDB"
)
type TextSpan struct {
NodeId int
StyleId int
Note *Notes
}
const (
BOLD = iota // BOLD = 0
ITALIC // ITALIC = 1
UNDERLINE // uNDERLINE = 2
)
var randnoTex int=0
func (Note1 *Notes) NewTextSpan(text string, Style string) *TextSpan {
var Text *TextSpan = new(TextSpan)
Text.Note = Note1
Style_name := "TS" + strconv.Itoa(rand.Intn(100)+randnoTex)
randnoTex=randnoTex+1;
if len(strings.TrimSpace(Style)) > 0 {
Style_name = strings.TrimSpace(Style)
}
//office_Text
Text.NodeId = Note1.WritetoScratchpad("<text:span text:style-name=\"" + Style_name + "\"></text:span>")
xmlDB.UpdateNodevalue(Note1.Content, Text.NodeId, text)
if len(strings.TrimSpace(Style)) == 0 {
//office_style
styletext := `<styles><office:automatic-styles>
<style:style style:name="` + Style_name + `" style:family="text">
<style:text-properties/>
</style:style>
</office:automatic-styles></styles>`
id := Note1.WritetoScratchpad(styletext)
Note1.IncludeStyle(id)
}
StyleNodeid, _ := xmlDB.GetNode(Note1.Content, Note1.Officeautostyleid, "style:style[style:name=\""+Style_name+"\"]")
Text.StyleId = StyleNodeid[0]
return Text
}
func (Text *TextSpan) Style() string {
Style_name := xmlDB.GetNodeAttribute(Text.Note.Content, Text.StyleId, "style:name")
return Style_name
}
func (Text *TextSpan) ToBold() {
styletextproperty, _ := xmlDB.GetNode(Text.Note.Content, Text.StyleId, "style:text-properties")
xmlDB.UpdateAttributevalue(Text.Note.Content, styletextproperty[0], "fo:font-weight", "bold")
xmlDB.UpdateAttributevalue(Text.Note.Content, styletextproperty[0], "style:font-weight-asian", "bold")
xmlDB.UpdateAttributevalue(Text.Note.Content, styletextproperty[0], "style:font-weight-complex", "bold")
}
func (Text *TextSpan) ToItalic() {
styletextproperty, _ := xmlDB.GetNode(Text.Note.Content, Text.StyleId, "style:text-properties")
xmlDB.UpdateAttributevalue(Text.Note.Content, styletextproperty[0], "fo:font-style", "italic")
xmlDB.UpdateAttributevalue(Text.Note.Content, styletextproperty[0], "style:font-style-asian", "italic")
xmlDB.UpdateAttributevalue(Text.Note.Content, styletextproperty[0], "style:font-style-complex", "italic")
}
func (Text *TextSpan) ToUnderLine() {
styletextproperty, _ := xmlDB.GetNode(Text.Note.Content, Text.StyleId, "style:text-properties")
xmlDB.UpdateAttributevalue(Text.Note.Content, styletextproperty[0], "style:text-underline-style", "solid")
xmlDB.UpdateAttributevalue(Text.Note.Content, styletextproperty[0], "style:text-underline-width", "auto")
xmlDB.UpdateAttributevalue(Text.Note.Content, styletextproperty[0], "style:text-underline-color", "font-color")
}
func (Text *TextSpan) ToNormal() {
styletextproperty, _ := xmlDB.GetNode(Text.Note.Content, Text.StyleId, "style:text-properties")
xmlDB.UpdateAttributevalue(Text.Note.Content, styletextproperty[0], "fo:font-weight", "normal")
xmlDB.UpdateAttributevalue(Text.Note.Content, styletextproperty[0], "style:font-weight-asian", "normal")
xmlDB.UpdateAttributevalue(Text.Note.Content, styletextproperty[0], "style:font-weight-complex", "normal")
xmlDB.UpdateAttributevalue(Text.Note.Content, styletextproperty[0], "style:text-underline-style", "")
xmlDB.UpdateAttributevalue(Text.Note.Content, styletextproperty[0], "style:text-underline-width", "")
xmlDB.UpdateAttributevalue(Text.Note.Content, styletextproperty[0], "style:text-underline-color", "")
xmlDB.UpdateAttributevalue(Text.Note.Content, styletextproperty[0], "fo:font-style", "")
xmlDB.UpdateAttributevalue(Text.Note.Content, styletextproperty[0], "style:font-style-asian", "")
xmlDB.UpdateAttributevalue(Text.Note.Content, styletextproperty[0], "style:font-style-complex", "")
}