Pretext exposes multiple preparation and layout entry points because different workloads need different tradeoffs.
| Use this | When you need | Cost profile |
|---|---|---|
Prepare |
Line count and height only | Lowest memory footprint |
PrepareWithSegments |
Segment metadata, line strings, or streamed iteration | Higher memory footprint, richer output |
If you are unsure, start with PrepareWithSegments during prototyping and move to Prepare later if a hot path only needs aggregate metrics.
| Use this | Output | Best for |
|---|---|---|
Layout |
LayoutResult |
Measurement passes, card sizing, line count probes |
LayoutWithLines |
LayoutLinesResult |
Rendering full line text, diagnostics, exports |
LayoutNextLine |
LayoutLine? |
Custom loops, obstacles, columns, stop-early flows |
WalkLineRanges |
line widths + cursors only | Geometry-only iteration with fewer allocations |
| Scenario | Recommended flow |
|---|---|
| Measure a card height from text and width | Prepare -> Layout |
| Draw a paragraph line-by-line in a custom canvas | PrepareWithSegments -> LayoutWithLines |
| Flow text through columns or around obstacles | PrepareWithSegments -> repeated LayoutNextLine |
| Find the widest visible line without allocating strings | PrepareWithSegments -> WalkLineRanges |
| Profile how expensive preparation is | ProfilePrepare |
Recreate prepared text when any of these change:
font stringWhiteSpaceModeSetLocaleDo not recreate prepared text when only these change:
If your code needs the actual line text, segment kinds, or cursor positions, prepare with segments. Otherwise, stay on the smaller Prepare + Layout path.