forked from tiechui1994/gopdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hr.go
67 lines (56 loc) · 1.09 KB
/
hr.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
package gopdf
import (
"github.com/tiechui1994/gopdf/core"
)
type HLine struct {
pdf *core.Report
color float64
width float64
margin core.Scope
}
func NewHLine(pdf *core.Report) *HLine {
return &HLine{
pdf: pdf,
color: 0,
width: 0.1,
margin: core.Scope{
Left: 0,
Right: 0,
Top: 0.3,
Bottom: 0.3,
},
}
}
func (h *HLine) SetColor(color float64) *HLine {
if color < 0 || color > 1.0 {
color = 0
}
h.color = color
return h
}
func (h *HLine) SetMargin(margin core.Scope) *HLine {
h.margin = margin
return h
}
func (h *HLine) SetWidth(width float64) *HLine {
h.width = width
return h
}
func (h *HLine) GenerateAtomicCell() {
var (
sx, sy = h.pdf.GetXY()
)
x := sx + h.margin.Left
y := sy + h.margin.Top
_, endY := h.pdf.GetPageEndXY()
if (sy >= endY || sy < endY) && sy+h.width > endY {
h.pdf.AddNewPage(false)
h.pdf.SetXY(h.pdf.GetPageStartXY())
h.GenerateAtomicCell()
return
}
cw, _ := h.pdf.GetContentWidthAndHeight()
h.pdf.LineGrayColor(x, y, cw, h.width, h.color)
x, _ = h.pdf.GetPageStartXY()
h.pdf.SetXY(x, y+h.margin.Bottom+h.width)
}