Class: Postsvg::Translation::Handlers::PolygonHandler
- Inherits:
-
Object
- Object
- Postsvg::Translation::Handlers::PolygonHandler
- Extended by:
- Shared
- Defined in:
- lib/postsvg/translation/handlers/polygon_handler.rb
Overview
SVG <polygon>: like <polyline> but the path is closed.
Emits moveto + NĂ—lineto + closepath + paint.
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
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/postsvg/translation/handlers/polygon_handler.rb', line 11 def self.call(element, context) context.emitter.emit(Model::Operators::GraphicsState::Gsave.new) emit_transform(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::Path::Closepath.new) emit_paint(element, context) context.emitter.emit(Model::Operators::GraphicsState::Grestore.new) xs = points.each_slice(2).map(&:first) ys = points.each_slice(2).map(&:last) (context, xs.min, ys.min, xs.max, ys.max) if xs.any? end |