Format cleanup

This commit is contained in:
be5invis 2022-07-17 00:31:02 -07:00
parent 36835216f5
commit e61edd0db9
13 changed files with 52 additions and 52 deletions

View file

@ -73,7 +73,7 @@ class Cache {
} }
} }
} }
export const load = async function (path, version, freshAgeKey) { export async function load(path, version, freshAgeKey) {
let cache = new Cache(freshAgeKey); let cache = new Cache(freshAgeKey);
if (path && fs.existsSync(path)) { if (path && fs.existsSync(path)) {
try { try {
@ -85,15 +85,15 @@ export const load = async function (path, version, freshAgeKey) {
} }
} }
return cache; return cache;
}; }
export const save = async function savePTCache(path, version, cache, diffOnly) { export async function save(path, version, cache, diffOnly) {
if (path) { if (path) {
const buf = encode(cache.toRep(version, diffOnly)); const buf = encode(cache.toRep(version, diffOnly));
const bufZip = zlib.gzipSync(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength)); const bufZip = zlib.gzipSync(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength));
await fs.promises.writeFile(path, bufZip); await fs.promises.writeFile(path, bufZip);
} }
}; }
export const merge = async function (base, diff, version, freshAgeKey) { export async function merge(base, diff, version, freshAgeKey) {
const cacheDiff = await load(diff, version, freshAgeKey); const cacheDiff = await load(diff, version, freshAgeKey);
if (!cacheDiff.isEmpty()) { if (!cacheDiff.isEmpty()) {
const cacheBase = await load(base, version, freshAgeKey); const cacheBase = await load(base, version, freshAgeKey);
@ -101,4 +101,4 @@ export const merge = async function (base, diff, version, freshAgeKey) {
await save(base, version, cacheBase, false); await save(base, version, cacheBase, false);
} }
if (fs.existsSync(diff)) await fs.promises.rm(diff); if (fs.existsSync(diff)) await fs.promises.rm(diff);
}; }

View file

@ -1,6 +1,6 @@
import { Ot } from "ot-builder"; import { Ot } from "ot-builder";
export const CreateEmptyFont = function (argv) { export function CreateEmptyFont(argv) {
let font = { let font = {
head: new Ot.Head.Table(), head: new Ot.Head.Table(),
hhea: new Ot.MetricHead.Hhea(), hhea: new Ot.MetricHead.Hhea(),
@ -14,4 +14,4 @@ export const CreateEmptyFont = function (argv) {
font.head.modified = new Date(process.env.SOURCE_DATE_EPOCH * 1000); font.head.modified = new Date(process.env.SOURCE_DATE_EPOCH * 1000);
} }
return font; return font;
}; }

View file

@ -139,9 +139,9 @@ function markGlyphsGsubReverse(sink, lookup, cfg) {
function sweep(glyphStore, gnSet) { function sweep(glyphStore, gnSet) {
return glyphStore.filterByName(gnSet); return glyphStore.filterByName(gnSet);
} }
export const gcFont = function (glyphStore, excludedChars, otl, cfg) { export function gcFont(glyphStore, excludedChars, otl, cfg) {
markSweepOtlLookups(otl.GSUB); markSweepOtlLookups(otl.GSUB);
markSweepOtlLookups(otl.GPOS); markSweepOtlLookups(otl.GPOS);
const sink = markGlyphs(glyphStore, excludedChars, otl, cfg); const sink = markGlyphs(glyphStore, excludedChars, otl, cfg);
return sweep(glyphStore, sink); return sweep(glyphStore, sink);
}; }

View file

@ -31,11 +31,11 @@ function validateMonospace(para, glyphStore) {
throw new Error("Unreachable! Building monospace with more than 2 character widths"); throw new Error("Unreachable! Building monospace with more than 2 character widths");
} }
} }
export const finalizeFont = function (cache, para, glyphStore, excludedCodePoints, restFont) { export function finalizeFont(cache, para, glyphStore, excludedCodePoints, restFont) {
assignGrAndCodeRank(glyphStore, Nwid, Wwid); assignGrAndCodeRank(glyphStore, Nwid, Wwid);
assignSubRank(glyphStore); assignSubRank(glyphStore);
glyphStore = gcFont(glyphStore, excludedCodePoints, restFont, {}); glyphStore = gcFont(glyphStore, excludedCodePoints, restFont, {});
glyphStore = finalizeGlyphs(cache, para, glyphStore); glyphStore = finalizeGlyphs(cache, para, glyphStore);
validateMonospace(para, glyphStore); validateMonospace(para, glyphStore);
return glyphStore; return glyphStore;
}; }

