Module: Postsvg::Visitors::PsVisitor::Transformations
- Included in:
- Postsvg::Visitors::PsVisitor
- Defined in:
- lib/postsvg/visitors/ps_visitor/transformations.rb
Overview
Coordinate transformation operator handlers. Each returns a new CTM via Matrix composition and updates the GraphicsContext.
Instance Method Summary collapse
- #visit_concat(op, _ctx) ⇒ Object
- #visit_currentmatrix(_op, _ctx) ⇒ Object
- #visit_dtransform(_op, _ctx) ⇒ Object
- #visit_idtransform(_op, _ctx) ⇒ Object
- #visit_itransform(_op, _ctx) ⇒ Object
- #visit_matrix(_op, _ctx) ⇒ Object
- #visit_rotate(op, _ctx) ⇒ Object
- #visit_scale(op, _ctx) ⇒ Object
- #visit_setmatrix(op, _ctx) ⇒ Object
- #visit_transform(_op, _ctx) ⇒ Object
- #visit_translate(op, _ctx) ⇒ Object
Instance Method Details
#visit_concat(op, _ctx) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/postsvg/visitors/ps_visitor/transformations.rb', line 24 def visit_concat(op, _ctx) matrix = matrix_from_operand(op.matrix) return unless matrix new_ctm = @graphics.current.ctm.multiply(matrix) @graphics.update(ctm: new_ctm) end |
#visit_currentmatrix(_op, _ctx) ⇒ Object
36 37 38 39 |
# File 'lib/postsvg/visitors/ps_visitor/transformations.rb', line 36 def visit_currentmatrix(_op, _ctx) ctm = @graphics.current.ctm @stack << [ctm.a, ctm.b, ctm.c, ctm.d, ctm.e, ctm.f] end |
#visit_dtransform(_op, _ctx) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/postsvg/visitors/ps_visitor/transformations.rb', line 57 def visit_dtransform(_op, _ctx) y = pop_number x = pop_number # Delta transform: ignore translation. ctm = @graphics.current.ctm dx = (x * ctm.a) + (y * ctm.c) dy = (x * ctm.b) + (y * ctm.d) @stack << dx @stack << dy end |
#visit_idtransform(_op, _ctx) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/postsvg/visitors/ps_visitor/transformations.rb', line 76 def visit_idtransform(_op, _ctx) y = pop_number x = pop_number inv = @graphics.current.ctm.invert dx = (x * inv.a) + (y * inv.c) dy = (x * inv.b) + (y * inv.d) @stack << dx @stack << dy end |
#visit_itransform(_op, _ctx) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/postsvg/visitors/ps_visitor/transformations.rb', line 68 def visit_itransform(_op, _ctx) y = pop_number x = pop_number p = @graphics.current.ctm.invert.apply_point(x, y) @stack << p[:x] @stack << p[:y] end |
#visit_matrix(_op, _ctx) ⇒ Object
32 33 34 |
# File 'lib/postsvg/visitors/ps_visitor/transformations.rb', line 32 def visit_matrix(_op, _ctx) @stack << [1, 0, 0, 1, 0, 0] end |
#visit_rotate(op, _ctx) ⇒ Object
19 20 21 22 |
# File 'lib/postsvg/visitors/ps_visitor/transformations.rb', line 19 def visit_rotate(op, _ctx) new_ctm = @graphics.current.ctm.rotate(op.angle.to_f) @graphics.update(ctm: new_ctm) end |
#visit_scale(op, _ctx) ⇒ Object
14 15 16 17 |
# File 'lib/postsvg/visitors/ps_visitor/transformations.rb', line 14 def visit_scale(op, _ctx) new_ctm = @graphics.current.ctm.scale(op.sx.to_f, op.sy.to_f) @graphics.update(ctm: new_ctm) end |
#visit_setmatrix(op, _ctx) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/postsvg/visitors/ps_visitor/transformations.rb', line 41 def visit_setmatrix(op, _ctx) matrix = matrix_from_operand(op.matrix) return unless matrix @graphics.update(ctm: matrix) end |
#visit_transform(_op, _ctx) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/postsvg/visitors/ps_visitor/transformations.rb', line 48 def visit_transform(_op, _ctx) # Transform a point by the CTM: x y transform -> x' y' y = pop_number x = pop_number p = @graphics.current.ctm.apply_point(x, y) @stack << p[:x] @stack << p[:y] end |
#visit_translate(op, _ctx) ⇒ Object
9 10 11 12 |
# File 'lib/postsvg/visitors/ps_visitor/transformations.rb', line 9 def visit_translate(op, _ctx) new_ctm = @graphics.current.ctm.translate(op.tx.to_f, op.ty.to_f) @graphics.update(ctm: new_ctm) end |