summaryrefslogtreecommitdiff
path: root/util.go
diff options
context:
space:
mode:
authorMarcus Downing <marcus@bang-on.net>2015-08-04 08:29:46 +0100
committerMarcus Downing <marcus@bang-on.net>2015-08-04 08:29:46 +0100
commit480d3959083ea26fed145ecf7e75361510c4e998 (patch)
tree677c7232f8704cce2fa21ceddf2b0c4efb60aaeb /util.go
parent8f46928acb094c8838f75d663b2f560dbf934773 (diff)
Templating fixes
Diffstat (limited to 'util.go')
-rw-r--r--util.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/util.go b/util.go
index ce391f5..11cb016 100644
--- a/util.go
+++ b/util.go
@@ -278,3 +278,37 @@ func (f *Fpdf) UnicodeTranslatorFromDescriptor(cpStr string) (rep func(string) s
}
return
}
+
+// Transform moves a point by given X, Y offset
+func (p *PointType) Transform(x, y float64) PointType {
+ return PointType{p.X + x, p.Y + y}
+}
+
+// Orientation returns the orientation of a given size:
+// "P" for portrait, "L" for landscape
+func (s *SizeType) Orientation() string {
+ if s == nil || s.Ht == s.Wd {
+ return ""
+ }
+ if s.Wd > s.Ht {
+ return "L"
+ }
+ return "P"
+}
+
+// ScaleBy expands a size by a certain factor
+func (s *SizeType) ScaleBy(factor float64) SizeType {
+ return SizeType{s.Wd * factor, s.Ht * factor}
+}
+
+// ScaleToWidth adjusts the height of a size to match the given width
+func (s *SizeType) ScaleToWidth(width float64) SizeType {
+ height := s.Ht * width / s.Wd
+ return SizeType{width, height}
+}
+
+// ScaleToHeight adjsuts the width of a size to match the given height
+func (s *SizeType) ScaleToHeight(height float64) SizeType {
+ width := s.Wd * height / s.Ht
+ return SizeType{width, height}
+}