/** * The pieces of a word, set as the word the layout measured (#764, #770). * * The line breaker cuts a word wherever a line may end inside it (its * syllables, a dash, the joints of an address), and a line carries each * piece as a segment of its own. The engine measures the pieces in one of * two ways. A plain paragraph hands them to its text library one by one: * each piece is as wide as it is alone. A paragraph with a style, a link * or a note in it is cut word by word, and there a piece is as wide as * the word grew by it: `instal·lació` comes as `ins`, `tal·`, `la`, `ció`, * and the width of `la` is that of `instal·la` less that of `instal·`. * * In the second way the browser measured those strings whole, and a face * may draw a character otherwise by what stands beside it across a cut. * Crimson Pro sets the dot of a Catalan `l·l` 0.586 em wide in Catalan * and 0.24 em anywhere else: `tal·` set alone has the narrow dot, the * piece after it the room of the wide one, and the word shows a hole * after `la`. A ligature (`ffi` of `of|fice`) and a kerned pair (`y|o` of * `Toy|ota`) across a cut go the same way. * * A line does not say which way its words were measured, so each output * asks the text setter it paints with (the canvas, the browser's layout, * the PDF's shaper): the pieces that follow each other in one style are * set as one text where that text is as wide as the layout measured the * pieces together and one of them alone is not as wide as its place. * Its glyphs are then the ones measured. Any other piece is set alone, as * every piece was up to postext 1.29. * * The hyphen a line ends on is measured alone, after the word's last * piece. Where that piece with its hyphen is not as wide as its place * (the face kerns the pair, or the piece is one of several), the hyphen * is set apart when what is left then is. * * A word broken across two lines is not put back. The piece that opens * the second line is as wide as the word grew by it from what stayed on * the first, so alone it is off by whatever the face drew across the * break. The pieces of that rest are set as one text when that text is * off by as much as its first piece alone: its letters then stand * together, and the difference falls after the word, where it stood * inside it. The layout's measure of that piece is not changed here. * * The canvas, the HTML and the PDF call {@link lineWordSegments}, so the * three set the same pieces together. * * The CJK composer goes the other way: it measures a Chinese or Japanese * character alone, as one cell, and a line carries the cells of one style * as one segment. Set as one text the browser kerns inside it, a kana * against the mark after it; {@link cellsOf} tells which texts are cells, * for an output to set them where they were measured. */ import type { VDTLine, VDTLineSegment } from './vdt.js'; /** A piece of a word as a line carries it: its text and the width the * layout gave it. */ export interface WordPiece { readonly text: string; readonly width: number; } /** Whether a text set `a` px wide is as wide as the `b` px measured. */ export declare function sameSetWidth(a: number, b: number): boolean; /** * The stretches of `pieces` that are set as one text, each as `[from, * to)`: pieces that follow each other with no space, in one style, whose * text set whole is as wide as the layout measured them together, where * one of them set alone is not as wide as its place. `widthOf` is the * width the output gives a text in the pieces' style, with the line's * tracking. `opensLine`: the pieces open their line, so the first may be * the rest of a word broken at the line before; when it is off alone, a * stretch from it on is also one text when it is off by as much. The * longest stretch from each piece on wins; a piece in no stretch is set * alone. Empty when every piece is as wide alone as measured (a plain * paragraph's, a word with nothing across its cuts). */ export declare function joinedWordPieces(pieces: readonly WordPiece[], widthOf: (text: string) => number, opensLine?: boolean): [from: number, to: number][]; /** * The segments a line is set from: its own, with the pieces of a word * joined into one segment where the word was measured whole, and the * hyphen of a line end set apart where it was measured apart (see the * module comment). `advanceOf` is the advance the output gives `text` in * the style of the segment `seg` (px, with the line's tracking). * * The line's own array when nothing changes: a line of the CJK composer * or down a vertical page (`composed`), a line that carries directions * (its `order` counts its segments: {@link lineWordSegmentsInOrder} sets * those), a line whose pieces are each as wide alone as measured. A * joined segment carries what its first piece does; the line's segments * are not touched, so what reads a piece's box from them (a link's area, * a selection) reads the same boxes. */ export declare function lineWordSegments(line: VDTLine, composed: boolean, advanceOf: (seg: VDTLineSegment, text: string) => number): VDTLineSegment[] | undefined; /** A line as an output sets it: its segments, and the order they advance * in along the line when the line carries one (`VDTLine.order`). */ export interface SetLine { segments: VDTLineSegment[] | undefined; order: readonly number[] | undefined; } /** * {@link lineWordSegments} for any line, one that carries directions * included: the segments it is set from and the `order` they advance in. * * A line with right-to-left text, and every line of a right-to-left page, * lists its segments in the order they stand along the line * (`VDTLine.order`). The pieces of a left-to-right word stand side by side * there, in reading order or, on a mirrored page, against it; they are * joined as on any line, and the order is written again for the segments * that result: the joined word where its pieces stood. A right-to-left * segment is one shaped run already and is never a piece. The line's own * segments and order when nothing changes. */ export declare function lineWordSegmentsInOrder(line: VDTLine, composed: boolean, advanceOf: (seg: VDTLineSegment, text: string) => number): SetLine; /** * The cells of `text`, a segment of a line of the CJK composer * (`VDTLine.cjkComposed`), a ruby base or a run of composed design text: * its characters when there are two or more and each is one the composer * measures alone (`isCjkGrapheme`: a Han character, a kana, a CJK mark, a * dash or a quote it treats as one). Undefined for any other text: a * Western run, which was measured whole with its kerning, and a single * character. */ export declare function cellsOf(text: string): string[] | undefined; //# sourceMappingURL=wordPieces.d.ts.map