/** * Right-to-left text in designs and chips: running heads, opener titles, * contents part rows, callout titles and the runs of an inline chip. * * A design text line is laid out in logical order, as the body is: wrapping, * justification and truncation never look at direction. Once a line is * cut, {@link directRuns} resolves its bidi levels (UAX #9, `bidi.ts`) at * the text's base direction, cuts its runs where the level changes, flags * the right-to-left ones (`rtl`) and gives the order in which a renderer * advances through them (`order`). Renderers then paint run after run, each * shaped in its own direction, the same way on the canvas, in the HTML and * in the PDF. * * The order depends on the frame the line is painted in. Running heads and * folios stand on the sheet: their runs go in visual order, left to right. * A design set in the flow of a mirrored page (an opener band, a heading * design, a contents part row) is painted through the mirror, where the x * axis runs from the sheet's right edge: its runs go in the reverse of the * visual order, as {@link VDTLine.order} does for body lines. A chip is * measured blind to its frame, like the body line it sits in; the build's * mirror pass (`pipeline/mirrorFrame.ts`) turns its order on mirrored * pages. */ import type { VDTDesignTextBlock } from '../vdt.js'; /** * Whether the runs of a design text or a chip are measured as they are * painted, each in its own direction (#770): in a document shaped in its * own language, in horizontal text. * * A renderer paints a right-to-left run with its context set right to * left (`paintRunInDirection` on the canvas). Up to postext 1.29 the * layout measured the line left to right, whole, and handed each run but * the last the width of its text measured left to right too. The two * differ. Markazi Text sets the opener `«الحرف العربي لا يعيش وحده.»` of * the Arabic novel 9.917 em wide left to right (the stop and the * guillemets are runs apart, shaped alone) and 9.712 em as the one * right-to-left run it is painted as: 5.55 px at 27 px. In Amiri the date * `(٧٣٢–٨٠٨هـ)` of the taḥqīq opener is five runs; the layout gave the * last, `هـ)`, what the whole line left over, 1.298 em, for a run painted * 1.095 em wide: 5.08 px at 25 px. Measured in Chrome 154. * * A document that keeps the host's language keeps the widths it had. */ export declare function measuresRunsAsPainted(): boolean; /** The advance of one run of a line, untracked, as it is painted: a * right-to-left run in a context set right to left (`rtlTextWidth`), any * other as a text of its own. */ export declare function paintedRunWidth(text: string, font: string, rtl: boolean): number; /** * The advance of `text` in `font`, untracked, as a line of it is painted * (see {@link measuresRunsAsPainted}): its bidi levels resolved at `base` * as {@link directRuns} resolves a line's, the text cut where the level * changes, each piece measured in its direction. A left-to-right text * with no right-to-left character is measured whole, as it is painted. */ export declare function directedTextWidth(text: string, font: string, base: 'ltr' | 'rtl', arabicNumbers?: boolean): number; /** A run of a design text line or of a chip, as far as ordering it goes. */ interface Run { text: string; width: number; /** A subscript set over a superscript (width 0), or a run the author * oriented in vertical text: never cut. */ stacked?: boolean; tcy?: true; orientation?: 'upright' | 'sideways'; /** An inline chip of a design text (#1162): one box, never cut. */ chip?: unknown; } /** The direction of the first strong letter of `text` (UAX #9 P2, isolates * not skipped), or undefined when it has none (digits, punctuation). */ export declare function firstStrongDirection(text: string): 'ltr' | 'rtl' | undefined; /** The base direction a design text is set at: its own `direction`, where * `'auto'` reads the first strong letter of `text`; else the document's. */ export declare function designBaseDirection(direction: 'ltr' | 'rtl' | 'auto' | undefined, text: string, documentDirection: 'ltr' | 'rtl'): 'ltr' | 'rtl'; /** Runs cut where the direction changes, and the order to paint them in * (see {@link directRuns}). */ export interface DirectedRuns { runs: (R & { rtl?: true; })[]; /** Indices into `runs` in paint order; absent when that is 0 … n − 1. */ order?: number[]; } /** * The runs of one line (or one chip) ordered for painting: the line's bidi * levels resolved at `base` (UAX #9, rules L1 and L2 for the line), each run * cut where the level changes, the pieces at an odd level flagged `rtl`, * and the order to paint them in — the visual order, or its reverse when * `mirrored` (the line is painted through a mirrored flow frame; see the * module comment). Undefined when there is nothing to do: a left-to-right * line with no right-to-left character, or one whose text resolves to one * even level throughout. * * A piece takes `widthOf(run, text, rtl)` as its advance; the last piece * of a run takes what is left of the run's width, so the line advances * exactly as far as it was measured (kerning across a cut stays inside the * run). With `asPainted` every piece takes its own advance, the last one * too, and the pieces of a run that is not cut are measured again in the * direction they are painted in: the caller then sets the line as wide as * its runs ({@link measuresRunsAsPainted}). * A stacked script or an oriented vertical run is never cut. */ export declare function directRuns(runs: readonly R[], base: 'ltr' | 'rtl', mirrored: boolean, widthOf: (run: R, text: string, rtl: boolean) => number, /** The text belongs to an Arabic-script document: a number that opens * it reads as an Arabic one (`BidiOptions.arabicNumbers`, #665). */ arabicNumbers?: boolean, asPainted?: boolean): DirectedRuns | undefined; /** * {@link directRuns} on every line of a design text block built by hand (a * callout's title, its continuation marker, a label tab), in place: lines * that need it get `runs` and `order`, and the block `direction` when * `base` is right to left. `trackingPx` is the tracking the lines were * measured with. */ export declare function directDesignTextBlock(block: VDTDesignTextBlock, base: 'ltr' | 'rtl', mirrored: boolean, trackingPx?: number, arabicNumbers?: boolean): void; /** * A chip's runs ordered for painting (`VDTChipRun.rtl`, `VDTChip.order`): * {@link directRuns} at the base direction of the chip's own first strong * letter (left to right when it has none), in visual order — the build's * mirror pass reverses the order on mirrored pages. `measure` is the width * the chip's runs were measured with. The runs come back as they were when * nothing needs ordering. */ export declare function directChipRuns(runs: R[], measure: (text: string, font: string, rtl: boolean) => number, /** Every run takes its own advance, in the direction it is painted in * ({@link measuresRunsAsPainted}): the chip is then as wide as its runs. */ asPainted?: boolean, /** The base direction, when the chip has one of its own (inline code * reads left to right, #845); else that of its first strong letter. */ base?: 'ltr' | 'rtl'): { runs: (R & { rtl?: true; })[]; order?: number[]; }; export {}; //# sourceMappingURL=bidiText.d.ts.map