forked from raykov/mdtopdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
document_style.go
41 lines (34 loc) · 1.04 KB
/
document_style.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
package document
func (d *Document) WithStyle(opts ...func(style any) error) {
newStyle := d.styles.Current().Clone()
for _, opt := range opts {
_ = opt(newStyle)
}
d.withStyle(newStyle)
}
// ResetStyle resets to previous style in PDF
func (d *Document) ResetStyle() {
_ = d.styles.Pop()
d.setStyle(d.styles.Current())
}
func (d *Document) withStyle(s *Style) {
if s.LeftMargin == 0 {
s.LeftMargin, _, _, _ = d.PDF.GetMargins()
s.CellMargin = s.LeftMargin / 10
}
d.styles.Add(s)
d.setStyle(s)
}
// setStyle sets style configs in PDF
func (d *Document) setStyle(s *Style) {
d.PDF.SetFont(s.FontFamily, s.FontStyle, s.FontSize)
d.PDF.SetTextColor(s.TextColor.R, s.TextColor.G, s.TextColor.B)
d.PDF.SetFillColor(s.FillColor.R, s.FillColor.G, s.FillColor.B)
d.PDF.SetDrawColor(1, 1, 1)
d.PDF.SetLeftMargin(s.LeftMargin)
d.PDF.SetCellMargin(s.CellMargin)
//d.PDF.SetLineCapStyle("round")
//d.PDF.SetTextRenderingMode(1)
//d.PDF.CellFormat(1000, 20, "lipsum", "1", 0, "", true, 0, "")
//d.PDF.MultiCell(1000, 15, "txtStr", "1", "", true)
}