Class: Pdfrb::Content::GraphicObject::Polyline

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

Overview

Open polyline through a list of points.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(points, closed: false) ⇒ Polyline

Returns a new instance of Polyline.



10
11
12
13
# File 'lib/pdfrb/content/graphic_object/polyline.rb', line 10

def initialize(points, closed: false)
  @points = points.map { |p| [p[0].to_f, p[1].to_f] }
  @closed = closed
end

Instance Attribute Details

#closedObject (readonly)

Returns the value of attribute closed.



8
9
10
# File 'lib/pdfrb/content/graphic_object/polyline.rb', line 8

def closed
  @closed
end

#pointsObject (readonly)

Returns the value of attribute points.



8
9
10
# File 'lib/pdfrb/content/graphic_object/polyline.rb', line 8

def points
  @points
end

Instance Method Details

#draw(canvas) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/pdfrb/content/graphic_object/polyline.rb', line 15

def draw(canvas)
  return canvas if @points.empty?

  first = @points.first
  canvas.move_to(first[0], first[1])
  @points.drop(1).each { |x, y| canvas.line_to(x, y) }
  canvas.close_path if @closed
  canvas
end