View file

@ -27,7 +27,7 @@ class BooleImpl {
); );
} }
} }
export const SetupBuilders = function (bindings) { export function SetupBuilders(bindings) {
const union = (...operands) => const union = (...operands) =>
new BooleImpl(bindings, TypoGeom.Boolean.ClipType.ctUnion, operands); new BooleImpl(bindings, TypoGeom.Boolean.ClipType.ctUnion, operands);
const intersection = (...operands) => const intersection = (...operands) =>
@ -39,4 +39,4 @@ export const SetupBuilders = function (bindings) {
intersection: intersection, intersection: intersection,
difference: difference difference: difference
}; };
}; }

View file

@ -96,7 +96,7 @@ function flattenImpl(sink, knots) {
function nCyclic(p, n) { function nCyclic(p, n) {
return (p + n + n) % n; return (p + n + n) % n;
} }
export const SetupBuilders = function (bindings) { export function SetupBuilders(bindings) {
const { Contrast, GlobalTransform, Stroke, Superness } = bindings; const { Contrast, GlobalTransform, Stroke, Superness } = bindings;
function validateCoord(x) { function validateCoord(x) {
if (!isFinite(x)) throw new TypeError("NaN detected"); if (!isFinite(x)) throw new TypeError("NaN detected");
@ -333,4 +333,4 @@ export const SetupBuilders = function (bindings) {
dispiro, dispiro,
"spiro-outline": spiroOutline "spiro-outline": spiroOutline
}; };
}; }

View file

@ -109,12 +109,12 @@ export class ReverseCurve {
export function convertShapeToArcs(shape) { export function convertShapeToArcs(shape) {
return shape.map(convertContourToArcs); return shape.map(convertContourToArcs);
} }
export const shapeToRep = function (shape) { export function shapeToRep(shape) {
return shape.map(contourToRep); return shape.map(contourToRep);
}; }
export const repToShape = function (shapeRep) { export function repToShape(shapeRep) {
return shapeRep.map(repToContour); return shapeRep.map(repToContour);
}; }
export class BezToContoursSink { export class BezToContoursSink {
constructor(gizmo) { constructor(gizmo) {
this.gizmo = gizmo || Transform.Id(); this.gizmo = gizmo || Transform.Id();

View file

@ -10,7 +10,7 @@ import { Point } from "./point.mjs";
import { SpiroExpander } from "./spiro-expand.mjs"; import { SpiroExpander } from "./spiro-expand.mjs";
import { Transform } from "./transform.mjs"; import { Transform } from "./transform.mjs";
class GeometryBase { export class GeometryBase {
asContours() { asContours() {
throw new Error("Unimplemented"); throw new Error("Unimplemented");
} }
@ -33,7 +33,8 @@ class GeometryBase {
return null; return null;
} }
} }
class ContourGeometry extends GeometryBase {
export class ContourGeometry extends GeometryBase {
constructor(points) { constructor(points) {
super(); super();
this.m_points = []; this.m_points = [];
@ -66,7 +67,8 @@ class ContourGeometry extends GeometryBase {
return Format.struct(`ContourGeometry`, Format.list(this.m_points.map(Format.typedPoint))); return Format.struct(`ContourGeometry`, Format.list(this.m_points.map(Format.typedPoint)));
} }
} }
class SpiroGeometry extends GeometryBase {
export class SpiroGeometry extends GeometryBase {
constructor(gizmo, closed, knots) { constructor(gizmo, closed, knots) {
super(); super();
this.m_knots = []; this.m_knots = [];
@ -108,7 +110,8 @@ class SpiroGeometry extends GeometryBase {
); );
} }
} }
class DiSpiroGeometry extends GeometryBase {
export class DiSpiroGeometry extends GeometryBase {
constructor(gizmo, contrast, closed, biKnots) { constructor(gizmo, contrast, closed, biKnots) {
super(); super();
this.m_biKnots = []; this.m_biKnots = [];
@ -178,7 +181,8 @@ class DiSpiroGeometry extends GeometryBase {
); );
} }
} }
class ReferenceGeometry extends GeometryBase {
export class ReferenceGeometry extends GeometryBase {
constructor(glyph, x, y) { constructor(glyph, x, y) {
super(); super();
if (!glyph || !glyph.geometry) throw new TypeError("Invalid glyph"); if (!glyph || !glyph.geometry) throw new TypeError("Invalid glyph");
@ -220,7 +224,8 @@ class ReferenceGeometry extends GeometryBase {
return Format.struct("ReferenceGeometry", sTarget, Format.n(this.m_x), Format.n(this.m_y)); return Format.struct("ReferenceGeometry", sTarget, Format.n(this.m_x), Format.n(this.m_y));
} }
} }
class TaggedGeometry extends GeometryBase {
export class TaggedGeometry extends GeometryBase {
constructor(g, tag) { constructor(g, tag) {
super(); super();
this.m_geom = g; this.m_geom = g;
@ -249,7 +254,8 @@ class TaggedGeometry extends GeometryBase {
return this.m_geom.toShapeStringOrNull(); return this.m_geom.toShapeStringOrNull();
} }
} }
class TransformedGeometry extends GeometryBase {
export class TransformedGeometry extends GeometryBase {
constructor(g, tfm) { constructor(g, tfm) {
super(); super();
this.m_geom = g; this.m_geom = g;
@ -310,7 +316,8 @@ class TransformedGeometry extends GeometryBase {
return Format.struct("TransformedGeometry", sTarget, Format.gizmo(this.m_transform)); return Format.struct("TransformedGeometry", sTarget, Format.gizmo(this.m_transform));
} }
} }
class CombineGeometry extends GeometryBase {
export class CombineGeometry extends GeometryBase {
constructor(parts) { constructor(parts) {
super(); super();
this.m_parts = parts || []; this.m_parts = parts || [];
@ -380,7 +387,8 @@ class CombineGeometry extends GeometryBase {
return Format.struct("CombineGeometry", Format.list(sParts)); return Format.struct("CombineGeometry", Format.list(sParts));
} }
} }
class BooleanGeometry extends GeometryBase {
export class BooleanGeometry extends GeometryBase {
constructor(operator, operands) { constructor(operator, operands) {
super(); super();
this.m_operator = operator; this.m_operator = operator;
@ -454,25 +462,17 @@ class BooleanGeometry extends GeometryBase {
return Format.struct("BooleanGeometry", this.m_operator, Format.list(sParts)); return Format.struct("BooleanGeometry", this.m_operator, Format.list(sParts));
} }
} }
function combineWith(a, b) {
export function combineWith(a, b) {
if (a instanceof CombineGeometry) { if (a instanceof CombineGeometry) {
return a.with(b); return a.with(b);
} else { } else {
return new CombineGeometry([a, b]); return new CombineGeometry([a, b]);
} }
} }
export const hashGeometry = function (geom) {
export function hashGeometry(geom) {
const s = geom.toShapeStringOrNull(); const s = geom.toShapeStringOrNull();
if (!s) return null; if (!s) return null;
return crypto.createHash("sha256").update(s).digest("hex"); return crypto.createHash("sha256").update(s).digest("hex");
}; }
export { GeometryBase };
export { SpiroGeometry };
export { DiSpiroGeometry };
export { ContourGeometry };
export { ReferenceGeometry };
export { TaggedGeometry };
export { TransformedGeometry };
export { CombineGeometry };
export { BooleanGeometry };
export { combineWith };

View file

@ -8,7 +8,7 @@ function createBuildup(simple, buildup) {
} }
return Array.from(ligSet); return Array.from(ligSet);
} }
export const applyLigationData = function (data, para, argv) { export function applyLigationData(data, para, argv) {
const defaultBuildup = {}; const defaultBuildup = {};
const hives = {}; const hives = {};
hives["default"] = { caltBuildup: [] }; hives["default"] = { caltBuildup: [] };
@ -43,4 +43,4 @@ export const applyLigationData = function (data, para, argv) {
argv.ligations.enables.map(x => `ligset-enable-${x}`) argv.ligations.enables.map(x => `ligset-enable-${x}`)
); );
} }
}; }

View file

@ -5,6 +5,6 @@ export function maskBit(x, y) {
export function maskBits(x, y) { export function maskBits(x, y) {
return x & y; return x & y;
} }
export const popCountByte = function (x) { export function popCountByte(x) {
return pcNibbleLookup[x & 0x0f] + pcNibbleLookup[(x >>> 4) & 0x0f]; return pcNibbleLookup[x & 0x0f] + pcNibbleLookup[(x >>> 4) & 0x0f];
}; }

View file

@ -1,4 +1,4 @@
export const monotonicInterpolate = function (xs, ys) { export function monotonicInterpolate(xs, ys) {
let i, let i,
length = xs.length; length = xs.length;
// Deal with length issues // Deal with length issues
@ -101,4 +101,4 @@ export const monotonicInterpolate = function (xs, ys) {
diffSq = diff * diff; diffSq = diff * diff;
return ys[i] + c1s[i] * diff + c2s[i] * diffSq + c3s[i] * diff * diffSq; return ys[i] + c1s[i] * diff + c2s[i] * diffSq + c3s[i] * diff * diffSq;
}; };
}; }

View file

@ -218,7 +218,7 @@ function buildLigationSet(ligData, getKey) {
} }
return ligationSets; return ligationSets;
} }
export const parseLigationData = async function () { export async function parseLigationData() {
const __dirname = url.fileURLToPath(new URL(".", import.meta.url)); const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
const ligToml = await fs.promises.readFile( const ligToml = await fs.promises.readFile(
path.join(__dirname, "../../params/ligation-set.toml"), path.join(__dirname, "../../params/ligation-set.toml"),
@ -238,4 +238,4 @@ export const parseLigationData = async function () {
sets: [...ligationSets.values()], sets: [...ligationSets.values()],
nonMergeSets: [...nonMergeLigationSets.values()] nonMergeSets: [...nonMergeLigationSets.values()]
}; };
}; }

View file

@ -140,7 +140,7 @@ function uniqueHotChars(cfgDefault, cfgSS) {
} }
return Array.from(s); return Array.from(s);
} }
export const parseVariantsData = async function () { export async function parseVariantsData() {
const __dirname = url.fileURLToPath(new URL(".", import.meta.url)); const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
const variantsToml = await fs.promises.readFile( const variantsToml = await fs.promises.readFile(
path.join(__dirname, "../../params/variants.toml"), path.join(__dirname, "../../params/variants.toml"),
@ -153,4 +153,4 @@ export const parseVariantsData = async function () {
const composites = getSsData(varDatParsed); const composites = getSsData(varDatParsed);
const defaults = getCompWithLens(varDatParsed, null, x => x.composition); const defaults = getCompWithLens(varDatParsed, null, x => x.composition);
return { primes, composites, specials, defaults }; return { primes, composites, specials, defaults };
}; }