Method: PDF::Wrapper#rounded_rectangle

Defined in:
lib/pdf/wrapper.rb

#rounded_rectangle(x, y, w, h, r, opts = {}) ⇒ Object

draw a rounded rectangle starting at x,y with w,h dimensions. Parameters:

:x

The x co-ordinate of the top left of the rectangle.

:y

The y co-ordinate of the top left of the rectangle.

:w

The width of the rectangle

:h

The height of the rectangle

:r

The size of the rounded corners

Options:

:color

The colour of the rectangle outline

:fill_color

The colour to fill the rectangle with. Defaults to nil (no fill)

Raises:

  • (ArgumentError)


485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
# File 'lib/pdf/wrapper.rb', line 485

def rounded_rectangle(x, y, w, h, r, opts = {})
  # TODO: raise an error if any unrecognised options were supplied 
  options = {:color => @default_color,
             :fill_color => nil
             }
  options.merge!(opts)
  
  raise ArgumentError, "Argument r must be less than both w and h arguments" if r >= w || r >= h
  
  # if the rectangle should be filled in
  if options[:fill_color]
    set_color(options[:fill_color])
    @context.rounded_rectangle(x, y, w, h, r).fill 
  end
  
  set_color(options[:color])
  @context.rounded_rectangle(x, y, w, h, r).stroke
  
  move_to(x+w, y+h)
end