define bezierCubic2Q2 [require 'node-sfnt/lib/math/bezierCubic2Q2'] define [Glyph name] : begin { set this.name name set this.unicode () set this.contours () set this.advanceWidth 500 return nothing } define [Glyph.prototype.set-width w] : begin { this.advanceWidth = w return this } define [Glyph.prototype.assign-unicode u] : begin { this.unicode.push [u.charCodeAt 0] return this } define [Glyph.prototype.start-from x y] : begin { this.contours.push ((.x x .y y .onCurve true)) return this } define [Glyph.prototype.line-to x y] : begin { this.contours`[this.contours.length - 1].push (.x x .y y .onCurve true) return this } define [Glyph.prototype.curve-to xc yc x y] : begin { this.contours`[this.contours.length - 1].push (.x xc .y yc .onCurve false) (.x x .y y .onCurve true) return this } define [Glyph.prototype.cubic-to x1 y1 x2 y2 x y] : begin { local lastContour this.contours`[this.contours.length - 1] local lastPoint lastContour`[lastContour.length - 1] local segments [bezierCubic2Q2 lastPoint (.x x1 .y y1) (.x x2 .y y2) (.x x .y y)] foreach (p0 (.x xc .y yc) (.x xf .y yf)) [items-of segments] : this.curve-to xc yc xf yf return this } define [Glyph.prototype.reverse-last] : begin { this.contours.[this.contours.length - 1] = [this.contours.[this.contours.length - 1].reverse] } define [Glyph.prototype.put-shapes contours] : begin { foreach contour [items-of contours] : begin { this.start-from contour.0.x contour.0.y for [local j 1] [j < contour.length] [inc j] : begin { local point contour`j if point.cubic [begin { local p2 contour`[j + 1] local p3 contour`[j + 2] this.cubic-to point.x point.y p2.x p2.y p3.x p3.y j = j + 2 }] [if point.onCurve [this.line-to point.x point.y] [begin { local p2 contour`[j + 1] this.curve-to point.x point.y p2.x p2.y j = j + 1 }]] } } return this } define [Glyph.prototype.include-glyph glyph] : this.put-shapes glyph.contours exports.Glyph = Glyph