Initial work of ESM transformation

This commit is contained in:
be5invis 2022-07-16 19:26:49 -07:00
parent 2472c9cff2
commit b8205a63aa
303 changed files with 1959 additions and 2450 deletions

View file

@ -1,13 +1,4 @@
"use strict";
const { Radical } = require("../../support/gr");
exports.gcFont = function (glyphStore, excludedChars, otl, cfg) {
markSweepOtlLookups(otl.GSUB);
markSweepOtlLookups(otl.GPOS);
const sink = markGlyphs(glyphStore, excludedChars, otl, cfg);
return sweep(glyphStore, sink);
};
import { Radical } from "../../support/gr.mjs";
function markSweepOtlLookups(table) {
if (!table || !table.features || !table.lookups) return;
@ -65,7 +56,6 @@ function sweepFeatures(table, accessibleLookupsIds) {
}
table.features = features1;
}
function markGlyphs(glyphStore, excludedChars, otl, cfg) {
const sink = markGlyphsInitial(glyphStore, excludedChars);
while (markGlyphsStep(glyphStore, sink, otl, cfg));
@ -88,7 +78,6 @@ function markGlyphsInitial(glyphStore, excludedChars) {
}
function markGlyphsStep(glyphStore, sink, otl, cfg) {
const glyphCount = sink.size;
if (otl.GSUB) {
for (const l in otl.GSUB.lookups) {
const lookup = otl.GSUB.lookups[l];
@ -99,7 +88,6 @@ function markGlyphsStep(glyphStore, sink, otl, cfg) {
const glyphCount1 = sink.size;
return glyphCount1 > glyphCount;
}
function markGlyphsLookupImpl(sink, lookup, cfg) {
switch (lookup.type) {
case "gsub_single":
@ -116,7 +104,6 @@ function markGlyphsLookupImpl(sink, lookup, cfg) {
return markGlyphsGsubReverse(sink, lookup, cfg);
}
}
function markGlyphsGsubSingle(sink, lookup, cfg) {
const st = lookup.substitutions;
for (const k in st) if (sink.has(k) && st[k]) sink.add(st[k]);
@ -149,7 +136,12 @@ function markGlyphsGsubReverse(sink, lookup, cfg) {
}
}
}
function sweep(glyphStore, gnSet) {
return glyphStore.filterByName(gnSet);
}
export const gcFont = function (glyphStore, excludedChars, otl, cfg) {
markSweepOtlLookups(otl.GSUB);
markSweepOtlLookups(otl.GPOS);
const sink = markGlyphs(glyphStore, excludedChars, otl, cfg);
return sweep(glyphStore, sink);
};

View file

@ -1,19 +1,10 @@
"use strict";
const TypoGeom = require("typo-geom");
const Geom = require("../../support/geometry/index");
const { Point } = require("../../support/geometry/point");
const { Transform } = require("../../support/geometry/transform");
const CurveUtil = require("../../support/geometry/curve-util");
exports.finalizeGlyphs = function finalizeGlyphs(cache, para, glyphStore) {
const skew = Math.tan(((para.slopeAngle || 0) / 180) * Math.PI);
regulateGlyphStore(cache, skew, glyphStore);
return glyphStore;
};
import * as TypoGeom from "typo-geom";
import * as Geom from "../../support/geometry/index.mjs";
import { Point } from "../../support/geometry/point.mjs";
import { Transform } from "../../support/geometry/transform.mjs";
import * as CurveUtil from "../../support/geometry/curve-util.mjs";
///////////////////////////////////////////////////////////////////////////////////////////////////
function regulateGlyphStore(cache, skew, glyphStore) {
const compositeMemo = new Map();
for (const g of glyphStore.glyphs()) {
@ -26,24 +17,19 @@ function regulateGlyphStore(cache, skew, glyphStore) {
if (!compositeMemo.get(g)) flattenSimpleGlyph(cache, skew, g);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
function memoSet(memo, g, v) {
memo.set(g, v);
return v;
}
function regulateCompositeGlyph(glyphStore, memo, g) {
if (memo.has(g)) return memo.get(g);
let refs = g.geometry.asReferences();
if (!refs) return memoSet(memo, g, false);
for (const sr of refs) {
const gn = glyphStore.queryNameOf(sr.glyph);
if (!gn) return memoSet(memo, g, false);
}
// De-doppelganger
while (refs.length === 1 && regulateCompositeGlyph(glyphStore, memo, refs[0].glyph)) {
const sr = refs[0];
@ -54,10 +40,8 @@ function regulateCompositeGlyph(glyphStore, memo, g) {
}
refs = g.geometry.asReferences();
}
return memoSet(memo, g, true);
}
function flattenSimpleGlyph(cache, skew, g) {
const ck = Geom.hashGeometry(g.geometry);
const cached = cache.getGF(ck);
@ -78,9 +62,7 @@ function flattenSimpleGlyph(cache, skew, g) {
if (ck) cache.saveGF(ck, CurveUtil.shapeToRep(cs));
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
class SimplifyGeometry extends Geom.GeometryBase {
constructor(g) {
super();
@ -120,7 +102,6 @@ class SimplifyGeometry extends Geom.GeometryBase {
return `SimplifyGeometry{${sTarget}}`;
}
}
class FairizedShapeSink {
constructor() {
this.contours = [];
@ -153,7 +134,6 @@ class FairizedShapeSink {
}
this.lineTo(x, y);
}
// Contour cleaning code
alignHVKnots(c0) {
const c = c0.slice(0);
@ -224,11 +204,9 @@ class FairizedShapeSink {
c.length = n;
lengthAfter = c.length;
} while (lengthAfter < lengthBefore);
return c;
}
}
// Disjoint set for coordinate alignment
class CoordinateAligner {
constructor(c, lens, lensSet) {
@ -268,12 +246,10 @@ class CoordinateAligner {
}
}
}
const GetX = z => z.x;
const SetX = (z, x) => (z.x = x);
const GetY = z => z.y;
const SetY = (z, y) => (z.y = y);
function isOccurrent(zFirst, zLast) {
return (
zFirst.type === Point.Type.Corner &&
@ -291,3 +267,8 @@ function aligned(a, b, c) {
function between(a, b, c) {
return (a <= b && b <= c) || (a >= b && b >= c);
}
export function finalizeGlyphs(cache, para, glyphStore) {
const skew = Math.tan(((para.slopeAngle || 0) / 180) * Math.PI);
regulateGlyphStore(cache, skew, glyphStore);
return glyphStore;
}

View file

@ -1,23 +1,11 @@
"use strict";
const { finalizeGlyphs } = require("./glyphs");
const { gcFont } = require("./gc");
const { Nwid, Wwid } = require("../../support/gr");
exports.finalizeFont = function (cache, para, glyphStore, excludedCodePoints, restFont) {
assignGrAndCodeRank(glyphStore, Nwid, Wwid);
assignSubRank(glyphStore);
glyphStore = gcFont(glyphStore, excludedCodePoints, restFont, {});
glyphStore = finalizeGlyphs(cache, para, glyphStore);
validateMonospace(para, glyphStore);
return glyphStore;
};
import { finalizeGlyphs } from "./glyphs.mjs";
import { gcFont } from "./gc.mjs";
import { Nwid, Wwid } from "../../support/gr.mjs";
function assignGrAndCodeRank(glyphStore, ...flatteners) {
for (const g of glyphStore.glyphs()) {
g.codeRank = 0xffffffff;
for (const c of glyphStore.flattenCodes(g, flatteners)) if (c < g.codeRank) g.codeRank = c;
g.grRank = 0;
for (let i = 0; i < flatteners.length; i++) if (flatteners[i].get(g)) g.grRank |= 1 << i;
}
@ -26,7 +14,6 @@ function assignSubRank(glyphStore) {
let sr = 0;
for (const g of glyphStore.glyphs()) g.subRank = sr++;
}
// In FontConfig, a font is considered "monospace" if and only if all non-combining characters
// (AW > 0) have the same width. We use this method to validate whether our "Fixed" subfamilies
// are properly built.
@ -43,3 +30,11 @@ function validateMonospace(para, glyphStore) {
throw new Error("Unreachable! Building monospace with more than 2 character widths");
}
}
export const finalizeFont = function (cache, para, glyphStore, excludedCodePoints, restFont) {
assignGrAndCodeRank(glyphStore, Nwid, Wwid);
assignSubRank(glyphStore);
glyphStore = gcFont(glyphStore, excludedCodePoints, restFont, {});
glyphStore = finalizeGlyphs(cache, para, glyphStore);
validateMonospace(para, glyphStore);
return glyphStore;
};