Class: Emfsvg::Translation::Handlers::PenState
- Inherits:
-
Object
- Object
- Emfsvg::Translation::Handlers::PenState
- Defined in:
- lib/emfsvg/translation/handlers/path_flattener.rb
Overview
Tracks current position and pending bezier control points while flattening a path. Single-use per flatten() call.
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#pending_curve_points ⇒ Object
readonly
Returns the value of attribute pending_curve_points.
Instance Method Summary collapse
- #cubic_to(command, absolute:) ⇒ Object
- #flush_curve_points ⇒ Object
- #h_line_to(command, absolute:) ⇒ Object
-
#initialize ⇒ PenState
constructor
A new instance of PenState.
- #line_to(command, absolute:) ⇒ Object
- #move_to(command, absolute:) ⇒ Object
- #v_line_to(command, absolute:) ⇒ Object
Constructor Details
#initialize ⇒ PenState
Returns a new instance of PenState.
83 84 85 86 |
# File 'lib/emfsvg/translation/handlers/path_flattener.rb', line 83 def initialize @current = [0.0, 0.0] @pending_curve_points = [] end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
81 82 83 |
# File 'lib/emfsvg/translation/handlers/path_flattener.rb', line 81 def current @current end |
#pending_curve_points ⇒ Object (readonly)
Returns the value of attribute pending_curve_points.
81 82 83 |
# File 'lib/emfsvg/translation/handlers/path_flattener.rb', line 81 def pending_curve_points @pending_curve_points end |
Instance Method Details
#cubic_to(command, absolute:) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/emfsvg/translation/handlers/path_flattener.rb', line 116 def cubic_to(command, absolute:) x1, y1, x2, y2, x, y = command.args if absolute @pending_curve_points = [[x1, y1], [x2, y2], [x, y]] @current = [x, y] else @pending_curve_points = [ [@current[0] + x1, @current[1] + y1], [@current[0] + x2, @current[1] + y2], [@current[0] + x, @current[1] + y] ] @current = @current.zip([x, y]).map { |a, b| a + b } end end |
#flush_curve_points ⇒ Object
131 132 133 134 135 |
# File 'lib/emfsvg/translation/handlers/path_flattener.rb', line 131 def flush_curve_points pts = @pending_curve_points @pending_curve_points = [] pts end |
#h_line_to(command, absolute:) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/emfsvg/translation/handlers/path_flattener.rb', line 98 def h_line_to(command, absolute:) x, = command.args @current = if absolute [x, @current[1]] else [@current[0] + x, @current[1]] end end |
#line_to(command, absolute:) ⇒ Object
93 94 95 96 |
# File 'lib/emfsvg/translation/handlers/path_flattener.rb', line 93 def line_to(command, absolute:) x, y = command.args @current = absolute ? [x, y] : [@current[0] + x, @current[1] + y] end |
#move_to(command, absolute:) ⇒ Object
88 89 90 91 |
# File 'lib/emfsvg/translation/handlers/path_flattener.rb', line 88 def move_to(command, absolute:) x, y = command.args @current = absolute ? [x, y] : [@current[0] + x, @current[1] + y] end |
#v_line_to(command, absolute:) ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'lib/emfsvg/translation/handlers/path_flattener.rb', line 107 def v_line_to(command, absolute:) y, = command.args @current = if absolute [@current[0], y] else [@current[0], @current[1] + y] end end |