forked from unidoc/unioffice
/
tableborders.go
85 lines (73 loc) · 3.06 KB
/
tableborders.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
// 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 (
"github.com/Preciselyco/unioffice"
"github.com/Preciselyco/unioffice/color"
"github.com/Preciselyco/unioffice/measurement"
"github.com/Preciselyco/unioffice/schema/soo/wml"
)
// TableBorders allows manipulation of borders on a table.
type TableBorders struct {
x *wml.CT_TblBorders
}
// X returns the inner wml.CT_TblBorders
func (b TableBorders) X() *wml.CT_TblBorders {
return b.x
}
func setBorder(brd *wml.CT_Border, t wml.ST_Border, c color.Color, thickness measurement.Distance) {
brd.ValAttr = t
brd.ColorAttr = &wml.ST_HexColor{}
if c.IsAuto() {
brd.ColorAttr.ST_HexColorAuto = wml.ST_HexColorAutoAuto
} else {
brd.ColorAttr.ST_HexColorRGB = c.AsRGBString()
}
if thickness != measurement.Zero {
// sz here is in 1/8'th points, the range is 0.25 to 12 pts
brd.SzAttr = unioffice.Uint64(uint64(thickness / measurement.Point * 8))
}
}
// SetAll sets all of the borders to a given value.
func (b TableBorders) SetAll(t wml.ST_Border, c color.Color, thickness measurement.Distance) {
b.SetBottom(t, c, thickness)
b.SetLeft(t, c, thickness)
b.SetRight(t, c, thickness)
b.SetTop(t, c, thickness)
b.SetInsideHorizontal(t, c, thickness)
b.SetInsideVertical(t, c, thickness)
}
// SetBottom sets the bottom border to a specified type, color and thickness.
func (b TableBorders) SetBottom(t wml.ST_Border, c color.Color, thickness measurement.Distance) {
b.x.Bottom = wml.NewCT_Border()
setBorder(b.x.Bottom, t, c, thickness)
}
// SetTop sets the top border to a specified type, color and thickness.
func (b TableBorders) SetTop(t wml.ST_Border, c color.Color, thickness measurement.Distance) {
b.x.Top = wml.NewCT_Border()
setBorder(b.x.Top, t, c, thickness)
}
// SetLeft sets the left border to a specified type, color and thickness.
func (b TableBorders) SetLeft(t wml.ST_Border, c color.Color, thickness measurement.Distance) {
b.x.Left = wml.NewCT_Border()
setBorder(b.x.Left, t, c, thickness)
}
// SetRight sets the right border to a specified type, color and thickness.
func (b TableBorders) SetRight(t wml.ST_Border, c color.Color, thickness measurement.Distance) {
b.x.Right = wml.NewCT_Border()
setBorder(b.x.Right, t, c, thickness)
}
// SetInsideHorizontal sets the interior horizontal borders to a specified type, color and thickness.
func (b TableBorders) SetInsideHorizontal(t wml.ST_Border, c color.Color, thickness measurement.Distance) {
b.x.InsideH = wml.NewCT_Border()
setBorder(b.x.InsideH, t, c, thickness)
}
// SetInsideVertical sets the interior vertical borders to a specified type, color and thickness.
func (b TableBorders) SetInsideVertical(t wml.ST_Border, c color.Color, thickness measurement.Distance) {
b.x.InsideV = wml.NewCT_Border()
setBorder(b.x.InsideV, t, c, thickness)
}