Class: Fontisan::SvgToGlyf::Path::State
- Inherits:
-
Object
- Object
- Fontisan::SvgToGlyf::Path::State
- Defined in:
- lib/fontisan/svg_to_glyf/path/state.rb
Overview
Mutable state carried through the contour-building walk. Tracks the current pen position, the subpath start (for Z closure), the last cubic and quadratic control points (for smooth-curve reflection), and the contour being assembled.
Instance Attribute Summary collapse
-
#contours ⇒ Object
readonly
Returns the value of attribute contours.
-
#cubic_control ⇒ Object
Returns the value of attribute cubic_control.
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#quad_control ⇒ Object
Returns the value of attribute quad_control.
-
#subpath_start ⇒ Object
readonly
Returns the value of attribute subpath_start.
Instance Method Summary collapse
-
#add_point(x, y, type) ⇒ Object
Append a point to the current contour and advance current position for on-curve points (off-curve control points do not advance).
-
#close_contour ⇒ Object
Mark the end of the current subpath.
-
#finalize_contour ⇒ Object
Flush the in-progress contour into the contours list if it has more than one point (a lone M with nothing else is degenerate and dropped).
-
#initialize ⇒ State
constructor
A new instance of State.
- #reset_controls ⇒ Object
-
#start_contour(x, y) ⇒ Object
Start a new subpath at (x, y).
Constructor Details
#initialize ⇒ State
Returns a new instance of State.
14 15 16 17 18 19 20 21 |
# File 'lib/fontisan/svg_to_glyf/path/state.rb', line 14 def initialize @contours = [] @current = nil @subpath_start = nil @cubic_control = nil @quad_control = nil @pending = nil end |
Instance Attribute Details
#contours ⇒ Object (readonly)
Returns the value of attribute contours.
11 12 13 |
# File 'lib/fontisan/svg_to_glyf/path/state.rb', line 11 def contours @contours end |
#cubic_control ⇒ Object
Returns the value of attribute cubic_control.
11 12 13 |
# File 'lib/fontisan/svg_to_glyf/path/state.rb', line 11 def cubic_control @cubic_control end |
#current ⇒ Object (readonly)
Returns the value of attribute current.
11 12 13 |
# File 'lib/fontisan/svg_to_glyf/path/state.rb', line 11 def current @current end |
#quad_control ⇒ Object
Returns the value of attribute quad_control.
11 12 13 |
# File 'lib/fontisan/svg_to_glyf/path/state.rb', line 11 def quad_control @quad_control end |
#subpath_start ⇒ Object (readonly)
Returns the value of attribute subpath_start.
11 12 13 |
# File 'lib/fontisan/svg_to_glyf/path/state.rb', line 11 def subpath_start @subpath_start end |
Instance Method Details
#add_point(x, y, type) ⇒ Object
Append a point to the current contour and advance current position for on-curve points (off-curve control points do not advance).
35 36 37 38 39 40 41 42 |
# File 'lib/fontisan/svg_to_glyf/path/state.rb', line 35 def add_point(x, y, type) return unless @pending @pending << Fontisan::Ufo::Point.new(x: x, y: y, type: type) return if type == "offcurve" @current = [x, y] end |
#close_contour ⇒ Object
Mark the end of the current subpath. The contour is closed implicitly (UFO contours wrap around). Reset current to the subpath start so a subsequent M picks up from the right place.
47 48 49 50 51 52 |
# File 'lib/fontisan/svg_to_glyf/path/state.rb', line 47 def close_contour return unless @pending finalize_contour @current = @subpath_start end |
#finalize_contour ⇒ Object
Flush the in-progress contour into the contours list if it has more than one point (a lone M with nothing else is degenerate and dropped).
57 58 59 60 61 62 |
# File 'lib/fontisan/svg_to_glyf/path/state.rb', line 57 def finalize_contour return unless @pending @contours << Fontisan::Ufo::Contour.new(@pending) if @pending.size > 1 @pending = nil end |
#reset_controls ⇒ Object
72 73 74 75 |
# File 'lib/fontisan/svg_to_glyf/path/state.rb', line 72 def reset_controls @cubic_control = nil @quad_control = nil end |
#start_contour(x, y) ⇒ Object
Start a new subpath at (x, y). Flushes any in-progress contour.
24 25 26 27 28 29 30 31 |
# File 'lib/fontisan/svg_to_glyf/path/state.rb', line 24 def start_contour(x, y) finalize_contour @pending = [] add_point(x, y, "line") @subpath_start = [x, y] @cubic_control = nil @quad_control = nil end |