Module: RGhost::Units

Defined in:
lib/rghost/units.rb

Overview

The postscript default unit is the 1/72th inch. RGhost uses the centimeters (cm) as it's default, mainly for positioning coordinates and numeric object sizes (if the size is a String, it won't be parsed to the default unit). This setting can be changed setting the value of RGhost::Config::GS before the document is created using any of the Units child classes.

Example:

Setting to inches.

RGhost::Config::GS=Units::Inch doc.moveto :x => 1, :y => 2 #=> 1 inch x 2 inches

Explicitly setting to Cm.

doc.moveto :x => '1 cm' , :y => '2 cm'

Using the Postscript unit

doc.moveto :x => '100' , :y => '200'

Defined Under Namespace

Classes: Cm, Inch, PSUnit, Unit

Class Method Summary collapse

Class Method Details

.parse(value) ⇒ Object

Parses units Units::DEFAULT=Utits::Cm Units.parse(2) #=> “2 cm” Units.parse(:current_row) #=> “current_row” Units.parse(“3 inch”) #=> “3 inch” Units.parse(“2”) #=> “2”

Using US metric

Units::DEFAULT=Utits::Inch
Units.parse(2)               #=> "2 inch"
Units.parse(:current_row)    #=> "current_row"
Units.parse("3 cm")          #=> "3 cm"
Units.parse("5")             #=> "5"

73
74
75
76
77
78
79
# File 'lib/rghost/units.rb', line 73

def self.parse(value)
  if value.is_a? Numeric
    RGhost::Config::GS[:unit].new(value)
  else
    RGhost::PsObject.new(value)
  end
end