Class: Ucode::Glyphs::LastResort::PathBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ucode/glyphs/last_resort/svg.rb

Overview

Internal helper: walks a contour’s points and emits SVG path commands per the UFO point-type rules.

Contour-start handling: the first on-curve point we encounter becomes the implicit ‘M` target. We do NOT also emit `L`/`C`/ `Q` for it — that would draw a degenerate zero-length segment. Subsequent on-curve points emit their proper command.

Instance Method Summary collapse

Constructor Details

#initialize(points) ⇒ PathBuilder

Returns a new instance of PathBuilder.



115
116
117
118
119
120
121
122
# File 'lib/ucode/glyphs/last_resort/svg.rb', line 115

def initialize(points)
  @points = points
  @out = +""
  @i = 0
  @pending_offcurve = []
  @last_oncurve = nil
  @started = false
end

Instance Method Details

#to_pathObject



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/ucode/glyphs/last_resort/svg.rb', line 124

def to_path
  until @i >= @points.length
    point = @points[@i]
    case point.kind
    when :offcurve then consume_offcurve(point)
    when :move     then emit_move(point)
    when :line     then emit_line(point)
    when :curve    then emit_curve(point)
    when :qcurve   then emit_qcurve(point)
    end
    @i += 1
  end
  flush_trailing_offcurve
  append_close
  @out.strip
end