More cleanup

This commit is contained in:
be5invis 2024-03-03 23:41:27 -08:00
parent c6fa4342a1
commit f72b039ec4
8 changed files with 58 additions and 57 deletions

View file

@ -47,7 +47,7 @@ glyph-block Symbol-Geometric-Plain : for-width-kinds WideWidth1
begin 0 begin 0
local outlines : glyph-proc : begin local outlines : glyph-proc : begin
set this.gizmo : Translate 0 0 set this.gizmo : Translate 0 0
foreach c [items-of : sh.geometry.asContours] : foreach j [range 0 c.length] : begin foreach c [items-of : sh.geometry.toContours] : foreach j [range 0 c.length] : begin
local a c.[if j (j - 1) (c.length - 1)] local a c.[if j (j - 1) (c.length - 1)]
local b c.(j) local b c.(j)
include : dispiro include : dispiro

View file

@ -30,7 +30,7 @@ glyph-block Symbol-Math-APL : begin
local corners : new-glyph : glyph-proc local corners : new-glyph : glyph-proc
set this.gizmo : Translate 0 0 set this.gizmo : Translate 0 0
foreach [c : items-of : overlay.geometry.asContours] : foreach [z : items-of c] : do foreach [c : items-of : overlay.geometry.toContours] : foreach [z : items-of c] : do
if (z.type === Point.Type.Corner) : begin if (z.type === Point.Type.Corner) : begin
define x z.x define x z.x
define y z.y define y z.y

View file

