@weasel-js/font 1.13.0 → 1.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-GQJL6VVQ.js → chunk-EQD3U7KB.js} +28 -14
- package/dist/chunk-EQD3U7KB.js.map +1 -0
- package/dist/index.d.ts +12 -7
- package/dist/index.js +33 -14
- package/dist/index.js.map +1 -1
- package/dist/{test-seams-CjRs8Yvp.d.ts → test-seams-BZPEYFPZ.d.ts} +2 -3
- package/dist/test-seams.d.ts +1 -1
- package/dist/test-seams.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-GQJL6VVQ.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { loadFontOutlines, outlineMetrics, fontPending, fallbackWarningClaimed, claimFallbackWarning, resolveGlyphFallback, registerFontOutlines, createOpenTypeParser, getFont, SDF_RADIUS, BAKE_SIZE, PAGE_SIZE } from './chunk-
|
|
2
|
-
export { DEFAULT_BAKE_BUDGET, PAGE_SIZE as DYNAMIC_PAGE_SIZE, MAX_SHARP_LEVEL, colorPageTextureId, cssFontFamily, cssFontFamilyLoading, dynamicPageTextureId, ensureFontTexture, faceGeneration, faceMetricsFor, fontOutlineRegistry, fontPending, fontRegistry, getDefaultFontFamily, getFont, getFontFallbackPolicy, glyphGeneration, glyphOutline, hasFontOutlines, isCanvasFont, listCanvasFonts, listFontOutlines, listFontWeights, listFonts, loadFontOutlines, markAllFontsNotUploaded, outlineMetrics, outlineStatus, refreshCanvasFont, registerCanvasFont, registerFont, registerFontOutlines, resetBakeBudget, resolveFontVariant, resolveGlyphFallback, setDefaultFontFamily, setFontFallbackPolicy, sharpColorPageTextureId, sharperColorGlyph, subscribeGlyphReady, syncColorPageTexture, syncDynamicPageTexture, syncSharpColorPageTexture, textureCacheKey, unregisterCanvasFont, unregisterFontOutlines, warmFonts } from './chunk-
|
|
1
|
+
import { loadFontOutlines, outlineMetrics, fontPending, fallbackWarningClaimed, claimFallbackWarning, resolveGlyphFallback, registerFontOutlines, createOpenTypeParser, getFont, SDF_RADIUS, BAKE_SIZE, PAGE_SIZE } from './chunk-EQD3U7KB.js';
|
|
2
|
+
export { DEFAULT_BAKE_BUDGET, PAGE_SIZE as DYNAMIC_PAGE_SIZE, MAX_SHARP_LEVEL, colorPageTextureId, cssFontFamily, cssFontFamilyLoading, dynamicPageTextureId, ensureFontTexture, faceGeneration, faceMetricsFor, fontOutlineRegistry, fontPending, fontRegistry, getDefaultFontFamily, getFont, getFontFallbackPolicy, glyphGeneration, glyphOutline, hasFontOutlines, isCanvasFont, listCanvasFonts, listFontOutlines, listFontWeights, listFonts, loadFontOutlines, markAllFontsNotUploaded, outlineMetrics, outlineStatus, refreshCanvasFont, registerCanvasFont, registerFont, registerFontOutlines, resetBakeBudget, resolveFontVariant, resolveGlyphFallback, setDefaultFontFamily, setFontFallbackPolicy, sharpColorPageTextureId, sharperColorGlyph, subscribeGlyphReady, syncColorPageTexture, syncDynamicPageTexture, syncSharpColorPageTexture, textureCacheKey, unregisterCanvasFont, unregisterFontOutlines, warmFonts } from './chunk-EQD3U7KB.js';
|
|
3
3
|
export { FIXTURE_FONT, cssFamilyName, faceMetricsFromTables, faceMetricsOf, parseBmFont, verticalMetricsFromTables } from './chunk-XQPRAGHF.js';
|
|
4
4
|
|
|
5
5
|
// src/outline/fontEmbedding.ts
|
|
@@ -37,9 +37,18 @@ function usableGlyph(glyph) {
|
|
|
37
37
|
return glyph.xadvance > 0 || glyph.width > 0 || glyph.page < 0 || isDefaultIgnorable(glyph.id);
|
|
38
38
|
}
|
|
39
39
|
function atlasMetrics(font, advanceOf) {
|
|
40
|
+
let seen = null;
|
|
41
|
+
let ascent = 0.5;
|
|
42
|
+
let descent;
|
|
40
43
|
const stated = () => {
|
|
41
44
|
const face = font.faceMetrics;
|
|
42
|
-
|
|
45
|
+
if (face !== seen) {
|
|
46
|
+
seen = face;
|
|
47
|
+
const has = face?.ascent !== void 0 && face.descent !== void 0;
|
|
48
|
+
ascent = has ? face.ascent * font.info.size : 0.5;
|
|
49
|
+
descent = has ? face.descent * font.info.size : void 0;
|
|
50
|
+
}
|
|
51
|
+
return descent !== void 0;
|
|
43
52
|
};
|
|
44
53
|
return {
|
|
45
54
|
size: font.info.size,
|
|
@@ -47,12 +56,10 @@ function atlasMetrics(font, advanceOf) {
|
|
|
47
56
|
return font.common.base;
|
|
48
57
|
},
|
|
49
58
|
get ascent() {
|
|
50
|
-
|
|
51
|
-
return face ? face.ascent * font.info.size : font.common.base;
|
|
59
|
+
return stated() ? ascent : font.common.base;
|
|
52
60
|
},
|
|
53
61
|
get descent() {
|
|
54
|
-
|
|
55
|
-
return face && face.descent * font.info.size;
|
|
62
|
+
return stated() ? descent : void 0;
|
|
56
63
|
},
|
|
57
64
|
advanceOf,
|
|
58
65
|
kernOf: (l, r) => font.kerningMap.get(l)?.get(r) ?? 0
|
|
@@ -121,24 +128,33 @@ function warnNoMetrics(family, weight, style) {
|
|
|
121
128
|
}
|
|
122
129
|
|
|
123
130
|
// src/resolveGlyph.ts
|
|
124
|
-
function glyphIn(resolved, cp) {
|
|
131
|
+
function glyphIn(resolved, cp, into) {
|
|
125
132
|
const metrics = metricsOf(resolved);
|
|
126
133
|
if (!metrics) return null;
|
|
127
134
|
if (resolved.outlineFace) {
|
|
128
135
|
const advance = metrics.advanceOf(cp);
|
|
129
|
-
return advance === null ? null :
|
|
136
|
+
return advance === null ? null : answer(into, resolved, metrics, advance, null, null);
|
|
130
137
|
}
|
|
131
138
|
const face = resolved.dynamicFace;
|
|
132
139
|
const font = resolved.entry?.font ?? face?.font;
|
|
133
140
|
const glyph = resolved.entry ? font?.charMap.get(cp) : face?.requestGlyph(cp);
|
|
134
141
|
if (!font || !glyph || face && !usableGlyph(glyph)) return null;
|
|
135
|
-
return
|
|
142
|
+
return answer(into, resolved, metrics, glyph.xadvance, font, glyph);
|
|
136
143
|
}
|
|
137
|
-
function
|
|
138
|
-
|
|
144
|
+
function answer(into, resolved, metrics, advance, font, glyph) {
|
|
145
|
+
if (!into) return { resolved, metrics, advance, font, glyph };
|
|
146
|
+
into.resolved = resolved;
|
|
147
|
+
into.metrics = metrics;
|
|
148
|
+
into.advance = advance;
|
|
149
|
+
into.font = font;
|
|
150
|
+
into.glyph = glyph;
|
|
151
|
+
return into;
|
|
152
|
+
}
|
|
153
|
+
function resolveGlyph(resolved, family, weight, style, cp, warn = true, into) {
|
|
154
|
+
const own = glyphIn(resolved, cp, into);
|
|
139
155
|
if (own) return own;
|
|
140
156
|
const fallback = resolveGlyphFallback(family, weight, style);
|
|
141
|
-
const escalated = fallback && glyphIn(fallback, cp);
|
|
157
|
+
const escalated = fallback && glyphIn(fallback, cp, into);
|
|
142
158
|
if (escalated) return escalated;
|
|
143
159
|
if (warn) warnMissingGlyph(resolved.resolved.family, cp);
|
|
144
160
|
return null;
|
|
@@ -254,8 +270,11 @@ function glyphFieldScale(source, family, weight, style) {
|
|
|
254
270
|
const font = getFont(family, weight, style)?.font;
|
|
255
271
|
if (!font) return void 0;
|
|
256
272
|
const range = font.distanceRange ?? DEFAULT_MSDF_RANGE;
|
|
257
|
-
|
|
273
|
+
const u = font.common.scaleW / range, v = font.common.scaleH / range;
|
|
274
|
+
if (lastFieldScale[0] !== u || lastFieldScale[1] !== v) lastFieldScale = [u, v];
|
|
275
|
+
return lastFieldScale;
|
|
258
276
|
}
|
|
277
|
+
var lastFieldScale = [NaN, NaN];
|
|
259
278
|
var SYNTH_BOLD_AMOUNT = 0.08;
|
|
260
279
|
function syntheticBoldGrowth(source, family, weight, style) {
|
|
261
280
|
if (source === "canvas") return SYNTH_BOLD_AMOUNT * SDF_RADIUS / BAKE_SIZE;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/outline/fontEmbedding.ts","../src/defaultIgnorable.ts","../src/glyphMetrics.ts","../src/emojiCluster.ts","../src/glyphWarnings.ts","../src/resolveGlyph.ts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4B,MAAA,EAAgB,MAAA,EAAgB,KAAA,EACrB;AACvC,EAAA,IAAI,MAAA,KAAW,UAAU,OAAO,kBAAA;AAChC,EAAA,MAAM,IAAA,GAAO,OAAA,CAAQ,MAAA,EAAQ,MAAA,EAAQ,KAAK,CAAA,EAAG,IAAA;AAC7C,EAAA,IAAI,CAAC,MAAM,OAAO,MAAA;AAClB,EAAA,MAAM,KAAA,GAAQ,KAAK,aAAA,IAAiB,kBAAA;AACpC,EAAA,OAAO,CAAC,KAAK,MAAA,CAAO,MAAA,GAAS,OAAO,IAAA,CAAK,MAAA,CAAO,SAAS,KAAK,CAAA;AAChE;AAOO,IAAM,iBAAA,GAAoB;AAS1B,SAAS,mBAAA,CACd,MAAA,EAA4B,MAAA,EAAgB,MAAA,EAAgB,KAAA,EACxC;AACpB,EAAA,IAAI,MAAA,KAAW,QAAA,EAAU,OAAQ,iBAAA,GAAoB,UAAA,GAAc,SAAA;AACnE,EAAA,MAAM,IAAA,GAAO,OAAA,CAAQ,MAAA,EAAQ,MAAA,EAAQ,KAAK,CAAA,EAAG,IAAA;AAC7C,EAAA,IAAI,CAAC,MAAM,OAAO,MAAA;AAClB,EAAA,OAAQ,iBAAA,IAAqB,IAAA,CAAK,aAAA,IAAiB,kBAAA,CAAA,GAAuB,KAAK,IAAA,CAAK,IAAA;AACtF","file":"index.js","sourcesContent":["import type { FontStyle } from '../fontStyle';\nimport type { FaceEmbedding } from './OutlineFace';\nimport { loadFontOutlines, outlineMetrics } from './outlineRegistry';\n\n/**\n * The embeddable sfnt and glyph map of a registered outline face, once its\n * bytes have loaded. `null` when nothing is registered for the variant, the\n * load failed, or the face's parser has no sfnt behind it.\n */\nexport async function fontEmbedding(\n family: string, weight: number, style: FontStyle,\n): Promise<FaceEmbedding | null> {\n if ((await loadFontOutlines(family, { weight, style })) !== 'ready') return null;\n return outlineMetrics(family, weight, style)?.embedding?.() ?? null;\n}\n","/** Unicode's `Default_Ignorable_Code_Point` ranges (DerivedCoreProperties.txt). */\nconst RANGES: ReadonlyArray<readonly [number, number]> = [\n [0x00ad, 0x00ad], [0x034f, 0x034f], [0x061c, 0x061c], [0x115f, 0x1160],\n [0x17b4, 0x17b5], [0x180b, 0x180f], [0x200b, 0x200f], [0x202a, 0x202e],\n [0x2060, 0x206f], [0x3164, 0x3164], [0xfe00, 0xfe0f], [0xfeff, 0xfeff],\n [0xffa0, 0xffa0], [0xfff0, 0xfff8], [0x1bca0, 0x1bca3], [0x1d173, 0x1d17a],\n [0xe0000, 0xe0fff],\n];\n\n/**\n * Whether `cp` is one a renderer shows as nothing by design: joiners,\n * variation selectors, zero-width spaces, bidi controls, the soft hyphen. A\n * face serving one as no advance and no ink has served it.\n */\nexport function isDefaultIgnorable(cp: number): boolean {\n return RANGES.some(([lo, hi]) => cp >= lo && cp <= hi);\n}\n","/**\n * One shape for the advances, kerning and baseline of whichever tier resolved\n * a face. A baked atlas and the canvas tier measure in their bake-size pixels\n * and a parsed face in ems; `size` is the divisor that takes any of them to\n * world units (`fontSize / size`), which is why an em-space face reports 1.\n */\nimport type { BmFont, BmFontChar } from './FontAtlas';\nimport { isDefaultIgnorable } from './defaultIgnorable';\nimport type { DynamicFace } from './dynamic/dynamicAtlas';\nimport type { OutlineFace } from './outline/OutlineFace';\nimport type { ResolveResult } from './registerFont';\n\n/** Where a face's advances, kerning and baseline come from. */\nexport interface GlyphMetrics {\n /** Units per em of everything else here. */\n readonly size: number;\n /** Line top to baseline in the glyph frame: what an atlas glyph's `yoffset`\n * is measured against. */\n readonly base: number;\n /** Baseline to the top of the face's line box: the ascent a browser sets\n * the face with, or `base` for a face that states none. */\n readonly ascent: number;\n /** Baseline to the bottom of the face's line box. Absent for a face that\n * states no ascent and descent, which hangs its baseline `base` below the\n * line top instead of centering the face in its line. */\n readonly descent?: number;\n /** Advance for `cp`, or null when the face has no glyph for it. On the\n * canvas tier this measures the glyph and queues its bake. */\n advanceOf(cp: number): number | null;\n kernOf(left: number, right: number): number;\n}\n\n/** A canvas face that cannot measure a code point reports no advance and no\n * ink for it, which is its only way to say it has no glyph, and exactly how\n * it serves a default-ignorable one. A glyph with ink has no width until its\n * bake lands, and says so with a negative page. */\nexport function usableGlyph(glyph: BmFontChar): boolean {\n return glyph.xadvance > 0 || glyph.width > 0 || glyph.page < 0 || isDefaultIgnorable(glyph.id);\n}\n\n/** Reads through to `font` rather than copying: the canvas tier measures a\n * face again in place when its web font lands. */\nfunction atlasMetrics(font: BmFont, advanceOf: (cp: number) => number | null): GlyphMetrics {\n const stated = (): { ascent: number; descent: number } | undefined => {\n const face = font.faceMetrics;\n return face?.ascent !== undefined && face.descent !== undefined\n ? face as { ascent: number; descent: number }\n : undefined;\n };\n return {\n size: font.info.size,\n get base() { return font.common.base; },\n get ascent() {\n const face = stated();\n return face ? face.ascent * font.info.size : font.common.base;\n },\n get descent() {\n const face = stated();\n return face && face.descent * font.info.size;\n },\n advanceOf,\n kernOf: (l, r) => font.kerningMap.get(l)?.get(r) ?? 0,\n };\n}\n\nfunction outlineMetricsOf(face: OutlineFace): GlyphMetrics {\n const descent = face.faceMetrics?.descent;\n return {\n size: 1,\n base: face.ascender,\n ascent: face.faceMetrics?.ascent ?? face.ascender,\n ...(descent !== undefined ? { descent } : {}),\n advanceOf: (cp) => face.advanceOf(cp),\n kernOf: (l, r) => face.kernOf(l, r),\n };\n}\n\nfunction canvasMetrics(face: DynamicFace): GlyphMetrics {\n return atlasMetrics(face.font, (cp) => {\n const glyph = face.requestGlyph(cp);\n return usableGlyph(glyph) ? glyph.xadvance : null;\n });\n}\n\nconst byFace = new WeakMap<object, GlyphMetrics>();\n\nfunction memo<F extends object>(face: F, build: (face: F) => GlyphMetrics): GlyphMetrics {\n let m = byFace.get(face);\n if (!m) {\n m = build(face);\n byFace.set(face, m);\n }\n return m;\n}\n\n/**\n * The metrics of whichever tier `result` resolved to, or `undefined` for a\n * miss, which has none. One object per face, so two results that landed on the\n * same face compare equal by identity.\n */\nexport function metricsOf(result: ResolveResult): GlyphMetrics | undefined {\n if (result.outlineFace) return memo(result.outlineFace, outlineMetricsOf);\n if (result.entry) {\n return memo(result.entry.font, (font) => atlasMetrics(font, (cp) => font.charMap.get(cp)?.xadvance ?? null));\n }\n if (result.dynamicFace) return memo(result.dynamicFace, canvasMetrics);\n return undefined;\n}\n","const EMOJI = /\\p{Emoji_Presentation}|\\p{Extended_Pictographic}\\uFE0F|\\uFE0F\\u20E3/u;\n\n/** The first code point that is an emoji by default (U+231A WATCH). */\nconst FIRST_DEFAULT_EMOJI = 0x231a;\n\n/**\n * Whether a grapheme cluster is drawn as an emoji rather than as text: it\n * holds a code point that is one by default, or one made so by U+FE0F, and no\n * U+FE0E asking for text.\n */\nexport function hasEmojiPresentation(cluster: string): boolean {\n if (cluster.length === 1 && cluster.charCodeAt(0) < FIRST_DEFAULT_EMOJI) return false;\n return EMOJI.test(cluster) && !cluster.includes('\\uFE0E');\n}\n","/**\n * Warnings about what the registered fonts cannot serve. Text is laid out per\n * frame, so each is claimed once through the fallback warning gate, which the\n * registry and fallback resets both clear.\n */\nimport { claimFallbackWarning, fallbackWarningClaimed } from './fallback';\nimport type { FontStyle } from './fontStyle';\nimport { fontPending } from './registerFont';\n\n/** Say, once per family and code point, that no tier has a glyph for it. */\nexport function warnMissingGlyph(family: string, cp: number): void {\n if (!claimFallbackWarning(`missing-glyph|${family}|${cp}`)) return;\n const ch = String.fromCodePoint(cp);\n console.warn(\n `weasel: no glyph for U+${cp.toString(16).toUpperCase().padStart(4, '0')} ` +\n `(${JSON.stringify(ch)}) in \"${family}\", and the dynamic tier could not ` +\n `rasterize it — skipping the character. Bake it into the atlas, or call ` +\n `registerCanvasFont(\"${family}\") to serve missing codepoints from ` +\n `installed fonts.`,\n );\n}\n\n/** The registry's own warnings that a face will draw nothing, by key prefix. */\nconst NOTHING_RENDERS = ['unusable-default', 'self-unusable-default', 'unregistered-default'];\n\n/**\n * Say, once per face, that text set in it has no metrics and lays out as\n * nothing. Silent while the face is still loading, which is late rather than\n * missing, and when the registry has already said why it cannot render.\n */\nexport function warnNoMetrics(family: string, weight: number, style: FontStyle): void {\n if (fontPending(family, weight, style)) return;\n const face = `${family}|${weight}|${style}`;\n if (NOTHING_RENDERS.some((kind) => fallbackWarningClaimed(`${kind}|${face}`))) return;\n if (!claimFallbackWarning(`no-metrics|${face}`)) return;\n console.warn(\n `weasel: no metrics for \"${family}\" ${weight}/${style} — neither ` +\n `an atlas nor an outline face resolved, so every run set in it lays out as ` +\n `nothing. Register it with registerFont / registerCanvasFont / ` +\n `registerFontOutlines. If you did, check for a duplicated @weasel-js/font in ` +\n `node_modules — its registry is module state, so a second copy is a second, ` +\n `empty one.`,\n );\n}\n","/**\n * Finding the glyph for one code point: in the tier a run resolved to, then\n * in the dynamic tier, then nowhere. A miss never draws a stand-in `?`, which\n * is indistinguishable from one the author wrote, and the BmFont atlas format\n * has no `.notdef` to draw.\n */\nimport type { BmFont, BmFontChar } from './FontAtlas';\nimport { hasEmojiPresentation } from './emojiCluster';\nimport type { FontStyle } from './fontStyle';\nimport { metricsOf, usableGlyph, type GlyphMetrics } from './glyphMetrics';\nimport { warnMissingGlyph } from './glyphWarnings';\nimport { resolveGlyphFallback, type ResolveResult } from './registerFont';\n\n/** A code point's glyph, and the tier that ended up serving it. */\nexport interface ResolvedGlyph {\n /** The tier serving the glyph. Not the run's own when the code point\n * escalated to the dynamic tier. */\n resolved: ResolveResult;\n /** That tier's metrics, which are what `advance` is measured in. */\n metrics: GlyphMetrics;\n advance: number;\n /** The atlas to sample and the glyph's record in it. Both null on the\n * outline tier, which has geometry instead. A canvas glyph's record gains\n * its atlas rect in place when its bake lands. */\n font: BmFont | null;\n glyph: BmFontChar | null;\n}\n\n/** The glyph for `cp` in the tier `resolved` landed on, or null when that\n * tier has none. */\nexport function glyphIn(resolved: ResolveResult, cp: number): ResolvedGlyph | null {\n const metrics = metricsOf(resolved);\n if (!metrics) return null;\n if (resolved.outlineFace) {\n const advance = metrics.advanceOf(cp);\n return advance === null ? null : { resolved, metrics, advance, font: null, glyph: null };\n }\n const face = resolved.dynamicFace;\n const font = resolved.entry?.font ?? face?.font;\n const glyph = resolved.entry ? font?.charMap.get(cp) : face?.requestGlyph(cp);\n if (!font || !glyph || (face && !usableGlyph(glyph))) return null;\n return { resolved, metrics, advance: glyph.xadvance, font, glyph };\n}\n\n/**\n * The glyph for `cp` in a run that asked for `(family, weight, style)` and\n * resolved to `resolved`: that tier's own, else the dynamic tier's under the\n * face the run asked for. Null when neither has it, with a warning naming the\n * code point unless `warn` is false.\n */\nexport function resolveGlyph(\n resolved: ResolveResult,\n family: string,\n weight: number,\n style: FontStyle,\n cp: number,\n warn = true,\n): ResolvedGlyph | null {\n const own = glyphIn(resolved, cp);\n if (own) return own;\n const fallback = resolveGlyphFallback(family, weight, style);\n const escalated = fallback && glyphIn(fallback, cp);\n if (escalated) return escalated;\n if (warn) warnMissingGlyph(resolved.resolved.family, cp);\n return null;\n}\n\n/**\n * The color glyph for a whole grapheme cluster with emoji presentation, in a\n * run that asked for `(family, weight, style)` and resolved to `resolved`.\n * The canvas tier is the only one that draws a cluster as one glyph or in its\n * own colors, so it serves these whatever tier serves the run's text. Null for\n * any other cluster, and where the canvas tier is not to be had or draws no\n * color for this one: the cluster is then laid out code point by code point.\n */\nexport function resolveColorCluster(\n resolved: ResolveResult,\n family: string,\n weight: number,\n style: FontStyle,\n cluster: string,\n): ResolvedGlyph | null {\n if (!hasEmojiPresentation(cluster)) return null;\n const tier = resolved.dynamicFace ? resolved : resolveGlyphFallback(family, weight, style);\n const face = tier?.dynamicFace;\n const metrics = tier && metricsOf(tier);\n const glyph = face?.requestCluster(cluster);\n if (!tier || !face || !metrics || !glyph) return null;\n return { resolved: tier, metrics, advance: glyph.xadvance, font: face.font, glyph };\n}\n","/**\n * Local Font Access → outline registrations.\n *\n * The dynamic canvas-SDF tier can render any installed family without ever\n * seeing its bytes: it asks canvas 2D to `fillText` and takes the pixels. The\n * outline tier cannot — it needs the actual font file — and the only web API\n * that hands one over is `window.queryLocalFonts()`, which is Chromium-only\n * and gated behind a permission prompt that requires a user gesture.\n *\n * So this is the one part of the tier a consumer has to *ask* for, from a\n * click. A refusal is ordinary: no registrations, and large text keeps\n * rendering from the SDF tier. Safari and Firefox have no equivalent API at\n * all, so \"denied\" is the permanent state for most of the web.\n *\n * Registration is eager but reading is lazy: every matching face gets a thunk\n * that calls `FontData.blob()` at first glyph request. A machine can have\n * hundreds of faces and a `.ttc` runs to tens of megabytes.\n */\n\nimport type { FontStyle } from '../fontStyle';\nimport { createOpenTypeParser } from './opentypeParser';\nimport { registerFontOutlines } from './outlineRegistry';\n\n/**\n * The slice of the Local Font Access API this module uses. `queryLocalFonts`\n * is not in TypeScript's DOM types.\n */\ninterface LocalFontData {\n postscriptName: string;\n fullName: string;\n family: string;\n style: string;\n blob(): Promise<Blob>;\n}\n\ntype LocalFontWindow = typeof globalThis & {\n queryLocalFonts?: (opts?: { postscriptNames?: string[] }) => Promise<LocalFontData[]>;\n};\n\n/** Is the Local Font Access API present at all? False on every non-Chromium\n * browser and in any non-secure context. */\nexport function canQueryLocalFonts(): boolean {\n return typeof globalThis !== 'undefined'\n && typeof (globalThis as LocalFontWindow).queryLocalFonts === 'function';\n}\n\n/**\n * CSS weights for the weight words that appear in a `style` string.\n *\n * Ordered longest-first where one name contains another (\"ExtraBold\" before\n * \"Bold\", \"DemiBold\" before \"Bold\"), because the match is a substring scan\n * and \"Bold\" would otherwise claim every heavier face for 700.\n */\nconst WEIGHT_WORDS: readonly (readonly [string, number])[] = [\n ['extrablack', 950], ['ultrablack', 950],\n ['extrabold', 800], ['ultrabold', 800],\n ['extralight', 200], ['ultralight', 200],\n ['semibold', 600], ['demibold', 600],\n ['semilight', 350],\n ['black', 900], ['heavy', 900],\n ['bold', 700],\n ['medium', 500],\n ['light', 300],\n ['thin', 100], ['hairline', 100],\n ['book', 400], ['regular', 400], ['normal', 400],\n];\n\n/** Lowercased, with a split weight name closed up: \"Demi Bold\" and\n * \"Semi-Bold\" read as the single words the table above lists. */\nfunction joinWeightWords(style: string): string {\n return style.toLowerCase().replace(/\\b(extra|ultra|semi|demi)[\\s_-]+/g, '$1');\n}\n\n/**\n * Parse a `FontData.style` string — \"Regular\", \"Bold Italic\", \"Condensed\n * ExtraLight Oblique\" — into the CSS variant the kit's registry is keyed by.\n *\n * Anything unrecognized lands on 400/normal.\n */\nexport function parseFontStyle(style: string): { weight: number; style: FontStyle } {\n const s = joinWeightWords(style);\n const italic = s.includes('italic') || s.includes('oblique');\n const weight = WEIGHT_WORDS.find(([word]) => s.includes(word))?.[1] ?? 400;\n return { weight, style: italic ? 'italic' : 'normal' };\n}\n\n/**\n * How many words of a `FontData.style` string are *not* weight or slant —\n * \"Condensed\", \"Display\", \"Poster\". A face with none of them is the plain\n * member of its slot, and the one to keep when two faces collide.\n */\nfunction styleQualifierCount(style: string): number {\n const words = joinWeightWords(style).split(/[\\s_-]+/).filter(Boolean);\n return words.filter((w) => w !== 'italic' && w !== 'oblique'\n && !WEIGHT_WORDS.some(([word]) => word === w)).length;\n}\n\n/** Options for `enableLocalFontOutlines`. */\nexport interface LocalFontOutlinesOptions {\n /**\n * Restrict registration to these families. Defaults to every installed\n * family, which can be hundreds of registry entries.\n */\n families?: readonly string[];\n}\n\n/** What `enableLocalFontOutlines` registered. */\nexport interface LocalFontOutlinesResult {\n /** Families that now have at least one outline face, in menu order. */\n families: readonly string[];\n /** Total faces registered across those families. */\n faces: number;\n}\n\n/**\n * Ask for permission to read installed fonts, and register outline sources\n * for the faces it returns. **Must be called from a user gesture** — the\n * permission prompt requires one, and without it the call rejects.\n *\n * Rejects when the API is missing or the user denies; neither leaves the\n * registry in a partial state.\n */\nexport async function enableLocalFontOutlines(\n opts: LocalFontOutlinesOptions = {},\n): Promise<LocalFontOutlinesResult> {\n const query = (globalThis as LocalFontWindow).queryLocalFonts;\n if (typeof query !== 'function') {\n throw new Error(\n 'weasel enableLocalFontOutlines: this browser has no Local Font Access API ' +\n '(queryLocalFonts). Large text keeps rendering from the SDF tier.',\n );\n }\n\n const wanted = opts.families ? new Set(opts.families) : null;\n const data = await query.call(globalThis);\n\n // Several installed faces can land on one (family, weight, style) slot —\n // \"Helvetica Neue Condensed Bold\" reduces to 700/normal exactly like\n // \"Helvetica Neue Bold\". Pick the least-qualified name for each slot.\n const chosen = new Map<string, { font: LocalFontData; qualifiers: number }>();\n for (const font of data) {\n if (wanted && !wanted.has(font.family)) continue;\n const { weight, style } = parseFontStyle(font.style);\n const key = `${font.family}|${weight}|${style}`;\n const qualifiers = styleQualifierCount(font.style);\n const prev = chosen.get(key);\n if (prev && prev.qualifiers <= qualifiers) continue;\n chosen.set(key, { font, qualifiers });\n }\n\n const families = new Set<string>();\n for (const { font } of chosen.values()) {\n registerFontOutlines(font.family, parseFontStyle(font.style), () => font.blob(), {\n // The PostScript name is how a member is picked out of a `.ttc`\n // collection, which is what most macOS system families ship as.\n parser: createOpenTypeParser(font.postscriptName),\n // The DOM already has every installed face; naming it avoids reading\n // the collection file a second time.\n cssSrc: `local(${JSON.stringify(font.postscriptName)})`,\n });\n families.add(font.family);\n }\n return {\n families: [...families].sort((a, b) => a.localeCompare(b)),\n faces: chosen.size,\n };\n}\n","/**\n * The GLSL that turns an atlas sample into glyph coverage, and the constants\n * naming which kind of atlas a sample came from.\n *\n * Not a program: glyphs stage into the renderer's batch alongside solid\n * geometry and image quads, and the batch shader pastes this in.\n *\n * MSDF channel layout: msdf-bmfont-xml writes R, G, and B as independent\n * signed-distance fields covering different edge directions, and the true\n * field is their median. The runtime canvas bake writes one channel that *is*\n * the field. Both encode the edge at 0.5, which is what lets one threshold\n * serve them.\n */\n\nimport type { FontStyle } from './fontStyle';\nimport { getFont } from './registerFont';\nimport { PAGE_SIZE, SDF_RADIUS } from './dynamic/dynamicAtlas';\nimport { BAKE_SIZE } from './dynamic/glyphRasterizer';\n\n/** `a_paintMode` value for glyphs off an MSDF atlas — the median of R,G,B. */\nexport const GLYPH_MODE_MSDF = 1;\n/** `a_paintMode` value for glyphs off a runtime canvas bake — `.r` alone. */\nexport const GLYPH_MODE_R8 = 2;\n\n/**\n * Glyph coverage from one atlas sample, as GLSL for a program to paste in.\n *\n * `mode` says which field the sample carries: `GLYPH_MODE_MSDF` takes the\n * median of R,G,B, `GLYPH_MODE_R8` reads `.r` alone.\n *\n * The antialiasing band has to be one *screen* pixel wide: `fieldPerUv` is how\n * far the field runs per unit of texture coordinate on each axis (see\n * `glyphFieldScale`), and the screen derivatives of `uv` turn that into field\n * units per screen pixel.\n *\n * Not `fwidth(field)`: that is the field's slope only where the field is a\n * straight ramp. Across a stem narrower than a pixel the two columns of a 2x2\n * quad sample either side of the ridge at equal values, the derivative reads\n * flat, and the stem is thresholded away. The derivative of `uv` is constant\n * across a glyph quad, so it cannot do that. Nor a constant band, which is\n * right at one scale only.\n *\n * **Nothing here branches, and the caller must not branch around it.**\n * A derivative in non-uniform control flow is undefined, so it has to\n * be taken before anything selects on paint mode. A merged program therefore\n * runs the glyph math on fragments that are not glyphs and discards the result.\n *\n * `synthBold` shifts the threshold to thicken strokes where the resolver fell\n * back from a missing bold variant to the regular atlas.\n */\nexport const GLYPH_COVERAGE_GLSL = /* glsl */ `\nfloat median(float r, float g, float b) {\n return max(min(r, g), min(max(r, g), b));\n}\n\nfloat glyphCoverage(vec4 texel, float mode, float synthBold, vec2 uv, vec2 fieldPerUv) {\n float field = mix(median(texel.r, texel.g, texel.b), texel.r, step(1.5, mode));\n float fieldPerPx = 0.5 * (length(dFdx(uv) * fieldPerUv) + length(dFdy(uv) * fieldPerUv));\n float aaW = max(0.5 * fieldPerPx, 0.0005);\n float threshold = 0.5 - synthBold;\n return smoothstep(threshold - aaW, threshold + aaW, field);\n}\n`;\n\n/** msdf-bmfont-xml's default `distanceRange`, for an atlas that records none. */\nconst DEFAULT_MSDF_RANGE = 4;\n\n/** A runtime canvas page: `PAGE_SIZE` texels, field 0 to 1 over `SDF_RADIUS` of them. */\nconst CANVAS_FIELD_SCALE = [PAGE_SIZE / SDF_RADIUS, PAGE_SIZE / SDF_RADIUS] as const;\n\n/**\n * Field units per unit of texture coordinate along u and v for the atlas a\n * glyph group samples — the `fieldPerUv` that `glyphCoverage` takes. A baked\n * MSDF atlas answers from its page size and `distanceRange`, a runtime canvas\n * page from the dynamic tier's page size and bake radius. `undefined` for an\n * atlas that is not registered.\n */\nexport function glyphFieldScale(\n source: 'atlas' | 'canvas', family: string, weight: number, style: FontStyle,\n): readonly [number, number] | undefined {\n if (source === 'canvas') return CANVAS_FIELD_SCALE;\n const font = getFont(family, weight, style)?.font;\n if (!font) return undefined;\n const range = font.distanceRange ?? DEFAULT_MSDF_RANGE;\n return [font.common.scaleW / range, font.common.scaleH / range];\n}\n\n/**\n * How far the field threshold drops for a glyph faked bold from a lighter\n * face. Tuned on Inter: it thickens strokes about a pixel at 16px without\n * breaking glyph topology.\n */\nexport const SYNTH_BOLD_AMOUNT = 0.08;\n\n/**\n * How far synthetic bold moves each edge of a glyph outward, in em, for the\n * atlas that serves it: `SYNTH_BOLD_AMOUNT` of the field's span, which is\n * `distanceRange` texels in a baked MSDF atlas and `SDF_RADIUS` in a runtime\n * canvas page, over the atlas's texels per em. `undefined` for an atlas that\n * is not registered.\n */\nexport function syntheticBoldGrowth(\n source: 'atlas' | 'canvas', family: string, weight: number, style: FontStyle,\n): number | undefined {\n if (source === 'canvas') return (SYNTH_BOLD_AMOUNT * SDF_RADIUS) / BAKE_SIZE;\n const font = getFont(family, weight, style)?.font;\n if (!font) return undefined;\n return (SYNTH_BOLD_AMOUNT * (font.distanceRange ?? DEFAULT_MSDF_RANGE)) / font.info.size;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/outline/fontEmbedding.ts","../src/defaultIgnorable.ts","../src/glyphMetrics.ts","../src/emojiCluster.ts","../src/glyphWarnings.ts","../src/resolveGlyph.ts","../src/outline/localFonts.ts","../src/textSdf.ts"],"names":[],"mappings":";;;;;AASA,eAAsB,aAAA,CACpB,MAAA,EAAgB,MAAA,EAAgB,KAAA,EACD;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GAAG,CAAA;AAOlD,IAAM,iBAAA,GAAoB;AAS1B,SAAS,mBAAA,CACd,MAAA,EAA4B,MAAA,EAAgB,MAAA,EAAgB,KAAA,EACxC;AACpB,EAAA,IAAI,MAAA,KAAW,QAAA,EAAU,OAAQ,iBAAA,GAAoB,UAAA,GAAc,SAAA;AACnE,EAAA,MAAM,IAAA,GAAO,OAAA,CAAQ,MAAA,EAAQ,MAAA,EAAQ,KAAK,CAAA,EAAG,IAAA;AAC7C,EAAA,IAAI,CAAC,MAAM,OAAO,MAAA;AAClB,EAAA,OAAQ,iBAAA,IAAqB,IAAA,CAAK,aAAA,IAAiB,kBAAA,CAAA,GAAuB,KAAK,IAAA,CAAK,IAAA;AACtF","file":"index.js","sourcesContent":["import type { FontStyle } from '../fontStyle';\nimport type { FaceEmbedding } from './OutlineFace';\nimport { loadFontOutlines, outlineMetrics } from './outlineRegistry';\n\n/**\n * The embeddable sfnt and glyph map of a registered outline face, once its\n * bytes have loaded. `null` when nothing is registered for the variant, the\n * load failed, or the face's parser has no sfnt behind it.\n */\nexport async function fontEmbedding(\n family: string, weight: number, style: FontStyle,\n): Promise<FaceEmbedding | null> {\n if ((await loadFontOutlines(family, { weight, style })) !== 'ready') return null;\n return outlineMetrics(family, weight, style)?.embedding?.() ?? null;\n}\n","/** Unicode's `Default_Ignorable_Code_Point` ranges (DerivedCoreProperties.txt). */\nconst RANGES: ReadonlyArray<readonly [number, number]> = [\n [0x00ad, 0x00ad], [0x034f, 0x034f], [0x061c, 0x061c], [0x115f, 0x1160],\n [0x17b4, 0x17b5], [0x180b, 0x180f], [0x200b, 0x200f], [0x202a, 0x202e],\n [0x2060, 0x206f], [0x3164, 0x3164], [0xfe00, 0xfe0f], [0xfeff, 0xfeff],\n [0xffa0, 0xffa0], [0xfff0, 0xfff8], [0x1bca0, 0x1bca3], [0x1d173, 0x1d17a],\n [0xe0000, 0xe0fff],\n];\n\n/**\n * Whether `cp` is one a renderer shows as nothing by design: joiners,\n * variation selectors, zero-width spaces, bidi controls, the soft hyphen. A\n * face serving one as no advance and no ink has served it.\n */\nexport function isDefaultIgnorable(cp: number): boolean {\n return RANGES.some(([lo, hi]) => cp >= lo && cp <= hi);\n}\n","/**\n * One shape for the advances, kerning and baseline of whichever tier resolved\n * a face. A baked atlas and the canvas tier measure in their bake-size pixels\n * and a parsed face in ems; `size` is the divisor that takes any of them to\n * world units (`fontSize / size`), which is why an em-space face reports 1.\n */\nimport type { BmFont, BmFontChar } from './FontAtlas';\nimport { isDefaultIgnorable } from './defaultIgnorable';\nimport type { DynamicFace } from './dynamic/dynamicAtlas';\nimport type { OutlineFace } from './outline/OutlineFace';\nimport type { ResolveResult } from './registerFont';\n\n/** Where a face's advances, kerning and baseline come from. */\nexport interface GlyphMetrics {\n /** Units per em of everything else here. */\n readonly size: number;\n /** Line top to baseline in the glyph frame: what an atlas glyph's `yoffset`\n * is measured against. */\n readonly base: number;\n /** Baseline to the top of the face's line box: the ascent a browser sets\n * the face with, or `base` for a face that states none. */\n readonly ascent: number;\n /** Baseline to the bottom of the face's line box. Absent for a face that\n * states no ascent and descent, which hangs its baseline `base` below the\n * line top instead of centering the face in its line. */\n readonly descent?: number;\n /** Advance for `cp`, or null when the face has no glyph for it. On the\n * canvas tier this measures the glyph and queues its bake. */\n advanceOf(cp: number): number | null;\n kernOf(left: number, right: number): number;\n}\n\n/** A canvas face that cannot measure a code point reports no advance and no\n * ink for it, which is its only way to say it has no glyph, and exactly how\n * it serves a default-ignorable one. A glyph with ink has no width until its\n * bake lands, and says so with a negative page. */\nexport function usableGlyph(glyph: BmFontChar): boolean {\n return glyph.xadvance > 0 || glyph.width > 0 || glyph.page < 0 || isDefaultIgnorable(glyph.id);\n}\n\n/** Reads through to `font` rather than copying: the canvas tier measures a\n * face again in place when its web font lands. */\nfunction atlasMetrics(font: BmFont, advanceOf: (cp: number) => number | null): GlyphMetrics {\n // The products are kept until the face's metrics object is replaced, since\n // each fresh one boxed a number on every read: 120 KB a frame of a HUD readout.\n let seen: BmFont['faceMetrics'] | null = null;\n let ascent = 0.5;\n let descent: number | undefined;\n const stated = (): boolean => {\n const face = font.faceMetrics;\n if (face !== seen) {\n seen = face;\n const has = face?.ascent !== undefined && face.descent !== undefined;\n ascent = has ? face.ascent! * font.info.size : 0.5;\n descent = has ? face.descent! * font.info.size : undefined;\n }\n return descent !== undefined;\n };\n return {\n size: font.info.size,\n get base() { return font.common.base; },\n get ascent() { return stated() ? ascent : font.common.base; },\n get descent() { return stated() ? descent : undefined; },\n advanceOf,\n kernOf: (l, r) => font.kerningMap.get(l)?.get(r) ?? 0,\n };\n}\n\nfunction outlineMetricsOf(face: OutlineFace): GlyphMetrics {\n const descent = face.faceMetrics?.descent;\n return {\n size: 1,\n base: face.ascender,\n ascent: face.faceMetrics?.ascent ?? face.ascender,\n ...(descent !== undefined ? { descent } : {}),\n advanceOf: (cp) => face.advanceOf(cp),\n kernOf: (l, r) => face.kernOf(l, r),\n };\n}\n\nfunction canvasMetrics(face: DynamicFace): GlyphMetrics {\n return atlasMetrics(face.font, (cp) => {\n const glyph = face.requestGlyph(cp);\n return usableGlyph(glyph) ? glyph.xadvance : null;\n });\n}\n\nconst byFace = new WeakMap<object, GlyphMetrics>();\n\nfunction memo<F extends object>(face: F, build: (face: F) => GlyphMetrics): GlyphMetrics {\n let m = byFace.get(face);\n if (!m) {\n m = build(face);\n byFace.set(face, m);\n }\n return m;\n}\n\n/**\n * The metrics of whichever tier `result` resolved to, or `undefined` for a\n * miss, which has none. One object per face, so two results that landed on the\n * same face compare equal by identity.\n */\nexport function metricsOf(result: ResolveResult): GlyphMetrics | undefined {\n if (result.outlineFace) return memo(result.outlineFace, outlineMetricsOf);\n if (result.entry) {\n return memo(result.entry.font, (font) => atlasMetrics(font, (cp) => font.charMap.get(cp)?.xadvance ?? null));\n }\n if (result.dynamicFace) return memo(result.dynamicFace, canvasMetrics);\n return undefined;\n}\n","const EMOJI = /\\p{Emoji_Presentation}|\\p{Extended_Pictographic}\\uFE0F|\\uFE0F\\u20E3/u;\n\n/** The first code point that is an emoji by default (U+231A WATCH). */\nconst FIRST_DEFAULT_EMOJI = 0x231a;\n\n/**\n * Whether a grapheme cluster is drawn as an emoji rather than as text: it\n * holds a code point that is one by default, or one made so by U+FE0F, and no\n * U+FE0E asking for text.\n */\nexport function hasEmojiPresentation(cluster: string): boolean {\n if (cluster.length === 1 && cluster.charCodeAt(0) < FIRST_DEFAULT_EMOJI) return false;\n return EMOJI.test(cluster) && !cluster.includes('\\uFE0E');\n}\n","/**\n * Warnings about what the registered fonts cannot serve. Text is laid out per\n * frame, so each is claimed once through the fallback warning gate, which the\n * registry and fallback resets both clear.\n */\nimport { claimFallbackWarning, fallbackWarningClaimed } from './fallback';\nimport type { FontStyle } from './fontStyle';\nimport { fontPending } from './registerFont';\n\n/** Say, once per family and code point, that no tier has a glyph for it. */\nexport function warnMissingGlyph(family: string, cp: number): void {\n if (!claimFallbackWarning(`missing-glyph|${family}|${cp}`)) return;\n const ch = String.fromCodePoint(cp);\n console.warn(\n `weasel: no glyph for U+${cp.toString(16).toUpperCase().padStart(4, '0')} ` +\n `(${JSON.stringify(ch)}) in \"${family}\", and the dynamic tier could not ` +\n `rasterize it — skipping the character. Bake it into the atlas, or call ` +\n `registerCanvasFont(\"${family}\") to serve missing codepoints from ` +\n `installed fonts.`,\n );\n}\n\n/** The registry's own warnings that a face will draw nothing, by key prefix. */\nconst NOTHING_RENDERS = ['unusable-default', 'self-unusable-default', 'unregistered-default'];\n\n/**\n * Say, once per face, that text set in it has no metrics and lays out as\n * nothing. Silent while the face is still loading, which is late rather than\n * missing, and when the registry has already said why it cannot render.\n */\nexport function warnNoMetrics(family: string, weight: number, style: FontStyle): void {\n if (fontPending(family, weight, style)) return;\n const face = `${family}|${weight}|${style}`;\n if (NOTHING_RENDERS.some((kind) => fallbackWarningClaimed(`${kind}|${face}`))) return;\n if (!claimFallbackWarning(`no-metrics|${face}`)) return;\n console.warn(\n `weasel: no metrics for \"${family}\" ${weight}/${style} — neither ` +\n `an atlas nor an outline face resolved, so every run set in it lays out as ` +\n `nothing. Register it with registerFont / registerCanvasFont / ` +\n `registerFontOutlines. If you did, check for a duplicated @weasel-js/font in ` +\n `node_modules — its registry is module state, so a second copy is a second, ` +\n `empty one.`,\n );\n}\n","/**\n * Finding the glyph for one code point: in the tier a run resolved to, then\n * in the dynamic tier, then nowhere. A miss never draws a stand-in `?`, which\n * is indistinguishable from one the author wrote, and the BmFont atlas format\n * has no `.notdef` to draw.\n */\nimport type { BmFont, BmFontChar } from './FontAtlas';\nimport { hasEmojiPresentation } from './emojiCluster';\nimport type { FontStyle } from './fontStyle';\nimport { metricsOf, usableGlyph, type GlyphMetrics } from './glyphMetrics';\nimport { warnMissingGlyph } from './glyphWarnings';\nimport { resolveGlyphFallback, type ResolveResult } from './registerFont';\n\n/** A code point's glyph, and the tier that ended up serving it. */\nexport interface ResolvedGlyph {\n /** The tier serving the glyph. Not the run's own when the code point\n * escalated to the dynamic tier. */\n resolved: ResolveResult;\n /** That tier's metrics, which are what `advance` is measured in. */\n metrics: GlyphMetrics;\n advance: number;\n /** The atlas to sample and the glyph's record in it. Both null on the\n * outline tier, which has geometry instead. A canvas glyph's record gains\n * its atlas rect in place when its bake lands. */\n font: BmFont | null;\n glyph: BmFontChar | null;\n}\n\n/** The glyph for `cp` in the tier `resolved` landed on, or null when that\n * tier has none. With `into`, the answer is written into it and it is\n * returned: a caller that reads the fields at once and keeps none allocates\n * nothing a code point. */\nexport function glyphIn(resolved: ResolveResult, cp: number, into?: ResolvedGlyph): ResolvedGlyph | null {\n const metrics = metricsOf(resolved);\n if (!metrics) return null;\n if (resolved.outlineFace) {\n const advance = metrics.advanceOf(cp);\n return advance === null ? null : answer(into, resolved, metrics, advance, null, null);\n }\n const face = resolved.dynamicFace;\n const font = resolved.entry?.font ?? face?.font;\n const glyph = resolved.entry ? font?.charMap.get(cp) : face?.requestGlyph(cp);\n if (!font || !glyph || (face && !usableGlyph(glyph))) return null;\n return answer(into, resolved, metrics, glyph.xadvance, font, glyph);\n}\n\nfunction answer(\n into: ResolvedGlyph | undefined, resolved: ResolveResult, metrics: GlyphMetrics, advance: number,\n font: BmFont | null, glyph: BmFontChar | null,\n): ResolvedGlyph {\n if (!into) return { resolved, metrics, advance, font, glyph };\n into.resolved = resolved; into.metrics = metrics; into.advance = advance; into.font = font; into.glyph = glyph;\n return into;\n}\n\n/**\n * The glyph for `cp` in a run that asked for `(family, weight, style)` and\n * resolved to `resolved`: that tier's own, else the dynamic tier's under the\n * face the run asked for. Null when neither has it, with a warning naming the\n * code point unless `warn` is false. `into` is as `glyphIn` takes it.\n */\nexport function resolveGlyph(\n resolved: ResolveResult,\n family: string,\n weight: number,\n style: FontStyle,\n cp: number,\n warn = true,\n into?: ResolvedGlyph,\n): ResolvedGlyph | null {\n const own = glyphIn(resolved, cp, into);\n if (own) return own;\n const fallback = resolveGlyphFallback(family, weight, style);\n const escalated = fallback && glyphIn(fallback, cp, into);\n if (escalated) return escalated;\n if (warn) warnMissingGlyph(resolved.resolved.family, cp);\n return null;\n}\n\n/**\n * The color glyph for a whole grapheme cluster with emoji presentation, in a\n * run that asked for `(family, weight, style)` and resolved to `resolved`.\n * The canvas tier is the only one that draws a cluster as one glyph or in its\n * own colors, so it serves these whatever tier serves the run's text. Null for\n * any other cluster, and where the canvas tier is not to be had or draws no\n * color for this one: the cluster is then laid out code point by code point.\n */\nexport function resolveColorCluster(\n resolved: ResolveResult,\n family: string,\n weight: number,\n style: FontStyle,\n cluster: string,\n): ResolvedGlyph | null {\n if (!hasEmojiPresentation(cluster)) return null;\n const tier = resolved.dynamicFace ? resolved : resolveGlyphFallback(family, weight, style);\n const face = tier?.dynamicFace;\n const metrics = tier && metricsOf(tier);\n const glyph = face?.requestCluster(cluster);\n if (!tier || !face || !metrics || !glyph) return null;\n return { resolved: tier, metrics, advance: glyph.xadvance, font: face.font, glyph };\n}\n","/**\n * Local Font Access → outline registrations.\n *\n * The dynamic canvas-SDF tier can render any installed family without ever\n * seeing its bytes: it asks canvas 2D to `fillText` and takes the pixels. The\n * outline tier cannot — it needs the actual font file — and the only web API\n * that hands one over is `window.queryLocalFonts()`, which is Chromium-only\n * and gated behind a permission prompt that requires a user gesture.\n *\n * So this is the one part of the tier a consumer has to *ask* for, from a\n * click. A refusal is ordinary: no registrations, and large text keeps\n * rendering from the SDF tier. Safari and Firefox have no equivalent API at\n * all, so \"denied\" is the permanent state for most of the web.\n *\n * Registration is eager but reading is lazy: every matching face gets a thunk\n * that calls `FontData.blob()` at first glyph request. A machine can have\n * hundreds of faces and a `.ttc` runs to tens of megabytes.\n */\n\nimport type { FontStyle } from '../fontStyle';\nimport { createOpenTypeParser } from './opentypeParser';\nimport { registerFontOutlines } from './outlineRegistry';\n\n/**\n * The slice of the Local Font Access API this module uses. `queryLocalFonts`\n * is not in TypeScript's DOM types.\n */\ninterface LocalFontData {\n postscriptName: string;\n fullName: string;\n family: string;\n style: string;\n blob(): Promise<Blob>;\n}\n\ntype LocalFontWindow = typeof globalThis & {\n queryLocalFonts?: (opts?: { postscriptNames?: string[] }) => Promise<LocalFontData[]>;\n};\n\n/** Is the Local Font Access API present at all? False on every non-Chromium\n * browser and in any non-secure context. */\nexport function canQueryLocalFonts(): boolean {\n return typeof globalThis !== 'undefined'\n && typeof (globalThis as LocalFontWindow).queryLocalFonts === 'function';\n}\n\n/**\n * CSS weights for the weight words that appear in a `style` string.\n *\n * Ordered longest-first where one name contains another (\"ExtraBold\" before\n * \"Bold\", \"DemiBold\" before \"Bold\"), because the match is a substring scan\n * and \"Bold\" would otherwise claim every heavier face for 700.\n */\nconst WEIGHT_WORDS: readonly (readonly [string, number])[] = [\n ['extrablack', 950], ['ultrablack', 950],\n ['extrabold', 800], ['ultrabold', 800],\n ['extralight', 200], ['ultralight', 200],\n ['semibold', 600], ['demibold', 600],\n ['semilight', 350],\n ['black', 900], ['heavy', 900],\n ['bold', 700],\n ['medium', 500],\n ['light', 300],\n ['thin', 100], ['hairline', 100],\n ['book', 400], ['regular', 400], ['normal', 400],\n];\n\n/** Lowercased, with a split weight name closed up: \"Demi Bold\" and\n * \"Semi-Bold\" read as the single words the table above lists. */\nfunction joinWeightWords(style: string): string {\n return style.toLowerCase().replace(/\\b(extra|ultra|semi|demi)[\\s_-]+/g, '$1');\n}\n\n/**\n * Parse a `FontData.style` string — \"Regular\", \"Bold Italic\", \"Condensed\n * ExtraLight Oblique\" — into the CSS variant the kit's registry is keyed by.\n *\n * Anything unrecognized lands on 400/normal.\n */\nexport function parseFontStyle(style: string): { weight: number; style: FontStyle } {\n const s = joinWeightWords(style);\n const italic = s.includes('italic') || s.includes('oblique');\n const weight = WEIGHT_WORDS.find(([word]) => s.includes(word))?.[1] ?? 400;\n return { weight, style: italic ? 'italic' : 'normal' };\n}\n\n/**\n * How many words of a `FontData.style` string are *not* weight or slant —\n * \"Condensed\", \"Display\", \"Poster\". A face with none of them is the plain\n * member of its slot, and the one to keep when two faces collide.\n */\nfunction styleQualifierCount(style: string): number {\n const words = joinWeightWords(style).split(/[\\s_-]+/).filter(Boolean);\n return words.filter((w) => w !== 'italic' && w !== 'oblique'\n && !WEIGHT_WORDS.some(([word]) => word === w)).length;\n}\n\n/** Options for `enableLocalFontOutlines`. */\nexport interface LocalFontOutlinesOptions {\n /**\n * Restrict registration to these families. Defaults to every installed\n * family, which can be hundreds of registry entries.\n */\n families?: readonly string[];\n}\n\n/** What `enableLocalFontOutlines` registered. */\nexport interface LocalFontOutlinesResult {\n /** Families that now have at least one outline face, in menu order. */\n families: readonly string[];\n /** Total faces registered across those families. */\n faces: number;\n}\n\n/**\n * Ask for permission to read installed fonts, and register outline sources\n * for the faces it returns. **Must be called from a user gesture** — the\n * permission prompt requires one, and without it the call rejects.\n *\n * Rejects when the API is missing or the user denies; neither leaves the\n * registry in a partial state.\n */\nexport async function enableLocalFontOutlines(\n opts: LocalFontOutlinesOptions = {},\n): Promise<LocalFontOutlinesResult> {\n const query = (globalThis as LocalFontWindow).queryLocalFonts;\n if (typeof query !== 'function') {\n throw new Error(\n 'weasel enableLocalFontOutlines: this browser has no Local Font Access API ' +\n '(queryLocalFonts). Large text keeps rendering from the SDF tier.',\n );\n }\n\n const wanted = opts.families ? new Set(opts.families) : null;\n const data = await query.call(globalThis);\n\n // Several installed faces can land on one (family, weight, style) slot —\n // \"Helvetica Neue Condensed Bold\" reduces to 700/normal exactly like\n // \"Helvetica Neue Bold\". Pick the least-qualified name for each slot.\n const chosen = new Map<string, { font: LocalFontData; qualifiers: number }>();\n for (const font of data) {\n if (wanted && !wanted.has(font.family)) continue;\n const { weight, style } = parseFontStyle(font.style);\n const key = `${font.family}|${weight}|${style}`;\n const qualifiers = styleQualifierCount(font.style);\n const prev = chosen.get(key);\n if (prev && prev.qualifiers <= qualifiers) continue;\n chosen.set(key, { font, qualifiers });\n }\n\n const families = new Set<string>();\n for (const { font } of chosen.values()) {\n registerFontOutlines(font.family, parseFontStyle(font.style), () => font.blob(), {\n // The PostScript name is how a member is picked out of a `.ttc`\n // collection, which is what most macOS system families ship as.\n parser: createOpenTypeParser(font.postscriptName),\n // The DOM already has every installed face; naming it avoids reading\n // the collection file a second time.\n cssSrc: `local(${JSON.stringify(font.postscriptName)})`,\n });\n families.add(font.family);\n }\n return {\n families: [...families].sort((a, b) => a.localeCompare(b)),\n faces: chosen.size,\n };\n}\n","/**\n * The GLSL that turns an atlas sample into glyph coverage, and the constants\n * naming which kind of atlas a sample came from.\n *\n * Not a program: glyphs stage into the renderer's batch alongside solid\n * geometry and image quads, and the batch shader pastes this in.\n *\n * MSDF channel layout: msdf-bmfont-xml writes R, G, and B as independent\n * signed-distance fields covering different edge directions, and the true\n * field is their median. The runtime canvas bake writes one channel that *is*\n * the field. Both encode the edge at 0.5, which is what lets one threshold\n * serve them.\n */\n\nimport type { FontStyle } from './fontStyle';\nimport { getFont } from './registerFont';\nimport { PAGE_SIZE, SDF_RADIUS } from './dynamic/dynamicAtlas';\nimport { BAKE_SIZE } from './dynamic/glyphRasterizer';\n\n/** `a_paintMode` value for glyphs off an MSDF atlas — the median of R,G,B. */\nexport const GLYPH_MODE_MSDF = 1;\n/** `a_paintMode` value for glyphs off a runtime canvas bake — `.r` alone. */\nexport const GLYPH_MODE_R8 = 2;\n\n/**\n * Glyph coverage from one atlas sample, as GLSL for a program to paste in.\n *\n * `mode` says which field the sample carries: `GLYPH_MODE_MSDF` takes the\n * median of R,G,B, `GLYPH_MODE_R8` reads `.r` alone.\n *\n * The antialiasing band has to be one *screen* pixel wide: `fieldPerUv` is how\n * far the field runs per unit of texture coordinate on each axis (see\n * `glyphFieldScale`), and the screen derivatives of `uv` turn that into field\n * units per screen pixel.\n *\n * Not `fwidth(field)`: that is the field's slope only where the field is a\n * straight ramp. Across a stem narrower than a pixel the two columns of a 2x2\n * quad sample either side of the ridge at equal values, the derivative reads\n * flat, and the stem is thresholded away. The derivative of `uv` is constant\n * across a glyph quad, so it cannot do that. Nor a constant band, which is\n * right at one scale only.\n *\n * **Nothing here branches, and the caller must not branch around it.**\n * A derivative in non-uniform control flow is undefined, so it has to\n * be taken before anything selects on paint mode. A merged program therefore\n * runs the glyph math on fragments that are not glyphs and discards the result.\n *\n * `synthBold` shifts the threshold to thicken strokes where the resolver fell\n * back from a missing bold variant to the regular atlas.\n */\nexport const GLYPH_COVERAGE_GLSL = /* glsl */ `\nfloat median(float r, float g, float b) {\n return max(min(r, g), min(max(r, g), b));\n}\n\nfloat glyphCoverage(vec4 texel, float mode, float synthBold, vec2 uv, vec2 fieldPerUv) {\n float field = mix(median(texel.r, texel.g, texel.b), texel.r, step(1.5, mode));\n float fieldPerPx = 0.5 * (length(dFdx(uv) * fieldPerUv) + length(dFdy(uv) * fieldPerUv));\n float aaW = max(0.5 * fieldPerPx, 0.0005);\n float threshold = 0.5 - synthBold;\n return smoothstep(threshold - aaW, threshold + aaW, field);\n}\n`;\n\n/** msdf-bmfont-xml's default `distanceRange`, for an atlas that records none. */\nconst DEFAULT_MSDF_RANGE = 4;\n\n/** A runtime canvas page: `PAGE_SIZE` texels, field 0 to 1 over `SDF_RADIUS` of them. */\nconst CANVAS_FIELD_SCALE = [PAGE_SIZE / SDF_RADIUS, PAGE_SIZE / SDF_RADIUS] as const;\n\n/**\n * Field units per unit of texture coordinate along u and v for the atlas a\n * glyph group samples — the `fieldPerUv` that `glyphCoverage` takes. A baked\n * MSDF atlas answers from its page size and `distanceRange`, a runtime canvas\n * page from the dynamic tier's page size and bake radius. `undefined` for an\n * atlas that is not registered.\n */\nexport function glyphFieldScale(\n source: 'atlas' | 'canvas', family: string, weight: number, style: FontStyle,\n): readonly [number, number] | undefined {\n if (source === 'canvas') return CANVAS_FIELD_SCALE;\n const font = getFont(family, weight, style)?.font;\n if (!font) return undefined;\n const range = font.distanceRange ?? DEFAULT_MSDF_RANGE;\n const u = font.common.scaleW / range, v = font.common.scaleH / range;\n // Asked once per text command per frame, so the last answer is kept.\n if (lastFieldScale[0] !== u || lastFieldScale[1] !== v) lastFieldScale = [u, v];\n return lastFieldScale;\n}\n\nlet lastFieldScale: readonly [number, number] = [NaN, NaN];\n\n/**\n * How far the field threshold drops for a glyph faked bold from a lighter\n * face. Tuned on Inter: it thickens strokes about a pixel at 16px without\n * breaking glyph topology.\n */\nexport const SYNTH_BOLD_AMOUNT = 0.08;\n\n/**\n * How far synthetic bold moves each edge of a glyph outward, in em, for the\n * atlas that serves it: `SYNTH_BOLD_AMOUNT` of the field's span, which is\n * `distanceRange` texels in a baked MSDF atlas and `SDF_RADIUS` in a runtime\n * canvas page, over the atlas's texels per em. `undefined` for an atlas that\n * is not registered.\n */\nexport function syntheticBoldGrowth(\n source: 'atlas' | 'canvas', family: string, weight: number, style: FontStyle,\n): number | undefined {\n if (source === 'canvas') return (SYNTH_BOLD_AMOUNT * SDF_RADIUS) / BAKE_SIZE;\n const font = getFont(family, weight, style)?.font;\n if (!font) return undefined;\n return (SYNTH_BOLD_AMOUNT * (font.distanceRange ?? DEFAULT_MSDF_RANGE)) / font.info.size;\n}\n"]}
|
|
@@ -412,8 +412,7 @@ declare function fontPending(family: string, weight?: number, style?: FontStyle)
|
|
|
412
412
|
* variant occupies its own texture slot.
|
|
413
413
|
*/
|
|
414
414
|
declare function ensureFontTexture(family: string, weight: number, style: FontStyle, textureCache: GlyphTextureSink): boolean;
|
|
415
|
-
|
|
416
|
-
declare function textureCacheKey(family: string, weight: number, style: FontStyle): string;
|
|
415
|
+
|
|
417
416
|
/** Kept as a no-op for context-restore call sites; per-cache dedup handles it now. */
|
|
418
417
|
declare function markAllFontsNotUploaded(): void;
|
|
419
418
|
/** What `resolveFontVariant` found: the atlas to draw with, the face it
|
|
@@ -690,4 +689,4 @@ declare function loadFontOutlines(family: string, variant?: OutlineVariant): Pro
|
|
|
690
689
|
/** @internal Test seam — registry and warn-once keys are module state. */
|
|
691
690
|
declare function _resetFontOutlinesForTests(): void;
|
|
692
691
|
|
|
693
|
-
export { syncColorPageTexture as $, hasFontOutlines as A, isCanvasFont as B, type CanvasFontEntry as C, type DynamicFace as D, listCanvasFonts as E, type FaceEmbedding as F, type GlyphTextureSink as G, listFontOutlines as H, listFontWeights as I, listFonts as J, loadFontOutlines as K, markAllFontsNotUploaded as L, outlineMetrics as M, outlineStatus as N, type OutlineFace as O, PAGE_SIZE as P, refreshCanvasFont as Q, type ResolveResult as R, registerCanvasFont as S, type TexSource as T, registerFont as U, registerFontOutlines as V, resolveFontVariant as W, resolveGlyphFallback as X, setDefaultFontFamily as Y, setFontFallbackPolicy as Z, sharpColorPageTextureId as _, type FontEntry as a, syncDynamicPageTexture as a0, syncSharpColorPageTexture as a1,
|
|
692
|
+
export { syncColorPageTexture as $, hasFontOutlines as A, isCanvasFont as B, type CanvasFontEntry as C, type DynamicFace as D, listCanvasFonts as E, type FaceEmbedding as F, type GlyphTextureSink as G, listFontOutlines as H, listFontWeights as I, listFonts as J, loadFontOutlines as K, markAllFontsNotUploaded as L, outlineMetrics as M, outlineStatus as N, type OutlineFace as O, PAGE_SIZE as P, refreshCanvasFont as Q, type ResolveResult as R, registerCanvasFont as S, type TexSource as T, registerFont as U, registerFontOutlines as V, resolveFontVariant as W, resolveGlyphFallback as X, setDefaultFontFamily as Y, setFontFallbackPolicy as Z, sharpColorPageTextureId as _, type FontEntry as a, syncDynamicPageTexture as a0, syncSharpColorPageTexture as a1, unregisterCanvasFont as a2, unregisterFontOutlines as a3, warmFonts as a4, __setGlyphRasterizerForTests as a5, _getPagesForTests as a6, _resetDomFacesForTests as a7, _resetDynamicFontsForTests as a8, _resetFallbackForTests as a9, _resetFontOutlinesForTests as aa, _resetFontRegistryForTests as ab, type FontFallbackPolicy as b, type FontFamilyFaces as c, type FontRequest as d, type FontVariant as e, type OutlineFaceInfo as f, type OutlineFontOptions as g, type OutlineParser as h, type OutlineSource as i, type OutlineStatus as j, type OutlineVariant as k, type RegisterFontOptions as l, type RegisteredFont as m, colorPageTextureId as n, cssFontFamily as o, cssFontFamilyLoading as p, dynamicPageTextureId as q, ensureFontTexture as r, faceMetricsFor as s, fontOutlineRegistry as t, fontPending as u, fontRegistry as v, getDefaultFontFamily as w, getFont as x, getFontFallbackPolicy as y, glyphOutline as z };
|
package/dist/test-seams.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { a5 as __setGlyphRasterizerForTests, a6 as _getPagesForTests, a7 as _resetDomFacesForTests, a8 as _resetDynamicFontsForTests, a9 as _resetFallbackForTests, aa as _resetFontOutlinesForTests, ab as _resetFontRegistryForTests } from './test-seams-BZPEYFPZ.js';
|
|
2
2
|
import '@weasel-js/registry';
|
|
3
3
|
import './fontStyle-D1y21YZ9.js';
|
package/dist/test-seams.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { __setGlyphRasterizerForTests, _getPagesForTests, _resetDomFacesForTests, _resetDynamicFontsForTests, _resetFallbackForTests, _resetFontOutlinesForTests, _resetFontRegistryForTests } from './chunk-
|
|
1
|
+
export { __setGlyphRasterizerForTests, _getPagesForTests, _resetDomFacesForTests, _resetDynamicFontsForTests, _resetFallbackForTests, _resetFontOutlinesForTests, _resetFontRegistryForTests } from './chunk-EQD3U7KB.js';
|
|
2
2
|
import './chunk-XQPRAGHF.js';
|
|
3
3
|
//# sourceMappingURL=test-seams.js.map
|
|
4
4
|
//# sourceMappingURL=test-seams.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weasel-js/font",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.1",
|
|
4
4
|
"description": "MSDF font atlases, glyph metrics, and runtime glyph rasterization for @weasel-js/core. Registry, kerning-aware glyph layout, and the SDF text shader source.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"provenance": true
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@weasel-js/registry": "1.
|
|
53
|
+
"@weasel-js/registry": "1.14.1",
|
|
54
54
|
"opentype.js": "2.0.0"
|
|
55
55
|
}
|
|
56
56
|
}
|