Class: Postsvg::Translation::Handlers::PolylineHandler

Inherits:
Object
  • Object
show all
Extended by:
Shared
Defined in:
lib/postsvg/translation/handlers/polyline_handler.rb

Class Method Summary collapse

Methods included from Shared

emit_fill, emit_paint, emit_paint_setup, emit_stroke, emit_transform, expand_bbox

Class Method Details

.call(element, context) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/postsvg/translation/handlers/polyline_handler.rb', line 9

def self.call(element, context)
  context.emitter.emit(Model::Operators::GraphicsState::Gsave.new)
  emit_transform(element, context)
  emit_stroke(element, context)
  context.emitter.emit(Model::Operators::Path::Newpath.new)
  points = element.points
  points.each_slice(2).with_index do |(x, y), idx|
    if idx.zero?
      context.emitter.emit(Model::Operators::Path::Moveto.new(x: x, y: y))
    else
      context.emitter.emit(Model::Operators::Path::Lineto.new(x: x, y: y))
    end
  end
  context.emitter.emit(Model::Operators::Painting::Stroke.new)
  context.emitter.emit(Model::Operators::GraphicsState::Grestore.new)
  xs = points.each_slice(2).map(&:first)
  ys = points.each_slice(2).map(&:last)
  expand_bbox(context, xs.min, ys.min, xs.max, ys.max) if xs.any?
end