Class: Prawn::SVG::Calculators::Pixels::Measurement

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 = nil, font_size: Prawn::SVG::Properties::EM) ⇒ Object



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

def self.to_pixels(value, axis_length = nil, font_size: Prawn::SVG::Properties::EM)
  if value.is_a?(String)
    if (match = value.match(/\d(em|ex|pc|cm|mm|in)$/))
      case match[1]
      when 'em'
        value.to_f * font_size
      when 'ex'
        value.to_f * (font_size / 2.0) # we don't have access to the x-height, so this is an approximation approved by the CSS spec
      when 'pc'
        value.to_f * 15 # according to http://www.w3.org/TR/SVG11/coords.html
      else
        send("#{match[1]}2pt", value.to_f)
      end
    elsif value[-1..] == '%'
      value.to_f * axis_length / 100.0
    else
      value.to_f
    end
  elsif value
    value.to_f
  end
end