-
Notifications
You must be signed in to change notification settings - Fork 281
/
rect.go
52 lines (44 loc) · 1.23 KB
/
rect.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
package gopdf
// Rect defines a rectangle.
type Rect struct {
W float64
H float64
unitOverride defaultUnitConfig
}
// PointsToUnits converts the rectangles width and height to Units. When this is called it is assumed the values of the rectangle are in Points
func (rect *Rect) PointsToUnits(t int) (r *Rect) {
if rect == nil {
return
}
unitCfg := defaultUnitConfig{Unit: t}
if rect.unitOverride.getUnit() != UnitUnset {
unitCfg = rect.unitOverride
}
r = &Rect{W: rect.W, H: rect.H}
pointsToUnitsVar(unitCfg, &r.W, &r.H)
return
}
// UnitsToPoints converts the rectanlges width and height to Points. When this is called it is assumed the values of the rectangle are in Units
func (rect *Rect) UnitsToPoints(t int) (r *Rect) {
if rect == nil {
return
}
unitCfg := defaultUnitConfig{Unit: t}
if rect.unitOverride.getUnit() != UnitUnset {
unitCfg = rect.unitOverride
}
r = &Rect{W: rect.W, H: rect.H}
unitsToPointsVar(unitCfg, &r.W, &r.H)
return
}
func (rect *Rect) unitsToPoints(unitCfg unitConfigurator) (r *Rect) {
if rect == nil {
return
}
if rect.unitOverride.getUnit() != UnitUnset {
unitCfg = rect.unitOverride
}
r = &Rect{W: rect.W, H: rect.H}
unitsToPointsVar(unitCfg, &r.W, &r.H)
return
}