@ -242,7 +242,7 @@ function analyzeReferenceGraph(glyphStore, markedGlyphs) {
function traverseReferenceTree(depthMap, aliasMap, g, d) { function traverseReferenceTree(depthMap, aliasMap, g, d) {
depthMapSet(depthMap, g, d); depthMapSet(depthMap, g, d);
let refs = g.geometry.asReferences(); let refs = g.geometry.toReferences();
if (!refs) return; if (!refs) return;
for (const sr of refs) { for (const sr of refs) {
@ -359,7 +359,7 @@ function rectifyGlyphAndMarkComponents(glyphStore, aliasMap, markedGlyphs, memo,
if (memo.has(g)) return; if (memo.has(g)) return;
memo.add(g); memo.add(g);
let refs = g.geometry.asReferences(); let refs = g.geometry.toReferences();
if (refs) { if (refs) {
let parts = []; let parts = [];
for (let sr of refs) { for (let sr of refs) {

View file

@ -29,7 +29,7 @@ function regulateGlyphStore(cache, skew, glyphStore) {
function regulateCompositeGlyph(glyphStore, memo, g) { function regulateCompositeGlyph(glyphStore, memo, g) {
if (memo.has(g)) return memo.get(g); if (memo.has(g)) return memo.get(g);
let refs = g.geometry.asReferences(); let refs = g.geometry.toReferences();
if (!refs) return memoSet(memo, g, false); if (!refs) return memoSet(memo, g, false);
for (const sr of refs) { for (const sr of refs) {
@ -71,7 +71,7 @@ function flattenSimpleGlyph(cache, skew, g) {
gSimplified = new Geom.SimplifyGeometry(g.geometry); gSimplified = new Geom.SimplifyGeometry(g.geometry);
} }
const cs = gSimplified.asContours(); const cs = gSimplified.toContours();
g.clearGeometry(); g.clearGeometry();
g.includeContours(cs); g.includeContours(cs);
if (ck) cache.saveGF(ck, cs); if (ck) cache.saveGF(ck, cs);

View file

@ -70,11 +70,11 @@ class MappedGlyphStore {
// Fill Geometry // Fill Geometry
if (source.geometry.measureComplexity() & Geom.CPLX_NON_EMPTY) { if (source.geometry.measureComplexity() & Geom.CPLX_NON_EMPTY) {
const rs = source.geometry.asReferences(); const rs = source.geometry.toReferences();
if (rs) { if (rs) {
this.fillReferences(g, rs); this.fillReferences(g, rs);
} else { } else {
this.fillContours(g, source.geometry.asContours()); this.fillContours(g, source.geometry.toContours());
} }
} }
} }

View file

@ -4,7 +4,7 @@ import zlib from "zlib";
import * as CurveUtil from "@iosevka/geometry/curve-util"; import * as CurveUtil from "@iosevka/geometry/curve-util";
import { encode, decode } from "@msgpack/msgpack"; import { encode, decode } from "@msgpack/msgpack";
const Edition = 35; const Edition = 36;
const MAX_AGE = 16; const MAX_AGE = 16;
class GfEntry { class GfEntry {
constructor(age, value) { constructor(age, value) {

View file

@ -1,13 +1,13 @@
import crypto from "crypto"; import crypto from "crypto";
import * as Format from "@iosevka/util/formatter"; import * as Format from "@iosevka/util/formatter";
import * as SpiroJs from "spiro";
import * as TypoGeom from "typo-geom"; import * as TypoGeom from "typo-geom";
import * as CurveUtil from "./curve-util.mjs"; import * as CurveUtil from "./curve-util.mjs";
import { Point } from "./point.mjs"; import { Point } from "./point.mjs";
import { QuadifySink } from "./quadify.mjs"; import { QuadifySink } from "./quadify.mjs";
import { SpiroExpander } from "./spiro-expand.mjs"; import { SpiroExpander } from "./spiro-expand.mjs";
import { spiroToOutline } from "./spiro-to-outline.mjs";
import { strokeArcs } from "./stroke.mjs"; import { strokeArcs } from "./stroke.mjs";
import { Transform } from "./transform.mjs"; import { Transform } from "./transform.mjs";
@ -17,10 +17,10 @@ export const CPLX_BROKEN = 0x04; // A geometry tree that contains broken contour
export const CPLX_UNKNOWN = 0xff; export const CPLX_UNKNOWN = 0xff;
export class GeometryBase { export class GeometryBase {
asContours() { toContours() {
throw new Error("Unimplemented"); throw new Error("Unimplemented");
} }
asReferences() { toReferences() {
throw new Error("Unimplemented"); throw new Error("Unimplemented");
} }
getDependencies() { getDependencies() {
@ -47,10 +47,10 @@ export class ContourSetGeometry extends GeometryBase {
super(); super();
this.m_contours = contours; this.m_contours = contours;
} }
asContours() { toContours() {
return this.m_contours; return this.m_contours;
} }
asReferences() { toReferences() {
return null; return null;
} }
getDependencies() { getDependencies() {
@ -84,19 +84,12 @@ export class SpiroGeometry extends GeometryBase {
this.m_gizmo = gizmo; this.m_gizmo = gizmo;
this.m_cachedContours = null; this.m_cachedContours = null;
} }
asContours() { toContours() {
if (this.m_cachedContours) return this.m_cachedContours; if (this.m_cachedContours) return this.m_cachedContours;
const s = new CurveUtil.BezToContoursSink(this.m_gizmo); this.m_cachedContours = spiroToOutline(this.m_knots, this.m_closed, this.m_gizmo);
SpiroJs.spiroToBezierOnContext(
this.m_knots,
this.m_closed,
s,
CurveUtil.GEOMETRY_PRECISION
);
this.m_cachedContours = s.contours;
return this.m_cachedContours; return this.m_cachedContours;
} }
asReferences() { toReferences() {
return null; return null;
} }
getDependencies() { getDependencies() {
@ -132,7 +125,7 @@ export class DiSpiroGeometry extends GeometryBase {
this.m_cachedExpansionResults = null; this.m_cachedExpansionResults = null;
this.m_cachedContours = null; this.m_cachedContours = null;
} }
asContours() { toContours() {
if (this.m_cachedContours) return this.m_cachedContours; if (this.m_cachedContours) return this.m_cachedContours;
const expandResult = this.expand(); const expandResult = this.expand();
const lhs = [...expandResult.lhsUntransformed]; const lhs = [...expandResult.lhsUntransformed];
@ -141,9 +134,9 @@ export class DiSpiroGeometry extends GeometryBase {
for (const k of rhs) k.reverseType(); for (const k of rhs) k.reverseType();
rhs.reverse(); rhs.reverse();
let rawGeometry; let outlineGeometry;
if (this.m_closed) { if (this.m_closed) {
rawGeometry = new CombineGeometry([ outlineGeometry = new CombineGeometry([
new SpiroGeometry(this.m_gizmo, true, lhs), new SpiroGeometry(this.m_gizmo, true, lhs),
new SpiroGeometry(this.m_gizmo, true, rhs) new SpiroGeometry(this.m_gizmo, true, rhs)
]); ]);
@ -151,9 +144,9 @@ export class DiSpiroGeometry extends GeometryBase {
lhs[0].type = lhs[lhs.length - 1].type = "corner"; lhs[0].type = lhs[lhs.length - 1].type = "corner";
rhs[0].type = rhs[rhs.length - 1].type = "corner"; rhs[0].type = rhs[rhs.length - 1].type = "corner";
const allKnots = lhs.concat(rhs); const allKnots = lhs.concat(rhs);
rawGeometry = new SpiroGeometry(this.m_gizmo, true, allKnots); outlineGeometry = new SpiroGeometry(this.m_gizmo, true, allKnots);
} }
this.m_cachedContours = rawGeometry.asContours(); this.m_cachedContours = outlineGeometry.toContours();
return this.m_cachedContours; return this.m_cachedContours;
} }
expand() { expand() {
@ -172,7 +165,7 @@ export class DiSpiroGeometry extends GeometryBase {
this.m_cachedExpansionResults = expander.expand(); this.m_cachedExpansionResults = expander.expand();
return this.m_cachedExpansionResults; return this.m_cachedExpansionResults;
} }
asReferences() { toReferences() {
return null; return null;
} }
getDependencies() { getDependencies() {
@ -213,10 +206,10 @@ export class ReferenceGeometry extends GeometryBase {
Transform.Translate(this.m_x, this.m_y) Transform.Translate(this.m_x, this.m_y)
); );
} }
asContours() { toContours() {
return this.unwrap().asContours(); return this.unwrap().toContours();
} }
asReferences() { toReferences() {
if (this.m_glyph.geometry.measureComplexity() & CPLX_NON_EMPTY) { if (this.m_glyph.geometry.measureComplexity() & CPLX_NON_EMPTY) {
return [{ glyph: this.m_glyph, x: this.m_x, y: this.m_y }]; return [{ glyph: this.m_glyph, x: this.m_x, y: this.m_y }];
} else { } else {
@ -249,11 +242,11 @@ export class TaggedGeometry extends GeometryBase {
this.m_geom = g; this.m_geom = g;
this.m_tag = tag; this.m_tag = tag;
} }
asContours() { toContours() {
return this.m_geom.asContours(); return this.m_geom.toContours();
} }
asReferences() { toReferences() {
return this.m_geom.asReferences(); return this.m_geom.toReferences();
} }
getDependencies() { getDependencies() {
return this.m_geom.getDependencies(); return this.m_geom.getDependencies();
@ -279,18 +272,18 @@ export class TransformedGeometry extends GeometryBase {
this.m_geom = g; this.m_geom = g;
this.m_transform = tfm; this.m_transform = tfm;
} }
asContours() { toContours() {
let result = []; let result = [];
for (const c of this.m_geom.asContours()) { for (const c of this.m_geom.toContours()) {
let c1 = []; let c1 = [];
for (const z of c) c1.push(Point.transformed(this.m_transform, z)); for (const z of c) c1.push(Point.transformed(this.m_transform, z));
result.push(c1); result.push(c1);
} }
return result; return result;
} }
asReferences() { toReferences() {
if (!Transform.isTranslate(this.m_transform)) return null; if (!Transform.isTranslate(this.m_transform)) return null;
const rs = this.m_geom.asReferences(); const rs = this.m_geom.toReferences();
if (!rs) return null; if (!rs) return null;
let result = []; let result = [];
for (const { glyph, x, y } of rs) for (const { glyph, x, y } of rs)
@ -343,10 +336,10 @@ export class RadicalGeometry extends GeometryBase {
super(); super();
this.m_geom = g; this.m_geom = g;
} }
asContours() { toContours() {
return this.m_geom.asContours(); return this.m_geom.toContours();
} }
asReferences() { toReferences() {
return null; return null;
} }
getDependencies() { getDependencies() {
@ -382,19 +375,19 @@ export class CombineGeometry extends GeometryBase {
return new CombineGeometry([...this.m_parts, g]); return new CombineGeometry([...this.m_parts, g]);
} }
} }
asContours() { toContours() {
let results = []; let results = [];
for (const part of this.m_parts) { for (const part of this.m_parts) {
for (const c of part.asContours()) { for (const c of part.toContours()) {
results.push(c); results.push(c);
} }
} }
return results; return results;
} }
asReferences() { toReferences() {
let results = []; let results = [];
for (const part of this.m_parts) { for (const part of this.m_parts) {
const rs = part.asReferences(); const rs = part.toReferences();
if (!rs) return null; if (!rs) return null;
for (const c of rs) { for (const c of rs) {
results.push(c); results.push(c);
@ -454,7 +447,7 @@ export class BooleanGeometry extends GeometryBase {
this.m_operands = operands; this.m_operands = operands;
this.m_resolved = null; this.m_resolved = null;
} }
asContours() { toContours() {
if (this.m_resolved) return this.m_resolved; if (this.m_resolved) return this.m_resolved;
this.m_resolved = this.asContoursImpl(); this.m_resolved = this.asContoursImpl();
return this.m_resolved; return this.m_resolved;
@ -487,14 +480,14 @@ export class BooleanGeometry extends GeometryBase {
sink.push({ sink.push({
type: "operand", type: "operand",
fillType: TypoGeom.Boolean.PolyFillType.pftNonZero, fillType: TypoGeom.Boolean.PolyFillType.pftNonZero,
shape: CurveUtil.convertShapeToArcs(operand.asContours()) shape: CurveUtil.convertShapeToArcs(operand.toContours())
}); });
} }
// Push operator if i > 0 // Push operator if i > 0
if (i > 0) sink.push({ type: "operator", operator: this.m_operator }); if (i > 0) sink.push({ type: "operator", operator: this.m_operator });
} }
} }
asReferences() { toReferences() {
return null; return null;
} }
getDependencies() { getDependencies() {
@ -549,11 +542,11 @@ export class StrokeGeometry extends GeometryBase {
this.m_fInside = fInside; this.m_fInside = fInside;
} }
asContours() { toContours() {
// Produce simplified arcs // Produce simplified arcs
const nonTransformedGeometry = new TransformedGeometry(this.m_geom, this.m_gizmo.inverse()); const nonTransformedGeometry = new TransformedGeometry(this.m_geom, this.m_gizmo.inverse());
let arcs = TypoGeom.Boolean.removeOverlap( let arcs = TypoGeom.Boolean.removeOverlap(
CurveUtil.convertShapeToArcs(nonTransformedGeometry.asContours()), CurveUtil.convertShapeToArcs(nonTransformedGeometry.toContours()),
TypoGeom.Boolean.PolyFillType.pftNonZero, TypoGeom.Boolean.PolyFillType.pftNonZero,
CurveUtil.BOOLE_RESOLUTION CurveUtil.BOOLE_RESOLUTION
); );
@ -575,7 +568,7 @@ export class StrokeGeometry extends GeometryBase {
return sink.contours; return sink.contours;
} }
asReferences() { toReferences() {
return null; return null;
} }
getDependencies() { getDependencies() {
@ -622,9 +615,9 @@ export class SimplifyGeometry extends GeometryBase {
super(); super();
this.m_geom = g; this.m_geom = g;
} }
asContours() { toContours() {
// Produce simplified arcs // Produce simplified arcs
let arcs = CurveUtil.convertShapeToArcs(this.m_geom.asContours()); let arcs = CurveUtil.convertShapeToArcs(this.m_geom.toContours());
if (this.m_geom.measureComplexity() & CPLX_NON_SIMPLE) { if (this.m_geom.measureComplexity() & CPLX_NON_SIMPLE) {
arcs = TypoGeom.Boolean.removeOverlap( arcs = TypoGeom.Boolean.removeOverlap(
arcs, arcs,
@ -642,7 +635,7 @@ export class SimplifyGeometry extends GeometryBase {
); );
return sink.contours; return sink.contours;
} }
asReferences() { toReferences() {
return null; return null;
} }
getDependencies() { getDependencies() {

View file

@ -0,0 +1,8 @@
import * as SpiroJs from "spiro";
import * as CurveUtil from "./curve-util.mjs";
export function spiroToOutline(knots, fClosed, gizmo) {
const s = new CurveUtil.BezToContoursSink(gizmo);
SpiroJs.spiroToBezierOnContext(knots, fClosed, s, CurveUtil.GEOMETRY_PRECISION);
return s.contours;
}