import type { PostextConfig, PostextContent } from '../types.js'; import type { VDTDocument } from '../vdt.js'; import { type FontContentText } from './usage.js'; import { type FontFaceLike, type FontFaceRequest, type FontFaceSetLike, type FontFallbackOptions } from './faces.js'; /** A font file: its bytes, or the URL to fetch it from (a CSS `src` * value — `url(…)`, `local(…)` — is taken as written). */ export type FontFileSource = ArrayBuffer | ArrayBufferView | string; /** A font file with the descriptors of its face, when they are not the * ones asked for: the slice a file covers (`unicodeRange`), a variable * weight range (`'100 900'`), an upright file given for an italic. */ export interface FontFile { source: FontFileSource; unicodeRange?: string; weight?: number | string; style?: 'normal' | 'italic' | string; } /** What a resolver answers: one file, several (the slices of a face, in * the order they are added to the font set), or nothing (it has no such * face). Throwing counts as nothing. */ export type FontResolverAnswer = FontFileSource | FontFile | readonly (FontFileSource | FontFile)[] | null | undefined; export interface FontResolveRequest { /** The characters the document sets (a space included), for a resolver * serving a family as slices: only the files holding them. */ text: string; codePoints: Set; } /** * A host's font files, asked for each face no `FontFace` of the font set * declares: `(family, weight, style, { text, codePoints })`. The shape of * postext-pdf's `PdfFontProvider`, so one function serves the screen and * the PDF. A resolver may also declare the face itself (add a style sheet, * a `FontFace`) and answer null: the engine then loads what it declared. */ export type FontResolver = (family: string, weight: number, style: 'normal' | 'italic', request: FontResolveRequest) => FontResolverAnswer | Promise; type FontFaceConstructor = new (family: string, source: string | ArrayBuffer | ArrayBufferView, descriptors?: FontFaceDescriptors) => FontFaceLike; export interface PrepareFontsOptions { /** The font set to load into: by default `document.fonts`, or * `self.fonts` in a worker. */ fontSet?: FontFaceSetLike | null; /** Files for the faces nothing declares. */ resolve?: FontResolver; /** Give up waiting after this many ms (default 10 000): a face still * loading then is reported missing. */ timeoutMs?: number; /** Watch the font set afterwards ({@link watchFonts}). Default true. */ watch?: boolean; /** Register the resolved files with the font registry, for SVG * pictures and layout workers. Default true. */ register?: boolean; /** Faces to load beyond the configuration's. */ faces?: readonly FontFaceRequest[]; /** The `FontFace` constructor (default the global one). */ FontFace?: FontFaceConstructor; /** The probe that tells an installed family from a missing one. */ measureWidth?: FontFallbackOptions['measureWidth']; /** Declare the glyph probe (#1105) in the font set the engine measures * with, so the builds report the characters a face lacks * (`glyphFallback`). Default true. */ glyphProbe?: boolean; } /** What a preparation found. */ export interface FontReport { /** Faces a loaded face of their weight and slant answers for (or an * installed family). */ loaded: FontFaceRequest[]; /** Faces no loaded face answers for (none of the family, or the one * that would is still loading): their text is measured with a fallback * face. */ missing: FontFaceRequest[]; /** Faces the family has no face for, which the browser draws from * another weight or slant of it (the nearest weight as it is, bold * made heavier, italic slanted). */ synthesized: FontFaceRequest[]; /** `FontFace`s added from the resolver's files. */ added: number; } /** The texts of a build's content: the Markdown, the metadata and the * resources' captions, notes and cells. */ export declare function contentTexts(content: PostextContent | FontContentText): string[]; /** * The characters a document sets — its text, its resources' and * metadata's, the configuration's own texts, the ASCII digits and letters * of folios and labels — once each: the sample a face is loaded for, so a * family served as slices (`unicode-range`: Latin Extended, Greek, Arabic, * the CJK slices) brings the files the document needs. */ export declare function fontSampleText(content: PostextContent | FontContentText, config?: PostextConfig): string; /** The faces a configuration and its text ask for, in a fixed order: * families as `configFontFamilies` lists them, then the weights from light * to heavy, upright before italic. */ export declare function configFontFaces(config: PostextConfig | undefined, text?: FontContentText): FontFaceRequest[]; /** * Load every face `config` and its text ask for (body, headings, lists, * callout titles and bodies, tables, design texts, running heads, * contents, code, comic lettering, in each weight and slant the * configuration sets) into the font set, for the characters the document * sets, before the first build. A face the set declares is loaded through * it (`fontSet.load`); one it does not is asked of `options.resolve`, and * the files it gives are added as `FontFace`s (and registered for SVG * pictures). The measurements of the families that changed are dropped. * Resolves with which faces are there, which are missing and which the * browser would synthesize. Where there is no font set (Node), every face * is reported loaded and nothing is done. */ export declare function prepareFonts(content: PostextContent | FontContentText, config?: PostextConfig, options?: PrepareFontsOptions): Promise; /** A document, or several (the chapters of a book). */ export type BuiltDocuments = VDTDocument | readonly VDTDocument[]; export interface LoadedFontsOptions extends PrepareFontsOptions { /** The text the documents set, for the sample faces are loaded for. * Default: the text of the documents' lines. */ text?: FontContentText; /** Extra builds at most (default 2). */ maxRounds?: number; /** Told what the last round found. */ onFonts?: (report: FontReport) => void; } /** * Run `build`, then load the faces its pages set text in that the font set * could not give (a weight the configuration did not name, a face * resolved only now; one a neighbour of the family answered for is asked * of the resolver like any other, #650), drop their measurements and * build again — at most `maxRounds` extra builds (2). `build` returns a * document or several. * Faces that stay missing are reported (`onFonts`) and listed by each * document's `fontFallback` warnings. */ export declare function withLoadedFonts(build: () => T | Promise, options?: LoadedFontsOptions): Promise; export {}; //# sourceMappingURL=prepare.d.ts.map