@forgeax/engine-font 0.1.27 → 0.1.28
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/README.md +3 -3
- package/dist/cli-font.mjs +5 -5
- package/dist/cli-font.mjs.map +1 -1
- package/dist/font-importer.mjs +5 -5
- package/dist/font-importer.mjs.map +1 -1
- package/package.json +6 -9
- package/src/__tests__/font.unit.test.ts +4 -17
- package/src/cli-font.ts +7 -7
- package/src/font-importer.ts +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @forgeax/engine-font
|
|
2
2
|
|
|
3
|
-
> Build-time MSDF font atlas baking + runtime `FontAsset` plumbing for world-space text. Bake a TTF into an MSDF atlas + glyph-metrics sidecar
|
|
3
|
+
> Build-time MSDF font atlas baking + runtime `FontAsset` plumbing for world-space text. Bake a TTF into an MSDF atlas + glyph-metrics sidecar with `forgeax asset import`; at runtime an AI user spawns a single `GlyphText` authoring component and the engine's `glyphTextLayoutSystem` lays out, bakes a one-mesh-per-segment `MeshAsset`, and attaches `MeshFilter` + `MeshRenderer` so the text rides the standard forward mesh path.
|
|
4
4
|
|
|
5
5
|
## Evidence and recovery
|
|
6
6
|
|
|
@@ -48,8 +48,8 @@ Runnable exemplar: `apps/hello/text` (four scenes -- HUD label, multi-line, HDR-
|
|
|
48
48
|
The bake pipeline reads a TTF and produces a `1024x1024` MSDF atlas PNG + a glyph-metrics sidecar (per-glyph uv / size / bearing / advance + a `distanceRange`).
|
|
49
49
|
|
|
50
50
|
```bash
|
|
51
|
-
#
|
|
52
|
-
forgeax
|
|
51
|
+
# The unified asset producer selects the font importer by extension.
|
|
52
|
+
forgeax asset import <font.ttf> --root ./game --json
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
| Stage | Detail |
|
package/dist/cli-font.mjs
CHANGED
|
@@ -255,10 +255,10 @@ async function realGeneratorFactory() {
|
|
|
255
255
|
}
|
|
256
256
|
function bakeHelpBody() {
|
|
257
257
|
return [
|
|
258
|
-
"forgeax
|
|
258
|
+
"forgeax asset import bake \u2014 bake MSDF font atlas from TTF",
|
|
259
259
|
"",
|
|
260
260
|
"Usage:",
|
|
261
|
-
" forgeax
|
|
261
|
+
" forgeax asset import bake <ttf> <out>",
|
|
262
262
|
"",
|
|
263
263
|
"Reads a TrueType font file and produces:",
|
|
264
264
|
` <out>/<basename>.atlas.png \u2014 ${DEFAULT_TEXTURE_SIZE}x${DEFAULT_TEXTURE_SIZE} MSDF atlas`,
|
|
@@ -268,10 +268,10 @@ function bakeHelpBody() {
|
|
|
268
268
|
}
|
|
269
269
|
function helpBody() {
|
|
270
270
|
return [
|
|
271
|
-
"forgeax
|
|
271
|
+
"forgeax asset import \u2014 MSDF font atlas baking",
|
|
272
272
|
"",
|
|
273
273
|
"Usage:",
|
|
274
|
-
" forgeax
|
|
274
|
+
" forgeax asset import bake <ttf> <out>",
|
|
275
275
|
""
|
|
276
276
|
].join("\n");
|
|
277
277
|
}
|
|
@@ -306,7 +306,7 @@ async function runBake(rest) {
|
|
|
306
306
|
const ttfPath = positionals[0];
|
|
307
307
|
const outDir = positionals[1];
|
|
308
308
|
if (ttfPath === void 0 || outDir === void 0) {
|
|
309
|
-
process.stderr.write("usage: forgeax
|
|
309
|
+
process.stderr.write("usage: forgeax asset import bake <ttf> <out>\n");
|
|
310
310
|
return 1;
|
|
311
311
|
}
|
|
312
312
|
try {
|
package/dist/cli-font.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/node-worker-adapter.ts","../src/cli-font.ts"],"names":[],"mappings":";;;;;;;;;;AAUO,IAAM,oBAAN,MAAwB;AAAA,EACZ,MAAA;AAAA,EACA,SAAA,uBAAgB,GAAA,EAA8C;AAAA,EACvE,kBAAA;AAAA,EAED,YAAY,GAAA,EAAmB;AACpC,IAAA,IAAA,CAAK,MAAA,GAAS,IAAI,MAAA,CAAO,GAAG,CAAA;AAAA,EAC9B;AAAA,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OAAA,GAAU,MAAA,CAAO,CAAC,CAAC;AAAA,CAAI,CAAA;AACnF,IAAA,OAAO,CAAA;AAAA,EACT;AACF;AAEA,IAAM,UAAA,GAAa,OAAO,YAA8B;AACtD,EAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,IAAA,CAAK,CAAC,CAAA;AAC5B,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,EAAU,OAAO,KAAA;AACtC,EAAA,MAAM,YAAY,MAAM,QAAA,CAAS,KAAK,CAAA,CAAE,KAAA,CAAM,MAAM,KAAK,CAAA;AACzD,EAAA,MAAM,WAAW,MAAM,QAAA,CAAS,cAAc,MAAA,CAAA,IAAA,CAAY,GAAG,CAAC,CAAA,CAAE,KAAA;AAAA,IAAM,MACpE,aAAA,CAAc,MAAA,CAAA,IAAA,CAAY,GAAG;AAAA,GAC/B;AACA,EAAA,OAAO,SAAA,KAAc,QAAA;AACvB,CAAA,GAAG;AAEH,IAAI,UAAA,EAAY;AACd,EAAA,MAAM,WAAW,MAAM,UAAA,CAAW,QAAQ,IAAA,CAAK,KAAA,CAAM,CAAC,CAAC,CAAA;AACvD,EAAA,OAAA,CAAQ,KAAK,QAAQ,CAAA;AACvB","file":"cli-font.mjs","sourcesContent":["import { Worker } from 'node:worker_threads';\n\ninterface MessageEventLike {\n readonly data: unknown;\n readonly origin: string;\n}\n\ntype MessageListener = (event: MessageEventLike) => void;\n\n/** Comlink's browser Worker-shaped endpoint backed by a Node worker thread. */\nexport class NodeWorkerAdapter {\n private readonly worker: Worker;\n private readonly listeners = new Map<MessageListener, (data: unknown) => void>();\n private terminationPromise?: Promise<number>;\n\n public constructor(url: string | URL) {\n this.worker = new Worker(url);\n }\n\n public postMessage(message: unknown, transferList: readonly ArrayBuffer[] = []): void {\n if (this.terminationPromise !== undefined) {\n return;\n }\n this.worker.postMessage(message, [...transferList]);\n }\n\n public addEventListener(type: string, listener: MessageListener): void {\n if (type !== 'message') return;\n const handler = (data: unknown) => listener({ data, origin: '*' });\n this.listeners.set(listener, handler);\n this.worker.on('message', handler);\n }\n\n public removeEventListener(type: string, listener: MessageListener): void {\n if (type !== 'message') return;\n const handler = this.listeners.get(listener);\n if (handler === undefined) return;\n this.listeners.delete(listener);\n this.worker.off('message', handler);\n }\n\n public terminate(): Promise<number> {\n if (this.terminationPromise === undefined) {\n this.terminationPromise = this.worker.terminate();\n }\n return this.terminationPromise;\n }\n}\n","#!/usr/bin/env node\n\n// @forgeax/engine-font/src/cli-font — `forgeax-engine-remote-font` plugin\n// bin. Discovered by the base bin via the kubectl 4th-path\n// `forgeax-engine-remote-` prefix scanner.\n//\n// `bake <ttf> <out>` reads a TrueType font and produces an MSDF atlas PNG +\n// a glyph-metrics sidecar JSON (importer: 'font'). The real bake calls\n// @zappar/msdf-generator (feat-20260531-world-space-msdf-text-rendering M5 /\n// w28 -- replaces the M1 placeholder).\n//\n// Error model (FontErrorCode, structured to stderr, exit code 1):\n// - non-TTF magic (not 0x00010000 / 'true' / 'OTTO') -> 'unsupported-font-format'\n// (AC-15 / plan-strategy D-11). The check runs BEFORE the generator so a\n// bad format never reaches the wasm path.\n// - @zappar/msdf-generator throws (wasm / Worker unavailable, internal error)\n// -> 'bake-failed' (charter P3: explicit failure, never a silent exit-0\n// no-atlas). In a plain Node CI without a Web Worker the generator throws\n// 'Worker is not defined' and the bake reports 'bake-failed' (exit 1) --\n// the best-effort real run requires a Worker + wasm host.\n\nimport { Buffer } from 'node:buffer';\nimport { mkdir, readFile, realpath, writeFile } from 'node:fs/promises';\nimport { basename, extname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { parseArgs } from 'node:util';\nimport { deflateSync } from 'node:zlib';\nimport { FontError, type GlyphMetric } from '@forgeax/engine-types';\nimport { NodeWorkerAdapter } from './node-worker-adapter.js';\n\n/**\n * Minimal subset of the @zappar/msdf-generator glyph record consumed by the\n * bake. Mirrors the package's `GlyphInfo` (dist/index.d.ts) -- only the fields\n * the BMFont -> FontAsset mapping needs (toolchain wiki section 4).\n */\nexport interface BakeGlyph {\n readonly unicode: number;\n readonly advance: number;\n readonly xoffset: number;\n readonly yoffset: number;\n readonly atlasPosition: readonly [number, number];\n readonly atlasSize: readonly [number, number];\n}\n\n/**\n * Minimal subset of the @zappar/msdf-generator `MSDFAtlas` consumed by the\n * bake. `texture` carries the RGBA pixel buffer + dimensions (the package's\n * `ImageData`-shaped texture, but reduced to POD so the bake stays\n * environment-agnostic for testing).\n */\nexport interface BakeAtlas {\n readonly texture: { readonly width: number; readonly height: number; readonly data: Uint8Array };\n readonly glyphs: readonly BakeGlyph[];\n readonly metrics: { readonly lineHeight: number; readonly ascender: number };\n readonly textureSize: readonly [number, number];\n readonly fieldRange: number;\n}\n\n/**\n * The bake-time MSDF generator contract. Injected into {@link bakeFont} so\n * unit tests can supply a mock (real path: `@zappar/msdf-generator`'s `MSDF`).\n */\nexport interface MsdfGenerator {\n generateAtlas(ttf: Uint8Array): Promise<BakeAtlas>;\n dispose(): Promise<void>;\n}\n\n/** Default charset baked into the atlas (printable ASCII). */\nconst DEFAULT_CHARSET = (() => {\n let s = '';\n for (let c = 0x20; c <= 0x7e; c++) s += String.fromCharCode(c);\n return s;\n})();\n\nconst DEFAULT_TEXTURE_SIZE = 1024;\nconst DEFAULT_FIELD_RANGE = 4;\nconst DEFAULT_FONT_SIZE = 48;\n\n/**\n * Bake-time sidecar JSON shape (importer: 'font'). Carries the glyph metrics\n * (BMFont -> FontAsset mapping, toolchain wiki section 4) + the common block\n * (distanceRange / atlas dimensions). Parsed by the runtime font load path.\n */\nexport interface BakeSidecar {\n readonly schemaVersion: string;\n readonly kind: 'external-asset-package';\n readonly importer: 'font';\n readonly source: string;\n readonly importSettings: { readonly colorSpace: 'linear'; readonly mipmap: 'none' };\n readonly common: {\n readonly lineHeight: number;\n readonly base: number;\n readonly distanceRange: number;\n readonly pxRange: number;\n readonly atlasWidth: number;\n readonly atlasHeight: number;\n };\n readonly glyphs: Record<number, GlyphMetric>;\n}\n\n/** TTF / OTF magic numbers (first 4 bytes). Per the OpenType spec. */\nfunction isSupportedFontMagic(bytes: Uint8Array): boolean {\n if (bytes.length < 4) return false;\n const b0 = bytes[0] ?? 0;\n const b1 = bytes[1] ?? 0;\n const b2 = bytes[2] ?? 0;\n const b3 = bytes[3] ?? 0;\n // 0x00010000 = TrueType outlines; 'true' (0x74727565) = legacy Apple TTF;\n // 'OTTO' (0x4f54544f) = OpenType with CFF outlines. WOFF/WOFF2 ('wOFF' /\n // 'wOF2') are rejected as non-TTF per AC-15.\n const isTrueType = b0 === 0x00 && b1 === 0x01 && b2 === 0x00 && b3 === 0x00;\n const isTrue = b0 === 0x74 && b1 === 0x72 && b2 === 0x75 && b3 === 0x65;\n const isOtto = b0 === 0x4f && b1 === 0x54 && b2 === 0x54 && b3 === 0x4f;\n return isTrueType || isTrue || isOtto;\n}\n\n/** CRC-32 (PNG / zlib polynomial) over a byte slice. */\nfunction crc32(bytes: Uint8Array): number {\n let crc = 0xffffffff;\n for (let i = 0; i < bytes.length; i++) {\n crc ^= bytes[i] ?? 0;\n for (let k = 0; k < 8; k++) {\n crc = crc & 1 ? (crc >>> 1) ^ 0xedb88320 : crc >>> 1;\n }\n }\n return (crc ^ 0xffffffff) >>> 0;\n}\n\nfunction pngChunk(type: string, data: Uint8Array): Uint8Array {\n const typeBytes = new Uint8Array([\n type.charCodeAt(0),\n type.charCodeAt(1),\n type.charCodeAt(2),\n type.charCodeAt(3),\n ]);\n const body = new Uint8Array(typeBytes.length + data.length);\n body.set(typeBytes, 0);\n body.set(data, typeBytes.length);\n const out = new Uint8Array(4 + body.length + 4);\n const dv = new DataView(out.buffer);\n dv.setUint32(0, data.length);\n out.set(body, 4);\n dv.setUint32(4 + body.length, crc32(body));\n return out;\n}\n\n/**\n * Encode an RGBA pixel buffer into a PNG (zlib deflate, no external deps).\n * The atlas texture from @zappar is RGBA8; this writes a standard 8-bit\n * RGBA PNG so any consumer (engine image importer / browser) can decode it.\n */\nexport function encodePng(width: number, height: number, rgba: Uint8Array): Uint8Array {\n // Filter byte 0 (None) prefixes each scanline.\n const stride = width * 4;\n const raw = new Uint8Array((stride + 1) * height);\n for (let y = 0; y < height; y++) {\n raw[y * (stride + 1)] = 0;\n raw.set(rgba.subarray(y * stride, y * stride + stride), y * (stride + 1) + 1);\n }\n const idat = deflateSync(raw);\n const ihdr = new Uint8Array(13);\n const dv = new DataView(ihdr.buffer);\n dv.setUint32(0, width);\n dv.setUint32(4, height);\n ihdr[8] = 8; // bit depth\n ihdr[9] = 6; // color type RGBA\n ihdr[10] = 0; // compression\n ihdr[11] = 0; // filter\n ihdr[12] = 0; // interlace\n const signature = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);\n const chunks = [\n signature,\n pngChunk('IHDR', ihdr),\n pngChunk('IDAT', new Uint8Array(idat)),\n pngChunk('IEND', new Uint8Array(0)),\n ];\n const total = chunks.reduce((n, c) => n + c.length, 0);\n const out = new Uint8Array(total);\n let off = 0;\n for (const c of chunks) {\n out.set(c, off);\n off += c.length;\n }\n return out;\n}\n\n/** Map a @zappar atlas into the FontAsset glyph-metrics sidecar shape. */\nexport function atlasToSidecar(atlas: BakeAtlas, sourcePng: string): BakeSidecar {\n const glyphs: Record<number, GlyphMetric> = {};\n for (const g of atlas.glyphs) {\n glyphs[g.unicode] = {\n advance: g.advance,\n bearingX: g.xoffset,\n bearingY: g.yoffset,\n size: { w: g.atlasSize[0], h: g.atlasSize[1] },\n region: {\n x: g.atlasPosition[0],\n y: g.atlasPosition[1],\n w: g.atlasSize[0],\n h: g.atlasSize[1],\n },\n };\n }\n return {\n schemaVersion: '1.0.0',\n kind: 'external-asset-package',\n importer: 'font',\n source: sourcePng,\n importSettings: { colorSpace: 'linear', mipmap: 'none' },\n common: {\n lineHeight: atlas.metrics.lineHeight,\n base: atlas.metrics.ascender,\n distanceRange: atlas.fieldRange,\n pxRange: atlas.fieldRange,\n atlasWidth: atlas.textureSize[0],\n atlasHeight: atlas.textureSize[1],\n },\n glyphs,\n };\n}\n\n/** Result of a successful bake -- the written artefact paths. */\nexport interface BakeResult {\n readonly atlasPath: string;\n readonly sidecarPath: string;\n}\n\n/**\n * Bake an MSDF atlas + glyph-metrics sidecar from a TTF.\n *\n * @param ttfPath path to the TrueType source.\n * @param outDir output directory (created if missing).\n * @param generatorFactory yields the MSDF generator (real: @zappar; tests: mock).\n * @returns `Result`-style: throws a {@link FontError} on every failure mode\n * (unsupported-font-format before the generator runs; bake-failed when the\n * generator throws). The CLI layer maps the thrown FontError to a structured\n * stderr line + exit code 1 -- never a silent exit 0 without artefacts\n * (charter P3).\n */\nexport async function bakeFont(\n ttfPath: string,\n outDir: string,\n generatorFactory: () => Promise<MsdfGenerator>,\n): Promise<BakeResult> {\n const ttf = await readFile(ttfPath);\n const ttfBytes = new Uint8Array(ttf.buffer, ttf.byteOffset, ttf.byteLength);\n if (!isSupportedFontMagic(ttfBytes)) {\n throw new FontError({\n code: 'unsupported-font-format',\n expected: 'ttf',\n hint: 'bake accepts TrueType (.ttf / 0x00010000 / \"true\") or OpenType-TTF (\"OTTO\") sources; WOFF / WOFF2 / other formats are not supported -- convert to TTF first',\n detail: { path: ttfPath },\n });\n }\n\n let atlas: BakeAtlas;\n let generator: MsdfGenerator | undefined;\n try {\n generator = await generatorFactory();\n atlas = await generator.generateAtlas(ttfBytes);\n } catch (e) {\n throw new FontError({\n code: 'bake-failed',\n expected: '@zappar/msdf-generator to produce an MSDF atlas',\n hint: 'the MSDF generator threw -- a Web Worker + wasm host is required (a plain Node process reports \"Worker is not defined\"); run the bake in a Worker-capable environment',\n detail: { cause: e instanceof Error ? e.message : String(e) },\n });\n } finally {\n if (generator !== undefined) {\n await generator.dispose().catch(() => undefined);\n }\n }\n\n await mkdir(outDir, { recursive: true });\n const base = basename(ttfPath, extname(ttfPath));\n const atlasName = `${base}.atlas.png`;\n const atlasPath = join(outDir, atlasName);\n const sidecarPath = join(outDir, `${base}.meta.json`);\n const png = encodePng(atlas.texture.width, atlas.texture.height, atlas.texture.data);\n await writeFile(atlasPath, png);\n const sidecar = atlasToSidecar(atlas, atlasName);\n await writeFile(sidecarPath, `${JSON.stringify(sidecar, null, 2)}\\n`);\n return { atlasPath, sidecarPath };\n}\n\n/**\n * Real @zappar/msdf-generator factory. Dynamically imported so a non-bake\n * subcommand (or a test that injects a mock) never pays the wasm load cost,\n * and so the package builds without the browser globals the generator needs.\n */\n/**\n * Shape of @zappar/msdf-generator's `MSDFAtlas` (dist/index.d.ts) that the\n * real factory adapts into the POD {@link BakeAtlas}. The package's `texture`\n * is an ImageData-shaped `{ width, height, data }`; we read those fields\n * structurally so the font package never needs the DOM `ImageData` type.\n */\ninterface ZapparAtlas {\n texture: { width: number; height: number; data: Uint8ClampedArray | Uint8Array };\n glyphs: ReadonlyArray<{\n unicode: number;\n advance: number;\n xoffset: number;\n yoffset: number;\n atlasPosition: [number, number];\n atlasSize: [number, number];\n }>;\n metrics: { lineHeight: number; ascender: number };\n textureSize: [number, number];\n fieldRange: number;\n}\n\nexport async function realGeneratorFactory(): Promise<MsdfGenerator> {\n const mod = (await import('@zappar/msdf-generator')) as unknown as {\n MSDF: new (config?: {\n workerUrl?: URL;\n wasmUrl?: string;\n }) => {\n initialize(): Promise<void>;\n generateAtlas(opts: {\n font: Uint8Array;\n charset: string;\n textureSize: [number, number];\n fieldRange: number;\n fontSize: number;\n }): Promise<ZapparAtlas>;\n dispose(): Promise<void>;\n };\n };\n\n const wasmModuleUrl = import.meta.resolve('@zappar/msdf-generator/msdfgen_wasm.wasm');\n const wasmBytes = await readFile(new URL(wasmModuleUrl));\n const wasmUrl = `data:application/octet-stream;base64,${Buffer.from(wasmBytes).toString('base64')}`;\n const nodeGlobal = globalThis as unknown as { Worker?: typeof NodeWorkerAdapter };\n const previousWorker = nodeGlobal.Worker;\n nodeGlobal.Worker = NodeWorkerAdapter;\n let msdf: InstanceType<typeof mod.MSDF> | undefined;\n try {\n msdf = new mod.MSDF({\n workerUrl: new URL('./node-msdf-worker.mjs', import.meta.url),\n wasmUrl,\n });\n await msdf.initialize();\n } finally {\n if (previousWorker === undefined) {\n delete nodeGlobal.Worker;\n } else {\n nodeGlobal.Worker = previousWorker;\n }\n }\n if (msdf === undefined) {\n throw new Error('the MSDF generator did not initialize');\n }\n return {\n async generateAtlas(ttf: Uint8Array): Promise<BakeAtlas> {\n const a = await msdf.generateAtlas({\n font: ttf,\n charset: DEFAULT_CHARSET,\n textureSize: [DEFAULT_TEXTURE_SIZE, DEFAULT_TEXTURE_SIZE],\n fieldRange: DEFAULT_FIELD_RANGE,\n fontSize: DEFAULT_FONT_SIZE,\n });\n return {\n texture: {\n width: a.texture.width,\n height: a.texture.height,\n data: new Uint8Array(a.texture.data),\n },\n glyphs: a.glyphs.map((g) => ({\n unicode: g.unicode,\n advance: g.advance,\n xoffset: g.xoffset,\n yoffset: g.yoffset,\n atlasPosition: [g.atlasPosition[0], g.atlasPosition[1]],\n atlasSize: [g.atlasSize[0], g.atlasSize[1]],\n })),\n metrics: { lineHeight: a.metrics.lineHeight, ascender: a.metrics.ascender },\n textureSize: [a.textureSize[0], a.textureSize[1]],\n fieldRange: a.fieldRange,\n };\n },\n async dispose(): Promise<void> {\n await msdf.dispose();\n },\n };\n}\n\nfunction bakeHelpBody(): string {\n return [\n 'forgeax-engine-remote-font bake — bake MSDF font atlas from TTF',\n '',\n 'Usage:',\n ' forgeax-engine-remote-font bake <ttf> <out>',\n '',\n 'Reads a TrueType font file and produces:',\n ` <out>/<basename>.atlas.png — ${DEFAULT_TEXTURE_SIZE}x${DEFAULT_TEXTURE_SIZE} MSDF atlas`,\n ' <out>/<basename>.meta.json — glyph metrics sidecar (importer: font)',\n '',\n ].join('\\n');\n}\n\nfunction helpBody(): string {\n return [\n 'forgeax-engine-remote-font — MSDF font atlas baking',\n '',\n 'Usage:',\n ' forgeax-engine-remote-font bake <ttf> <out>',\n '',\n ].join('\\n');\n}\n\nexport async function runCliFont(argv: string[]): Promise<number> {\n const [sub, ...rest] = argv;\n if (sub === undefined || sub === '--help' || sub === '-h') {\n process.stdout.write(`${helpBody()}\\n`);\n return 0;\n }\n if (sub !== 'bake') {\n process.stderr.write(`unknown subcommand: ${sub}\\n`);\n return 1;\n }\n return runBake(rest);\n}\n\nasync function runBake(rest: string[]): Promise<number> {\n if (rest[0] === '--help' || rest[0] === '-h') {\n process.stdout.write(`${bakeHelpBody()}\\n`);\n return 0;\n }\n let positionals: string[];\n try {\n const parsed = parseArgs({ args: rest, allowPositionals: true, strict: true });\n positionals = [...parsed.positionals];\n } catch {\n process.stderr.write('error parsing CLI args\\n');\n return 1;\n }\n const ttfPath = positionals[0];\n const outDir = positionals[1];\n if (ttfPath === undefined || outDir === undefined) {\n process.stderr.write('usage: forgeax-engine-remote-font bake <ttf> <out>\\n');\n return 1;\n }\n try {\n const result = await bakeFont(ttfPath, outDir, realGeneratorFactory);\n process.stdout.write(`baked ${result.atlasPath} + ${result.sidecarPath}\\n`);\n return 0;\n } catch (e) {\n if (e instanceof FontError) {\n process.stderr.write(\n `${JSON.stringify({ code: e.code, expected: e.expected, hint: e.hint, detail: e.detail })}\\n`,\n );\n return 1;\n }\n process.stderr.write(`bake failed: ${e instanceof Error ? e.message : String(e)}\\n`);\n return 1;\n }\n}\n\nconst isBinEntry = await (async (): Promise<boolean> => {\n const argv1 = process.argv[1];\n if (typeof argv1 !== 'string') return false;\n const argv1Real = await realpath(argv1).catch(() => argv1);\n const selfReal = await realpath(fileURLToPath(import.meta.url)).catch(() =>\n fileURLToPath(import.meta.url),\n );\n return argv1Real === selfReal;\n})();\n\nif (isBinEntry) {\n const exitCode = await runCliFont(process.argv.slice(2));\n process.exit(exitCode);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/node-worker-adapter.ts","../src/cli-font.ts"],"names":[],"mappings":";;;;;;;;;;AAUO,IAAM,oBAAN,MAAwB;AAAA,EACZ,MAAA;AAAA,EACA,SAAA,uBAAgB,GAAA,EAA8C;AAAA,EACvE,kBAAA;AAAA,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AAA;AAAA,IACT;AACA,IAAA,OAAA,CAAQ,MAAA,CAAO,MAAM,CAAA,aAAA,EAAgB,CAAA,YAAa,QAAQ,CAAA,CAAE,OAAA,GAAU,MAAA,CAAO,CAAC,CAAC;AAAA,CAAI,CAAA;AACnF,IAAA,OAAO,CAAA;AAAA,EACT;AACF;AAEA,IAAM,UAAA,GAAa,OAAO,YAA8B;AACtD,EAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,IAAA,CAAK,CAAC,CAAA;AAC5B,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,EAAU,OAAO,KAAA;AACtC,EAAA,MAAM,YAAY,MAAM,QAAA,CAAS,KAAK,CAAA,CAAE,KAAA,CAAM,MAAM,KAAK,CAAA;AACzD,EAAA,MAAM,WAAW,MAAM,QAAA,CAAS,cAAc,MAAA,CAAA,IAAA,CAAY,GAAG,CAAC,CAAA,CAAE,KAAA;AAAA,IAAM,MACpE,aAAA,CAAc,MAAA,CAAA,IAAA,CAAY,GAAG;AAAA,GAC/B;AACA,EAAA,OAAO,SAAA,KAAc,QAAA;AACvB,CAAA,GAAG;AAEH,IAAI,UAAA,EAAY;AACd,EAAA,MAAM,WAAW,MAAM,UAAA,CAAW,QAAQ,IAAA,CAAK,KAAA,CAAM,CAAC,CAAC,CAAA;AACvD,EAAA,OAAA,CAAQ,KAAK,QAAQ,CAAA;AACvB","file":"cli-font.mjs","sourcesContent":["import { Worker } from 'node:worker_threads';\n\ninterface MessageEventLike {\n readonly data: unknown;\n readonly origin: string;\n}\n\ntype MessageListener = (event: MessageEventLike) => void;\n\n/** Comlink's browser Worker-shaped endpoint backed by a Node worker thread. */\nexport class NodeWorkerAdapter {\n private readonly worker: Worker;\n private readonly listeners = new Map<MessageListener, (data: unknown) => void>();\n private terminationPromise?: Promise<number>;\n\n public constructor(url: string | URL) {\n this.worker = new Worker(url);\n }\n\n public postMessage(message: unknown, transferList: readonly ArrayBuffer[] = []): void {\n if (this.terminationPromise !== undefined) {\n return;\n }\n this.worker.postMessage(message, [...transferList]);\n }\n\n public addEventListener(type: string, listener: MessageListener): void {\n if (type !== 'message') return;\n const handler = (data: unknown) => listener({ data, origin: '*' });\n this.listeners.set(listener, handler);\n this.worker.on('message', handler);\n }\n\n public removeEventListener(type: string, listener: MessageListener): void {\n if (type !== 'message') return;\n const handler = this.listeners.get(listener);\n if (handler === undefined) return;\n this.listeners.delete(listener);\n this.worker.off('message', handler);\n }\n\n public terminate(): Promise<number> {\n if (this.terminationPromise === undefined) {\n this.terminationPromise = this.worker.terminate();\n }\n return this.terminationPromise;\n }\n}\n","#!/usr/bin/env node\n\n// @forgeax/engine-font/src/cli-font — `forgeax asset import` plugin\n// bin. Discovered by the base bin via the kubectl 4th-path\n// unified `forgeax asset import` producer.\n//\n// `bake <ttf> <out>` reads a TrueType font and produces an MSDF atlas PNG +\n// a glyph-metrics sidecar JSON (importer: 'font'). The real bake calls\n// @zappar/msdf-generator (feat-20260531-world-space-msdf-text-rendering M5 /\n// w28 -- replaces the M1 placeholder).\n//\n// Error model (FontErrorCode, structured to stderr, exit code 1):\n// - non-TTF magic (not 0x00010000 / 'true' / 'OTTO') -> 'unsupported-font-format'\n// (AC-15 / plan-strategy D-11). The check runs BEFORE the generator so a\n// bad format never reaches the wasm path.\n// - @zappar/msdf-generator throws (wasm / Worker unavailable, internal error)\n// -> 'bake-failed' (charter P3: explicit failure, never a silent exit-0\n// no-atlas). In a plain Node CI without a Web Worker the generator throws\n// 'Worker is not defined' and the bake reports 'bake-failed' (exit 1) --\n// the best-effort real run requires a Worker + wasm host.\n\nimport { Buffer } from 'node:buffer';\nimport { mkdir, readFile, realpath, writeFile } from 'node:fs/promises';\nimport { basename, extname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { parseArgs } from 'node:util';\nimport { deflateSync } from 'node:zlib';\nimport { FontError, type GlyphMetric } from '@forgeax/engine-types';\nimport { NodeWorkerAdapter } from './node-worker-adapter.js';\n\n/**\n * Minimal subset of the @zappar/msdf-generator glyph record consumed by the\n * bake. Mirrors the package's `GlyphInfo` (dist/index.d.ts) -- only the fields\n * the BMFont -> FontAsset mapping needs (toolchain wiki section 4).\n */\nexport interface BakeGlyph {\n readonly unicode: number;\n readonly advance: number;\n readonly xoffset: number;\n readonly yoffset: number;\n readonly atlasPosition: readonly [number, number];\n readonly atlasSize: readonly [number, number];\n}\n\n/**\n * Minimal subset of the @zappar/msdf-generator `MSDFAtlas` consumed by the\n * bake. `texture` carries the RGBA pixel buffer + dimensions (the package's\n * `ImageData`-shaped texture, but reduced to POD so the bake stays\n * environment-agnostic for testing).\n */\nexport interface BakeAtlas {\n readonly texture: { readonly width: number; readonly height: number; readonly data: Uint8Array };\n readonly glyphs: readonly BakeGlyph[];\n readonly metrics: { readonly lineHeight: number; readonly ascender: number };\n readonly textureSize: readonly [number, number];\n readonly fieldRange: number;\n}\n\n/**\n * The bake-time MSDF generator contract. Injected into {@link bakeFont} so\n * unit tests can supply a mock (real path: `@zappar/msdf-generator`'s `MSDF`).\n */\nexport interface MsdfGenerator {\n generateAtlas(ttf: Uint8Array): Promise<BakeAtlas>;\n dispose(): Promise<void>;\n}\n\n/** Default charset baked into the atlas (printable ASCII). */\nconst DEFAULT_CHARSET = (() => {\n let s = '';\n for (let c = 0x20; c <= 0x7e; c++) s += String.fromCharCode(c);\n return s;\n})();\n\nconst DEFAULT_TEXTURE_SIZE = 1024;\nconst DEFAULT_FIELD_RANGE = 4;\nconst DEFAULT_FONT_SIZE = 48;\n\n/**\n * Bake-time sidecar JSON shape (importer: 'font'). Carries the glyph metrics\n * (BMFont -> FontAsset mapping, toolchain wiki section 4) + the common block\n * (distanceRange / atlas dimensions). Parsed by the runtime font load path.\n */\nexport interface BakeSidecar {\n readonly schemaVersion: string;\n readonly kind: 'external-asset-package';\n readonly importer: 'font';\n readonly source: string;\n readonly importSettings: { readonly colorSpace: 'linear'; readonly mipmap: 'none' };\n readonly common: {\n readonly lineHeight: number;\n readonly base: number;\n readonly distanceRange: number;\n readonly pxRange: number;\n readonly atlasWidth: number;\n readonly atlasHeight: number;\n };\n readonly glyphs: Record<number, GlyphMetric>;\n}\n\n/** TTF / OTF magic numbers (first 4 bytes). Per the OpenType spec. */\nfunction isSupportedFontMagic(bytes: Uint8Array): boolean {\n if (bytes.length < 4) return false;\n const b0 = bytes[0] ?? 0;\n const b1 = bytes[1] ?? 0;\n const b2 = bytes[2] ?? 0;\n const b3 = bytes[3] ?? 0;\n // 0x00010000 = TrueType outlines; 'true' (0x74727565) = legacy Apple TTF;\n // 'OTTO' (0x4f54544f) = OpenType with CFF outlines. WOFF/WOFF2 ('wOFF' /\n // 'wOF2') are rejected as non-TTF per AC-15.\n const isTrueType = b0 === 0x00 && b1 === 0x01 && b2 === 0x00 && b3 === 0x00;\n const isTrue = b0 === 0x74 && b1 === 0x72 && b2 === 0x75 && b3 === 0x65;\n const isOtto = b0 === 0x4f && b1 === 0x54 && b2 === 0x54 && b3 === 0x4f;\n return isTrueType || isTrue || isOtto;\n}\n\n/** CRC-32 (PNG / zlib polynomial) over a byte slice. */\nfunction crc32(bytes: Uint8Array): number {\n let crc = 0xffffffff;\n for (let i = 0; i < bytes.length; i++) {\n crc ^= bytes[i] ?? 0;\n for (let k = 0; k < 8; k++) {\n crc = crc & 1 ? (crc >>> 1) ^ 0xedb88320 : crc >>> 1;\n }\n }\n return (crc ^ 0xffffffff) >>> 0;\n}\n\nfunction pngChunk(type: string, data: Uint8Array): Uint8Array {\n const typeBytes = new Uint8Array([\n type.charCodeAt(0),\n type.charCodeAt(1),\n type.charCodeAt(2),\n type.charCodeAt(3),\n ]);\n const body = new Uint8Array(typeBytes.length + data.length);\n body.set(typeBytes, 0);\n body.set(data, typeBytes.length);\n const out = new Uint8Array(4 + body.length + 4);\n const dv = new DataView(out.buffer);\n dv.setUint32(0, data.length);\n out.set(body, 4);\n dv.setUint32(4 + body.length, crc32(body));\n return out;\n}\n\n/**\n * Encode an RGBA pixel buffer into a PNG (zlib deflate, no external deps).\n * The atlas texture from @zappar is RGBA8; this writes a standard 8-bit\n * RGBA PNG so any consumer (engine image importer / browser) can decode it.\n */\nexport function encodePng(width: number, height: number, rgba: Uint8Array): Uint8Array {\n // Filter byte 0 (None) prefixes each scanline.\n const stride = width * 4;\n const raw = new Uint8Array((stride + 1) * height);\n for (let y = 0; y < height; y++) {\n raw[y * (stride + 1)] = 0;\n raw.set(rgba.subarray(y * stride, y * stride + stride), y * (stride + 1) + 1);\n }\n const idat = deflateSync(raw);\n const ihdr = new Uint8Array(13);\n const dv = new DataView(ihdr.buffer);\n dv.setUint32(0, width);\n dv.setUint32(4, height);\n ihdr[8] = 8; // bit depth\n ihdr[9] = 6; // color type RGBA\n ihdr[10] = 0; // compression\n ihdr[11] = 0; // filter\n ihdr[12] = 0; // interlace\n const signature = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);\n const chunks = [\n signature,\n pngChunk('IHDR', ihdr),\n pngChunk('IDAT', new Uint8Array(idat)),\n pngChunk('IEND', new Uint8Array(0)),\n ];\n const total = chunks.reduce((n, c) => n + c.length, 0);\n const out = new Uint8Array(total);\n let off = 0;\n for (const c of chunks) {\n out.set(c, off);\n off += c.length;\n }\n return out;\n}\n\n/** Map a @zappar atlas into the FontAsset glyph-metrics sidecar shape. */\nexport function atlasToSidecar(atlas: BakeAtlas, sourcePng: string): BakeSidecar {\n const glyphs: Record<number, GlyphMetric> = {};\n for (const g of atlas.glyphs) {\n glyphs[g.unicode] = {\n advance: g.advance,\n bearingX: g.xoffset,\n bearingY: g.yoffset,\n size: { w: g.atlasSize[0], h: g.atlasSize[1] },\n region: {\n x: g.atlasPosition[0],\n y: g.atlasPosition[1],\n w: g.atlasSize[0],\n h: g.atlasSize[1],\n },\n };\n }\n return {\n schemaVersion: '1.0.0',\n kind: 'external-asset-package',\n importer: 'font',\n source: sourcePng,\n importSettings: { colorSpace: 'linear', mipmap: 'none' },\n common: {\n lineHeight: atlas.metrics.lineHeight,\n base: atlas.metrics.ascender,\n distanceRange: atlas.fieldRange,\n pxRange: atlas.fieldRange,\n atlasWidth: atlas.textureSize[0],\n atlasHeight: atlas.textureSize[1],\n },\n glyphs,\n };\n}\n\n/** Result of a successful bake -- the written artefact paths. */\nexport interface BakeResult {\n readonly atlasPath: string;\n readonly sidecarPath: string;\n}\n\n/**\n * Bake an MSDF atlas + glyph-metrics sidecar from a TTF.\n *\n * @param ttfPath path to the TrueType source.\n * @param outDir output directory (created if missing).\n * @param generatorFactory yields the MSDF generator (real: @zappar; tests: mock).\n * @returns `Result`-style: throws a {@link FontError} on every failure mode\n * (unsupported-font-format before the generator runs; bake-failed when the\n * generator throws). The CLI layer maps the thrown FontError to a structured\n * stderr line + exit code 1 -- never a silent exit 0 without artefacts\n * (charter P3).\n */\nexport async function bakeFont(\n ttfPath: string,\n outDir: string,\n generatorFactory: () => Promise<MsdfGenerator>,\n): Promise<BakeResult> {\n const ttf = await readFile(ttfPath);\n const ttfBytes = new Uint8Array(ttf.buffer, ttf.byteOffset, ttf.byteLength);\n if (!isSupportedFontMagic(ttfBytes)) {\n throw new FontError({\n code: 'unsupported-font-format',\n expected: 'ttf',\n hint: 'bake accepts TrueType (.ttf / 0x00010000 / \"true\") or OpenType-TTF (\"OTTO\") sources; WOFF / WOFF2 / other formats are not supported -- convert to TTF first',\n detail: { path: ttfPath },\n });\n }\n\n let atlas: BakeAtlas;\n let generator: MsdfGenerator | undefined;\n try {\n generator = await generatorFactory();\n atlas = await generator.generateAtlas(ttfBytes);\n } catch (e) {\n throw new FontError({\n code: 'bake-failed',\n expected: '@zappar/msdf-generator to produce an MSDF atlas',\n hint: 'the MSDF generator threw -- a Web Worker + wasm host is required (a plain Node process reports \"Worker is not defined\"); run the bake in a Worker-capable environment',\n detail: { cause: e instanceof Error ? e.message : String(e) },\n });\n } finally {\n if (generator !== undefined) {\n await generator.dispose().catch(() => undefined);\n }\n }\n\n await mkdir(outDir, { recursive: true });\n const base = basename(ttfPath, extname(ttfPath));\n const atlasName = `${base}.atlas.png`;\n const atlasPath = join(outDir, atlasName);\n const sidecarPath = join(outDir, `${base}.meta.json`);\n const png = encodePng(atlas.texture.width, atlas.texture.height, atlas.texture.data);\n await writeFile(atlasPath, png);\n const sidecar = atlasToSidecar(atlas, atlasName);\n await writeFile(sidecarPath, `${JSON.stringify(sidecar, null, 2)}\\n`);\n return { atlasPath, sidecarPath };\n}\n\n/**\n * Real @zappar/msdf-generator factory. Dynamically imported so a non-bake\n * subcommand (or a test that injects a mock) never pays the wasm load cost,\n * and so the package builds without the browser globals the generator needs.\n */\n/**\n * Shape of @zappar/msdf-generator's `MSDFAtlas` (dist/index.d.ts) that the\n * real factory adapts into the POD {@link BakeAtlas}. The package's `texture`\n * is an ImageData-shaped `{ width, height, data }`; we read those fields\n * structurally so the font package never needs the DOM `ImageData` type.\n */\ninterface ZapparAtlas {\n texture: { width: number; height: number; data: Uint8ClampedArray | Uint8Array };\n glyphs: ReadonlyArray<{\n unicode: number;\n advance: number;\n xoffset: number;\n yoffset: number;\n atlasPosition: [number, number];\n atlasSize: [number, number];\n }>;\n metrics: { lineHeight: number; ascender: number };\n textureSize: [number, number];\n fieldRange: number;\n}\n\nexport async function realGeneratorFactory(): Promise<MsdfGenerator> {\n const mod = (await import('@zappar/msdf-generator')) as unknown as {\n MSDF: new (config?: {\n workerUrl?: URL;\n wasmUrl?: string;\n }) => {\n initialize(): Promise<void>;\n generateAtlas(opts: {\n font: Uint8Array;\n charset: string;\n textureSize: [number, number];\n fieldRange: number;\n fontSize: number;\n }): Promise<ZapparAtlas>;\n dispose(): Promise<void>;\n };\n };\n\n const wasmModuleUrl = import.meta.resolve('@zappar/msdf-generator/msdfgen_wasm.wasm');\n const wasmBytes = await readFile(new URL(wasmModuleUrl));\n const wasmUrl = `data:application/octet-stream;base64,${Buffer.from(wasmBytes).toString('base64')}`;\n const nodeGlobal = globalThis as unknown as { Worker?: typeof NodeWorkerAdapter };\n const previousWorker = nodeGlobal.Worker;\n nodeGlobal.Worker = NodeWorkerAdapter;\n let msdf: InstanceType<typeof mod.MSDF> | undefined;\n try {\n msdf = new mod.MSDF({\n workerUrl: new URL('./node-msdf-worker.mjs', import.meta.url),\n wasmUrl,\n });\n await msdf.initialize();\n } finally {\n if (previousWorker === undefined) {\n delete nodeGlobal.Worker;\n } else {\n nodeGlobal.Worker = previousWorker;\n }\n }\n if (msdf === undefined) {\n throw new Error('the MSDF generator did not initialize');\n }\n return {\n async generateAtlas(ttf: Uint8Array): Promise<BakeAtlas> {\n const a = await msdf.generateAtlas({\n font: ttf,\n charset: DEFAULT_CHARSET,\n textureSize: [DEFAULT_TEXTURE_SIZE, DEFAULT_TEXTURE_SIZE],\n fieldRange: DEFAULT_FIELD_RANGE,\n fontSize: DEFAULT_FONT_SIZE,\n });\n return {\n texture: {\n width: a.texture.width,\n height: a.texture.height,\n data: new Uint8Array(a.texture.data),\n },\n glyphs: a.glyphs.map((g) => ({\n unicode: g.unicode,\n advance: g.advance,\n xoffset: g.xoffset,\n yoffset: g.yoffset,\n atlasPosition: [g.atlasPosition[0], g.atlasPosition[1]],\n atlasSize: [g.atlasSize[0], g.atlasSize[1]],\n })),\n metrics: { lineHeight: a.metrics.lineHeight, ascender: a.metrics.ascender },\n textureSize: [a.textureSize[0], a.textureSize[1]],\n fieldRange: a.fieldRange,\n };\n },\n async dispose(): Promise<void> {\n await msdf.dispose();\n },\n };\n}\n\nfunction bakeHelpBody(): string {\n return [\n 'forgeax asset import bake — bake MSDF font atlas from TTF',\n '',\n 'Usage:',\n ' forgeax asset import bake <ttf> <out>',\n '',\n 'Reads a TrueType font file and produces:',\n ` <out>/<basename>.atlas.png — ${DEFAULT_TEXTURE_SIZE}x${DEFAULT_TEXTURE_SIZE} MSDF atlas`,\n ' <out>/<basename>.meta.json — glyph metrics sidecar (importer: font)',\n '',\n ].join('\\n');\n}\n\nfunction helpBody(): string {\n return [\n 'forgeax asset import — MSDF font atlas baking',\n '',\n 'Usage:',\n ' forgeax asset import bake <ttf> <out>',\n '',\n ].join('\\n');\n}\n\nexport async function runCliFont(argv: string[]): Promise<number> {\n const [sub, ...rest] = argv;\n if (sub === undefined || sub === '--help' || sub === '-h') {\n process.stdout.write(`${helpBody()}\\n`);\n return 0;\n }\n if (sub !== 'bake') {\n process.stderr.write(`unknown subcommand: ${sub}\\n`);\n return 1;\n }\n return runBake(rest);\n}\n\nasync function runBake(rest: string[]): Promise<number> {\n if (rest[0] === '--help' || rest[0] === '-h') {\n process.stdout.write(`${bakeHelpBody()}\\n`);\n return 0;\n }\n let positionals: string[];\n try {\n const parsed = parseArgs({ args: rest, allowPositionals: true, strict: true });\n positionals = [...parsed.positionals];\n } catch {\n process.stderr.write('error parsing CLI args\\n');\n return 1;\n }\n const ttfPath = positionals[0];\n const outDir = positionals[1];\n if (ttfPath === undefined || outDir === undefined) {\n process.stderr.write('usage: forgeax asset import bake <ttf> <out>\\n');\n return 1;\n }\n try {\n const result = await bakeFont(ttfPath, outDir, realGeneratorFactory);\n process.stdout.write(`baked ${result.atlasPath} + ${result.sidecarPath}\\n`);\n return 0;\n } catch (e) {\n if (e instanceof FontError) {\n process.stderr.write(\n `${JSON.stringify({ code: e.code, expected: e.expected, hint: e.hint, detail: e.detail })}\\n`,\n );\n return 1;\n }\n process.stderr.write(`bake failed: ${e instanceof Error ? e.message : String(e)}\\n`);\n return 1;\n }\n}\n\nconst isBinEntry = await (async (): Promise<boolean> => {\n const argv1 = process.argv[1];\n if (typeof argv1 !== 'string') return false;\n const argv1Real = await realpath(argv1).catch(() => argv1);\n const selfReal = await realpath(fileURLToPath(import.meta.url)).catch(() =>\n fileURLToPath(import.meta.url),\n );\n return argv1Real === selfReal;\n})();\n\nif (isBinEntry) {\n const exitCode = await runCliFont(process.argv.slice(2));\n process.exit(exitCode);\n}\n"]}
|
package/dist/font-importer.mjs
CHANGED
|
@@ -255,10 +255,10 @@ async function realGeneratorFactory() {
|
|
|
255
255
|
}
|
|
256
256
|
function bakeHelpBody() {
|
|
257
257
|
return [
|
|
258
|
-
"forgeax
|
|
258
|
+
"forgeax asset import bake \u2014 bake MSDF font atlas from TTF",
|
|
259
259
|
"",
|
|
260
260
|
"Usage:",
|
|
261
|
-
" forgeax
|
|
261
|
+
" forgeax asset import bake <ttf> <out>",
|
|
262
262
|
"",
|
|
263
263
|
"Reads a TrueType font file and produces:",
|
|
264
264
|
` <out>/<basename>.atlas.png \u2014 ${DEFAULT_TEXTURE_SIZE}x${DEFAULT_TEXTURE_SIZE} MSDF atlas`,
|
|
@@ -268,10 +268,10 @@ function bakeHelpBody() {
|
|
|
268
268
|
}
|
|
269
269
|
function helpBody() {
|
|
270
270
|
return [
|
|
271
|
-
"forgeax
|
|
271
|
+
"forgeax asset import \u2014 MSDF font atlas baking",
|
|
272
272
|
"",
|
|
273
273
|
"Usage:",
|
|
274
|
-
" forgeax
|
|
274
|
+
" forgeax asset import bake <ttf> <out>",
|
|
275
275
|
""
|
|
276
276
|
].join("\n");
|
|
277
277
|
}
|
|
@@ -306,7 +306,7 @@ async function runBake(rest) {
|
|
|
306
306
|
const ttfPath = positionals[0];
|
|
307
307
|
const outDir = positionals[1];
|
|
308
308
|
if (ttfPath === void 0 || outDir === void 0) {
|
|
309
|
-
process.stderr.write("usage: forgeax
|
|
309
|
+
process.stderr.write("usage: forgeax asset import bake <ttf> <out>\n");
|
|
310
310
|
return 1;
|
|
311
311
|
}
|
|
312
312
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/node-worker-adapter.ts","../src/cli-font.ts","../src/font-importer.ts"],"names":[],"mappings":";;;;;;;;;;AAUO,IAAM,oBAAN,MAAwB;AAAA,EACZ,MAAA;AAAA,EACA,SAAA,uBAAgB,GAAA,EAA8C;AAAA,EACvE,kBAAA;AAAA,EAED,YAAY,GAAA,EAAmB;AACpC,IAAA,IAAA,CAAK,MAAA,GAAS,IAAI,MAAA,CAAO,GAAG,CAAA;AAAA,EAC9B;AAAA,EAEO,WAAA,CAAY,OAAA,EAAkB,Y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;AAAA,MACT,IAAA,EAAM;AAAA,QACJ,GAAI,QAAA,KAAa,MAAA,GAAY,CAAC,EAAE,MAAM,QAAA,CAAS,IAAA,EAAM,CAAA,GAAI,EAAC;AAAA,QAC1D,GAAI,UAAA,KAAe,MAAA,GAAY,CAAC,EAAE,MAAM,UAAA,CAAW,IAAA,EAAM,CAAA,GAAI;AAAC,OAChE;AAAA,MACA,WAAW;AAAC,KACb,CAAA;AAAA,EACH;AACA,EAAA,OAAO,EAAE,EAAA,EAAI,IAAA,EAAM,KAAA,EAAO,EAAE,QAAQ,GAAA,EAAK,kBAAA,EAAoB,EAAC,EAAE,EAAE;AACpE;AAcO,IAAM,YAAA,GAAyB;AAAA,EACpC,GAAA,EAAK,MAAA;AAAA,EACL,MAAA,EAAQ;AACV","file":"font-importer.mjs","sourcesContent":["import { Worker } from 'node:worker_threads';\n\ninterface MessageEventLike {\n readonly data: unknown;\n readonly origin: string;\n}\n\ntype MessageListener = (event: MessageEventLike) => void;\n\n/** Comlink's browser Worker-shaped endpoint backed by a Node worker thread. */\nexport class NodeWorkerAdapter {\n private readonly worker: Worker;\n private readonly listeners = new Map<MessageListener, (data: unknown) => void>();\n private terminationPromise?: Promise<number>;\n\n public constructor(url: string | URL) {\n this.worker = new Worker(url);\n }\n\n public postMessage(message: unknown, transferList: readonly ArrayBuffer[] = []): void {\n if (this.terminationPromise !== undefined) {\n return;\n }\n this.worker.postMessage(message, [...transferList]);\n }\n\n public addEventListener(type: string, listener: MessageListener): void {\n if (type !== 'message') return;\n const handler = (data: unknown) => listener({ data, origin: '*' });\n this.listeners.set(listener, handler);\n this.worker.on('message', handler);\n }\n\n public removeEventListener(type: string, listener: MessageListener): void {\n if (type !== 'message') return;\n const handler = this.listeners.get(listener);\n if (handler === undefined) return;\n this.listeners.delete(listener);\n this.worker.off('message', handler);\n }\n\n public terminate(): Promise<number> {\n if (this.terminationPromise === undefined) {\n this.terminationPromise = this.worker.terminate();\n }\n return this.terminationPromise;\n }\n}\n","#!/usr/bin/env node\n\n// @forgeax/engine-font/src/cli-font — `forgeax-engine-remote-font` plugin\n// bin. Discovered by the base bin via the kubectl 4th-path\n// `forgeax-engine-remote-` prefix scanner.\n//\n// `bake <ttf> <out>` reads a TrueType font and produces an MSDF atlas PNG +\n// a glyph-metrics sidecar JSON (importer: 'font'). The real bake calls\n// @zappar/msdf-generator (feat-20260531-world-space-msdf-text-rendering M5 /\n// w28 -- replaces the M1 placeholder).\n//\n// Error model (FontErrorCode, structured to stderr, exit code 1):\n// - non-TTF magic (not 0x00010000 / 'true' / 'OTTO') -> 'unsupported-font-format'\n// (AC-15 / plan-strategy D-11). The check runs BEFORE the generator so a\n// bad format never reaches the wasm path.\n// - @zappar/msdf-generator throws (wasm / Worker unavailable, internal error)\n// -> 'bake-failed' (charter P3: explicit failure, never a silent exit-0\n// no-atlas). In a plain Node CI without a Web Worker the generator throws\n// 'Worker is not defined' and the bake reports 'bake-failed' (exit 1) --\n// the best-effort real run requires a Worker + wasm host.\n\nimport { Buffer } from 'node:buffer';\nimport { mkdir, readFile, realpath, writeFile } from 'node:fs/promises';\nimport { basename, extname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { parseArgs } from 'node:util';\nimport { deflateSync } from 'node:zlib';\nimport { FontError, type GlyphMetric } from '@forgeax/engine-types';\nimport { NodeWorkerAdapter } from './node-worker-adapter.js';\n\n/**\n * Minimal subset of the @zappar/msdf-generator glyph record consumed by the\n * bake. Mirrors the package's `GlyphInfo` (dist/index.d.ts) -- only the fields\n * the BMFont -> FontAsset mapping needs (toolchain wiki section 4).\n */\nexport interface BakeGlyph {\n readonly unicode: number;\n readonly advance: number;\n readonly xoffset: number;\n readonly yoffset: number;\n readonly atlasPosition: readonly [number, number];\n readonly atlasSize: readonly [number, number];\n}\n\n/**\n * Minimal subset of the @zappar/msdf-generator `MSDFAtlas` consumed by the\n * bake. `texture` carries the RGBA pixel buffer + dimensions (the package's\n * `ImageData`-shaped texture, but reduced to POD so the bake stays\n * environment-agnostic for testing).\n */\nexport interface BakeAtlas {\n readonly texture: { readonly width: number; readonly height: number; readonly data: Uint8Array };\n readonly glyphs: readonly BakeGlyph[];\n readonly metrics: { readonly lineHeight: number; readonly ascender: number };\n readonly textureSize: readonly [number, number];\n readonly fieldRange: number;\n}\n\n/**\n * The bake-time MSDF generator contract. Injected into {@link bakeFont} so\n * unit tests can supply a mock (real path: `@zappar/msdf-generator`'s `MSDF`).\n */\nexport interface MsdfGenerator {\n generateAtlas(ttf: Uint8Array): Promise<BakeAtlas>;\n dispose(): Promise<void>;\n}\n\n/** Default charset baked into the atlas (printable ASCII). */\nconst DEFAULT_CHARSET = (() => {\n let s = '';\n for (let c = 0x20; c <= 0x7e; c++) s += String.fromCharCode(c);\n return s;\n})();\n\nconst DEFAULT_TEXTURE_SIZE = 1024;\nconst DEFAULT_FIELD_RANGE = 4;\nconst DEFAULT_FONT_SIZE = 48;\n\n/**\n * Bake-time sidecar JSON shape (importer: 'font'). Carries the glyph metrics\n * (BMFont -> FontAsset mapping, toolchain wiki section 4) + the common block\n * (distanceRange / atlas dimensions). Parsed by the runtime font load path.\n */\nexport interface BakeSidecar {\n readonly schemaVersion: string;\n readonly kind: 'external-asset-package';\n readonly importer: 'font';\n readonly source: string;\n readonly importSettings: { readonly colorSpace: 'linear'; readonly mipmap: 'none' };\n readonly common: {\n readonly lineHeight: number;\n readonly base: number;\n readonly distanceRange: number;\n readonly pxRange: number;\n readonly atlasWidth: number;\n readonly atlasHeight: number;\n };\n readonly glyphs: Record<number, GlyphMetric>;\n}\n\n/** TTF / OTF magic numbers (first 4 bytes). Per the OpenType spec. */\nfunction isSupportedFontMagic(bytes: Uint8Array): boolean {\n if (bytes.length < 4) return false;\n const b0 = bytes[0] ?? 0;\n const b1 = bytes[1] ?? 0;\n const b2 = bytes[2] ?? 0;\n const b3 = bytes[3] ?? 0;\n // 0x00010000 = TrueType outlines; 'true' (0x74727565) = legacy Apple TTF;\n // 'OTTO' (0x4f54544f) = OpenType with CFF outlines. WOFF/WOFF2 ('wOFF' /\n // 'wOF2') are rejected as non-TTF per AC-15.\n const isTrueType = b0 === 0x00 && b1 === 0x01 && b2 === 0x00 && b3 === 0x00;\n const isTrue = b0 === 0x74 && b1 === 0x72 && b2 === 0x75 && b3 === 0x65;\n const isOtto = b0 === 0x4f && b1 === 0x54 && b2 === 0x54 && b3 === 0x4f;\n return isTrueType || isTrue || isOtto;\n}\n\n/** CRC-32 (PNG / zlib polynomial) over a byte slice. */\nfunction crc32(bytes: Uint8Array): number {\n let crc = 0xffffffff;\n for (let i = 0; i < bytes.length; i++) {\n crc ^= bytes[i] ?? 0;\n for (let k = 0; k < 8; k++) {\n crc = crc & 1 ? (crc >>> 1) ^ 0xedb88320 : crc >>> 1;\n }\n }\n return (crc ^ 0xffffffff) >>> 0;\n}\n\nfunction pngChunk(type: string, data: Uint8Array): Uint8Array {\n const typeBytes = new Uint8Array([\n type.charCodeAt(0),\n type.charCodeAt(1),\n type.charCodeAt(2),\n type.charCodeAt(3),\n ]);\n const body = new Uint8Array(typeBytes.length + data.length);\n body.set(typeBytes, 0);\n body.set(data, typeBytes.length);\n const out = new Uint8Array(4 + body.length + 4);\n const dv = new DataView(out.buffer);\n dv.setUint32(0, data.length);\n out.set(body, 4);\n dv.setUint32(4 + body.length, crc32(body));\n return out;\n}\n\n/**\n * Encode an RGBA pixel buffer into a PNG (zlib deflate, no external deps).\n * The atlas texture from @zappar is RGBA8; this writes a standard 8-bit\n * RGBA PNG so any consumer (engine image importer / browser) can decode it.\n */\nexport function encodePng(width: number, height: number, rgba: Uint8Array): Uint8Array {\n // Filter byte 0 (None) prefixes each scanline.\n const stride = width * 4;\n const raw = new Uint8Array((stride + 1) * height);\n for (let y = 0; y < height; y++) {\n raw[y * (stride + 1)] = 0;\n raw.set(rgba.subarray(y * stride, y * stride + stride), y * (stride + 1) + 1);\n }\n const idat = deflateSync(raw);\n const ihdr = new Uint8Array(13);\n const dv = new DataView(ihdr.buffer);\n dv.setUint32(0, width);\n dv.setUint32(4, height);\n ihdr[8] = 8; // bit depth\n ihdr[9] = 6; // color type RGBA\n ihdr[10] = 0; // compression\n ihdr[11] = 0; // filter\n ihdr[12] = 0; // interlace\n const signature = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);\n const chunks = [\n signature,\n pngChunk('IHDR', ihdr),\n pngChunk('IDAT', new Uint8Array(idat)),\n pngChunk('IEND', new Uint8Array(0)),\n ];\n const total = chunks.reduce((n, c) => n + c.length, 0);\n const out = new Uint8Array(total);\n let off = 0;\n for (const c of chunks) {\n out.set(c, off);\n off += c.length;\n }\n return out;\n}\n\n/** Map a @zappar atlas into the FontAsset glyph-metrics sidecar shape. */\nexport function atlasToSidecar(atlas: BakeAtlas, sourcePng: string): BakeSidecar {\n const glyphs: Record<number, GlyphMetric> = {};\n for (const g of atlas.glyphs) {\n glyphs[g.unicode] = {\n advance: g.advance,\n bearingX: g.xoffset,\n bearingY: g.yoffset,\n size: { w: g.atlasSize[0], h: g.atlasSize[1] },\n region: {\n x: g.atlasPosition[0],\n y: g.atlasPosition[1],\n w: g.atlasSize[0],\n h: g.atlasSize[1],\n },\n };\n }\n return {\n schemaVersion: '1.0.0',\n kind: 'external-asset-package',\n importer: 'font',\n source: sourcePng,\n importSettings: { colorSpace: 'linear', mipmap: 'none' },\n common: {\n lineHeight: atlas.metrics.lineHeight,\n base: atlas.metrics.ascender,\n distanceRange: atlas.fieldRange,\n pxRange: atlas.fieldRange,\n atlasWidth: atlas.textureSize[0],\n atlasHeight: atlas.textureSize[1],\n },\n glyphs,\n };\n}\n\n/** Result of a successful bake -- the written artefact paths. */\nexport interface BakeResult {\n readonly atlasPath: string;\n readonly sidecarPath: string;\n}\n\n/**\n * Bake an MSDF atlas + glyph-metrics sidecar from a TTF.\n *\n * @param ttfPath path to the TrueType source.\n * @param outDir output directory (created if missing).\n * @param generatorFactory yields the MSDF generator (real: @zappar; tests: mock).\n * @returns `Result`-style: throws a {@link FontError} on every failure mode\n * (unsupported-font-format before the generator runs; bake-failed when the\n * generator throws). The CLI layer maps the thrown FontError to a structured\n * stderr line + exit code 1 -- never a silent exit 0 without artefacts\n * (charter P3).\n */\nexport async function bakeFont(\n ttfPath: string,\n outDir: string,\n generatorFactory: () => Promise<MsdfGenerator>,\n): Promise<BakeResult> {\n const ttf = await readFile(ttfPath);\n const ttfBytes = new Uint8Array(ttf.buffer, ttf.byteOffset, ttf.byteLength);\n if (!isSupportedFontMagic(ttfBytes)) {\n throw new FontError({\n code: 'unsupported-font-format',\n expected: 'ttf',\n hint: 'bake accepts TrueType (.ttf / 0x00010000 / \"true\") or OpenType-TTF (\"OTTO\") sources; WOFF / WOFF2 / other formats are not supported -- convert to TTF first',\n detail: { path: ttfPath },\n });\n }\n\n let atlas: BakeAtlas;\n let generator: MsdfGenerator | undefined;\n try {\n generator = await generatorFactory();\n atlas = await generator.generateAtlas(ttfBytes);\n } catch (e) {\n throw new FontError({\n code: 'bake-failed',\n expected: '@zappar/msdf-generator to produce an MSDF atlas',\n hint: 'the MSDF generator threw -- a Web Worker + wasm host is required (a plain Node process reports \"Worker is not defined\"); run the bake in a Worker-capable environment',\n detail: { cause: e instanceof Error ? e.message : String(e) },\n });\n } finally {\n if (generator !== undefined) {\n await generator.dispose().catch(() => undefined);\n }\n }\n\n await mkdir(outDir, { recursive: true });\n const base = basename(ttfPath, extname(ttfPath));\n const atlasName = `${base}.atlas.png`;\n const atlasPath = join(outDir, atlasName);\n const sidecarPath = join(outDir, `${base}.meta.json`);\n const png = encodePng(atlas.texture.width, atlas.texture.height, atlas.texture.data);\n await writeFile(atlasPath, png);\n const sidecar = atlasToSidecar(atlas, atlasName);\n await writeFile(sidecarPath, `${JSON.stringify(sidecar, null, 2)}\\n`);\n return { atlasPath, sidecarPath };\n}\n\n/**\n * Real @zappar/msdf-generator factory. Dynamically imported so a non-bake\n * subcommand (or a test that injects a mock) never pays the wasm load cost,\n * and so the package builds without the browser globals the generator needs.\n */\n/**\n * Shape of @zappar/msdf-generator's `MSDFAtlas` (dist/index.d.ts) that the\n * real factory adapts into the POD {@link BakeAtlas}. The package's `texture`\n * is an ImageData-shaped `{ width, height, data }`; we read those fields\n * structurally so the font package never needs the DOM `ImageData` type.\n */\ninterface ZapparAtlas {\n texture: { width: number; height: number; data: Uint8ClampedArray | Uint8Array };\n glyphs: ReadonlyArray<{\n unicode: number;\n advance: number;\n xoffset: number;\n yoffset: number;\n atlasPosition: [number, number];\n atlasSize: [number, number];\n }>;\n metrics: { lineHeight: number; ascender: number };\n textureSize: [number, number];\n fieldRange: number;\n}\n\nexport async function realGeneratorFactory(): Promise<MsdfGenerator> {\n const mod = (await import('@zappar/msdf-generator')) as unknown as {\n MSDF: new (config?: {\n workerUrl?: URL;\n wasmUrl?: string;\n }) => {\n initialize(): Promise<void>;\n generateAtlas(opts: {\n font: Uint8Array;\n charset: string;\n textureSize: [number, number];\n fieldRange: number;\n fontSize: number;\n }): Promise<ZapparAtlas>;\n dispose(): Promise<void>;\n };\n };\n\n const wasmModuleUrl = import.meta.resolve('@zappar/msdf-generator/msdfgen_wasm.wasm');\n const wasmBytes = await readFile(new URL(wasmModuleUrl));\n const wasmUrl = `data:application/octet-stream;base64,${Buffer.from(wasmBytes).toString('base64')}`;\n const nodeGlobal = globalThis as unknown as { Worker?: typeof NodeWorkerAdapter };\n const previousWorker = nodeGlobal.Worker;\n nodeGlobal.Worker = NodeWorkerAdapter;\n let msdf: InstanceType<typeof mod.MSDF> | undefined;\n try {\n msdf = new mod.MSDF({\n workerUrl: new URL('./node-msdf-worker.mjs', import.meta.url),\n wasmUrl,\n });\n await msdf.initialize();\n } finally {\n if (previousWorker === undefined) {\n delete nodeGlobal.Worker;\n } else {\n nodeGlobal.Worker = previousWorker;\n }\n }\n if (msdf === undefined) {\n throw new Error('the MSDF generator did not initialize');\n }\n return {\n async generateAtlas(ttf: Uint8Array): Promise<BakeAtlas> {\n const a = await msdf.generateAtlas({\n font: ttf,\n charset: DEFAULT_CHARSET,\n textureSize: [DEFAULT_TEXTURE_SIZE, DEFAULT_TEXTURE_SIZE],\n fieldRange: DEFAULT_FIELD_RANGE,\n fontSize: DEFAULT_FONT_SIZE,\n });\n return {\n texture: {\n width: a.texture.width,\n height: a.texture.height,\n data: new Uint8Array(a.texture.data),\n },\n glyphs: a.glyphs.map((g) => ({\n unicode: g.unicode,\n advance: g.advance,\n xoffset: g.xoffset,\n yoffset: g.yoffset,\n atlasPosition: [g.atlasPosition[0], g.atlasPosition[1]],\n atlasSize: [g.atlasSize[0], g.atlasSize[1]],\n })),\n metrics: { lineHeight: a.metrics.lineHeight, ascender: a.metrics.ascender },\n textureSize: [a.textureSize[0], a.textureSize[1]],\n fieldRange: a.fieldRange,\n };\n },\n async dispose(): Promise<void> {\n await msdf.dispose();\n },\n };\n}\n\nfunction bakeHelpBody(): string {\n return [\n 'forgeax-engine-remote-font bake — bake MSDF font atlas from TTF',\n '',\n 'Usage:',\n ' forgeax-engine-remote-font bake <ttf> <out>',\n '',\n 'Reads a TrueType font file and produces:',\n ` <out>/<basename>.atlas.png — ${DEFAULT_TEXTURE_SIZE}x${DEFAULT_TEXTURE_SIZE} MSDF atlas`,\n ' <out>/<basename>.meta.json — glyph metrics sidecar (importer: font)',\n '',\n ].join('\\n');\n}\n\nfunction helpBody(): string {\n return [\n 'forgeax-engine-remote-font — MSDF font atlas baking',\n '',\n 'Usage:',\n ' forgeax-engine-remote-font bake <ttf> <out>',\n '',\n ].join('\\n');\n}\n\nexport async function runCliFont(argv: string[]): Promise<number> {\n const [sub, ...rest] = argv;\n if (sub === undefined || sub === '--help' || sub === '-h') {\n process.stdout.write(`${helpBody()}\\n`);\n return 0;\n }\n if (sub !== 'bake') {\n process.stderr.write(`unknown subcommand: ${sub}\\n`);\n return 1;\n }\n return runBake(rest);\n}\n\nasync function runBake(rest: string[]): Promise<number> {\n if (rest[0] === '--help' || rest[0] === '-h') {\n process.stdout.write(`${bakeHelpBody()}\\n`);\n return 0;\n }\n let positionals: string[];\n try {\n const parsed = parseArgs({ args: rest, allowPositionals: true, strict: true });\n positionals = [...parsed.positionals];\n } catch {\n process.stderr.write('error parsing CLI args\\n');\n return 1;\n }\n const ttfPath = positionals[0];\n const outDir = positionals[1];\n if (ttfPath === undefined || outDir === undefined) {\n process.stderr.write('usage: forgeax-engine-remote-font bake <ttf> <out>\\n');\n return 1;\n }\n try {\n const result = await bakeFont(ttfPath, outDir, realGeneratorFactory);\n process.stdout.write(`baked ${result.atlasPath} + ${result.sidecarPath}\\n`);\n return 0;\n } catch (e) {\n if (e instanceof FontError) {\n process.stderr.write(\n `${JSON.stringify({ code: e.code, expected: e.expected, hint: e.hint, detail: e.detail })}\\n`,\n );\n return 1;\n }\n process.stderr.write(`bake failed: ${e instanceof Error ? e.message : String(e)}\\n`);\n return 1;\n }\n}\n\nconst isBinEntry = await (async (): Promise<boolean> => {\n const argv1 = process.argv[1];\n if (typeof argv1 !== 'string') return false;\n const argv1Real = await realpath(argv1).catch(() => argv1);\n const selfReal = await realpath(fileURLToPath(import.meta.url)).catch(() =>\n fileURLToPath(import.meta.url),\n );\n return argv1Real === selfReal;\n})();\n\nif (isBinEntry) {\n const exitCode = await runCliFont(process.argv.slice(2));\n process.exit(exitCode);\n}\n","// font-importer.ts - the build-time fontImporter (feat-20260603-asset-import-loader-injection M3 / w24).\n//\n// The `{ key: 'font', import }` Importer the @forgeax/engine-import runner\n// dispatches a `*.meta.json` with `importer: 'font'` to. It absorbs the MSDF\n// bake that previously lived only behind the `forgeax-engine-remote-font\n// bake` CLI: read the `.ttf` source -> @zappar/msdf-generator atlas ->\n// (a) one atlas `TextureAsset` ImportedAsset (the RGBA MSDF atlas, kind\n// 'texture') under the declared `kind: 'texture'` sub-asset GUID, (b) one\n// sampler ImportedAsset under the declared `kind: 'sampler'` sub-asset GUID,\n// and (c) one font glyph-metrics ImportedAsset (kind 'font') under the\n// declared `kind: 'font'` sub-asset GUID. The font carries the BMFont ->\n// FontAsset glyph map + the common block + atlas/sampler GUID refs.\n//\n// Build-time-only boundary (AC-18 / requirements callout): @zappar/msdf-generator\n// is a generator dependency that MUST stay out of the runtime bundle. The\n// runtime today statically imports ZERO @forgeax/engine-font and ZERO @zappar\n// symbols (research Finding 7); this importer keeps that invariant. fontImporter\n// is a NODE-ONLY sub-export (`@forgeax/engine-font/font-importer`,\n// `default: null` under browser conditions); the generator is dynamically\n// imported (cli-font realGeneratorFactory) so even the build-time graph only\n// pays the wasm load cost when a font is actually baked. The runtime fontLoader\n// (M1 w6) reads an already-baked atlas DDC and has no bake dependency.\n//\n// GUID import-stable iron law: produced GUIDs come from `ctx.subAssets[]`. The\n// font sidecar declares `texture`, `sampler`, and `font` sub-assets; this\n// importer maps the bake output onto those declared GUIDs and stamps nothing\n// of its own.\n//\n// `ctx.importSettings` may inject a test `generatorFactory` (an\n// `() => Promise<MsdfGenerator>`) so unit tests drive the bake with a mock\n// instead of the real wasm generator; production import calls fall through to\n// the real @zappar factory.\n\nimport type {\n FontAsset,\n GlyphMetric,\n ImportContext,\n ImportedAsset,\n Importer,\n ImportResult,\n SamplerAsset,\n TextureAsset,\n} from '@forgeax/engine-types';\nimport type { BakeAtlas, MsdfGenerator } from './cli-font.js';\nimport { realGeneratorFactory } from './cli-font.js';\n\n/** Stable semantic identities for the three writable font outputs. */\nexport function sourceKeyForFontOutput(kind: string): string | undefined {\n const normalizedKind = kind.trim();\n return normalizedKind.length === 0 ? undefined : `font:${normalizedKind}`;\n}\n\nexport function fontOutputSourceKeys(): readonly string[] {\n return ['texture', 'sampler', 'font'].map((kind) => sourceKeyForFontOutput(kind) as string);\n}\n\n/** Map the @zappar atlas glyphs into the FontAsset glyph-metrics record. */\nfunction atlasGlyphsToMetrics(atlas: BakeAtlas): Record<number, GlyphMetric> {\n const glyphs: Record<number, GlyphMetric> = {};\n for (const g of atlas.glyphs) {\n glyphs[g.unicode] = {\n advance: g.advance,\n bearingX: g.xoffset,\n bearingY: g.yoffset,\n size: { w: g.atlasSize[0], h: g.atlasSize[1] },\n region: {\n x: g.atlasPosition[0],\n y: g.atlasPosition[1],\n w: g.atlasSize[0],\n h: g.atlasSize[1],\n },\n };\n }\n return glyphs;\n}\n\nfunction makeAtlasTexture(atlas: BakeAtlas): TextureAsset {\n return {\n kind: 'texture',\n shape: {\n viewDimension: '2d',\n extent: { width: atlas.texture.width, height: atlas.texture.height },\n },\n // MSDF atlas is linear-space RGBA8 (signed-distance channels, never gamma).\n format: 'rgba8unorm',\n data: atlas.texture.data,\n colorSpace: 'linear',\n mips: { kind: 'none' },\n };\n}\n\nfunction makeFontCommon(atlas: BakeAtlas): FontAsset['common'] {\n return {\n lineHeight: atlas.metrics.lineHeight,\n base: atlas.metrics.ascender,\n distanceRange: atlas.fieldRange,\n pxRange: atlas.fieldRange,\n atlasWidth: atlas.textureSize[0],\n atlasHeight: atlas.textureSize[1],\n };\n}\n\nfunction makeAtlasSampler(): SamplerAsset {\n return {\n kind: 'sampler',\n addressModeU: 'clamp-to-edge',\n addressModeV: 'clamp-to-edge',\n addressModeW: 'clamp-to-edge',\n magFilter: 'linear',\n minFilter: 'linear',\n mipmapFilter: 'nearest',\n };\n}\n\nasync function importFont(ctx: ImportContext): Promise<ImportResult> {\n const read = await ctx.readSource();\n if (!read.ok) {\n throw new Error(\n `fontImporter: readSource failed: ${read.error instanceof Error ? read.error.message : String(read.error)}`,\n );\n }\n\n const factory =\n (ctx.importSettings.generatorFactory as (() => Promise<MsdfGenerator>) | undefined) ??\n realGeneratorFactory;\n const generator = await factory();\n let atlas: BakeAtlas;\n try {\n atlas = await generator.generateAtlas(read.value);\n } finally {\n await generator.dispose().catch(() => undefined);\n }\n\n const atlasSub = ctx.subAssets.find((s) => s.kind === 'texture');\n const samplerSub = ctx.subAssets.find((s) => s.kind === 'sampler');\n const fontSub = ctx.subAssets.find((s) => s.kind === 'font');\n const out: ImportedAsset[] = [];\n if (atlasSub !== undefined) {\n out.push({\n guid: atlasSub.guid,\n kind: 'texture',\n payload: makeAtlasTexture(atlas),\n refs: [],\n artifacts: {\n atlas: {\n // Pack v2's runtime texture loader consumes non-Basis artifacts as\n // raw pixels. Keep the baked RGBA8 MSDF atlas in that form here;\n // the CLI still emits a PNG for standalone bake output.\n mediaType: 'application/octet-stream',\n bytes: atlas.texture.data,\n },\n },\n });\n }\n if (samplerSub !== undefined) {\n out.push({\n guid: samplerSub.guid,\n kind: 'sampler',\n payload: makeAtlasSampler(),\n refs: [],\n artifacts: {},\n });\n }\n if (fontSub !== undefined) {\n // The runtime font loader reads atlasGuid / samplerGuid / glyphs / common\n // off the DDC payload (asset-registry loadFontAsset); the produced payload\n // mirrors that shape. atlas Handle / sampler Handle are runtime-resolved\n // from the GUID refs, so the build-time payload carries the GUID strings\n // (cast through FontAsset for the ImportedAsset.payload Asset slot, same\n // build-time POD-vs-Handle bridge the gltfImporter scene arm uses).\n const fontPayload = {\n kind: 'font',\n atlasGuid: atlasSub?.guid ?? '',\n samplerGuid: samplerSub?.guid ?? '',\n glyphs: atlasGlyphsToMetrics(atlas),\n common: makeFontCommon(atlas),\n } as unknown as FontAsset;\n out.push({\n guid: fontSub.guid,\n kind: 'font',\n payload: fontPayload,\n refs: [\n ...(atlasSub !== undefined ? [{ guid: atlasSub.guid }] : []),\n ...(samplerSub !== undefined ? [{ guid: samplerSub.guid }] : []),\n ],\n artifacts: {},\n });\n }\n return { ok: true, value: { assets: out, sourceDependencies: [] } };\n}\n\n/**\n * The font {@link Importer}. Register it into an `ImporterRegistry` so the\n * import runner dispatches `meta.importer === 'font'` sidecars here.\n *\n * @example\n * ```ts\n * import { ImporterRegistry } from '@forgeax/engine-import';\n * import { fontImporter } from '@forgeax/engine-font/font-importer';\n * const importers = new ImporterRegistry();\n * importers.register(fontImporter);\n * ```\n */\nexport const fontImporter: Importer = {\n key: 'font',\n import: importFont,\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/node-worker-adapter.ts","../src/cli-font.ts","../src/font-importer.ts"],"names":[],"mappings":";;;;;;;;;;AAU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Y,IAAA,IAAQ,EAAA;AAAA,MACjC,MAAA,EAAQ,qBAAqB,KAAK,CAAA;AAAA,MAClC,MAAA,EAAQ,eAAe,KAAK;AAAA,KAC9B;AACA,IAAA,GAAA,CAAI,IAAA,CAAK;AAAA,MACP,MAAM,OAAA,CAAQ,IAAA;AAAA,MACd,IAAA,EAAM,MAAA;AAAA,MACN,OAAA,EAAS,WAAA;AAAA,MACT,IAAA,EAAM;AAAA,QACJ,GAAI,QAAA,KAAa,MAAA,GAAY,CAAC,EAAE,MAAM,QAAA,CAAS,IAAA,EAAM,CAAA,GAAI,EAAC;AAAA,QAC1D,GAAI,UAAA,KAAe,MAAA,GAAY,CAAC,EAAE,MAAM,UAAA,CAAW,IAAA,EAAM,CAAA,GAAI;AAAC,OAChE;AAAA,MACA,WAAW;AAAC,KACb,CAAA;AAAA,EACH;AACA,EAAA,OAAO,EAAE,EAAA,EAAI,IAAA,EAAM,KAAA,EAAO,EAAE,QAAQ,GAAA,EAAK,kBAAA,EAAoB,EAAC,EAAE,EAAE;AACpE;AAcO,IAAM,YAAA,GAAyB;AAAA,EACpC,GAAA,EAAK,MAAA;AAAA,EACL,MAAA,EAAQ;AACV","file":"font-importer.mjs","sourcesContent":["import { Worker } from 'node:worker_threads';\n\ninterface MessageEventLike {\n readonly data: unknown;\n readonly origin: string;\n}\n\ntype MessageListener = (event: MessageEventLike) => void;\n\n/** Comlink's browser Worker-shaped endpoint backed by a Node worker thread. */\nexport class NodeWorkerAdapter {\n private readonly worker: Worker;\n private readonly listeners = new Map<MessageListener, (data: unknown) => void>();\n private terminationPromise?: Promise<number>;\n\n public constructor(url: string | URL) {\n this.worker = new Worker(url);\n }\n\n public postMessage(message: unknown, transferList: readonly ArrayBuffer[] = []): void {\n if (this.terminationPromise !== undefined) {\n return;\n }\n this.worker.postMessage(message, [...transferList]);\n }\n\n public addEventListener(type: string, listener: MessageListener): void {\n if (type !== 'message') return;\n const handler = (data: unknown) => listener({ data, origin: '*' });\n this.listeners.set(listener, handler);\n this.worker.on('message', handler);\n }\n\n public removeEventListener(type: string, listener: MessageListener): void {\n if (type !== 'message') return;\n const handler = this.listeners.get(listener);\n if (handler === undefined) return;\n this.listeners.delete(listener);\n this.worker.off('message', handler);\n }\n\n public terminate(): Promise<number> {\n if (this.terminationPromise === undefined) {\n this.terminationPromise = this.worker.terminate();\n }\n return this.terminationPromise;\n }\n}\n","#!/usr/bin/env node\n\n// @forgeax/engine-font/src/cli-font — `forgeax asset import` plugin\n// bin. Discovered by the base bin via the kubectl 4th-path\n// unified `forgeax asset import` producer.\n//\n// `bake <ttf> <out>` reads a TrueType font and produces an MSDF atlas PNG +\n// a glyph-metrics sidecar JSON (importer: 'font'). The real bake calls\n// @zappar/msdf-generator (feat-20260531-world-space-msdf-text-rendering M5 /\n// w28 -- replaces the M1 placeholder).\n//\n// Error model (FontErrorCode, structured to stderr, exit code 1):\n// - non-TTF magic (not 0x00010000 / 'true' / 'OTTO') -> 'unsupported-font-format'\n// (AC-15 / plan-strategy D-11). The check runs BEFORE the generator so a\n// bad format never reaches the wasm path.\n// - @zappar/msdf-generator throws (wasm / Worker unavailable, internal error)\n// -> 'bake-failed' (charter P3: explicit failure, never a silent exit-0\n// no-atlas). In a plain Node CI without a Web Worker the generator throws\n// 'Worker is not defined' and the bake reports 'bake-failed' (exit 1) --\n// the best-effort real run requires a Worker + wasm host.\n\nimport { Buffer } from 'node:buffer';\nimport { mkdir, readFile, realpath, writeFile } from 'node:fs/promises';\nimport { basename, extname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { parseArgs } from 'node:util';\nimport { deflateSync } from 'node:zlib';\nimport { FontError, type GlyphMetric } from '@forgeax/engine-types';\nimport { NodeWorkerAdapter } from './node-worker-adapter.js';\n\n/**\n * Minimal subset of the @zappar/msdf-generator glyph record consumed by the\n * bake. Mirrors the package's `GlyphInfo` (dist/index.d.ts) -- only the fields\n * the BMFont -> FontAsset mapping needs (toolchain wiki section 4).\n */\nexport interface BakeGlyph {\n readonly unicode: number;\n readonly advance: number;\n readonly xoffset: number;\n readonly yoffset: number;\n readonly atlasPosition: readonly [number, number];\n readonly atlasSize: readonly [number, number];\n}\n\n/**\n * Minimal subset of the @zappar/msdf-generator `MSDFAtlas` consumed by the\n * bake. `texture` carries the RGBA pixel buffer + dimensions (the package's\n * `ImageData`-shaped texture, but reduced to POD so the bake stays\n * environment-agnostic for testing).\n */\nexport interface BakeAtlas {\n readonly texture: { readonly width: number; readonly height: number; readonly data: Uint8Array };\n readonly glyphs: readonly BakeGlyph[];\n readonly metrics: { readonly lineHeight: number; readonly ascender: number };\n readonly textureSize: readonly [number, number];\n readonly fieldRange: number;\n}\n\n/**\n * The bake-time MSDF generator contract. Injected into {@link bakeFont} so\n * unit tests can supply a mock (real path: `@zappar/msdf-generator`'s `MSDF`).\n */\nexport interface MsdfGenerator {\n generateAtlas(ttf: Uint8Array): Promise<BakeAtlas>;\n dispose(): Promise<void>;\n}\n\n/** Default charset baked into the atlas (printable ASCII). */\nconst DEFAULT_CHARSET = (() => {\n let s = '';\n for (let c = 0x20; c <= 0x7e; c++) s += String.fromCharCode(c);\n return s;\n})();\n\nconst DEFAULT_TEXTURE_SIZE = 1024;\nconst DEFAULT_FIELD_RANGE = 4;\nconst DEFAULT_FONT_SIZE = 48;\n\n/**\n * Bake-time sidecar JSON shape (importer: 'font'). Carries the glyph metrics\n * (BMFont -> FontAsset mapping, toolchain wiki section 4) + the common block\n * (distanceRange / atlas dimensions). Parsed by the runtime font load path.\n */\nexport interface BakeSidecar {\n readonly schemaVersion: string;\n readonly kind: 'external-asset-package';\n readonly importer: 'font';\n readonly source: string;\n readonly importSettings: { readonly colorSpace: 'linear'; readonly mipmap: 'none' };\n readonly common: {\n readonly lineHeight: number;\n readonly base: number;\n readonly distanceRange: number;\n readonly pxRange: number;\n readonly atlasWidth: number;\n readonly atlasHeight: number;\n };\n readonly glyphs: Record<number, GlyphMetric>;\n}\n\n/** TTF / OTF magic numbers (first 4 bytes). Per the OpenType spec. */\nfunction isSupportedFontMagic(bytes: Uint8Array): boolean {\n if (bytes.length < 4) return false;\n const b0 = bytes[0] ?? 0;\n const b1 = bytes[1] ?? 0;\n const b2 = bytes[2] ?? 0;\n const b3 = bytes[3] ?? 0;\n // 0x00010000 = TrueType outlines; 'true' (0x74727565) = legacy Apple TTF;\n // 'OTTO' (0x4f54544f) = OpenType with CFF outlines. WOFF/WOFF2 ('wOFF' /\n // 'wOF2') are rejected as non-TTF per AC-15.\n const isTrueType = b0 === 0x00 && b1 === 0x01 && b2 === 0x00 && b3 === 0x00;\n const isTrue = b0 === 0x74 && b1 === 0x72 && b2 === 0x75 && b3 === 0x65;\n const isOtto = b0 === 0x4f && b1 === 0x54 && b2 === 0x54 && b3 === 0x4f;\n return isTrueType || isTrue || isOtto;\n}\n\n/** CRC-32 (PNG / zlib polynomial) over a byte slice. */\nfunction crc32(bytes: Uint8Array): number {\n let crc = 0xffffffff;\n for (let i = 0; i < bytes.length; i++) {\n crc ^= bytes[i] ?? 0;\n for (let k = 0; k < 8; k++) {\n crc = crc & 1 ? (crc >>> 1) ^ 0xedb88320 : crc >>> 1;\n }\n }\n return (crc ^ 0xffffffff) >>> 0;\n}\n\nfunction pngChunk(type: string, data: Uint8Array): Uint8Array {\n const typeBytes = new Uint8Array([\n type.charCodeAt(0),\n type.charCodeAt(1),\n type.charCodeAt(2),\n type.charCodeAt(3),\n ]);\n const body = new Uint8Array(typeBytes.length + data.length);\n body.set(typeBytes, 0);\n body.set(data, typeBytes.length);\n const out = new Uint8Array(4 + body.length + 4);\n const dv = new DataView(out.buffer);\n dv.setUint32(0, data.length);\n out.set(body, 4);\n dv.setUint32(4 + body.length, crc32(body));\n return out;\n}\n\n/**\n * Encode an RGBA pixel buffer into a PNG (zlib deflate, no external deps).\n * The atlas texture from @zappar is RGBA8; this writes a standard 8-bit\n * RGBA PNG so any consumer (engine image importer / browser) can decode it.\n */\nexport function encodePng(width: number, height: number, rgba: Uint8Array): Uint8Array {\n // Filter byte 0 (None) prefixes each scanline.\n const stride = width * 4;\n const raw = new Uint8Array((stride + 1) * height);\n for (let y = 0; y < height; y++) {\n raw[y * (stride + 1)] = 0;\n raw.set(rgba.subarray(y * stride, y * stride + stride), y * (stride + 1) + 1);\n }\n const idat = deflateSync(raw);\n const ihdr = new Uint8Array(13);\n const dv = new DataView(ihdr.buffer);\n dv.setUint32(0, width);\n dv.setUint32(4, height);\n ihdr[8] = 8; // bit depth\n ihdr[9] = 6; // color type RGBA\n ihdr[10] = 0; // compression\n ihdr[11] = 0; // filter\n ihdr[12] = 0; // interlace\n const signature = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);\n const chunks = [\n signature,\n pngChunk('IHDR', ihdr),\n pngChunk('IDAT', new Uint8Array(idat)),\n pngChunk('IEND', new Uint8Array(0)),\n ];\n const total = chunks.reduce((n, c) => n + c.length, 0);\n const out = new Uint8Array(total);\n let off = 0;\n for (const c of chunks) {\n out.set(c, off);\n off += c.length;\n }\n return out;\n}\n\n/** Map a @zappar atlas into the FontAsset glyph-metrics sidecar shape. */\nexport function atlasToSidecar(atlas: BakeAtlas, sourcePng: string): BakeSidecar {\n const glyphs: Record<number, GlyphMetric> = {};\n for (const g of atlas.glyphs) {\n glyphs[g.unicode] = {\n advance: g.advance,\n bearingX: g.xoffset,\n bearingY: g.yoffset,\n size: { w: g.atlasSize[0], h: g.atlasSize[1] },\n region: {\n x: g.atlasPosition[0],\n y: g.atlasPosition[1],\n w: g.atlasSize[0],\n h: g.atlasSize[1],\n },\n };\n }\n return {\n schemaVersion: '1.0.0',\n kind: 'external-asset-package',\n importer: 'font',\n source: sourcePng,\n importSettings: { colorSpace: 'linear', mipmap: 'none' },\n common: {\n lineHeight: atlas.metrics.lineHeight,\n base: atlas.metrics.ascender,\n distanceRange: atlas.fieldRange,\n pxRange: atlas.fieldRange,\n atlasWidth: atlas.textureSize[0],\n atlasHeight: atlas.textureSize[1],\n },\n glyphs,\n };\n}\n\n/** Result of a successful bake -- the written artefact paths. */\nexport interface BakeResult {\n readonly atlasPath: string;\n readonly sidecarPath: string;\n}\n\n/**\n * Bake an MSDF atlas + glyph-metrics sidecar from a TTF.\n *\n * @param ttfPath path to the TrueType source.\n * @param outDir output directory (created if missing).\n * @param generatorFactory yields the MSDF generator (real: @zappar; tests: mock).\n * @returns `Result`-style: throws a {@link FontError} on every failure mode\n * (unsupported-font-format before the generator runs; bake-failed when the\n * generator throws). The CLI layer maps the thrown FontError to a structured\n * stderr line + exit code 1 -- never a silent exit 0 without artefacts\n * (charter P3).\n */\nexport async function bakeFont(\n ttfPath: string,\n outDir: string,\n generatorFactory: () => Promise<MsdfGenerator>,\n): Promise<BakeResult> {\n const ttf = await readFile(ttfPath);\n const ttfBytes = new Uint8Array(ttf.buffer, ttf.byteOffset, ttf.byteLength);\n if (!isSupportedFontMagic(ttfBytes)) {\n throw new FontError({\n code: 'unsupported-font-format',\n expected: 'ttf',\n hint: 'bake accepts TrueType (.ttf / 0x00010000 / \"true\") or OpenType-TTF (\"OTTO\") sources; WOFF / WOFF2 / other formats are not supported -- convert to TTF first',\n detail: { path: ttfPath },\n });\n }\n\n let atlas: BakeAtlas;\n let generator: MsdfGenerator | undefined;\n try {\n generator = await generatorFactory();\n atlas = await generator.generateAtlas(ttfBytes);\n } catch (e) {\n throw new FontError({\n code: 'bake-failed',\n expected: '@zappar/msdf-generator to produce an MSDF atlas',\n hint: 'the MSDF generator threw -- a Web Worker + wasm host is required (a plain Node process reports \"Worker is not defined\"); run the bake in a Worker-capable environment',\n detail: { cause: e instanceof Error ? e.message : String(e) },\n });\n } finally {\n if (generator !== undefined) {\n await generator.dispose().catch(() => undefined);\n }\n }\n\n await mkdir(outDir, { recursive: true });\n const base = basename(ttfPath, extname(ttfPath));\n const atlasName = `${base}.atlas.png`;\n const atlasPath = join(outDir, atlasName);\n const sidecarPath = join(outDir, `${base}.meta.json`);\n const png = encodePng(atlas.texture.width, atlas.texture.height, atlas.texture.data);\n await writeFile(atlasPath, png);\n const sidecar = atlasToSidecar(atlas, atlasName);\n await writeFile(sidecarPath, `${JSON.stringify(sidecar, null, 2)}\\n`);\n return { atlasPath, sidecarPath };\n}\n\n/**\n * Real @zappar/msdf-generator factory. Dynamically imported so a non-bake\n * subcommand (or a test that injects a mock) never pays the wasm load cost,\n * and so the package builds without the browser globals the generator needs.\n */\n/**\n * Shape of @zappar/msdf-generator's `MSDFAtlas` (dist/index.d.ts) that the\n * real factory adapts into the POD {@link BakeAtlas}. The package's `texture`\n * is an ImageData-shaped `{ width, height, data }`; we read those fields\n * structurally so the font package never needs the DOM `ImageData` type.\n */\ninterface ZapparAtlas {\n texture: { width: number; height: number; data: Uint8ClampedArray | Uint8Array };\n glyphs: ReadonlyArray<{\n unicode: number;\n advance: number;\n xoffset: number;\n yoffset: number;\n atlasPosition: [number, number];\n atlasSize: [number, number];\n }>;\n metrics: { lineHeight: number; ascender: number };\n textureSize: [number, number];\n fieldRange: number;\n}\n\nexport async function realGeneratorFactory(): Promise<MsdfGenerator> {\n const mod = (await import('@zappar/msdf-generator')) as unknown as {\n MSDF: new (config?: {\n workerUrl?: URL;\n wasmUrl?: string;\n }) => {\n initialize(): Promise<void>;\n generateAtlas(opts: {\n font: Uint8Array;\n charset: string;\n textureSize: [number, number];\n fieldRange: number;\n fontSize: number;\n }): Promise<ZapparAtlas>;\n dispose(): Promise<void>;\n };\n };\n\n const wasmModuleUrl = import.meta.resolve('@zappar/msdf-generator/msdfgen_wasm.wasm');\n const wasmBytes = await readFile(new URL(wasmModuleUrl));\n const wasmUrl = `data:application/octet-stream;base64,${Buffer.from(wasmBytes).toString('base64')}`;\n const nodeGlobal = globalThis as unknown as { Worker?: typeof NodeWorkerAdapter };\n const previousWorker = nodeGlobal.Worker;\n nodeGlobal.Worker = NodeWorkerAdapter;\n let msdf: InstanceType<typeof mod.MSDF> | undefined;\n try {\n msdf = new mod.MSDF({\n workerUrl: new URL('./node-msdf-worker.mjs', import.meta.url),\n wasmUrl,\n });\n await msdf.initialize();\n } finally {\n if (previousWorker === undefined) {\n delete nodeGlobal.Worker;\n } else {\n nodeGlobal.Worker = previousWorker;\n }\n }\n if (msdf === undefined) {\n throw new Error('the MSDF generator did not initialize');\n }\n return {\n async generateAtlas(ttf: Uint8Array): Promise<BakeAtlas> {\n const a = await msdf.generateAtlas({\n font: ttf,\n charset: DEFAULT_CHARSET,\n textureSize: [DEFAULT_TEXTURE_SIZE, DEFAULT_TEXTURE_SIZE],\n fieldRange: DEFAULT_FIELD_RANGE,\n fontSize: DEFAULT_FONT_SIZE,\n });\n return {\n texture: {\n width: a.texture.width,\n height: a.texture.height,\n data: new Uint8Array(a.texture.data),\n },\n glyphs: a.glyphs.map((g) => ({\n unicode: g.unicode,\n advance: g.advance,\n xoffset: g.xoffset,\n yoffset: g.yoffset,\n atlasPosition: [g.atlasPosition[0], g.atlasPosition[1]],\n atlasSize: [g.atlasSize[0], g.atlasSize[1]],\n })),\n metrics: { lineHeight: a.metrics.lineHeight, ascender: a.metrics.ascender },\n textureSize: [a.textureSize[0], a.textureSize[1]],\n fieldRange: a.fieldRange,\n };\n },\n async dispose(): Promise<void> {\n await msdf.dispose();\n },\n };\n}\n\nfunction bakeHelpBody(): string {\n return [\n 'forgeax asset import bake — bake MSDF font atlas from TTF',\n '',\n 'Usage:',\n ' forgeax asset import bake <ttf> <out>',\n '',\n 'Reads a TrueType font file and produces:',\n ` <out>/<basename>.atlas.png — ${DEFAULT_TEXTURE_SIZE}x${DEFAULT_TEXTURE_SIZE} MSDF atlas`,\n ' <out>/<basename>.meta.json — glyph metrics sidecar (importer: font)',\n '',\n ].join('\\n');\n}\n\nfunction helpBody(): string {\n return [\n 'forgeax asset import — MSDF font atlas baking',\n '',\n 'Usage:',\n ' forgeax asset import bake <ttf> <out>',\n '',\n ].join('\\n');\n}\n\nexport async function runCliFont(argv: string[]): Promise<number> {\n const [sub, ...rest] = argv;\n if (sub === undefined || sub === '--help' || sub === '-h') {\n process.stdout.write(`${helpBody()}\\n`);\n return 0;\n }\n if (sub !== 'bake') {\n process.stderr.write(`unknown subcommand: ${sub}\\n`);\n return 1;\n }\n return runBake(rest);\n}\n\nasync function runBake(rest: string[]): Promise<number> {\n if (rest[0] === '--help' || rest[0] === '-h') {\n process.stdout.write(`${bakeHelpBody()}\\n`);\n return 0;\n }\n let positionals: string[];\n try {\n const parsed = parseArgs({ args: rest, allowPositionals: true, strict: true });\n positionals = [...parsed.positionals];\n } catch {\n process.stderr.write('error parsing CLI args\\n');\n return 1;\n }\n const ttfPath = positionals[0];\n const outDir = positionals[1];\n if (ttfPath === undefined || outDir === undefined) {\n process.stderr.write('usage: forgeax asset import bake <ttf> <out>\\n');\n return 1;\n }\n try {\n const result = await bakeFont(ttfPath, outDir, realGeneratorFactory);\n process.stdout.write(`baked ${result.atlasPath} + ${result.sidecarPath}\\n`);\n return 0;\n } catch (e) {\n if (e instanceof FontError) {\n process.stderr.write(\n `${JSON.stringify({ code: e.code, expected: e.expected, hint: e.hint, detail: e.detail })}\\n`,\n );\n return 1;\n }\n process.stderr.write(`bake failed: ${e instanceof Error ? e.message : String(e)}\\n`);\n return 1;\n }\n}\n\nconst isBinEntry = await (async (): Promise<boolean> => {\n const argv1 = process.argv[1];\n if (typeof argv1 !== 'string') return false;\n const argv1Real = await realpath(argv1).catch(() => argv1);\n const selfReal = await realpath(fileURLToPath(import.meta.url)).catch(() =>\n fileURLToPath(import.meta.url),\n );\n return argv1Real === selfReal;\n})();\n\nif (isBinEntry) {\n const exitCode = await runCliFont(process.argv.slice(2));\n process.exit(exitCode);\n}\n","// font-importer.ts - the build-time fontImporter (feat-20260603-asset-import-loader-injection M3 / w24).\n//\n// The `{ key: 'font', import }` Importer the @forgeax/engine-import runner\n// dispatches a `*.meta.json` with `importer: 'font'` to. It absorbs the MSDF\n// bake that previously lived only behind the `forgeax asset import\n// bake` CLI: read the `.ttf` source -> @zappar/msdf-generator atlas ->\n// (a) one atlas `TextureAsset` ImportedAsset (the RGBA MSDF atlas, kind\n// 'texture') under the declared `kind: 'texture'` sub-asset GUID, (b) one\n// sampler ImportedAsset under the declared `kind: 'sampler'` sub-asset GUID,\n// and (c) one font glyph-metrics ImportedAsset (kind 'font') under the\n// declared `kind: 'font'` sub-asset GUID. The font carries the BMFont ->\n// FontAsset glyph map + the common block + atlas/sampler GUID refs.\n//\n// Build-time-only boundary (AC-18 / requirements callout): @zappar/msdf-generator\n// is a generator dependency that MUST stay out of the runtime bundle. The\n// runtime today statically imports ZERO @forgeax/engine-font and ZERO @zappar\n// symbols (research Finding 7); this importer keeps that invariant. fontImporter\n// is a NODE-ONLY sub-export (`@forgeax/engine-font/font-importer`,\n// `default: null` under browser conditions); the generator is dynamically\n// imported (cli-font realGeneratorFactory) so even the build-time graph only\n// pays the wasm load cost when a font is actually baked. The runtime fontLoader\n// (M1 w6) reads an already-baked atlas DDC and has no bake dependency.\n//\n// GUID import-stable iron law: produced GUIDs come from `ctx.subAssets[]`. The\n// font sidecar declares `texture`, `sampler`, and `font` sub-assets; this\n// importer maps the bake output onto those declared GUIDs and stamps nothing\n// of its own.\n//\n// `ctx.importSettings` may inject a test `generatorFactory` (an\n// `() => Promise<MsdfGenerator>`) so unit tests drive the bake with a mock\n// instead of the real wasm generator; production import calls fall through to\n// the real @zappar factory.\n\nimport type {\n FontAsset,\n GlyphMetric,\n ImportContext,\n ImportedAsset,\n Importer,\n ImportResult,\n SamplerAsset,\n TextureAsset,\n} from '@forgeax/engine-types';\nimport type { BakeAtlas, MsdfGenerator } from './cli-font.js';\nimport { realGeneratorFactory } from './cli-font.js';\n\n/** Stable semantic identities for the three writable font outputs. */\nexport function sourceKeyForFontOutput(kind: string): string | undefined {\n const normalizedKind = kind.trim();\n return normalizedKind.length === 0 ? undefined : `font:${normalizedKind}`;\n}\n\nexport function fontOutputSourceKeys(): readonly string[] {\n return ['texture', 'sampler', 'font'].map((kind) => sourceKeyForFontOutput(kind) as string);\n}\n\n/** Map the @zappar atlas glyphs into the FontAsset glyph-metrics record. */\nfunction atlasGlyphsToMetrics(atlas: BakeAtlas): Record<number, GlyphMetric> {\n const glyphs: Record<number, GlyphMetric> = {};\n for (const g of atlas.glyphs) {\n glyphs[g.unicode] = {\n advance: g.advance,\n bearingX: g.xoffset,\n bearingY: g.yoffset,\n size: { w: g.atlasSize[0], h: g.atlasSize[1] },\n region: {\n x: g.atlasPosition[0],\n y: g.atlasPosition[1],\n w: g.atlasSize[0],\n h: g.atlasSize[1],\n },\n };\n }\n return glyphs;\n}\n\nfunction makeAtlasTexture(atlas: BakeAtlas): TextureAsset {\n return {\n kind: 'texture',\n shape: {\n viewDimension: '2d',\n extent: { width: atlas.texture.width, height: atlas.texture.height },\n },\n // MSDF atlas is linear-space RGBA8 (signed-distance channels, never gamma).\n format: 'rgba8unorm',\n data: atlas.texture.data,\n colorSpace: 'linear',\n mips: { kind: 'none' },\n };\n}\n\nfunction makeFontCommon(atlas: BakeAtlas): FontAsset['common'] {\n return {\n lineHeight: atlas.metrics.lineHeight,\n base: atlas.metrics.ascender,\n distanceRange: atlas.fieldRange,\n pxRange: atlas.fieldRange,\n atlasWidth: atlas.textureSize[0],\n atlasHeight: atlas.textureSize[1],\n };\n}\n\nfunction makeAtlasSampler(): SamplerAsset {\n return {\n kind: 'sampler',\n addressModeU: 'clamp-to-edge',\n addressModeV: 'clamp-to-edge',\n addressModeW: 'clamp-to-edge',\n magFilter: 'linear',\n minFilter: 'linear',\n mipmapFilter: 'nearest',\n };\n}\n\nasync function importFont(ctx: ImportContext): Promise<ImportResult> {\n const read = await ctx.readSource();\n if (!read.ok) {\n throw new Error(\n `fontImporter: readSource failed: ${read.error instanceof Error ? read.error.message : String(read.error)}`,\n );\n }\n\n const factory =\n (ctx.importSettings.generatorFactory as (() => Promise<MsdfGenerator>) | undefined) ??\n realGeneratorFactory;\n const generator = await factory();\n let atlas: BakeAtlas;\n try {\n atlas = await generator.generateAtlas(read.value);\n } finally {\n await generator.dispose().catch(() => undefined);\n }\n\n const atlasSub = ctx.subAssets.find((s) => s.kind === 'texture');\n const samplerSub = ctx.subAssets.find((s) => s.kind === 'sampler');\n const fontSub = ctx.subAssets.find((s) => s.kind === 'font');\n const out: ImportedAsset[] = [];\n if (atlasSub !== undefined) {\n out.push({\n guid: atlasSub.guid,\n kind: 'texture',\n payload: makeAtlasTexture(atlas),\n refs: [],\n artifacts: {\n atlas: {\n // Pack v2's runtime texture loader consumes non-Basis artifacts as\n // raw pixels. Keep the baked RGBA8 MSDF atlas in that form here;\n // the CLI still emits a PNG for standalone bake output.\n mediaType: 'application/octet-stream',\n bytes: atlas.texture.data,\n },\n },\n });\n }\n if (samplerSub !== undefined) {\n out.push({\n guid: samplerSub.guid,\n kind: 'sampler',\n payload: makeAtlasSampler(),\n refs: [],\n artifacts: {},\n });\n }\n if (fontSub !== undefined) {\n // The runtime font loader reads atlasGuid / samplerGuid / glyphs / common\n // off the DDC payload (asset-registry loadFontAsset); the produced payload\n // mirrors that shape. atlas Handle / sampler Handle are runtime-resolved\n // from the GUID refs, so the build-time payload carries the GUID strings\n // (cast through FontAsset for the ImportedAsset.payload Asset slot, same\n // build-time POD-vs-Handle bridge the gltfImporter scene arm uses).\n const fontPayload = {\n kind: 'font',\n atlasGuid: atlasSub?.guid ?? '',\n samplerGuid: samplerSub?.guid ?? '',\n glyphs: atlasGlyphsToMetrics(atlas),\n common: makeFontCommon(atlas),\n } as unknown as FontAsset;\n out.push({\n guid: fontSub.guid,\n kind: 'font',\n payload: fontPayload,\n refs: [\n ...(atlasSub !== undefined ? [{ guid: atlasSub.guid }] : []),\n ...(samplerSub !== undefined ? [{ guid: samplerSub.guid }] : []),\n ],\n artifacts: {},\n });\n }\n return { ok: true, value: { assets: out, sourceDependencies: [] } };\n}\n\n/**\n * The font {@link Importer}. Register it into an `ImporterRegistry` so the\n * import runner dispatches `meta.importer === 'font'` sidecars here.\n *\n * @example\n * ```ts\n * import { ImporterRegistry } from '@forgeax/engine-import';\n * import { fontImporter } from '@forgeax/engine-font/font-importer';\n * const importers = new ImporterRegistry();\n * importers.register(fontImporter);\n * ```\n */\nexport const fontImporter: Importer = {\n key: 'font',\n import: importFont,\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forgeax/engine-font",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.28",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"sideEffects": false,
|
|
8
|
-
"description": "Build-time MSDF font atlas baking and runtime font asset loading for the
|
|
9
|
-
"bin": {
|
|
10
|
-
"forgeax-engine-remote-font": "./dist/cli-font.mjs"
|
|
11
|
-
},
|
|
8
|
+
"description": "Build-time MSDF font atlas baking and runtime font asset loading for the ForgeaX engine. The unified ForgeaX asset command owns the public producer entry.",
|
|
12
9
|
"exports": {
|
|
13
10
|
".": {
|
|
14
11
|
"types": "./dist/index.d.ts",
|
|
@@ -39,13 +36,13 @@
|
|
|
39
36
|
"LICENSE"
|
|
40
37
|
],
|
|
41
38
|
"dependencies": {
|
|
42
|
-
"@forgeax/engine-pack": "0.1.
|
|
43
|
-
"@forgeax/engine-types": "0.1.
|
|
39
|
+
"@forgeax/engine-pack": "0.1.28",
|
|
40
|
+
"@forgeax/engine-types": "0.1.28",
|
|
44
41
|
"@zappar/msdf-generator": "1.2.4"
|
|
45
42
|
},
|
|
46
43
|
"devDependencies": {
|
|
47
|
-
"@forgeax/engine-import": "0.1.
|
|
48
|
-
"@forgeax/engine-remote": "0.1.
|
|
44
|
+
"@forgeax/engine-import": "0.1.28",
|
|
45
|
+
"@forgeax/engine-remote": "0.1.28",
|
|
49
46
|
"@types/node": "^20.14.0"
|
|
50
47
|
},
|
|
51
48
|
"forgeax": {
|
|
@@ -324,7 +324,7 @@ describe('font package root surface', () => {
|
|
|
324
324
|
const PKG_DIR = resolve(dirname(fileURLToPath(import.meta.url)), '../..');
|
|
325
325
|
|
|
326
326
|
describe('plugin-discoverable.test.ts', () => {
|
|
327
|
-
describe('plugin-discoverable (forgeax
|
|
327
|
+
describe('plugin-discoverable (forgeax asset import)', () => {
|
|
328
328
|
describe('bake subcommand routing (a)', () => {
|
|
329
329
|
it('--help on root exits 0 and prints usage', async () => {
|
|
330
330
|
const code = await runCliFont(['--help']);
|
|
@@ -352,25 +352,12 @@ describe('font package root surface', () => {
|
|
|
352
352
|
});
|
|
353
353
|
});
|
|
354
354
|
|
|
355
|
-
describe('
|
|
356
|
-
it('
|
|
355
|
+
describe('unified command ownership (b)', () => {
|
|
356
|
+
it('does not publish a standalone bin', async () => {
|
|
357
357
|
const pkgPath = join(PKG_DIR, 'package.json');
|
|
358
358
|
const raw = await readFile(pkgPath, 'utf-8');
|
|
359
359
|
const pkg = JSON.parse(raw) as Record<string, unknown>;
|
|
360
|
-
|
|
361
|
-
expect(bin).toBeDefined();
|
|
362
|
-
expect(typeof bin).toBe('object');
|
|
363
|
-
expect(bin['forgeax-engine-remote-font']).toBe('./dist/cli-font.mjs');
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
it('bin name starts with forgeax-engine-remote- (PLUGIN_PREFIX contract)', async () => {
|
|
367
|
-
const pkgPath = join(PKG_DIR, 'package.json');
|
|
368
|
-
const raw = await readFile(pkgPath, 'utf-8');
|
|
369
|
-
const pkg = JSON.parse(raw) as Record<string, unknown>;
|
|
370
|
-
const bin = pkg.bin as Record<string, string>;
|
|
371
|
-
const binNames = Object.keys(bin);
|
|
372
|
-
expect(binNames.length).toBe(1);
|
|
373
|
-
expect(binNames[0]).toBe('forgeax-engine-remote-font');
|
|
360
|
+
expect(pkg.bin).toBeUndefined();
|
|
374
361
|
});
|
|
375
362
|
});
|
|
376
363
|
|
package/src/cli-font.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
// @forgeax/engine-font/src/cli-font — `forgeax
|
|
3
|
+
// @forgeax/engine-font/src/cli-font — `forgeax asset import` plugin
|
|
4
4
|
// bin. Discovered by the base bin via the kubectl 4th-path
|
|
5
|
-
// `forgeax
|
|
5
|
+
// unified `forgeax asset import` producer.
|
|
6
6
|
//
|
|
7
7
|
// `bake <ttf> <out>` reads a TrueType font and produces an MSDF atlas PNG +
|
|
8
8
|
// a glyph-metrics sidecar JSON (importer: 'font'). The real bake calls
|
|
@@ -386,10 +386,10 @@ export async function realGeneratorFactory(): Promise<MsdfGenerator> {
|
|
|
386
386
|
|
|
387
387
|
function bakeHelpBody(): string {
|
|
388
388
|
return [
|
|
389
|
-
'forgeax
|
|
389
|
+
'forgeax asset import bake — bake MSDF font atlas from TTF',
|
|
390
390
|
'',
|
|
391
391
|
'Usage:',
|
|
392
|
-
' forgeax
|
|
392
|
+
' forgeax asset import bake <ttf> <out>',
|
|
393
393
|
'',
|
|
394
394
|
'Reads a TrueType font file and produces:',
|
|
395
395
|
` <out>/<basename>.atlas.png — ${DEFAULT_TEXTURE_SIZE}x${DEFAULT_TEXTURE_SIZE} MSDF atlas`,
|
|
@@ -400,10 +400,10 @@ function bakeHelpBody(): string {
|
|
|
400
400
|
|
|
401
401
|
function helpBody(): string {
|
|
402
402
|
return [
|
|
403
|
-
'forgeax
|
|
403
|
+
'forgeax asset import — MSDF font atlas baking',
|
|
404
404
|
'',
|
|
405
405
|
'Usage:',
|
|
406
|
-
' forgeax
|
|
406
|
+
' forgeax asset import bake <ttf> <out>',
|
|
407
407
|
'',
|
|
408
408
|
].join('\n');
|
|
409
409
|
}
|
|
@@ -437,7 +437,7 @@ async function runBake(rest: string[]): Promise<number> {
|
|
|
437
437
|
const ttfPath = positionals[0];
|
|
438
438
|
const outDir = positionals[1];
|
|
439
439
|
if (ttfPath === undefined || outDir === undefined) {
|
|
440
|
-
process.stderr.write('usage: forgeax
|
|
440
|
+
process.stderr.write('usage: forgeax asset import bake <ttf> <out>\n');
|
|
441
441
|
return 1;
|
|
442
442
|
}
|
|
443
443
|
try {
|
package/src/font-importer.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
//
|
|
3
3
|
// The `{ key: 'font', import }` Importer the @forgeax/engine-import runner
|
|
4
4
|
// dispatches a `*.meta.json` with `importer: 'font'` to. It absorbs the MSDF
|
|
5
|
-
// bake that previously lived only behind the `forgeax
|
|
5
|
+
// bake that previously lived only behind the `forgeax asset import
|
|
6
6
|
// bake` CLI: read the `.ttf` source -> @zappar/msdf-generator atlas ->
|
|
7
7
|
// (a) one atlas `TextureAsset` ImportedAsset (the RGBA MSDF atlas, kind
|
|
8
8
|
// 'texture') under the declared `kind: 'texture'` sub-asset GUID, (b) one
|