Class | Magick::Geometry |
In: |
lib/RMagick.rb
|
Parent: | Object |
FLAGS | = | ['', '%', '!', '<', '>', '@'] | ||
RFLAGS | = | { '%' => PercentGeometry, '!' => AspectGeometry, '<' => LessGeometry, '>' => GreaterGeometry, '@' => AreaGeometry } | ||
RE | = | /\A(\d*)(?:x(\d+))?([-+]\d+)?([-+]\d+)?([%!<>@]?)\Z/ | Construct an object from a geometry string |
flag | [RW] | |
height | [RW] | |
width | [RW] | |
x | [RW] | |
y | [RW] |
# File lib/RMagick.rb, line 75 75: def Geometry.from_s(str) 76: Kernel.raise(ArgumentError, "no geometry string specified") unless str 77: 78: m = RE.match(str) 79: if m 80: width = m[1].to_i 81: height = m[2].to_i 82: x = m[3].to_i 83: y = m[4].to_i 84: flag = RFLAGS[m[5]] 85: else 86: Kernel.raise ArgumentError, "invalid geometry format" 87: end 88: Geometry.new(width, height, x, y, flag) 89: end
# File lib/RMagick.rb, line 48 48: def initialize(width=nil, height=nil, x=nil, y=nil, flag=nil) 49: 50: # Support floating-point width and height arguments so Geometry 51: # objects can be used to specify Image#density= arguments. 52: if width == nil 53: @width = 0 54: elsif width.to_f >= 0.0 55: @width = width.to_f 56: else 57: Kernel.raise ArgumentError, "width must be >= 0: #{width}" 58: end 59: if height == nil 60: @height = 0 61: elsif height.to_f >= 0.0 62: @height = height.to_f 63: else 64: Kernel.raise ArgumentError, "height must be >= 0: #{height}" 65: end 66: 67: @x = x.to_i 68: @y = y.to_i 69: @flag = flag 70: end
Convert object to a geometry string
# File lib/RMagick.rb, line 92 92: def to_s 93: str = '' 94: str << sprintf("%g", @width) if @width > 0 95: str << 'x' if (@width > 0 || @height > 0) 96: str << sprintf("%g", @height) if @height > 0 97: str << sprintf("%+d%+d", @x, @y) if (@x != 0 || @y != 0) 98: str << FLAGS[@flag.to_i] 99: end