Class: Prune::Shapes::Line
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, from_x, from_y, to_x, to_y, options = {}) ⇒ Line
constructor
Draw line.
-
#render ⇒ Object
Render shape.
Methods included from Functions
Constructor Details
#initialize(page, from_x, from_y, to_x, to_y, options = {}) ⇒ Line
Draw line.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/prune/shapes/line.rb', line 12 def initialize(page, from_x, from_y, to_x, to_y, = {}) super(page) # Check arguments. raise LineArgumentError unless from_x.is_a?(Numeric) raise LineArgumentError unless from_y.is_a?(Numeric) raise LineArgumentError unless to_x.is_a?(Numeric) raise LineArgumentError unless to_y.is_a?(Numeric) # Set instance variables. @id = [:id] if .key?(:id) @x = from_x @y = from_y @to_x = to_x @to_y = to_y @width = to_x - from_x @height = -(to_y - from_y) @options = # Parse options. @style = [:style] || :none @width = [:width] || 1.0 @color = [:color] || "#000000" end |
Instance Method Details
#render ⇒ Object
Render shape.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/prune/shapes/line.rb', line 35 def render return [] if @style == :none return [] if @width <= 0.0 raise LineStyleError unless STYLES.include?(@style) stream = [] stream << "q" stream << "2 J" stream << "0 j" stream << STYLES[@style] stream << "%s RG" % convert_color_str(@color) stream << "%.2f w" % width stream << "%.2f %.2f m" % [@x, @y] stream << "%.2f %.2f l" % [@to_x, @to_y] stream << "s" stream << "Q" super(stream) end |