computeCharPositions()
Compute per-grapheme boxes for already-broken lines.
Import
Section titled “Import”import { computeCharPositions } from "@graphrefly/ts/solutions/reactive-layout";Signature
Section titled “Signature”function computeCharPositions( lineBreaks: LineBreaksResult, segments: readonly PreparedSegment[], lineHeight: number, segmentAdapter?: SegmentAdapter,): readonly CharPosition[]Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
lineBreaks | LineBreaksResult | Line break result whose cursors identify the visible grapheme ranges. |
segments | readonly PreparedSegment[] | Prepared segments used to produce the line breaks. |
lineHeight | number | Height assigned to every line box. |
segmentAdapter | SegmentAdapter | Optional segmentation adapter; defaults to the built-in adapter. |
Returns
Section titled “Returns”Character-position boxes in visual order, each with x, y, width, height, and zero-based line index.
Example
Section titled “Example”import { analyzeAndMeasure, computeCharPositions, computeLineBreaks,} from "@graphrefly/ts/solutions/reactive-layout";
const segments = analyzeAndMeasure( "Hello world", "16px system-ui", { measureSegment: (segment) => ({ width: segment.length * 8 }) }, new Map(),);const lineBreaks = computeLineBreaks(segments, 64);const positions = computeCharPositions(lineBreaks, segments, 20);Remarks
Section titled “Remarks”- Already measured: Widths come from the prepared segments; this helper only maps the line cursors into per-grapheme rectangles.
Source
Section titled “Source”packages/ts/src/solutions/reactive-layout/line.ts