From 2a9be6e81598cd3d358fd798712c51a5fba3b6c0 Mon Sep 17 00:00:00 2001 From: be5invis Date: Mon, 19 Feb 2024 17:59:01 -0800 Subject: [PATCH] Minor optimization of references -- now spaces will not be referenced. --- .../font-glyphs/src/letter/latin/lower-y.ptl | 2 +- packages/font-glyphs/src/letter/latin/z.ptl | 2 +- packages/font/src/finalize/index.mjs | 17 +++-- packages/font/src/otd-conv/glyphs.mjs | 75 ++++++++++--------- packages/geometry-cache/src/index.mjs | 2 +- packages/geometry/src/index.mjs | 7 +- 6 files changed, 56 insertions(+), 49 deletions(-) diff --git a/packages/font-glyphs/src/letter/latin/lower-y.ptl b/packages/font-glyphs/src/letter/latin/lower-y.ptl index 01a220014..da716b670 100644 --- a/packages/font-glyphs/src/letter/latin/lower-y.ptl +++ b/packages/font-glyphs/src/letter/latin/lower-y.ptl @@ -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 diff --git a/packages/font-glyphs/src/letter/latin/z.ptl b/packages/font-glyphs/src/letter/latin/z.ptl index 8aa0c3ce2..d4559d86b 100644 --- a/packages/font-glyphs/src/letter/latin/z.ptl +++ b/packages/font-glyphs/src/letter/latin/z.ptl @@ -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 diff --git a/packages/font/src/finalize/index.mjs b/packages/font/src/finalize/index.mjs index dc68812ae..e360bc949 100644 --- a/packages/font/src/finalize/index.mjs +++ b/packages/font/src/finalize/index.mjs @@ -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; -} diff --git a/packages/font/src/otd-conv/glyphs.mjs b/packages/font/src/otd-conv/glyphs.mjs index 6b16c97fe..d2950e15d 100644 --- a/packages/font/src/otd-conv/glyphs.mjs +++ b/packages/font/src/otd-conv/glyphs.mjs @@ -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 + ); +} diff --git a/packages/geometry-cache/src/index.mjs b/packages/geometry-cache/src/index.mjs index b0885a0d4..51c6aa885 100644 --- a/packages/geometry-cache/src/index.mjs +++ b/packages/geometry-cache/src/index.mjs @@ -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) { diff --git a/packages/geometry/src/index.mjs b/packages/geometry/src/index.mjs index 405da8850..dc0cd2b10 100644 --- a/packages/geometry/src/index.mjs +++ b/packages/geometry/src/index.mjs @@ -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];