Pretext

Pretext is a deterministic text preparation and line-layout engine with pluggable text-measurement backends. It prepares text once, exposes segment and break metadata, and lets you compute line counts, materialized lines, or streamed line geometry without relying on control reflow.

What This Library Does

Prepare once, reuse often

`Prepare` and `PrepareWithSegments` precompute widths, break opportunities, and whitespace behavior so repeated layout passes stay cheap.

Batch and streaming layout

Use `Layout` for quick metrics, `LayoutWithLines` for materialized lines, or `LayoutNextLine` and `WalkLineRanges` for incremental custom layout engines.

Real text behavior

The engine handles grapheme-aware breaks, discretionary hyphens, tabs, preserved whitespace, bidi text, and locale-aware segmentation on desktop targets.

Scope

Pretext is a layout engine, not a text renderer. It answers questions such as:

  • how many lines fit in a given width
  • what text ends up on each line
  • where the next line should start for a custom flow algorithm
  • which whitespace, punctuation, and discretionary break opportunities should stay visible

You still own:

  • drawing the text in your host UI
  • choosing the line height and baseline policy
  • arranging lines into columns, cards, obstacles, or custom panels
  • invalidating or repainting your UI when layout inputs change

Documentation Map

Getting Started

Install the packages, learn the font string contract, and build the first useful `Prepare` + `Layout` flow.

Open section

Concepts

Understand the prepared-text lifecycle, whitespace modes, break kinds, locale-aware segmentation, bidi, and line fitting.

Open section

Guides

Integrate `Pretext` into Uno, native Windows/Linux/macOS hosts, or any SkiaSharp-based renderer, then reuse the shared sample-host patterns for shrinkwrap, editorial, and obstacle-aware layouts.

Open section

Reference

Browse every public type and operation, the package-by-package reference pages, platform notes, and repository structure.

Open section

Repository Layout

Path Purpose
src/Pretext The packable library project containing PretextLayout and the text preparation/layout pipeline.
src/Pretext.Contracts Shared backend contracts and first-party font-string parsing helpers.
src/Pretext.Layout Platform-neutral wrap and obstacle-layout helpers built on top of Pretext.
src/Pretext.DirectWrite Windows DirectWrite measurement backend.
src/Pretext.FreeType Linux FreeType + Fontconfig measurement backend.
src/Pretext.CoreText macOS CoreText measurement backend.
src/Pretext.SkiaSharp Portable SkiaSharp measurement backend and fallback.
src/Pretext.Uno The source for the Pretext.Uno package, with Uno-specific reusable controls and render scheduling helpers.
tests/Pretext.Uno.Tests Deterministic parity tests for whitespace handling, break behavior, bidi text, and line walking.
samples/PretextSamples.Shared Shared sample catalog, assets, and data/model layer reused by the sample hosts.
samples/PretextSamples.Uno A Uno sample host with layout demos including bubbles, masonry, editorial, and justification views.
samples/PretextSamples.MacOS A native AppKit sample host on net10.0-macos using Pretext.CoreText.

Published Packages

Package Purpose
Pretext Backend-agnostic text preparation and layout engine.
Pretext.Contracts Public backend contracts and shared font parsing.
Pretext.Layout Platform-neutral wrap and obstacle-layout helpers.
Pretext.DirectWrite Windows-native DirectWrite backend.
Pretext.FreeType Linux-native FreeType + Fontconfig backend.
Pretext.CoreText macOS-native CoreText backend.
Pretext.SkiaSharp Portable SkiaSharp backend and fallback.
Pretext.Uno Uno-specific controls layered on top of Pretext.

Start With These Pages

Repository