/** `text` as the measurer hands it to the canvas in a document shaped in * its own language: a Latin-1 text one byte a character, any other as it * is. A painter that hands its strings the same way has them shaped as * they were measured. */ export declare function canvasText(text: string): string; /** * The width of `text` in `font` under a letter-spacing of `spacingPx` * (`ctx.letterSpacing`: the spacing after every letter counted in), in * the language measured in and on the context its kind of string is * measured on, kept nowhere. Undefined where the canvas has no * letter-spacing. For what asks how the browser shapes a tracked text * (`measure/trackedLigatures.ts`): under a letter-spacing it sets no * optional ligature. */ export declare function measureSpacedWidth(text: string, font: string, spacingPx: number): number | undefined; /** * The width of `text` in `font` as the canvas gives it, in the language * measured in, kept nowhere: for a caller with a cache of its own (the * text library's segments, `measure/pretextLanguage.ts`). */ export declare function measureUncachedWidth(text: string, font: string): number; /** * Measure in `language` from now on: a BCP 47 tag (`zh-Hans`, `ca`), the * empty string for no language at all, or undefined for the host's (what * a context has when nobody sets one: the page's on a page, none in a * worker; a configuration with `bodyText.shapingLanguage: 'host'`). The * build sets the document's and puts back what it found; a block and a run * that name their own set it for their text ({@link withMeasureLanguage}). * Each language keeps its own widths, so going from one to another drops * nothing measured; a cache kept elsewhere of what was measured in a font * holds the language in its key ({@link measureLanguageKey}). */ export declare function setMeasureLanguage(language: string | undefined): void; /** The language set by {@link setMeasureLanguage}. */ export declare function getMeasureLanguage(): string | undefined; /** Run `fn` measuring in `language`, then measure again in the language * in force before, also when `fn` throws. */ export declare function withMeasureLanguage(language: string | undefined, fn: () => T): T; /** The part of a measurement cache key the language decides: empty for * the host's, so those keys are unchanged. */ export declare function measureLanguageKey(): string; export declare function measureTextWidth(text: string, font: string): number; /** * The width of `text` set in one run, as the browser paints it: two CJK * marks that meet are not measured apart (see {@link measureTextWidth}). * For the pieces a renderer paints apart (`markPieces`), each of which * holds only pairs the layout measured whole. */ export declare function measureRunWidth(text: string, font: string): number; /** * The width of `text` set between `lead` and `trail`, less theirs: `text` * as the browser shapes it in the script of the mark beside it (#725, see * `measure/script.ts`; a word with no letter takes the script of the text * it stands in). `rtl`: measured in a right-to-left context, as the word is * painted. The mark is glued with a no-break space, so nothing kerns * across. For text with no CJK character (it is measured in one run). */ export declare function measureMarkedWidth(text: string, font: string, lead: string, trail: string, rtl: boolean): number; /** * Whether the face `font` draws punctuation or digits otherwise by script: * a fixed row of them is measured beside each of `marks` (a character of * each script, glued after it) and the widths compared. One false answer * a font string for nearly every face, which then goes no further; the * answer is dropped with the cached widths when faces change. A measurer * that tells nothing apart (no canvas, a stub) answers false. */ export declare function scriptSensitive(font: string, marks: readonly string[]): boolean; /** Drop all cached text widths. Must be called whenever font faces are * (un)registered: widths measured against fallback glyphs are stale. */ export declare function clearTextWidthCache(): void; /** The current measurement generation: a counter bumped by every * {@link evictTextWidths} (and so by `clearMeasurementCache` and the * per-family eviction when faces arrive). */ export declare function measurementGeneration(): number; /** What changed since `generation`: every family (`all`), or the * families named by the evictions after it (lower case). */ export declare function evictionsSince(generation: number): { all: boolean; families: Set; }; /** Drop the cached widths measured in `families` (case-insensitive), or * every width when `families` is null, and bump the measurement * generation. The listeners of {@link onTextWidthCacheClear} (caches of * ink and baselines) clear whole. */ export declare function evictTextWidths(families: Iterable | null): void; /** Called whenever {@link clearTextWidthCache} drops the widths (fonts * changed): other font-dependent caches clear with it. */ export declare function onTextWidthCacheClear(listener: () => void): void; /** The ink box of `text` in `font` above and below the alphabetic * baseline (px), or null when the measurer gives no ink metrics. Not * cached. */ export declare function measureInkBox(text: string, font: string): { ascent: number; descent: number; } | null; /** The line box `font` is laid out in, above and below the alphabetic * baseline (px), or null when the measurer gives no face metrics. These * are the numbers a browser sets a line box by: text in a box of * `line-height: L` stands on a baseline `(L + ascent − descent) / 2` * from the box's top, and `line-height: normal` makes L their sum. */ export declare function measureFontBox(font: string): { ascent: number; descent: number; } | null; /** Whether the measurer has a face of `font`'s own family (by family, by * weight and by slant), rather than setting it in its fallback: the same * probe in a family nothing has is measured and its line box read, and * the face counts as present where either differs. * * A host may hold a book's faces without having registered them where it * measures — a worker has none of the page's fonts — and everything it * measures is then set in the fallback. Text whose places the layout * already holds is unharmed; text measured again as it is written out is * not, so the writer asks this before it measures anything of its own. * * A book set in a generic family (`serif`, `sans-serif`) reads as absent, * since that is what the fallback is: the writer then keeps to what it * can place from the layout, which is never wrong, only less exact. */ export declare function measuresOwnFace(font: string): boolean; /** How far the ink of a text reaches above and below the baseline at each * pixel column along it (see {@link measureInkProfile}). */ export interface InkProfile { /** Where column 0 stands, px from the pen's origin (negative when the * ink overhangs the origin). */ start: number; /** The text's advance, px. */ advance: number; /** Per column: px of ink above the baseline (−Infinity: no ink). */ above: Float32Array; /** Per column: px of ink below the baseline (−Infinity: no ink). */ below: Float32Array; } /** * The ink of `text` in `font` column by column: the text is painted from * its left edge, left to right as the page paints it, and each pixel * column records its highest and lowest inked pixel. Null when nothing can * be painted and read back (no canvas, or a measurer without pixels) or * the text has no ink. Not cached. */ export declare function measureInkProfile(text: string, font: string): InkProfile | null; /** Where the ink of `text` in `font` starts and ends along the line, px * from the pen's origin (the start is negative when the ink overhangs * it), or null when the measurer gives no ink metrics or the text has no * ink. Not cached. */ export declare function measureInkExtent(text: string, font: string): { start: number; end: number; } | null; /** Measure a short glyph (e.g. a list bullet) in the given font. */ export declare function measureGlyphWidth(text: string, font: string): number; /** Compute the normal space width for a given font, used to express justified * spacing as a multiplier of the natural space. */ export declare function normalSpaceWidthFor(font: string): number; export declare function cleanSoftHyphens(text: string): string; //# sourceMappingURL=canvas.d.ts.map