More cleanup
This commit is contained in:
parent
c6fa4342a1
commit
f72b039ec4
8 changed files with 58 additions and 57 deletions
|
@ -47,7 +47,7 @@ glyph-block Symbol-Geometric-Plain : for-width-kinds WideWidth1
|
|||
begin 0
|
||||
local outlines : glyph-proc : begin
|
||||
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 b c.(j)
|
||||
include : dispiro
|
||||
|
|
|
@ -30,7 +30,7 @@ glyph-block Symbol-Math-APL : begin
|
|||
|
||||
local corners : new-glyph : glyph-proc
|
||||
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
|
||||
define x z.x
|
||||
define y z.y
|
||||
|
|
|
@ -242,7 +242,7 @@ function analyzeReferenceGraph(glyphStore, markedGlyphs) {
|
|||
function traverseReferenceTree(depthMap, aliasMap, g, d) {
|
||||
depthMapSet(depthMap, g, d);
|
||||
|
||||
let refs = g.geometry.asReferences();
|
||||
let refs = g.geometry.toReferences();
|
||||
if (!refs) return;
|
||||
|
||||
for (const sr of refs) {
|
||||
|
@ -359,7 +359,7 @@ function rectifyGlyphAndMarkComponents(glyphStore, aliasMap, markedGlyphs, memo,
|
|||
if (memo.has(g)) return;
|
||||
memo.add(g);
|
||||
|
||||
let refs = g.geometry.asReferences();
|
||||
let refs = g.geometry.toReferences();
|
||||
if (refs) {
|
||||
let parts = [];
|
||||
for (let sr of refs) {
|
||||
|
|
|
@ -29,7 +29,7 @@ function regulateGlyphStore(cache, skew, glyphStore) {
|
|||
function regulateCompositeGlyph(glyphStore, memo, 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);
|
||||
|
||||
for (const sr of refs) {
|
||||
|
@ -71,7 +71,7 @@ function flattenSimpleGlyph(cache, skew, g) {
|
|||
gSimplified = new Geom.SimplifyGeometry(g.geometry);
|
||||
}
|
||||
|
||||
const cs = gSimplified.asContours();
|
||||
const cs = gSimplified.toContours();
|
||||
g.clearGeometry();
|
||||
g.includeContours(cs);
|
||||
if (ck) cache.saveGF(ck, cs);
|
||||
|
|
|
@ -70,11 +70,11 @@ class MappedGlyphStore {
|
|||
|
||||
// Fill Geometry
|
||||
if (source.geometry.measureComplexity() & Geom.CPLX_NON_EMPTY) {
|
||||
const rs = source.geometry.asReferences();
|
||||
const rs = source.geometry.toReferences();
|
||||
if (rs) {
|
||||
this.fillReferences(g, rs);
|
||||
} else {
|
||||
this.fillContours(g, source.geometry.asContours());
|
||||
this.fillContours(g, source.geometry.toContours());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import zlib from "zlib";
|
|||
import * as CurveUtil from "@iosevka/geometry/curve-util";
|
||||
import { encode, decode } from "@msgpack/msgpack";
|
||||
|
||||
const Edition = 35;
|
||||
const Edition = 36;
|
||||
const MAX_AGE = 16;
|
||||
class GfEntry {
|
||||
constructor(age, value) {
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import crypto from "crypto";
|
||||
|
||||
import * as Format from "@iosevka/util/formatter";
|
||||
import * as SpiroJs from "spiro";
|
||||
import * as TypoGeom from "typo-geom";
|
||||
|
||||
import * as CurveUtil from "./curve-util.mjs";
|
||||
import { Point } from "./point.mjs";
|
||||
import { QuadifySink } from "./quadify.mjs";
|
||||
import { SpiroExpander } from "./spiro-expand.mjs";
|
||||
import { spiroToOutline } from "./spiro-to-outline.mjs";
|
||||
import { strokeArcs } from "./stroke.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 class GeometryBase {
|
||||
asContours() {
|
||||
toContours() {
|
||||
throw new Error("Unimplemented");
|
||||
}
|
||||
asReferences() {
|
||||
toReferences() {
|
||||
throw new Error("Unimplemented");
|
||||
}
|
||||
getDependencies() {
|
||||
|
@ -47,10 +47,10 @@ export class ContourSetGeometry extends GeometryBase {
|
|||
super();
|
||||
this.m_contours = contours;
|
||||
}
|
||||
asContours() {
|
||||
toContours() {
|
||||
return this.m_contours;
|
||||
}
|
||||
asReferences() {
|
||||
toReferences() {
|
||||
return null;
|
||||
}
|
||||
getDependencies() {
|
||||
|
@ -84,19 +84,12 @@ export class SpiroGeometry extends GeometryBase {
|
|||
this.m_gizmo = gizmo;
|
||||
this.m_cachedContours = null;
|
||||
}
|
||||
asContours() {
|
||||
toContours() {
|
||||
if (this.m_cachedContours) return this.m_cachedContours;
|
||||
const s = new CurveUtil.BezToContoursSink(this.m_gizmo);
|
||||
SpiroJs.spiroToBezierOnContext(
|
||||
this.m_knots,
|
||||
this.m_closed,
|
||||
s,
|
||||
CurveUtil.GEOMETRY_PRECISION
|
||||
);
|
||||
this.m_cachedContours = s.contours;
|
||||
this.m_cachedContours = spiroToOutline(this.m_knots, this.m_closed, this.m_gizmo);
|
||||
return this.m_cachedContours;
|
||||
}
|
||||
asReferences() {
|
||||
toReferences() {
|
||||
return null;
|
||||
}
|
||||
getDependencies() {
|
||||
|
@ -132,7 +125,7 @@ export class DiSpiroGeometry extends GeometryBase {
|
|||
this.m_cachedExpansionResults = null;
|
||||
this.m_cachedContours = null;
|
||||
}
|
||||
asContours() {
|
||||
toContours() {
|
||||
if (this.m_cachedContours) return this.m_cachedContours;
|
||||
const expandResult = this.expand();
|
||||
const lhs = [...expandResult.lhsUntransformed];
|
||||
|
@ -141,9 +134,9 @@ export class DiSpiroGeometry extends GeometryBase {
|
|||
for (const k of rhs) k.reverseType();
|
||||
rhs.reverse();
|
||||
|
||||
let rawGeometry;
|
||||
let outlineGeometry;
|
||||
if (this.m_closed) {
|
||||
rawGeometry = new CombineGeometry([
|
||||
outlineGeometry = new CombineGeometry([
|
||||
new SpiroGeometry(this.m_gizmo, true, lhs),
|
||||
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";
|
||||
rhs[0].type = rhs[rhs.length - 1].type = "corner";
|
||||
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;
|
||||
}
|
||||
expand() {
|
||||
|
@ -172,7 +165,7 @@ export class DiSpiroGeometry extends GeometryBase {
|
|||
this.m_cachedExpansionResults = expander.expand();
|
||||
return this.m_cachedExpansionResults;
|
||||
}
|
||||
asReferences() {
|
||||
toReferences() {
|
||||
return null;
|
||||
}
|
||||
getDependencies() {
|
||||
|
@ -213,10 +206,10 @@ export class ReferenceGeometry extends GeometryBase {
|
|||
Transform.Translate(this.m_x, this.m_y)
|
||||
);
|
||||
}
|
||||
asContours() {
|
||||
return this.unwrap().asContours();
|
||||
toContours() {
|
||||
return this.unwrap().toContours();
|
||||
}
|
||||
asReferences() {
|
||||
toReferences() {
|
||||
if (this.m_glyph.geometry.measureComplexity() & CPLX_NON_EMPTY) {
|
||||
return [{ glyph: this.m_glyph, x: this.m_x, y: this.m_y }];
|
||||
} else {
|
||||
|
@ -249,11 +242,11 @@ export class TaggedGeometry extends GeometryBase {
|
|||
this.m_geom = g;
|
||||
this.m_tag = tag;
|
||||
}
|
||||
asContours() {
|
||||
return this.m_geom.asContours();
|
||||
toContours() {
|
||||
return this.m_geom.toContours();
|
||||
}
|
||||
asReferences() {
|
||||
return this.m_geom.asReferences();
|
||||
toReferences() {
|
||||
return this.m_geom.toReferences();
|
||||
}
|
||||
getDependencies() {
|
||||
return this.m_geom.getDependencies();
|
||||
|
@ -279,18 +272,18 @@ export class TransformedGeometry extends GeometryBase {
|
|||
this.m_geom = g;
|
||||
this.m_transform = tfm;
|
||||
}
|
||||
asContours() {
|
||||
toContours() {
|
||||
let result = [];
|
||||
for (const c of this.m_geom.asContours()) {
|
||||
for (const c of this.m_geom.toContours()) {
|
||||
let c1 = [];
|
||||
for (const z of c) c1.push(Point.transformed(this.m_transform, z));
|
||||
result.push(c1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
asReferences() {
|
||||
toReferences() {
|
||||
if (!Transform.isTranslate(this.m_transform)) return null;
|
||||
const rs = this.m_geom.asReferences();
|
||||
const rs = this.m_geom.toReferences();
|
||||
if (!rs) return null;
|
||||
let result = [];
|
||||
for (const { glyph, x, y } of rs)
|
||||
|
@ -343,10 +336,10 @@ export class RadicalGeometry extends GeometryBase {
|
|||
super();
|
||||
this.m_geom = g;
|
||||
}
|
||||
asContours() {
|
||||
return this.m_geom.asContours();
|
||||
toContours() {
|
||||
return this.m_geom.toContours();
|
||||
}
|
||||
asReferences() {
|
||||
toReferences() {
|
||||
return null;
|
||||
}
|
||||
getDependencies() {
|
||||
|
@ -382,19 +375,19 @@ export class CombineGeometry extends GeometryBase {
|
|||
return new CombineGeometry([...this.m_parts, g]);
|
||||
}
|
||||
}
|
||||
asContours() {
|
||||
toContours() {
|
||||
let results = [];
|
||||
for (const part of this.m_parts) {
|
||||
for (const c of part.asContours()) {
|
||||
for (const c of part.toContours()) {
|
||||
results.push(c);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
asReferences() {
|
||||
toReferences() {
|
||||
let results = [];
|
||||
for (const part of this.m_parts) {
|
||||
const rs = part.asReferences();
|
||||
const rs = part.toReferences();
|
||||
if (!rs) return null;
|
||||
for (const c of rs) {
|
||||
results.push(c);
|
||||
|
@ -454,7 +447,7 @@ export class BooleanGeometry extends GeometryBase {
|
|||
this.m_operands = operands;
|
||||
this.m_resolved = null;
|
||||
}
|
||||
asContours() {
|
||||
toContours() {
|
||||
if (this.m_resolved) return this.m_resolved;
|
||||
this.m_resolved = this.asContoursImpl();
|
||||
return this.m_resolved;
|
||||
|
@ -487,14 +480,14 @@ export class BooleanGeometry extends GeometryBase {
|
|||
sink.push({
|
||||
type: "operand",
|
||||
fillType: TypoGeom.Boolean.PolyFillType.pftNonZero,
|
||||
shape: CurveUtil.convertShapeToArcs(operand.asContours())
|
||||
shape: CurveUtil.convertShapeToArcs(operand.toContours())
|
||||
});
|
||||
}
|
||||
// Push operator if i > 0
|
||||
if (i > 0) sink.push({ type: "operator", operator: this.m_operator });
|
||||
}
|
||||
}
|
||||
asReferences() {
|
||||
toReferences() {
|
||||
return null;
|
||||
}
|
||||
getDependencies() {
|
||||
|
@ -549,11 +542,11 @@ export class StrokeGeometry extends GeometryBase {
|
|||
this.m_fInside = fInside;
|
||||
}
|
||||
|
||||
asContours() {
|
||||
toContours() {
|
||||
// Produce simplified arcs
|
||||
const nonTransformedGeometry = new TransformedGeometry(this.m_geom, this.m_gizmo.inverse());
|
||||
let arcs = TypoGeom.Boolean.removeOverlap(
|
||||
CurveUtil.convertShapeToArcs(nonTransformedGeometry.asContours()),
|
||||
CurveUtil.convertShapeToArcs(nonTransformedGeometry.toContours()),
|
||||
TypoGeom.Boolean.PolyFillType.pftNonZero,
|
||||
CurveUtil.BOOLE_RESOLUTION
|
||||
);
|
||||
|
@ -575,7 +568,7 @@ export class StrokeGeometry extends GeometryBase {
|
|||
|
||||
return sink.contours;
|
||||
}
|
||||
asReferences() {
|
||||
toReferences() {
|
||||
return null;
|
||||
}
|
||||
getDependencies() {
|
||||
|
@ -622,9 +615,9 @@ export class SimplifyGeometry extends GeometryBase {
|
|||
super();
|
||||
this.m_geom = g;
|
||||
}
|
||||
asContours() {
|
||||
toContours() {
|
||||
// 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) {
|
||||
arcs = TypoGeom.Boolean.removeOverlap(
|
||||
arcs,
|
||||
|
@ -642,7 +635,7 @@ export class SimplifyGeometry extends GeometryBase {
|
|||
);
|
||||
return sink.contours;
|
||||
}
|
||||
asReferences() {
|
||||
toReferences() {
|
||||
return null;
|
||||
}
|
||||
getDependencies() {
|
||||
|
|
8
packages/geometry/src/spiro-to-outline.mjs
Normal file
8
packages/geometry/src/spiro-to-outline.mjs
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue