forked from 36150592/unioffice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
font.go
62 lines (53 loc) · 1.33 KB
/
font.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
// 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 spreadsheet
import (
"baliance.com/gooxml/color"
"baliance.com/gooxml/schema/soo/sml"
)
// Font allows editing fonts within a spreadsheet stylesheet.
type Font struct {
font *sml.CT_Font
styles *sml.StyleSheet
}
// X returns the inner wrapped XML type.
func (f Font) X() *sml.CT_Font {
return f.font
}
func (f Font) Index() uint32 {
for i, sf := range f.styles.Fonts.Font {
if f.font == sf {
return uint32(i)
}
}
return 0
}
func (f Font) SetBold(b bool) {
if b {
f.font.B = []*sml.CT_BooleanProperty{{}}
} else {
f.font.B = nil
}
}
func (f Font) SetItalic(b bool) {
if b {
f.font.I = []*sml.CT_BooleanProperty{{}}
} else {
f.font.I = nil
}
}
func (f Font) SetName(name string) {
f.font.Name = []*sml.CT_FontName{{ValAttr: name}}
}
func (f Font) SetSize(size float64) {
f.font.Sz = []*sml.CT_FontSize{{ValAttr: size}}
}
func (f Font) SetColor(c color.Color) {
clr := sml.NewCT_Color()
clr.RgbAttr = c.AsRGBString()
f.font.Color = []*sml.CT_Color{clr}
}