forked from signintech/gopdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
78 lines (70 loc) · 1.97 KB
/
config.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
package gopdf
// The units that can be used in the document
const (
Unit_Unset = iota // No units were set, when conversion is called on nothing will happen
Unit_PT // Points
Unit_MM // Millimeters
Unit_CM // centimeters
Unit_IN // inches
// The math needed to convert units to points
conversion_Unit_PT = 1.0
conversion_Unit_MM = 72.0 / 25.4
conversion_Unit_CM = 72.0 / 2.54
conversion_Unit_IN = 72.0
)
//Config static config
type Config struct {
Unit int // The unit type to use when composing the document.
PageSize Rect // The default page size for all pages in the document
K float64 // Not sure
Protection PDFProtectionConfig // Protection settings
}
//PDFProtectionConfig config of pdf protection
type PDFProtectionConfig struct {
UseProtection bool
Permissions int
UserPass []byte
OwnerPass []byte
}
// UnitsToPoints converts units of the provided type to points
func UnitsToPoints(t int, u float64) float64 {
switch t {
case Unit_PT:
return u * conversion_Unit_PT
case Unit_MM:
return u * conversion_Unit_MM
case Unit_CM:
return u * conversion_Unit_CM
case Unit_IN:
return u * conversion_Unit_IN
default:
return u
}
}
// PointsToUnits converts points to the provided units
func PointsToUnits(t int, u float64) float64 {
switch t {
case Unit_PT:
return u / conversion_Unit_PT
case Unit_MM:
return u / conversion_Unit_MM
case Unit_CM:
return u / conversion_Unit_CM
case Unit_IN:
return u / conversion_Unit_IN
default:
return u
}
}
// UnitsToPointsVar converts units of the provided type to points for all variables supplied
func UnitsToPointsVar(t int, u ...*float64) {
for x := 0; x < len(u); x++ {
*u[x] = UnitsToPoints(t, *u[x])
}
}
// PointsToUnitsVar converts points to the provided units for all variables supplied
func PointsToUnitsVar(t int, u ...*float64) {
for x := 0; x < len(u); x++ {
*u[x] = PointsToUnits(t, *u[x])
}
}