> ## Documentation Index
> Fetch the complete documentation index at: https://docs.reducto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Parse, layout and render

The low-level pipeline under `toPdf`. Use it for markup views or to reuse one layout for several outputs. See [DOCX to PDF](https://docs.reducto.ai/office/docx/conversion/pdf.md).

## `parseDocx()`

```ts theme={null}
function parseDocx(input: ParseInput, opts?: ParseOptions): Promise<DocModel>
```

Import from `@reductoai/docx/browser`.

## `renderPdfBytes()`

```ts theme={null}
function renderPdfBytes(
  ir: LayoutDocument,
  registry?: FontRegistry,
  opts?: RenderPdfOptions,
): Promise<RenderPdfResult>
```

Build the PDF for a fully laid `ir`; `createPdfWriter` is the page-at-a-time form.

Import from `@reductoai/docx/browser`.

## `FontRegistry`

Owns one document's font state (builtins, overlay, fontTable decls).

Import from `@reductoai/docx/browser`.

### FontRegistry properties

| Name | Type | Description |
| - | - | - |
| `fontFallbacks` | `FontFallback[]` | read-only Families this document asked for and did not get, worst reason retained. A host with an incomplete font set does not fail — it silently measures with another face and the page count drifts (Kokila absent turned a 20-page document into 25 on the portable profile). This ledger is the only way a serverless caller can tell that outcome from a correct render, so every resolution path that swaps a name records here. Reset per document by `applyFontDeclarations`. |
| `lookupCount` | `number` | read-only |
| `noSubsetFaceIds` | `ReadonlySet<string>` | read-only |
| `revision` | `number` | read-only |

### `ansiOnly()`

```ts theme={null}
ansiOnly(requested: string | null | undefined): boolean
```

### `applyEmbeddedFonts()`

```ts theme={null}
applyEmbeddedFonts(map: EmbeddedFontMap): void
```

Overlay a document's embedded faces onto the registry, replacing any
previous document's. Must be called once per document before measuring and
again before rendering. Registrations do not carry over between documents.

A partially-embedded family keeps the builtin faces of the family the name
would otherwise resolve to, so a doc that embeds only the bold face still
measures its regular runs with the substitute.

### `applyFontDeclarations()`

```ts theme={null}
applyFontDeclarations(map: FontDeclMap): void
```

Install a document's fontTable declarations, replacing any previous
document's. Same per-document contract as `applyEmbeddedFonts`.

### `builtinCjkFamilies()`

```ts theme={null}
builtinCjkFamilies(): string[]
```

Family names marked CJK-capable, for a host mirroring this registry: without
replaying them through `markCjkFamilies`, `resolveCjkFamily` would rewrite
every eastAsia name to Arial Unicode MS.

### `builtinFamilyIds()`

```ts theme={null}
builtinFamilyIds(): Record<string, Partial<Record<FaceKey, string>>>
```

### `cjkFaceId()`

```ts theme={null}
cjkFaceId(): string | undefined
```

The id of the regular CJK face, when registered (dedupes / CJK metrics).

### `documentScope()`

```ts theme={null}
documentScope(
  header: { embeddedFonts?: EmbeddedFontMap; fontDecls?: FontDeclMap },
): this
```

This registry's installed faces under one document's own fontTable and embedded faces.

### `familySet()`

```ts theme={null}
familySet(family: string): Partial<Record<FaceKey, FaceSource>> | undefined
```

The registered faces of a canonical family (document overlay first).

Every read path goes through here — `resolveFace`, `cjkFaceId`, the
measurer's and painter's Times fallback — which is why the face trace is
recorded at this one point. All four slots of a touched family are recorded,
not just the requested one: cheap, and it keeps bold/italic switching within
a family from needing a third pass.

### `hasFamily()`

```ts theme={null}
hasFamily(family: string): boolean
```

True when `family` (lowercased) has faces, without recording a lookup or a fallback.

### `installedTable()`

```ts theme={null}
installedTable(): { cjk: string[]; families: [string, Partial<Record<FaceKey, FaceSource>>][] }
```

Installed families and CJK marks, for an engine that replays the table (`wasmFontManifest`).

### `isCjkFace()`

```ts theme={null}
isCjkFace(sourceId: string): boolean
```

True when a face file belongs to a CJK family, so a painter's baseline uses
the same Word CJK box the measurer charged (`isCjkFamily`), not hhea + gap.

### `isCjkFamily()`

```ts theme={null}
isCjkFamily(requested: string | null | undefined): boolean
```

True when the resolved face uses CJK line metrics.

### `isCjkFontRequest()`

```ts theme={null}
isCjkFontRequest(requested: string): boolean
```

### `isEmbeddedOnly()`

```ts theme={null}
isEmbeddedOnly(family: string): boolean
```

True when `family` (lowercased) has faces only because the document embeds them.

### `isRegisteredFontFile()`

```ts theme={null}
isRegisteredFontFile(id: string): boolean
```

True when `id` names a face this registry can hand out (builtin or the
current document's overlay). For node system fonts the id is the file path,
so this remains a path allow-list for the demo server.

### `markCjkFamilies()`

```ts theme={null}
markCjkFamilies(names: string[]): void
```

Mark registered families as CJK-capable. Word bundles the real face
(KaiTi, SimSun, …); without this, resolveCjkFamily would still fall through
to Arial Unicode MS for every eastAsia name.

### `markNoSubsetFaces()`

```ts theme={null}
markNoSubsetFaces(ids: string[]): void
```

Mark face source ids that must be embedded whole: faces fontkit's
subsetter corrupts (empty outlines, invalid tables). The PDF backend
unions these into its per-document no-subset set.

### `noteScriptFace()`

```ts theme={null}
noteScriptFace(requested: string, served: string): void
```

A script the requested face cannot draw paints in `served`, a portable face.

### `quietly()`

```ts theme={null}
quietly<T>(fn: () => T): T
```

Runs `fn` noting no swap: a face probed for glyphs is not one the document asked for.

### `recordFallbacks()`

```ts theme={null}
recordFallbacks<T>(sink: FontFallback[], fn: () => T): T
```

Collect every swap noted while `fn` runs. A layout memo stores the list
and feeds it back through `replayFallbacks` when it skips the work, so the
per-document ledger reads the same whether or not the memo hit.

### `registerBuiltinFamilies()`

```ts theme={null}
registerBuiltinFamilies(families: Record<string, FaceSet>): void
```

Install (or replace) builtin families. Called by environment adapters.

### `registeredFaceBytes()`

```ts theme={null}
registeredFaceBytes(id: string): Uint8Array<ArrayBufferLike> | null
```

The bytes of a registered face by id, or null. Used by the demo server to
serve `/api/font` from the registry instead of trusting client paths.

### `replayFallbacks()`

```ts theme={null}
replayFallbacks(notes: readonly FontFallback[]): void
```

Replays verbatim, so a sink's length still counts what it was fed.

### `resolveArabicFamily()`

```ts theme={null}
resolveArabicFamily(requested: string | null | undefined): string
```

### `resolveCjkFamily()`

```ts theme={null}
resolveCjkFamily(requested: string | null | undefined, text?: string): string
```

### `resolveDevanagariFamily()`

```ts theme={null}
resolveDevanagariFamily(requested: string | null | undefined): string
```

Resolve unsupported Devanagari through the portable face or Word's Mangal.

### `resolveFace()`

```ts theme={null}
resolveFace(
  requested: string | null | undefined,
  bold: boolean,
  italic: boolean,
): { family: string; key: FaceKey; source?: FaceSource; synthBold?: true; synthItalic?: true }
```

Resolve a requested family name to \{ family, key, source } preserving
bold/italic. `source` is absent when the resolved family has no registered
face for that slot (nothing installed, or a partial embed edge case);
consumers fall back (measurer -> Times -> width heuristic, painter -> Times).

### `resolveFamily()`

```ts theme={null}
resolveFamily(requested: string | null | undefined): string
```

Map a requested family name to a canonical registered family key.

### `resolveHebrewFamily()`

```ts theme={null}
resolveHebrewFamily(requested: string | null | undefined): string
```

Portable-only Hebrew counterpart to resolveArabicFamily.

### `resolveThaiFamily()`

```ts theme={null}
resolveThaiFamily(requested: string | null | undefined): string
```

Word falls unsupported Thai complex-script text through to Tahoma.

### `startFaceTrace()`

```ts theme={null}
startFaceTrace(): void
```

Start recording the ids of every face this registry hands out.

A browser host needs this because `FaceSource.bytes()` is SYNCHRONOUS while
fetching is not: it cannot load a face on demand mid-layout. So it installs
the whole family table with empty faces, lays out once under a trace to
learn which faces the document actually reaches, fetches exactly those, and
lays out again. Pass two asks for the same set — resolution depends on the
family table and the document, never on whether bytes were present — so the
second pass is the real one.

### `takeFaceTrace()`

```ts theme={null}
takeFaceTrace(): string[]
```

Ids recorded since `startFaceTrace`, and stop recording.
