/
html.go
278 lines (251 loc) · 6.04 KB
/
html.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
package input
import (
"github.com/dynamicpdf-api/go-client/resource"
"github.com/google/uuid"
)
// Represents a HTML input.
type Html struct {
Input
smaller float32
larger float32
}
var _ InputCollector = (*Html)(nil)
/*
Initializes a new instance of the `HTMLInput` class.
- @param { string} input The html embeded as a string.
*/
func NewHtmlInputWithString(inputString string) *Html {
var p Html
var ep resource.HtmlResource
var name = uuid.NewString()
resourceData := []byte(inputString)
ep = resource.HtmlResource{Resource: *resource.NewResourceWithByteValue(resourceData, name)}
p.resources = append(p.resources, ep.Resource)
p.inputType = p.InputType()
p.getPaperSize(Letter)
p.SetPageHeight(p.larger)
p.SetPageWidth(p.smaller)
p.ResourceName = ep.ResourceName
return &p
}
/*
Initializes a new instance of the `HTMLInput` class.
- @param { string} input The html embeded as a string.
*/
func NewHtmlInputWithResource(resource resource.HtmlResource) *Html {
var p Html
p.resources = append(p.resources, resource.Resource)
p.SetId(uuid.NewString())
p.inputType = p.InputType()
p.getPaperSize(Letter)
p.SetPageHeight(p.larger)
p.SetPageWidth(p.smaller)
p.ResourceName = resource.ResourceName
return &p
}
func (p *Html) Resources() []resource.Resource {
return p.resources
}
func (p *Html) InputType() InputType {
return HtmlInput
}
// Gets the pageWidth.
func (p *Html) PageWidth() float32 {
return p.pageWidth
}
// sets the pageWidth.
func (p *Html) SetPageWidth(value float32) {
p.pageWidth = value
}
// Gets the PageHeight.
func (p *Html) PageHeight() float32 {
return p.pageHeight
}
// sets the PageHeight.
func (p *Html) SetPageHeight(value float32) {
p.pageHeight = value
}
// Gets the BasePath.
func (p *Html) BasePath() string {
return p.basePath
}
// sets the BasePath.
func (p *Html) SetBasePath(value string) {
p.basePath = value
}
// Gets the TopMargin.
func (p *Html) TopMargin() float32 {
return p.topMargin
}
// sets the TopMargin.
func (p *Html) SetTopMargin(value float32) {
p.topMargin = value
}
// Gets the BottomMargin.
func (p *Html) BottomMargin() float32 {
return p.bottomMargin
}
// sets the BottomMargin.
func (p *Html) SetBottomMargin(value float32) {
p.bottomMargin = value
}
// Gets the LeftMargin.
func (p *Html) LeftMargin() float32 {
return p.leftMargin
}
// sets the LeftMargin.
func (p *Html) SetLeftMargin(value float32) {
p.leftMargin = value
}
// Gets the RightMargin.
func (p *Html) RightMargin() float32 {
return p.rightMargin
}
// sets the RightMargin.
func (p *Html) SetRightMargin(value float32) {
p.rightMargin = value
}
// Gets the PageSize.
func (p *Html) PageSize() PageSize {
return p.pageSize
}
// sets the PageSize.
func (p *Html) SetPageSize(value PageSize) {
p.pageSize = value
p.getPaperSize(value)
if p.pageOrientation == Landscape {
p.applyOrientation(Landscape)
}
p.pageHeight = p.larger
p.pageWidth = p.smaller
}
// Gets the PageOrientation.
func (p *Html) PageOrientation() Orientation {
return p.pageOrientation
}
// sets the PageOrientation.
func (p *Html) SetPageOrientation(value Orientation) {
p.pageOrientation = value
if p.pageOrientation == Landscape {
p.applyOrientation(Landscape)
}
p.pageHeight = p.larger
p.pageWidth = p.smaller
}
func (p *Html) applyOrientation(value Orientation) {
if value == Landscape {
var temp = p.smaller
p.smaller = p.larger
p.larger = temp
}
}
func (p *Html) getPaperSize(size PageSize) {
switch size {
case Letter:
p.smaller = p.InchesToPoints(8.5)
p.larger = p.InchesToPoints(11)
break
case Legal:
p.smaller = p.InchesToPoints(8.5)
p.larger = p.InchesToPoints(14)
break
case Executive:
p.smaller = p.InchesToPoints(7.25)
p.larger = p.InchesToPoints(10.5)
break
case Tabloid:
p.smaller = p.InchesToPoints(11)
p.larger = p.InchesToPoints(17)
break
case Envelope10:
p.smaller = p.InchesToPoints(4.125)
p.larger = p.InchesToPoints(9.5)
break
case EnvelopeMonarch:
p.smaller = p.InchesToPoints(3.875)
p.larger = p.InchesToPoints(7.5)
break
case Folio:
p.smaller = p.InchesToPoints(8.5)
p.larger = p.InchesToPoints(13)
break
case Statement:
p.smaller = p.InchesToPoints(5.5)
p.larger = p.InchesToPoints(8.5)
break
case A4:
p.smaller = p.MillimetersToPoints(210)
p.larger = p.MillimetersToPoints(297)
break
case A5:
p.smaller = p.MillimetersToPoints(148)
p.larger = p.MillimetersToPoints(210)
break
case B4:
p.smaller = p.MillimetersToPoints(250)
p.larger = p.MillimetersToPoints(353)
break
case B5:
p.smaller = p.MillimetersToPoints(176)
p.larger = p.MillimetersToPoints(250)
break
case A3:
p.smaller = p.MillimetersToPoints(297)
p.larger = p.MillimetersToPoints(420)
break
case B3:
p.smaller = p.MillimetersToPoints(353)
p.larger = p.MillimetersToPoints(500)
break
case A6:
p.smaller = p.MillimetersToPoints(105)
p.larger = p.MillimetersToPoints(148)
break
case B5JIS:
p.smaller = p.MillimetersToPoints(182)
p.larger = p.MillimetersToPoints(257)
break
case EnvelopeDL:
p.smaller = p.MillimetersToPoints(110)
p.larger = p.MillimetersToPoints(220)
break
case EnvelopeC5:
p.smaller = p.MillimetersToPoints(162)
p.larger = p.MillimetersToPoints(229)
break
case EnvelopeB5:
p.smaller = p.MillimetersToPoints(176)
p.larger = p.MillimetersToPoints(250)
break
case PRC16K:
p.smaller = p.MillimetersToPoints(146)
p.larger = p.MillimetersToPoints(215)
break
case PRC32K:
p.smaller = p.MillimetersToPoints(97)
p.larger = p.MillimetersToPoints(151)
break
case Quatro:
p.smaller = p.MillimetersToPoints(215)
p.larger = p.MillimetersToPoints(275)
break
case DoublePostcard:
p.smaller = p.MillimetersToPoints(148.0)
p.larger = p.MillimetersToPoints(200.0)
break
case Postcard:
p.smaller = p.InchesToPoints(3.94)
p.larger = p.InchesToPoints(5.83)
break
default:
p.smaller = p.InchesToPoints(8.5)
p.larger = p.InchesToPoints(11)
break
}
}
func (p *Html) InchesToPoints(size float32) float32 {
return size * 72.0
}
func (p *Html) MillimetersToPoints(size float32) float32 {
return size * 2.8346456692913385826771653543307
}