Skip to content
This repository was archived by the owner on Aug 20, 2026. It is now read-only.

Commit 05b51bd

Browse files
committed
refactor(fonts): read font faces via pdf-codec's readFontFace
runtime/font-face.ts's hand-rolled sfnt 'name'/'OS/2'/'head' table reader duplicated logic pdf-codec now exports directly (readFontFace, FontFaceParseError, published in pdf-codec 1.11.0) -- deleted along with its own test suite, since that coverage now lives in pdf-codec's own repository against the same real font fixtures. loadProvidedFonts calls pdf-codec's readFontFace directly rather than through documents.js: a standalone font-file inspector has no source-document-extraction analogue, which is documents.js's own stated font-resolution boundary, so routing it through documents.js would work around that boundary rather than respect it.
1 parent 0848086 commit 05b51bd

3 files changed

Lines changed: 4 additions & 275 deletions

File tree

src/runtime/font-face.test.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/runtime/font-face.ts

Lines changed: 0 additions & 221 deletions
This file was deleted.

src/runtime/fonts.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { readFile } from 'node:fs/promises';
22
import type { ProvidedFont } from 'documents.js';
3-
import { describeFontFace } from './font-face';
3+
// A deliberate exception to this repo's usual "everything pdf-codec-sourced comes through documents.js" pattern: readFontFace is a standalone font-FILE inspector, not source-document font extraction, which is documents.js's own stated boundary (see its README -- extractSourceFonts/extractSourceFontsForFormat cover extracting fonts a document already embeds, not describing an arbitrary font file). Imported directly from pdf-codec, a genuine direct dependency of this package now, rather than forcing a re-export into documents.js that would work around that boundary.
4+
import { readFontFace } from 'pdf-codec';
45

5-
// Reads each font file and pairs its bytes with the family/bold/italic triple the file itself declares (see font-face.ts), producing exactly the ProvidedFont shape documents.js's own conversion options and DocumentConverter port both take. Shared by the CLI's --font-file flag and the TUI's own font-file field so the two can never derive a face differently from the same file.
6+
// Reads each font file and pairs its bytes with the family/bold/italic triple the file itself declares (pdf-codec's own readFontFace, parsed from the font's own sfnt tables), producing exactly the ProvidedFont shape documents.js's own conversion options and DocumentConverter port both take. Shared by the CLI's --font-file flag and the TUI's own font-file field so the two can never derive a face differently from the same file.
67
//
78
// Read sequentially rather than through Promise.all: a caller passing several fonts and mistyping one wants the error to name that file, and a sequential loop reports the first bad path with nothing else in flight. Font files are a handful of small local reads, so there is no throughput case for the parallel form here.
89
export async function loadProvidedFonts(paths: readonly string[], options?: { readonly signal?: AbortSignal }): Promise<ProvidedFont[]> {
910
const fonts: ProvidedFont[] = [];
1011
for (const path of paths) {
1112
// Rewrapped through the constructor's ArrayLike overload for the same reason readInput does it (src/runtime/io.ts): ProvidedFont.bytes is Uint8Array<ArrayBuffer>, which a Buffer is not.
1213
const bytes = new Uint8Array(await readFile(path, { signal: options?.signal }));
13-
const face = describeFontFace(bytes, path);
14+
const face = readFontFace(bytes, path);
1415
fonts.push({ family: face.family, bold: face.bold, italic: face.italic, bytes });
1516
}
1617
return fonts;

0 commit comments

Comments
 (0)