Class: Emfsvg::Translation::Handlers::PenState

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializePenState

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

#currentObject (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_pointsObject (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_pointsObject



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