diff options
author | Kurt Jung <kurt.w.jung@gmail.com> | 2015-08-12 16:16:26 -0400 |
---|---|---|
committer | Kurt Jung <kurt.w.jung@gmail.com> | 2015-08-12 16:16:26 -0400 |
commit | 64e9d36a887ca3f36dc5880153e4b062e0416ac5 (patch) | |
tree | b3e1222cdc4f7aca41b3ac39b4e2168ac77ee36e /util.go | |
parent | 798fdbd15806d1b27a36d47f394cb58b06a9af1e (diff) | |
parent | 0ab52d3f38a38a63fe1bba1a757fe4f28cd6a026 (diff) |
Merge branch 'marcusatbang-templating'
Diffstat (limited to 'util.go')
-rw-r--r-- | util.go | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -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} +} |