Module: Magick::RVG::Stretchable

Includes:
PreserveAspectRatio
Included in:
Magick::RVG, Pattern
Defined in:
lib/rvg/stretchable.rb

Overview

The methods in this module describe the user-coordinate space. RVG and Pattern objects are stretchable.

Instance Method Summary collapse

Methods included from PreserveAspectRatio

#preserve_aspect_ratio

Instance Method Details

#viewbox(x, y, width, height) {|_self| ... } ⇒ Object

Describe a user coordinate system to be imposed on the viewbox. The arguments must be numbers and the width and height arguments must be positive.

Yields:

  • (_self)

Yield Parameters:

Raises:

  • (ArgumentError)


131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/rvg/stretchable.rb', line 131

def viewbox(x, y, width, height)
  begin
    @vbx_x = Float(x)
    @vbx_y = Float(y)
    @vbx_width = Float(width)
    @vbx_height = Float(height)
  rescue ArgumentError
    raise ArgumentError, "arguments must be convertable to float (got #{x.class}, #{y.class}, #{width.class}, #{height.class})"
  end
  raise(ArgumentError, "viewbox width must be > 0 (#{@vbx_width} given)") unless @vbx_width >= 0
  raise(ArgumentError, "viewbox height must be > 0 (#{@vbx_height} given)") unless @vbx_height >= 0

  # return the user-coordinate space attributes if defined
  class << self
    unless defined? @redefined
      @redefined = true
      define_method(:x) { @vbx_x }
      define_method(:y) { @vbx_y }
      define_method(:width) { @vbx_width }
      define_method(:height) { @vbx_height }
    end
  end

  yield(self) if block_given?
  self
end