layoutWithLines() lays out a paragraph at a fixed max width and returns the text and measured width of each line, along with the total line count and height. Use it when you need the actual line contents for rendering.
Signature
Parameters
The handle returned by
prepareWithSegments(). Must be the segment-aware variant — the plain PreparedText from prepare() is not accepted here.Maximum line width in pixels. All lines use the same width. Use
layoutNextLine() if you need variable widths per line.Line height in pixels. Must match the CSS
line-height for the element. The returned height is lineCount * lineHeight.Returns
Number of wrapped lines.
Total block height in pixels. Equal to
lineCount * lineHeight.Array of per-line objects, one per wrapped line.
layout() vs layoutWithLines()
layout() | layoutWithLines() | |
|---|---|---|
| Input | PreparedText | PreparedTextWithSegments |
| Returns line text | No | Yes |
| Returns line widths | No | Yes |
| Returns cursors | No | Yes |
| Resize hot path | Yes | No — keep off the hot path |
layout() when you only need the height. Use layoutWithLines() when you need to render the line contents.