Class: Pdfrb::Content::GraphicObject::Rectangle
- Inherits:
-
Object
- Object
- Pdfrb::Content::GraphicObject::Rectangle
- 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
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#radius ⇒ Object
readonly
Returns the value of attribute radius.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #draw(canvas) ⇒ Object
-
#initialize(x:, y:, width:, height:, radius: 0) ⇒ Rectangle
constructor
A new instance of Rectangle.
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
#height ⇒ Object (readonly)
Returns the value of attribute height.
12 13 14 |
# File 'lib/pdfrb/content/graphic_object/rectangle.rb', line 12 def height @height end |
#radius ⇒ Object (readonly)
Returns the value of attribute radius.
12 13 14 |
# File 'lib/pdfrb/content/graphic_object/rectangle.rb', line 12 def radius @radius end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
12 13 14 |
# File 'lib/pdfrb/content/graphic_object/rectangle.rb', line 12 def width @width end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
12 13 14 |
# File 'lib/pdfrb/content/graphic_object/rectangle.rb', line 12 def x @x end |
#y ⇒ Object (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 |