Class: Prune::Shapes::Rectangle
- Defined in:
- lib/prune/shapes/rectangle.rb
Constant Summary collapse
- STYLES =
{ :solid => "[] 0 d", :dashed => "[5 5] 0 d" }
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(page, x, y, width, height, options = {}) ⇒ Rectangle
constructor
Draw rectangle.
-
#render ⇒ Object
Render shape.
Methods included from Functions
Constructor Details
#initialize(page, x, y, width, height, options = {}) ⇒ Rectangle
Draw rectangle.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/prune/shapes/rectangle.rb', line 12 def initialize(page, x, y, width, height, = {}) super(page) # Check arguments. raise RectangleArgumentError unless x.is_a?(Numeric) raise RectangleArgumentError unless y.is_a?(Numeric) raise RectangleArgumentError unless width.is_a?(Numeric) raise RectangleArgumentError unless height.is_a?(Numeric) # Set instance variables. @id = [:id] if .key?(:id) @x = x @y = y @width = width @height = height @options = # Parse options. @style = [:style] || :none @border_width = [:width] || 1.0 @border_color = [:color] || "#000000" @fill = [:fill] || false @fill_color = [:fill_color] || "#000000" end |
Instance Method Details
#render ⇒ Object
Render shape.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/prune/shapes/rectangle.rb', line 37 def render stream = [] boundary = [@x, @y, @width, -@height] stream << "q" # Set fill color. if @fill stream << "%s rg" % convert_color_str(@fill_color) stream << "%.2f %.2f %.2f %.2f re" % boundary stream << "f" end # Draw boundary. unless @style == :none raise RectangleStyleError unless STYLES.include?(@style) stream << "2 J" stream << "0 j" stream << STYLES[@style] stream << "%s RG" % convert_color_str(@border_color) stream << "%.2f w" % @border_width stream << "%.2f %.2f %.2f %.2f re" % boundary stream << "s" end stream << "Q" super(stream) end |