Class: Pdfrb::Content::GraphicObject::Rectangle

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfrb/content/graphic_object/rectangle.rb

Overview

Rectangle with optional rounded corners, drawn as four Bezier curves when radii are non-zero.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x:, y:, width:, height:, radius: 0) ⇒ Rectangle

Returns a new instance of Rectangle.



14
15
16
17
18
19
20
# File 'lib/pdfrb/content/graphic_object/rectangle.rb', line 14

def initialize(x:, y:, width:, height:, radius: 0)
  @x = x.to_f
  @y = y.to_f
  @width = width.to_f
  @height = height.to_f
  @radius = radius.to_f
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



12
13
14
# File 'lib/pdfrb/content/graphic_object/rectangle.rb', line 12

def height
  @height
end

#radiusObject (readonly)

Returns the value of attribute radius.



12
13
14
# File 'lib/pdfrb/content/graphic_object/rectangle.rb', line 12

def radius
  @radius
end

#widthObject (readonly)

Returns the value of attribute width.



12
13
14
# File 'lib/pdfrb/content/graphic_object/rectangle.rb', line 12

def width
  @width
end

#xObject (readonly)

Returns the value of attribute x.



12
13
14
# File 'lib/pdfrb/content/graphic_object/rectangle.rb', line 12

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



12
13
14
# File 'lib/pdfrb/content/graphic_object/rectangle.rb', line 12

def y
  @y
end

Instance Method Details

#draw(canvas) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/pdfrb/content/graphic_object/rectangle.rb', line 22

def draw(canvas)
  if @radius.zero?
    canvas.rectangle(@x, @y, @width, @height)
  else
    draw_rounded(canvas)
  end
  canvas
end