Class: Prawn::Svg::Calculators::Pixels

Inherits:
Object
  • Object
show all
Extended by:
Measurements
Defined in:
lib/prawn/svg/calculators/pixels.rb

Class Method Summary collapse

Class Method Details

.to_pixels(value, axis_length) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/prawn/svg/calculators/pixels.rb', line 5

def self.to_pixels(value, axis_length)
  if value.is_a?(String)
    if match = value.match(/\d(cm|dm|ft|in|m|mm|yd)$/)
      send("#{match[1]}2pt", value.to_f)
    elsif match = value.match(/\dpc$/)
      value.to_f * 15 # according to http://www.w3.org/TR/SVG11/coords.html
    elsif value[-1..-1] == "%"
      value.to_f * axis_length / 100.0
    else
      value.to_f
    end
  elsif value
    value.to_f
  end
end