File: measurements.rb

package info (click to toggle)
ruby-prawn 1.0.0~rc1%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,248 kB
  • sloc: ruby: 17,499; sh: 44; makefile: 17
file content (71 lines) | stat: -rw-r--r-- 1,333 bytes parent folder | download
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
# encoding: utf-8
# measurements.rb: Conversions from other measurements to PDF points
#
# Copyright December 2008, Florian Witteler.  All Rights Reserved.
#
module Prawn  
  module Measurements
  
    # ============================================================================
    #metric conversions
    def cm2mm(cm)
      return cm*10
    end
  
    def dm2mm(dm)
      return dm*100  
    end
  
    def m2mm(m)
      return m*1000
    end
  
    # ============================================================================
    # imperial conversions    
    # from http://en.wikipedia.org/wiki/Imperial_units
  
    def ft2in(ft)
      return ft * 12
    end  

    def yd2in(yd)
      return yd*36
    end

  
    # ============================================================================
    # PostscriptPoint-converisons
  
    def in2pt(inch)
      return inch * 72    
    end
  
    def ft2pt(ft)
      return in2pt(ft2in(ft))
    end
  
    def yd2pt(yd)
      return in2pt(yd2in(yd))
    end
  
    def mm2pt(mm)
        return mm*(72 / 25.4)
    end
  
    def cm2pt(cm)
      return mm2pt(cm2mm(cm))
    end
  
    def dm2pt(dm)
      return mm2pt(dm2mm(dm))
    end
  
    def m2pt(m)
      return mm2pt(m2mm(m))
    end
  
    def pt2mm(pt)    
      return pt * 1 / mm2pt(1)# (25.4 / 72)
    end
  end
end