/** * Tracked words keep their ligatures (#663). * * A tracked word is measured as its natural width plus the tracking times * its letters (`measure/rich.ts`, `knuthPlass/tracking.ts`), and its natural * width counts the ligatures of the face (fi, fl, ffi…). Painted with the * context's `letterSpacing`, the browser shapes it without them (CSS Text: * no optional ligatures where the letter-spacing is not zero): "first" in * Newsreader comes out 4.5 px wider at 40 px than the place the layout * holds for it, and runs into the word space after it. The canvas has no * way to ask for the ligatures back, so such a word is painted in pieces: * each ligature alone with no letter-spacing, the letters between them * tracked, every piece where the natural shaping puts it. The PDF does the * same by construction (it shapes the word and spaces its glyphs). * * Which words: the ones whose width at a letter-spacing, less that * letter-spacing, is not their natural width. A word the browser shapes * the same either way (nearly all of them) is painted as before, with one * `fillText`. * * The same holds for any tracked text painted with one `fillText` (#703): * a line or a run of a design text (running heads, openers, callout * titles, balloon lettering) and the sideways Latin run of a vertical * line come through here as a word does. * * Three rules of direction (#685, #703): * - the pieces are one run. On a right-to-left page, painted through a * mirror that turns every `fillText` back about its own box * (`mirrorFrame.ts`), the word is turned once, about the box it was * measured in, and its pieces are set inside it from its left end, as on * a left-to-right page. Turned one by one they stood in the mirror's * order: "five" read "vefi"; * - a word that holds a letter of a joining script (Arabic…) is never cut, * whoever asks: painted in pieces it loses its joins. Nor is a text in * two directions (a Hebrew word with a number or a Latin letter in it): * its pieces would not stand in one order; * - a right-to-left word of a script that does not join (Hebrew) is cut * like any other, where the painter set the context right to left for * it (`fillSegmentWord`, `paintRunInDirection`): its pieces are set from * the right end of its box, each painted right to left. * * The tracking of a ligature (#770). The layout counts the tracking once * a letter: a word is its natural width and the tracking times its * letters, and that is what the browser paints wherever the * letter-spacing dissolves nothing (Geist's `fi` is one glyph as wide as * `f` and `i`: under a letter-spacing the two letters are set apart, each * with the tracking after it). A ligature painted alone advanced by one * tracking, as one glyph, so a word that held one ended a tracking short * of its box for each letter the ligature had joined: `shift` in Source * Serif 4 at 19.58 px on a line justified with 0.39 px a letter, box * 43.37 px, painted 42.98 px, and `efit` on a line tightened by 0.34 px * ran 0.34 px over the word after it. In a document shaped in its own * language ({@link setLetterTracking}) the piece after a ligature starts * the tracking of every letter before it further on, the ligature's * letters each counted: the word ends where its box does, and the HTML * and the PDF set it the same. A document that keeps its host's language * is painted as it was, and so is a right-to-left word of any document * (a Hebrew face with a ligature): one tracking a ligature in the three * outputs. * * What a letter-spacing takes away besides ligatures (#770). Chrome sets * no contextual alternate either under a letter-spacing (`calt`, with * `liga` and `clig`), and the canvas cannot ask for them back. Cormorant * SC draws the hyphen between two capitals 1.47 px wider at 17.71 px: the * running head `A MAD TEA-PARTY`, tracked 2.5 px, was measured 192.76 px * and painted 191.30 px, no pair of its letters being a ligature. Playpen * Sans gives nearly every letter another form by its neighbours, so most * pairs read as ligatures and their pieces stood where no shaping puts * them: `UNIT 12` at 18.75 px, measured 98.52 px, ended at 97.70 px, and * `FOR PARENTS AND CARERS` 1.31 px past its 322.85 px. In a document * shaped in its own language a word whose pieces do not end where the * word was measured to end, or that the letter-spacing reshapes with no * ligature to keep, is painted whole at the letter-spacing that ends it * there: the tracking, and what the reshaping took or gave shared among * its letters (2.66 px a letter for `TEA-PARTY`). A text of several words * is then painted word by word, each where the natural shaping puts it * with the tracking of every letter before it, as the HTML sets its boxes * ({@link fittedParts}). The forms are the ones the browser draws under a * letter-spacing; the widths are the ones measured. * * A ligature and a form by the neighbours told apart (#770). To the probe * they read the same: two neighbours whose width under a letter-spacing, * the spacing taken off, is not their natural width. A ligature is one * glyph, which no spacing opens; a form by the neighbours is still a * glyph a letter, and under a letter-spacing the browser sets the same * letters in their plain forms, each spaced. Playpen Sans reshapes `FO` * and `OR` so: `FOR`, read as a ligature of three, was painted with no * tracking inside and the tracking of its three letters after it. In * `FOR PARENTS AND CARERS` at 17.71 px, tracked 3.125 px, its letters * stood as close as in untracked text, those of the three other words * 2.9 to 3.2 px apart, and 18.2 px lay between `FOR` and `PARENTS` * against 12 px between the other words. A zero width non-joiner between * the two letters tells them apart: it dissolves a ligature and leaves a * form by the neighbours as it is. Chrome 154: `fi` in Source Serif 4 at * 40 px is 26.16 px, 28.92 px under a letter-spacing and 28.92 px across * a non-joiner; `FO` in Playpen Sans at 17.71 px 24.178, 24.107 and * 24.178 px. The kerning stands across it: `AV` in Source Serif 4 is * 52.08 px with and without, 56.84 px its two letters apart. * In a document shaped in its own language two neighbours as wide across * a non-joiner as without one are no ligature ({@link ligated}), and a * word with none is painted whole at the letter-spacing that ends it on * its box, as any other the letter-spacing reshapes: `FOR` at 2.68 px a * letter. A document that keeps its host's language is painted as it * was, and so is a right-to-left word of any document, which is never * painted at a letter-spacing of its own. */ /** One piece of a word painted apart from the rest. */ export interface TrackedPiece { text: string; /** Where the piece starts in the word's natural shaping, px from its * start: its left end, or its right end for a right-to-left word. */ offset: number; /** Glyphs of the word before the piece: each takes the tracking once (a * ligature is one glyph, as in the PDF of a document that keeps its * host's language). */ glyphsBefore: number; /** Letters (graphemes) of the word before the piece, the letters of a * ligature each counted: what the layout counted the tracking of. */ lettersBefore: number; /** A ligature: painted with no letter-spacing. */ ligature: boolean; } /** Give a ligature of a tracked word the tracking of every letter it * joins from now on (`on`), as the layout counted it, or of one glyph as * up to postext 1.29: the page painter says which for the document it * paints (`bodyText.shapingLanguage`, through `setSegmentLanguages`). */ export declare function setLetterTracking(on: boolean): void; /** * Whether the browser shapes `text`, in the context's font, otherwise once * a letter-spacing is set: its width at a letter-spacing, that spacing * taken off, is not its natural width (it holds a ligature the * letter-spacing turns off). False where the context measures no * letter-spacing. The context's `letterSpacing` is put back as it was * found. */ export declare function shapedOtherwise(ctx: CanvasRenderingContext2D, text: string): boolean; /** * The pieces a tracked word is painted in, in the context's font and * direction, or null when it is painted whole (the browser shapes it the * same under letter-spacing, the context measures none, the word holds a * joining letter or text in two directions, or the context paints the * other way). The context's `letterSpacing` is put back as it was found. */ export declare function trackedPieces(ctx: CanvasRenderingContext2D, text: string): readonly TrackedPiece[] | null; /** * Paint a word of a tracked line, or any tracked text set as one run (a * line or a run of a design text, a sideways run of a vertical line), with * `paint` (the caller's `fillText`) at `x`, `y`: its left end on a * left-to-right page, the start of its box in a mirrored frame. `tracking` * is the context's `letterSpacing` on entry, px, and on return. A text * that would lose its ligatures to it is painted in its * {@link trackedPieces}, as one run (`paintAsOneRun`): its box is the one * the frame turns a text painted whole about, its natural width and the * tracking after each letter. A right-to-left word (the context set right * to left and aligned on its left edge by the caller) has its pieces set * from the right end of that box. Any other text with one `paint`. * Returns the advance of a text painted in pieces, the width it was * measured at, and undefined for one painted whole. */ export declare function fillTrackedWord(ctx: CanvasRenderingContext2D, text: string, x: number, y: number, tracking: number, paint: (text: string, x: number, y: number) => void): number | undefined; //# sourceMappingURL=trackedText.d.ts.map