class Prawn::SVG::Elements::Rect

Public Instance Methods

apply() click to toggle source
# File lib/prawn/svg/elements/rect.rb, line 21
def apply
  if @radius
    # n.b. does not support both rx and ry being specified with different values
    add_call "rounded_rectangle", [@x, @y], @width, @height, @radius
  else
    add_call "rectangle", [@x, @y], @width, @height
  end
end
bounding_box() click to toggle source
# File lib/prawn/svg/elements/rect.rb, line 30
def bounding_box
  [@x, @y, @x + @width, @y - @height]
end
parse() click to toggle source
# File lib/prawn/svg/elements/rect.rb, line 2
def parse
  require_attributes 'width', 'height'

  @x = x(attributes['x'] || '0')
  @y = y(attributes['y'] || '0')
  @width = x_pixels(attributes['width'])
  @height = y_pixels(attributes['height'])

  require_positive_value @width, @height

  @radius = x_pixels(attributes['rx']) || y_pixels(attributes['ry'])
  if @radius
    # If you implement separate rx and ry in the future, you'll want to change this
    # so that rx is constrained to @width/2 and ry is constrained to @height/2.
    max_value = [@width, @height].min / 2.0
    @radius = clamp(@radius, 0, max_value)
  end
end