Move glyph.ptl to glyph.js

This commit is contained in:
be5invis 2020-06-19 04:13:18 -07:00
parent 1205a6d735
commit c442ad2b93
15 changed files with 206 additions and 195 deletions

View file

@ -67,7 +67,7 @@ export all : define [buildGlyphs para recursive recursiveCodes] : begin
if para.verbose : console.log ensuredGlyphName
local glyphObject [new Glyph ensuredGlyphName]
glyphObject.set-width Width
glyphObject.setWidth Width
glyphObject.gizmo = globalTransform
if saveGlyphName : begin
@ -94,7 +94,7 @@ export all : define [buildGlyphs para recursive recursiveCodes] : begin
`[@actions] : return : createAndSaveGlyphImpl null null actions
define [$assignUnicodeImpl$ g unicode] : begin
g.assign-unicode unicode
g.assignUnicode unicode
set unicodeGlyphs.(g.unicode.((g.unicode.length - 1))) g
define [$save$ _name unicode] : begin

View file

@ -98,8 +98,8 @@ glyph-block CommonShapes : begin
define [vcombine newid unicode id1 id2 spacing] : create-glyph [fallback newid : 'vcombine_' + id1 + '_' + id2] : glyph-construction
if unicode : assign-unicode unicode
set-width [query-glyph id1].advanceWidth
depends-on [query-glyph id1]
depends-on [query-glyph id2]
currentGlyph.dependsOn [query-glyph id1]
currentGlyph.dependsOn [query-glyph id2]
include : create-glyph : glyph-construction
include [refer-glyph id2]
apply-transform : Upright
@ -591,7 +591,7 @@ glyph-block CommonShapes : begin
local faf toFinish.af
set toFinish.af : lambda [] : begin
if faf : faf.apply this arguments
if this.heads-to : this.heads-to : if doSwash
if this.headsTo : this.headsTo : if doSwash
then : begin {
.x (Contrast / [Math.sqrt : 1 + skew * skew] * [if dtu (-1) 1])
.y (skew / [Math.sqrt : 1 + skew * skew] * [if ltr 1 (-1)])

View file

@ -3792,7 +3792,7 @@ glyph-block Letter-Latin-Lower-U : begin
include : refer-glyph "n"
eject-contour 'serifRB'
eject-contour 'serifLB'
currentGlyph.retag-contour 'serifLT' 'serifRB'
currentGlyph.reTagContour 'serifLT' 'serifRB'
include : FlipAround Middle (XH / 2)
if SLAB : begin
@ -5271,6 +5271,7 @@ glyph-block Letter-Latin-Upper-AE-OE : begin
glyph-block-import Overmarks
sketch # AE
define eBarPos : if SLAB 0.52 0.54
local df : DivFrame para.diversityM 3
set-width df.width
include df.markSet.capital
@ -5295,7 +5296,7 @@ glyph-block Letter-Latin-Upper-AE-OE : begin
# E half
include : VBarLeft eleft 0 CAP df.mvs
include : HBarTop (eleft - O) df.rightSB CAP
include : HBar (eleft - O) (df.rightSB - df.mvs / 4) (CAP * 0.54)
include : HBar (eleft - O) (df.rightSB - df.mvs / 4) (CAP * eBarPos)
include : HBarBottom (eleft - O) df.rightSB 0
if SLAB : begin
include : CenterBottomSerif (df.leftSB + df.mvs / 2 * HVContrast) 0 Jut df.mvs
@ -5305,12 +5306,12 @@ glyph-block Letter-Latin-Upper-AE-OE : begin
save 'cyrAE' 0x4D4
define [OEShape top df] : glyph-construction
local eleft df.middle
define eleft df.middle
define eBarPos : if SLAB 0.52 0.54
define sw : adviceBlackness2 designParameters.lllcrowdedness 3 top df.div
# O half
include : dispiro
widths.lhs df.mvs 0
widths.lhs sw 0
straight.left.start eleft top [heading Leftward]
archv
flat df.leftSB (top - SmoothA)
@ -5319,14 +5320,19 @@ glyph-block Letter-Latin-Upper-AE-OE : begin
straight.right.end eleft 0 [heading Rightward]
# E half
include : VBarLeft eleft 0 top df.mvs
include : HBarTop (eleft - O) df.rightSB top
include : HBar (eleft - O) (df.rightSB - df.mvs / 4) (top * 0.54)
include : HBarBottom (eleft - O) df.rightSB 0
include : VBarLeft eleft 0 top (sw / 2)
include : VBarRight eleft sw (top - sw / 2) (sw / 2)
include : HBarTop (eleft - O) df.rightSB top sw
include : HBar (eleft - O) (df.rightSB - sw / 4) (top * 0.54) sw
include : HBarBottom (eleft - O) df.rightSB 0 sw
if SLAB : begin
include : DownwardRightSerif df.rightSB top VJut df.mvs
include : UpwardRightSerif df.rightSB 0 VJut df.mvs
local jutTop : Math.min VJut
top - [mix (top - sw) (top * eBarPos + sw / 2) 0.5]
local jutBot : Math.min VJut
mix sw (top * eBarPos + sw / 2) 0.5
include : DownwardRightSerif df.rightSB top jutTop sw
include : UpwardRightSerif df.rightSB 0 jutBot sw
sketch # OE
local df : DivFrame para.diversityM 3

View file

@ -1496,10 +1496,10 @@ glyph-block Overmarks : begin
create-glyph toGN : glyph-construction
include g AS_BASE ALSO_METRICS
set currentGlyph.markAnchors.(akTo) currentGlyph.markAnchors.(akFrom)
currentGlyph.delete-mark-anchor akFrom
currentGlyph.deleteMarkAnchor akFrom
set currentGlyph.baseAnchors.(akTo) currentGlyph.baseAnchors.(akFrom)
currentGlyph.delete-base-anchor akFrom
currentGlyph.delete-base-anchor akBrace
currentGlyph.deleteBaseAnchor akFrom
currentGlyph.deleteBaseAnchor akBrace
TieMark.set g toGN
glyph-block-export markExtend markHalfStroke markStress markFine markMiddle markDotsRadius aboveMarkTop aboveMarkBot aboveMarkMid belowMarkBot belowMarkTop commaOvershoot commaOvershoot2 commaAboveRadius TildeShape HornShape HornMarkAnchor HornBaseAnchor

View file

@ -24,7 +24,7 @@ glyph-block Symbol-Geometric : begin
define [hollow newid unicode oldid zx zy cx cy] : create-glyph newid : glyph-construction
set-width MosaicWidth
depends-on : query-glyph oldid
currentGlyph.dependsOn : query-glyph oldid
local zoom : hollowScale squareRadiusFW
include : difference
create-glyph : glyph-construction
@ -36,7 +36,7 @@ glyph-block Symbol-Geometric : begin
define [hollowWithCenter newid unicode oldid zx zy cx cy] : create-glyph newid : glyph-construction
set-width MosaicWidth
depends-on : query-glyph oldid
currentGlyph.dependsOn : query-glyph oldid
local zoom : hollowScale squareRadiusFW
local zx1 : mix [fallback zx zoom] 1 0.25
local zx2 : mix zx1 0 0.5
@ -56,7 +56,7 @@ glyph-block Symbol-Geometric : begin
define [doubleHollow newid unicode oldid zx zy cx cy] : create-glyph newid : glyph-construction
set-width MosaicWidth
depends-on : query-glyph oldid
currentGlyph.dependsOn : query-glyph oldid
local zoom : hollowScale squareRadiusFW
local zx1 : mix [fallback zx zoom] 1 0.25
local zx2 : [mix zx1 0 0.5] + (1 - zx1) / 2

View file

@ -151,7 +151,7 @@ export : define [calculateMetrics para] : begin
define [adviceBlackness2 cowX cowY refH div] : Math.min
adviceBlackness cowX (refH / DarknessMockWidth2)
adviceBlackness cowY div
define [MVertStrokeD div] : adviceBlackness [fallback para.lllcrowdedness (3 + 1 / 3)] div
define [MVertStrokeD div] : adviceBlackness designParameters.lllcrowdedness div
define MVertStroke : MVertStrokeD 1
define OverlayStroke : adviceBlackness 3.75
define OperatorStroke : adviceBlackness 3.125
@ -295,6 +295,8 @@ export : define designParameters : object
braceCurlyM2 0.45
braceOvershoot 0.02
lllcrowdedness (3 + 1 / 3)
export : define [GenDivFrame metrics] : lambda [_div _hPack _sbMul] : begin
local div : fallback _div 1
local hPack : Math.max 2 [fallback _hPack 0]

View file

@ -66,19 +66,17 @@ define-macro glyph-construction : syntax-rules
]] env}
# Remap Glyph's methods to macros in order to simplify writing
define-macro set-width : syntax-rules
`[set-width @::args] {'.syntactic-closure' `[currentGlyph.set-width @::args] env}
`[set-width @::args] {'.syntactic-closure' `[currentGlyph.setWidth @::args] env}
define-macro include : syntax-rules
`[include @::args] {'.syntactic-closure' `[currentGlyph.include @::args] env}
define-macro set-mark-anchor : syntax-rules
`[set-mark-anchor @::args] {'.syntactic-closure' `[currentGlyph.set-mark-anchor @::args] env}
`[set-mark-anchor @::args] {'.syntactic-closure' `[currentGlyph.setMarkAnchor @::args] env}
define-macro set-base-anchor : syntax-rules
`[set-base-anchor @::args] {'.syntactic-closure' `[currentGlyph.set-base-anchor @::args] env}
`[set-base-anchor @::args] {'.syntactic-closure' `[currentGlyph.setBaseAnchor @::args] env}
define-macro apply-transform : syntax-rules
`[apply-transform @::args] {'.syntactic-closure' `[currentGlyph.apply-transform @::args] env}
define-macro depends-on : syntax-rules
`[depends-on @::args] {'.syntactic-closure' `[currentGlyph.depends-on @::args] env}
`[apply-transform @::args] {'.syntactic-closure' `[currentGlyph.applyTransform @::args] env}
define-macro eject-contour : syntax-rules
`[eject-contour @::args] {'.syntactic-closure' `[currentGlyph.eject-contour @::args] env}
`[eject-contour @::args] {'.syntactic-closure' `[currentGlyph.ejectContour @::args] env}
define-macro assign-unicode : syntax-rules
`[assign-unicode @code] {".syntactic-closure" `[$assignUnicodeImpl$ currentGlyph @code
] env}

View file

@ -80,9 +80,9 @@ export : define [BuildCompatLigatures glyphs glyphList unicodeGlyphs GSUB GDEF c
set g1.unicode {cldef.unicode}
foreach [gn : items-of gnames] : begin
local g glyphs.(gn)
g1.apply-transform : new Transform 1 0 0 1 (-g1.advanceWidth) 0
g1.applyTransform : new Transform 1 0 0 1 (-g1.advanceWidth) 0
g1.includeGlyph g
g1.apply-transform : new Transform 1 0 0 1 (g1.advanceWidth) 0
g1.applyTransform : new Transform 1 0 0 1 (g1.advanceWidth) 0
set g1.advanceWidth : g1.advanceWidth + g.advanceWidth
set glyphs.(g1.name) g1

View file

@ -43,8 +43,6 @@ shoulderfineMin = 0.8
isItalic = false # Use italic shapes?
isOblique = false # Use oblique shapes?
lllcrowdedness = 3.33333333
spacing = 1 # Spacing indicator
# Powerline-specific parameters

1
support/geometry.js Normal file
View file

@ -0,0 +1 @@
"use strict";

138
support/glyph.js Normal file
View file

@ -0,0 +1,138 @@
"use strict";
const Transform = require("./transform");
const Point = require("./point");
const Anchor = require("./anchor");
module.exports = class Glyph {
constructor(name) {
Object.defineProperty(this, "name", { value: name, writable: false });
this.unicode = [];
this.contours = [];
this.advanceWidth = 500;
this.autoRefPriority = 0;
this.markAnchors = {};
this.baseAnchors = {};
this.gizmo = Transform.Id();
this.dependencies = [];
this.defaultTag = null;
}
// PTL pattern matching
static unapply(obj, arity) {
if (obj instanceof Glyph) return [obj];
else return null;
}
// Metrics
setWidth(w) {
this.advanceWidth = w;
}
// Encoding
assignUnicode(u) {
if (typeof u === "string") this.unicode.push(u.codePointAt(0));
else this.unicode.push(u);
}
// Dependency
dependsOn(glyph) {
if (glyph.name) this.dependencies.push(glyph.name);
if (glyph.dependencies) for (const dep of glyph.dependencies) this.dependencies.push(dep);
}
// Contour Tagging
reTagContour(oldTag, newTag) {
for (const c of this.contours) if (c.tag === oldTag) c.tag = newTag;
}
ejectContour(tag) {
let i = 0,
j = 0;
for (; i < this.contours.length; i++) {
if (!this.contours[i].tag || this.contours[i].tag !== tag)
this.contours[j++] = this.contours[i];
}
this.contours.length = j;
}
// Inclusion
include(component, copyAnchors, copyWidth) {
if (component instanceof Function) {
const t = this.defaultTag;
if (component.tag) this.defaultTag = component.tag;
component.call(this, copyAnchors, copyWidth);
this.defaultTag = t;
return;
} else if (component instanceof Transform) {
this.applyTransform(component, copyAnchors);
} else if (component instanceof Array) {
throw new Error("Attempt to include an array.");
} else {
this.includeGlyph(component, copyAnchors, copyWidth);
}
}
includeGlyph(g, copyAnchors, copyWidth) {
if (g instanceof Function) throw new Error("Unreachable");
// Combine anchors and get offset
let shift = { x: 0, y: 0 };
if (g.markAnchors) {
for (const m in this.baseAnchors) {
this.combineAnchor(shift, this.baseAnchors[m], g.markAnchors[m], g.baseAnchors);
}
}
this.includeGeometry(g, shift.x, shift.y);
if (copyAnchors || g.isMarkSet) this.copyAnchors(g);
if (copyWidth && g.advanceWidth >= 0) this.advanceWidth = g.advanceWidth;
this.dependsOn(g);
}
includeGeometry(geom, shiftX, shiftY) {
if (!geom || !geom.contours) return;
for (const contour of geom.contours) {
let c = [];
c.tag = contour.tag || geom.tag || this.defaultTag;
for (const z of contour) c.push(Point.translated(z, shiftX, shiftY));
this.contours.push(c);
}
}
combineAnchor(shift, baseThis, markThat, basesThat) {
if (!baseThis || !markThat) return;
shift.x = baseThis.x - markThat.x;
shift.y = baseThis.y - markThat.y;
if (basesThat) {
for (const bk in basesThat) {
this.baseAnchors[bk] = new Anchor(
shift.x + basesThat[bk].x,
shift.y + basesThat[bk].y
);
}
}
}
copyAnchors(g) {
if (g.markAnchors) for (const k in g.markAnchors) this.markAnchors[k] = g.markAnchors[k];
if (g.baseAnchors) for (const k in g.baseAnchors) this.baseAnchors[k] = g.baseAnchors[k];
}
applyTransform(tfm, alsoAnchors) {
for (const c of this.contours)
for (let j = 0; j < c.length; j++) {
c[j] = Point.transformed(tfm, c[j]);
}
if (alsoAnchors) {
for (const k in this.baseAnchors)
this.baseAnchors[k] = Anchor.transform(tfm, this.baseAnchors[k]);
for (const k in this.markAnchors)
this.markAnchors[k] = Anchor.transform(tfm, this.markAnchors[k]);
}
}
// Anchors
setBaseAnchor(id, x, y) {
this.baseAnchors[id] = new Anchor(x, y).transform(this.gizmo);
}
setMarkAnchor(id, x, y, mbx, mby) {
this.markAnchors[id] = new Anchor(x, y).transform(this.gizmo);
if (mbx != null && mby != null) {
this.baseAnchors[id] = new Anchor(mbx, mby).transform(this.gizmo);
}
}
deleteBaseAnchor(id) {
delete this.baseAnchors[id];
}
deleteMarkAnchor(id) {
delete this.markAnchors[id];
}
};

View file

@ -1,138 +0,0 @@
extern isFinite
import './point' as Point
import './transform' as : Transform && [object [transformPoint tp] [untransform utp] inverse]
import './anchor' as Anchor
import "./utils" as [object fallback mix ratio]
define-macro xytransform : syntax-rules
`[xytransform @tfm @x @y] : begin
set [env.declarations.get [formOf x]].isParameter 0
set [env.declarations.get [formOf y]].isParameter 0
let [t : env.newt] `[begin \\
set @t @x
set @x : @x * @tfm.xx + @y * @tfm.yx + @tfm.x
set @y : @t * @tfm.xy + @y * @tfm.yy + @tfm.y
]
export all : class Glyph
public [new name] : begin
set this.name name
set this.unicode {}
set this.contours {}
set this.advanceWidth 500
set this.autoRefPriority 0
set this.markAnchors {.}
set this.baseAnchors {.}
set this.gizmo : Transform.Id
set this.dependencies {}
set this.defaultTag null
return nothing
static is {.unapply [function [obj arity] [if (obj <@ Glyph) {obj} null]]}
public [set-width w] : begin
this.advanceWidth = w
return this
public [assign-unicode u] : begin
this.unicode.push : piecewise
([typeof u] === 'string') : u.charCodeAt 0
true u
return this
public [retag-contour oldtag newtag] : begin
if this.contours : foreach [c : items-of this.contours] : if (c.tag === oldtag) : set c.tag newtag
return this
public [eject-contour tag] : begin
set this.contours : this.contours.filter : lambda [c] (c.tag !== tag)
return this
public [depends-on glyph] : begin
piecewise
glyph.name : this.dependencies.push glyph.name
glyph.dependencies : this.dependencies = [this.dependencies.concat glyph.dependencies]
return this
public [includeGeometry geom shiftx shifty] : begin
if (!geom || !geom.contours) : return nothing
foreach [contour : items-of geom.contours] : begin
local c {}
set c.tag : contour.tag || geom.tag || this.defaultTag
foreach [point : items-of contour] : c.push : Point.translated point shiftx shifty
this.contours.push c
public [combineAnchor markCls shift baseThis markThat basesThat] : begin
if (!baseThis || !markThat) : return nothing
set shift.x : baseThis.x - markThat.x
set shift.y : baseThis.y - markThat.y
if basesThat : foreach {bk baseThat} [pairs-of basesThat] : begin
set this.baseAnchors.(bk) : new Anchor
* (shift.x + baseThat.x)
* (shift.y + baseThat.y)
public [includeGlyph glyph copyAnchors copyWidth] : begin
if (glyph <@ Function) : begin
throw "\(this.name): Cannot include a function using includeGlyph. Use include instead."
local shift {.x 0 .y 0}
if glyph.markAnchors : foreach { markid baseThis } [pairs-of this.baseAnchors] : begin
local markThat glyph.markAnchors.(markid)
this.combineAnchor markid shift baseThis markThat glyph.baseAnchors
this.includeGeometry glyph shift.x shift.y
if ((copyAnchors || glyph.isMarkSet) && glyph.markAnchors) : begin
foreach [k : items-of : Object.keys glyph.markAnchors] : begin
set this.markAnchors.(k) glyph.markAnchors.(k)
if ((copyAnchors || glyph.isMarkSet) && glyph.baseAnchors) : begin
foreach [k : items-of : Object.keys glyph.baseAnchors] : begin
set this.baseAnchors.(k) glyph.baseAnchors.(k)
if (glyph.advanceWidth >= 0 && copyWidth) : set this.advanceWidth glyph.advanceWidth
if glyph.name : this.dependencies.push glyph.name
if glyph.dependencies : this.dependencies = [this.dependencies.concat glyph.dependencies]
return this
public [include component copyAnchors copyWidth] : begin
piecewise
(component <@ Function) : begin
local t this.defaultTag
if component.tag : set this.defaultTag component.tag
component.call this copyAnchors copyWidth
set this.defaultTag t
return this
(component <@ Transform) : return : this.apply-transform component copyAnchors
(component <@ Array) : begin
return : this.includeGlyph {.contours component} copyAnchors copyWidth
true : begin
return : this.includeGlyph component copyAnchors copyWidth
public [apply-transform transform alsoAnchors] : begin
foreach [c : items-of this.contours] : foreach [j : range 0 c.length] : set c.(j) : tp transform c.(j)
if alsoAnchors : begin
foreach key [items-of [Object.keys this.baseAnchors]] : begin
set this.baseAnchors.(key) : Anchor.transform transform this.baseAnchors.(key)
foreach key [items-of [Object.keys this.markAnchors]] : begin
set this.markAnchors.(key) : Anchor.transform transform this.markAnchors.(key)
return this
public [set-base-anchor id x y] : begin
xytransform this.gizmo x y
set this.baseAnchors.(id) : new Anchor x y
return this
public [set-mark-anchor id x y mbx mby] : begin
xytransform this.gizmo x y
set this.markAnchors.(id) : new Anchor x y
if (mbx !== nothing && mby !== nothing) : begin
xytransform this.gizmo mbx mby
set this.baseAnchors.(id) : new Anchor mbx mby
return this
public [delete-base-anchor id] : begin
local anchors : this.baseAnchors || {.}
local newAnchors {.}
foreach {k v} [pairs-of anchors] : if (k !== id) : set newAnchors.(k) v
set this.baseAnchors newAnchors
public [delete-mark-anchor id] : begin
local anchors : this.markAnchors || {.}
local newAnchors {.}
foreach {k v} [pairs-of anchors] : if (k !== id) : set newAnchors.(k) v
set this.markAnchors newAnchors

View file

@ -55,7 +55,13 @@ export all : class Point
static [offFromXY x y] : new Point (x || 0) (y || 0) false false false
static [cubicOffFromXY x y] : new Point (x || 0) (y || 0) false true false
static [transformed tfm x y on cubic subdivided] : new Point
static [transformed tfm z] : new Point
* z.x * tfm.xx + z.y * tfm.yx + tfm.x
* z.x * tfm.xy + z.y * tfm.yy + tfm.y
* z.on
* z.cubic
* z.subdivided
static [transformedXY tfm x y on cubic subdivided] : new Point
* x * tfm.xx + y * tfm.yx + tfm.x
* x * tfm.xy + y * tfm.yy + tfm.y
* on

View file

@ -36,7 +36,7 @@ export : define [SetupBuilders args] : begin
[fallback kt.r kt] (x + d.x * a.r) (y + d.y * a.r) f
# Aux functions
define [widths l r] : lambda [] : if this.set-width : this.set-width l r
define [widths l r] : lambda [] : if this.setWidth : this.setWidth l r
define [widths.lhs w] : widths [fallback w Stroke] 0
define [widths.rhs w] : widths 0 [fallback w Stroke]
define [widths.center w] : widths ([fallback w Stroke] / 2) ([fallback w Stroke] / 2)
@ -45,19 +45,19 @@ export : define [SetupBuilders args] : begin
define [disable-gizmo] : lambda [] : set this.gizmo [Transform.Id]
define [disable-contrast] : lambda [] : set this.contrast 1
define [heading d] : lambda [] : if (this.heads-to) : this.heads-to d
define [heading d] : lambda [] : if (this.headsTo) : this.headsTo d
define [widths.heading l r d] : lambda [] : begin
if this.set-width : this.set-width l r
if this.heads-to : this.heads-to d
if this.setWidth : this.setWidth l r
if this.headsTo : this.headsTo d
define [widths.lhs.heading w d] : lambda [] : begin
if this.set-width : this.set-width [fallback w Stroke] 0
if this.heads-to : this.heads-to d
if this.setWidth : this.setWidth [fallback w Stroke] 0
if this.headsTo : this.headsTo d
define [widths.rhs.heading w d] : lambda [] : begin
if this.set-width : this.set-width 0 [fallback w Stroke]
if this.heads-to : this.heads-to d
if this.setWidth : this.setWidth 0 [fallback w Stroke]
if this.headsTo : this.headsTo d
define [widths.center.heading w d] : lambda [] : begin
if this.set-width : this.set-width ([fallback w Stroke] / 2) ([fallback w Stroke] / 2)
if this.heads-to : this.heads-to d
if this.setWidth : this.setWidth ([fallback w Stroke] / 2) ([fallback w Stroke] / 2)
if this.headsTo : this.headsTo d
define [unimportant] : begin
if (this.points && this.points.length && this.points.(this.points.length - 1)) : this.points.(this.points.length - 1).subdivided = true
if (this.controlKnots && this.controlKnots.length && this.controlKnots.(this.controlKnots.length - 1)) : this.controlKnots.(this.controlKnots.length - 1).unimportant = true
@ -164,7 +164,7 @@ export : define [SetupBuilders args] : begin
local {.knots knots .closed closed .lastafs lastafs} : prepareSpiroKnots [{}.slice.call args 0] s
foreach knot [items-of knots] : let [ty knot.type] [af knot.af] : begin
set knot.af : lambda [] : begin
this.set-type ty
this.setType ty
if af : af.apply this args
SpiroJs.spiroToBezierOnContext knots closed s
foreach af [items-of lastafs] : if af : af.call s

View file

@ -58,19 +58,19 @@ class SpiroExpansionContext
set thisKnot.normalAngle normalAngle
this.controlKnots.push thisKnot
public [set-width l r] : begin
public [setWidth l r] : begin
local lastKnot this.controlKnots.(this.controlKnots.length - 1)
if lastKnot : then
lastKnot.d1 = l; lastKnot.d2 = r
: else
this.defaultd1 = l; this.defaultd2 = r
public [heads-to direction] : begin
public [headsTo direction] : begin
local lastKnot this.controlKnots.(this.controlKnots.length - 1)
if lastKnot : begin
lastKnot.proposedNormal = direction
public [set-type type] : begin
public [setType type] : begin
local lastKnot this.controlKnots.(this.controlKnots.length - 1)
if lastKnot : begin
lastKnot.type = type
@ -164,27 +164,27 @@ class SpiroContourContext
public [endShape] : begin
public [moveTo x y] : begin
local contour {[Point.transformed this.gizmo x y true]}
local contour {[Point.transformedXY this.gizmo x y true]}
set contour.tag this.defaultTag
this.contours.push contour
return this
public [lineTo x y] : begin
this.contours.((this.contours.length - 1)).push
Point.transformed this.gizmo x y true
Point.transformedXY this.gizmo x y true
return this
public [curveTo xc yc x y] : begin
this.contours.((this.contours.length - 1)).push
Point.transformed this.gizmo xc yc false
Point.transformed this.gizmo x y true
Point.transformedXY this.gizmo xc yc false
Point.transformedXY this.gizmo x y true
return this
public [cubicTo x1 y1 x2 y2 x y] : begin
this.contours.((this.contours.length - 1)).push
Point.transformed this.gizmo x1 y1 false true
Point.transformed this.gizmo x2 y2 false true
Point.transformed this.gizmo x y true
Point.transformedXY this.gizmo x1 y1 false true
Point.transformedXY this.gizmo x2 y2 false true
Point.transformedXY this.gizmo x y true
return this
export SpiroExpansionContext