forked from johnfercher/maroto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prop.go
243 lines (204 loc) · 5.67 KB
/
prop.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
package props
import "github.com/eyesore/maroto/pkg/consts"
// Proportion represents a proportion from a rectangle, example: 16x9, 4x3...
type Proportion struct {
// Width from the rectangle: Barcode, image and etc
Width float64
// Height from the rectangle: Barcode, image and etc
Height float64
}
// Barcode represents properties from a barcode inside a cell
type Barcode struct {
// Left is the space between the left cell boundary to the barcode, if center is false
Left float64
// Top is space between the upper cell limit to the barcode, if center is false
Top float64
// Percent is how much the barcode will occupy the cell,
// ex 100%: The barcode will fulfill the entire cell
// ex 50%: The greater side from the barcode will have half the size of the cell
Percent float64
// Proportion is the proportion between size of the barcode
// Ex: 16x9, 4x3...
Proportion Proportion
// Center define that the barcode will be vertically and horizontally centralized
Center bool
}
// Rect represents properties from a rectangle (Image, QrCode or Barcode) inside a cell
type Rect struct {
// Left is the space between the left cell boundary to the rectangle, if center is false
Left float64
// Top is space between the upper cell limit to the barcode, if center is false
Top float64
// Percent is how much the rectangle will occupy the cell,
// ex 100%: The rectangle will fulfill the entire cell
// ex 50%: The greater side from the rectangle will have half the size of the cell
Percent float64
// Center define that the barcode will be vertically and horizontally centralized
Center bool
}
// Text represents properties from a Text inside a cell
type Text struct {
// Top is space between the upper cell limit to the barcode, if align is not center
Top float64
// Family of the text, ex: consts.Arial, helvetica and etc
Family consts.Family
// Style of the text, ex: consts.Normal, bold and etc
Style consts.Style
// Size of the text
Size float64
// Align of the text
Align consts.Align
// Extrapolate define if the text will automatically add a new line when
// text reach the right cell boundary
Extrapolate bool
}
// Font represents properties from a text
type Font struct {
// Family of the text, ex: consts.Arial, helvetica and etc
Family consts.Family
// Style of the text, ex: consts.Normal, bold and etc
Style consts.Style
// Size of the text
Size float64
}
// TableList represents properties from a TableList
type TableList struct {
// HeaderHeight is the height of the cell with headers
HeaderHeight float64
// HeaderProp is the custom properties of the text inside
// the headers
HeaderProp Font
// ContentHeight is the height of the cells with contents
ContentHeight float64
// ContentProp is the custom properties of the text inside
// the contents
ContentProp Font
// Align is the align of the text (header and content) inside the columns
Align consts.Align
// HeaderContentSpace is the space between the header and the contents
HeaderContentSpace float64
// Width Multipliers for columns in list, default 1
WidthMultipliers []int
// Number of col spaces made, used with width multipliers
ColSpaces int
}
// MakeValid from Rect means will make the properties from a rectangle reliable to fit inside a cell
// and define default values for a rectangle
func (r *Rect) MakeValid() {
if r.Percent <= 0.0 || r.Percent > 100.0 {
r.Percent = 100.0
}
if r.Center {
r.Left = 0
r.Top = 0
}
if r.Left < 0.0 {
r.Left = 0.0
}
if r.Top < 0.0 {
r.Top = 0
}
}
// MakeValid from Barcode means will make the properties from a barcode reliable to fit inside a cell
// and define default values for a barcode
func (r *Barcode) MakeValid() {
if r.Percent <= 0.0 || r.Percent > 100.0 {
r.Percent = 100.0
}
if r.Center {
r.Left = 0
r.Top = 0
}
if r.Left < 0.0 {
r.Left = 0.0
}
if r.Top < 0.0 {
r.Top = 0
}
if r.Proportion.Width <= 0 {
r.Proportion.Width = 1
}
if r.Proportion.Height <= 0 {
r.Proportion.Height = 1
}
if r.Proportion.Height > r.Proportion.Width*0.20 {
r.Proportion.Height = r.Proportion.Width * 0.20
} else if r.Proportion.Height < r.Proportion.Width*0.10 {
r.Proportion.Height = r.Proportion.Width * 0.10
}
}
// MakeValid from Text define default values for a Text
func (f *Text) MakeValid() {
if f.Family == "" {
f.Family = consts.Arial
}
if f.Style == "" {
f.Style = consts.Normal
}
if f.Align == "" {
f.Align = consts.Left
}
if f.Size == 0.0 {
f.Size = 10.0
}
if f.Top < 0.0 {
f.Top = 0.0
}
}
// MakeValid from Font define default values for a Signature
func (f *Font) MakeValid() {
if f.Family == "" {
f.Family = consts.Arial
}
if f.Style == "" {
f.Style = consts.Bold
}
if f.Size == 0.0 {
f.Size = 8.0
}
}
// ToTextProp from Font return a Text based on Font
func (f *Font) ToTextProp(align consts.Align, top float64) Text {
textProp := Text{
Family: f.Family,
Style: f.Style,
Size: f.Size,
Align: align,
Top: top,
}
textProp.MakeValid()
return textProp
}
// MakeValid from TableList define default values for a TableList
func (t *TableList) MakeValid() {
if t.HeaderProp.Size == 0.0 {
t.HeaderProp.Size = 10.0
}
if t.HeaderProp.Family == "" {
t.HeaderProp.Family = consts.Arial
}
if t.HeaderProp.Style == "" {
t.HeaderProp.Style = consts.Bold
}
if t.HeaderHeight == 0.0 {
t.HeaderHeight = 7.0
}
if t.Align == "" {
t.Align = consts.Left
}
if t.ContentProp.Size == 0.0 {
t.ContentProp.Size = 10.0
}
if t.ContentProp.Family == "" {
t.ContentProp.Family = consts.Arial
}
if t.ContentProp.Style == "" {
t.ContentProp.Style = consts.Normal
}
if t.ContentHeight == 0.0 {
t.ContentHeight = 5.0
}
if t.HeaderContentSpace == 0.0 {
t.HeaderContentSpace = 4.0
}
}