Minor optimization of references -- now spaces will not be referenced.

This commit is contained in:
be5invis 2024-02-19 17:59:01 -08:00
parent 6459be6f68
commit 2a9be6e815
6 changed files with 56 additions and 49 deletions

View file

@ -1,7 +1,7 @@
$$include '../../meta/macros.ptl'
import [mix linreg fallback SuffixCfg] from "@iosevka/util"
import [LowerYDotAtBelow Dotless CvDecompose MathSansSerif OgonekTrY] from "@iosevka/glyph/relation"
import [LowerYDotAtBelow Dotless MathSansSerif OgonekTrY] from "@iosevka/glyph/relation"
glyph-module

View file

@ -1,7 +1,7 @@
$$include '../../meta/macros.ptl'
import [mix SuffixCfg fallback] from "@iosevka/util"
import [CvDecompose MathSansSerif] from "@iosevka/glyph/relation"
import [MathSansSerif] from "@iosevka/glyph/relation"
glyph-module

View file

@ -3,6 +3,15 @@ import { Nwid, Wwid } from "@iosevka/glyph/relation";
import { gcFont } from "./gc.mjs";
import { finalizeGlyphs } from "./glyphs.mjs";
export function finalizeFont(cache, para, glyphStore, excludedCodePoints, restFont) {
assignGrAndCodeRank(glyphStore, Wwid, Nwid);
assignSubRank(glyphStore);
glyphStore = gcFont(glyphStore, excludedCodePoints, restFont);
glyphStore = finalizeGlyphs(cache, para, glyphStore);
validateMonospace(para, glyphStore);
return glyphStore;
}
function assignGrAndCodeRank(glyphStore, ...flatteners) {
for (const g of glyphStore.glyphs()) {
g.codeRank = 0xffffffff;
@ -32,11 +41,3 @@ function validateMonospace(para, glyphStore) {
throw new Error("Unreachable! Building monospace with more than 2 character widths");
}
}
export function finalizeFont(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;
}

View file

@ -5,14 +5,36 @@ import { Ot } from "ot-builder";
import * as GlyphName from "./glyph-name.mjs";
function byRank([gna, a], [gnb, b]) {
return (
b.glyphRank - a.glyphRank ||
a.grRank - b.grRank ||
a.codeRank - b.codeRank ||
a.subRank - b.subRank
);
export function convertGlyphs(gsOrig) {
const sortedEntries = Array.from(gsOrig.namedEntries(Gr.Nwid, Gr.Wwid)).sort(byRank);
const gs = new MappedGlyphStore();
const cmap = new Ot.Cmap.Table();
// initialize
for (const [name, gSrc] of sortedEntries) {
gs.declare(name, gSrc);
const us = gsOrig.queryUnicodeOf(gSrc);
if (us) {
for (const u of us) {
if (!(isFinite(u - 0) && u)) continue;
cmap.unicode.set(u, gs.queryBySourceGlyph(gSrc));
gs.setPrimaryUnicode(gSrc, u);
}
}
}
// fill geometry
for (const [name, gSrc] of sortedEntries) gs.fill(name, gSrc);
// fill VS
addVsLinks(gsOrig, gs, cmap, Gr.VS01, 0xfe00);
// fill glyph names
gs.fillOtGlyphNames();
return { glyphs: gs, cmap };
}
class MappedGlyphStore {
constructor() {
this.m_nameMapping = new Map();
@ -150,36 +172,6 @@ class MappedGlyphStore {
}
}
export function convertGlyphs(gsOrig) {
const sortedEntries = Array.from(gsOrig.namedEntries(Gr.Nwid, Gr.Wwid)).sort(byRank);
const gs = new MappedGlyphStore();
const cmap = new Ot.Cmap.Table();
// initialize
for (const [name, gSrc] of sortedEntries) {
gs.declare(name, gSrc);
const us = gsOrig.queryUnicodeOf(gSrc);
if (us) {
for (const u of us) {
if (!(isFinite(u - 0) && u)) continue;
cmap.unicode.set(u, gs.queryBySourceGlyph(gSrc));
gs.setPrimaryUnicode(gSrc, u);
}
}
}
// fill geometry
for (const [name, gSrc] of sortedEntries) gs.fill(name, gSrc);
// fill VS
addVsLinks(gsOrig, gs, cmap, Gr.VS01, 0xfe00);
// fill glyph names
gs.fillOtGlyphNames();
return { glyphs: gs, cmap };
}
function addVsLinks(gsOrig, gs, cmap, gr, vs) {
for (const gSrc of gsOrig.glyphs()) {
const us = gsOrig.queryUnicodeOf(gSrc);
@ -200,3 +192,12 @@ function addVsLinks(gsOrig, gs, cmap, gr, vs) {
}
}
}
function byRank([gna, a], [gnb, b]) {
return (
b.glyphRank - a.glyphRank ||
a.grRank - b.grRank ||
a.codeRank - b.codeRank ||
a.subRank - b.subRank
);
}

View file

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

View file

@ -217,7 +217,12 @@ export class ReferenceGeometry extends GeometryBase {
return this.unwrap().asContours();
}
asReferences() {
return [{ glyph: this.m_glyph, x: this.m_x, y: this.m_y }];
if (this.m_glyph.geometry.measureComplexity() & CPLX_NON_EMPTY) {
return [{ glyph: this.m_glyph, x: this.m_x, y: this.m_y }];
} else {
// A reference to a space is meaningless, thus return nothing
return [];
}
}
getDependencies() {
return [this.m_glyph];