Module: Postsvg::Visitors::PsVisitor::Path

Included in:
Postsvg::Visitors::PsVisitor
Defined in:
lib/postsvg/visitors/ps_visitor/path.rb

Overview

Path construction operator handlers. Each appends a command to @path (PathState). CTM-aware: when the current CTM is not identity, the renderer will wrap emitted paths in a <g transform=>. Points are stored in user-space coordinates; the visitor delegates to the SvgBuilder for transform emission.

Instance Method Summary collapse

Instance Method Details

#visit_arc(op, _ctx) ⇒ Object



45
46
47
# File 'lib/postsvg/visitors/ps_visitor/path.rb', line 45

def visit_arc(op, _ctx)
  append_arc(op.x, op.y, op.radius, op.angle1, op.angle2, sweep: true)
end

#visit_arcn(op, _ctx) ⇒ Object



49
50
51
# File 'lib/postsvg/visitors/ps_visitor/path.rb', line 49

def visit_arcn(op, _ctx)
  append_arc(op.x, op.y, op.radius, op.angle1, op.angle2, sweep: false)
end

#visit_closepath(_op, _ctx) ⇒ Object



53
54
55
# File 'lib/postsvg/visitors/ps_visitor/path.rb', line 53

def visit_closepath(_op, _ctx)
  @path.close
end

#visit_currentpoint(_op, _ctx) ⇒ Object



57
58
59
60
# File 'lib/postsvg/visitors/ps_visitor/path.rb', line 57

def visit_currentpoint(_op, _ctx)
  @stack << @path.current_x
  @stack << @path.current_y
end

#visit_curveto(op, _ctx) ⇒ Object



37
38
39
# File 'lib/postsvg/visitors/ps_visitor/path.rb', line 37

def visit_curveto(op, _ctx)
  @path.curve_to(op.x1, op.y1, op.x2, op.y2, op.x3, op.y3)
end

#visit_lineto(op, _ctx) ⇒ Object



29
30
31
# File 'lib/postsvg/visitors/ps_visitor/path.rb', line 29

def visit_lineto(op, _ctx)
  @path.line_to(op.x, op.y)
end

#visit_moveto(op, _ctx) ⇒ Object



16
17
18
19
# File 'lib/postsvg/visitors/ps_visitor/path.rb', line 16

def visit_moveto(op, _ctx)
  @path.move_to(op.x, op.y)
  @graphics.update(last_text_position: { x: op.x, y: op.y })
end

#visit_newpath(_op, _ctx) ⇒ Object



12
13
14
# File 'lib/postsvg/visitors/ps_visitor/path.rb', line 12

def visit_newpath(_op, _ctx)
  @path.reset
end

#visit_rcurveto(op, _ctx) ⇒ Object



41
42
43
# File 'lib/postsvg/visitors/ps_visitor/path.rb', line 41

def visit_rcurveto(op, _ctx)
  @path.curve_to_rel(op.dx1, op.dy1, op.dx2, op.dy2, op.dx3, op.dy3)
end

#visit_rlineto(op, _ctx) ⇒ Object



33
34
35
# File 'lib/postsvg/visitors/ps_visitor/path.rb', line 33

def visit_rlineto(op, _ctx)
  @path.line_to_rel(op.dx, op.dy)
end

#visit_rmoveto(op, _ctx) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/postsvg/visitors/ps_visitor/path.rb', line 21

def visit_rmoveto(op, _ctx)
  @path.move_to_rel(op.dx, op.dy)
  pos = @graphics.current.last_text_position
  base_x = pos ? pos[:x] : 0
  base_y = pos ? pos[:y] : 0
  @graphics.update(last_text_position: { x: base_x + op.dx, y: base_y + op.dy })
end