import type { VDTDocument } from '../vdt.js'; import { type FontFaceRequest } from '../measure/fontString.js'; export type { FontFaceRequest } from '../measure/fontString.js'; /** The part of a `FontFace` the engine reads. */ export interface FontFaceLike { family: string; /** `'400'`, `'bold'`, or a variable range `'100 900'`. */ weight: string; /** `'normal'`, `'italic'` or `'oblique …'`. */ style: string; status: 'unloaded' | 'loading' | 'loaded' | 'error' | string; unicodeRange?: string; load?(): Promise; } /** The part of a `FontFaceSet` (`document.fonts`, a worker's `self.fonts`) * the engine uses. Tests pass a fake. */ export interface FontFaceSetLike extends Iterable { readonly size?: number; /** `'loading'` while faces of the set load, up to its `loadingdone`. */ readonly status?: string; load(font: string, text?: string): Promise; add(face: FontFaceLike): unknown; addEventListener?(type: 'loadingdone', listener: (event: { fontfaces?: readonly FontFaceLike[]; }) => void): void; removeEventListener?(type: 'loadingdone', listener: (event: { fontfaces?: readonly FontFaceLike[]; }) => void): void; } /** The page's font set (`document.fonts`), a worker's (`self.fonts`), or * undefined where there is none (Node). */ export declare function defaultFontSet(): FontFaceSetLike | undefined; /** The family of the glyph probe face (#1105, `fonts/glyphFallback.ts`): * no text is set in it, and the font set's record leaves it out. */ export declare const GLYPH_PROBE_FAMILY = "Postext Glyph Probe"; export declare function isGenericFamily(family: string): boolean; /** A face of the font set, read once. */ export interface IndexedFace { weight: [number, number]; style: 'normal' | 'italic'; status: string; } /** The faces of `fontSet`, by family (lower case); only the families in * `families` when given. */ export declare function indexFontSet(fontSet: Iterable, families?: ReadonlySet): Map; /** * `items` in the order CSS font matching tries them for the weight * `desired` (CSS Fonts 4, §5.2), each answering for the weights of * `span(item)` (one weight, or the range of a variable face): first those * that hold `desired`; then, from 400 to 500, the heavier ones up to 500 * ascending, the lighter ones descending, the rest of the heavier ones * ascending; below 400, the lighter ones descending and then the heavier * ones ascending; above 500, the heavier ones ascending and then the * lighter ones descending. The one rule the engine's fallback report, the * Sandbox's choice of a static cut, the command line and the PDF writer * all choose a weight by, so they choose the same face a browser does. */ export declare function cssWeightOrderOf(desired: number, items: readonly T[], span: (item: T) => readonly [number, number]): T[]; /** * `weights` in the order CSS font matching tries them for `desired` * ({@link cssWeightOrderOf}), each once: the first is the weight a browser * sets `desired` in when a family has those cuts and no other. A 600 of a * family with a 400 and a 700 is its 700, and so is a 550, where the 400 * is as near; a 450 between a 400 and a 500 is the 500; a 300 is the 400. */ export declare function cssWeightOrder(desired: number, weights: readonly number[]): number[]; /** How `faces` answer for a weight and slant: the face CSS matching * picks, whether it is a face of that weight and slant (`exact`: its * weight, or its variable range, holds the one asked, in the slant * asked), and whether the browser draws it bolder or slanted * (`synthesized`: a bold of 600 or more set from a face of 500 or less; * an italic set from an upright face). A face neither exact nor * synthesized is drawn as it is: the 700 for a 600, the italic for an * upright. Undefined when `faces` is empty. */ export declare function matchFace(faces: readonly IndexedFace[], weight: number, style: 'normal' | 'italic'): { face: IndexedFace; exact: boolean; synthesized: boolean; } | undefined; /** A key per face request. */ export declare function faceRequestKey(f: FontFaceRequest): string; /** The faces (family, weight, slant) the text of a laid-out document is * set in: its blocks' lines and segments, list markers, drop caps, * captions, notes and table cells, running heads, folios and design * texts, line numbers and the lettering of comic pages. */ export declare function documentFontFaces(doc: VDTDocument): FontFaceRequest[]; /** The font families the text of a laid-out document is set in. */ export declare function documentFontFamilies(doc: VDTDocument): string[]; /** * The families no font answers for — neither registered nor installed — so * their text was measured with a generic fallback. A family is there when * naming it in front of a generic family changes the width of a probe * string for at least one of three generics. */ export declare function unavailableFontFamilies(families: string[], measureWidth: (font: string, text: string) => number): string[]; /** Why a face fell back: no loaded face answered, so the text was set in * the fallback font (`missing`), or the family has no face of that * weight or slant and the browser drew it from another one, as it is or * made bolder or slanted (`synthesized`). */ export type FontFallbackReason = 'missing' | 'synthesized'; export interface FontFallback extends FontFaceRequest { reason: FontFallbackReason; } export interface FontFallbackOptions { /** Width of `text` in `font`, for the probe that tells an installed * family from a missing one. Default: the engine's measuring canvas, * when there is one. Null: no probe (a family with no face in the set * is missing). */ measureWidth?: ((font: string, text: string) => number) | null; } /** Forget the probe's answers (the faces changed). */ export declare function forgetInstalledFamilies(): void; /** * The faces of `faces` that `fontSet` could not give. The weight and slant * are matched among the faces the family declares, as CSS does (#650). * `missing`: the family has no face (and is not installed, by the width * probe), or the one matching settles on has not loaded, so the browser * set the text in the fallback font. `synthesized`: that face is loaded * but is not one of the weight and slant asked — the 700 answering for a * 600, a regular made bold, an upright slanted — so the text was measured * with another cut than the file a PDF embeds for the face. Generic * families are never reported. */ export declare function fontFallbacks(faces: readonly FontFaceRequest[], fontSet: Iterable, options?: FontFallbackOptions): FontFallback[]; //# sourceMappingURL=faces.d.ts.map