forked from johnfercher/maroto
-
Notifications
You must be signed in to change notification settings - Fork 1
/
font.go
84 lines (69 loc) · 1.88 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package internal
import (
"github.com/johnfercher/maroto/pkg/consts"
"github.com/jung-kurt/gofpdf"
)
// Font is the abstraction which deals of how to set font configurations
type Font interface {
SetFamily(family consts.Family)
SetStyle(style consts.Style)
SetSize(size float64)
SetFont(family consts.Family, style consts.Style, size float64)
GetFamily() consts.Family
GetStyle() consts.Style
GetSize() float64
GetFont() (consts.Family, consts.Style, float64)
}
type font struct {
pdf gofpdf.Pdf
size float64
family consts.Family
style consts.Style
}
// NewFont create a Font
func NewFont(pdf gofpdf.Pdf, size float64, family consts.Family, style consts.Style) *font {
return &font{
pdf,
size,
family,
style,
}
}
// GetFamily return the currently Font family configured
func (s *font) GetFamily() consts.Family {
return s.family
}
// GetStyle return the currently Font style configured
func (s *font) GetStyle() consts.Style {
return s.style
}
// GetSize return the currently Font size configured
func (s *font) GetSize() float64 {
return s.size
}
// GetFont return all the currently Font properties configured
func (s *font) GetFont() (consts.Family, consts.Style, float64) {
return s.family, s.style, s.size
}
// SetFamily defines a new Font family
func (s *font) SetFamily(family consts.Family) {
s.family = family
s.pdf.SetFont(string(s.family), string(s.style), s.size)
}
// SetStyle defines a new Font style
func (s *font) SetStyle(style consts.Style) {
s.style = style
s.pdf.SetFontStyle(string(s.style))
}
// SetSize defines a new Font size
func (s *font) SetSize(size float64) {
s.size = size
s.pdf.SetFontSize(s.size)
}
// SetFont defines all new Font properties
func (s *font) SetFont(family consts.Family, style consts.Style, size float64) {
s.family = family
s.style = style
s.size = size
s.pdf.SetFont(string(s.family), string(s.style), s.size)
}