Pretext.Uno
0.1.0-preview.1
See the version list below for details.
dotnet add package Pretext.Uno --version 0.1.0-preview.1
NuGet\Install-Package Pretext.Uno -Version 0.1.0-preview.1
<PackageReference Include="Pretext.Uno" Version="0.1.0-preview.1" />
<PackageVersion Include="Pretext.Uno" Version="0.1.0-preview.1" />
<PackageReference Include="Pretext.Uno" />
paket add Pretext.Uno --version 0.1.0-preview.1
#r "nuget: Pretext.Uno, 0.1.0-preview.1"
#:package Pretext.Uno@0.1.0-preview.1
#addin nuget:?package=Pretext.Uno&version=0.1.0-preview.1&prerelease
#tool nuget:?package=Pretext.Uno&version=0.1.0-preview.1&prerelease
Pretext
Universal text preparation and line layout for any SkiaSharp-based UI, with grapheme-aware wrapping, locale-aware segmentation, bidi support, and streaming line walking.
PretextSharp is a .NET/C# port of the original pretext project by Cheng Lou.
Documentation site: wieslawsoltes.github.io/PretextSharp
Key documentation:
- Getting Started Overview
- Quickstart: Prepare and Layout
- Choosing an API
- Prepared Text Lifecycle
- Public Types and Operations
- Pretext.Uno Helpers
NuGet Packages
Features
- Prepare text once and reuse the result across repeated layout passes with
PrepareandPrepareWithSegments. - Compute fast aggregate metrics with
Layout, or materialize full line data withLayoutWithLines. - Stream line geometry incrementally with
LayoutNextLineandWalkLineRangesfor custom layout engines. - Handle ordinary spaces, preserved spaces, tabs, hard breaks, non-breaking spaces, zero-width breaks, and soft hyphens.
- Support multilingual text with locale-aware segmentation on desktop targets and bidi-aware segment levels.
- Depend only on
SkiaSharpin the core library so the package can be used outside Uno as well. - Ship with a published
Pretext.Unocompanion library for reusable Uno host controls and obstacle-aware flow helpers. - Ship with deterministic parity tests and a Uno sample app that demonstrates bubbles, masonry, editorial, and justification layouts.
Core API
| API | Purpose |
|---|---|
Prepare |
Prepare text for repeated layout when you only need aggregate metrics. |
PrepareWithSegments |
Prepare text and expose segments, widths, break metadata, and segment levels. |
Layout |
Return line count and total height for a given width and line height. |
LayoutWithLines |
Return materialized line text and line widths. |
LayoutNextLine |
Stream the next line from a given cursor for custom layout flows. |
WalkLineRanges |
Iterate line geometry without allocating full line text. |
ProfilePrepare |
Measure preparation cost for profiling and diagnostics. |
SetLocale |
Override locale-sensitive segmentation behavior when needed. |
ClearCache |
Reset cached font state and prepared segment text caches. |
API Selection
| Need | Start with |
|---|---|
| Line count and total height only | Prepare + Layout |
| Actual line text and widths | PrepareWithSegments + LayoutWithLines |
| One line at a time in a custom loop | PrepareWithSegments + LayoutNextLine |
| Geometry only, fewer allocations | PrepareWithSegments + WalkLineRanges |
| Preparation cost diagnostics | ProfilePrepare |
Quick Start
Install from NuGet:
dotnet add package Pretext
Then prepare and lay out text:
using Pretext;
const string text = "Hello soft\u00ADwrapped world";
const string font = "16px Inter";
const double lineHeight = 20;
var prepared = PretextLayout.PrepareWithSegments(text, font);
var metrics = PretextLayout.Layout(prepared, maxWidth: 160, lineHeight);
var lines = PretextLayout.LayoutWithLines(prepared, maxWidth: 160, lineHeight);
Console.WriteLine(metrics.LineCount);
Console.WriteLine(metrics.Height);
foreach (var line in lines.Lines)
{
Console.WriteLine($"{line.Text} ({line.Width})");
}
The core package exposes the Pretext namespace and is not tied to Uno. Use it anywhere you use SkiaSharp.
The font argument is a CSS-like subset such as 16px Inter, italic 16px Georgia, or 700 18px "IBM Plex Sans". Line height is supplied separately to layout calls.
Use WhiteSpaceMode.PreWrap when your layout needs preserved spaces, tabs, or hard breaks:
var prepared = PretextLayout.PrepareWithSegments(
"foo\tbar\nbaz",
"16px Inter",
new PrepareOptions(WhiteSpaceMode.PreWrap));
Uno Companion
Install the Uno companion package when you want the reusable Uno-specific helpers on top of the core engine:
dotnet add package Pretext.Uno
It brings the Pretext core package transitively and exposes:
Pretext.PretextLayoutPretext.Uno.Controls.StretchScrollHostPretext.Uno.Controls.UiRenderSchedulerPretext.Uno.Layout.PreparedTextMetricsPretext.Uno.Layout.ColumnFlowLayoutPretext.Uno.Layout.ObstacleLayoutHelper
Sample App
The sample app lives in samples/PretextSamples and demonstrates the library in visually different layouts. It uses Uno Platform, exercises the core Pretext APIs together with the Pretext.Uno companion helpers, and keeps only sample-specific UI/theme code in the sample tree.
- Overview
- Accordion
- Bubbles
- Masonry
- Rich Text
- Dynamic Layout
- Editorial Engine
- Justification Comparison
- Variable ASCII
Run it with:
dotnet run --project samples/PretextSamples/PretextSamples.csproj -f net10.0-desktop
Building
Prerequisites
- .NET 10 SDK
- Uno.Sdk 6.5.x for the sample app only
Build, test, and pack
dotnet build PretextSamples.slnx
dotnet test tests/Pretext.Uno.Tests/Pretext.Uno.Tests.csproj
dotnet pack src/Pretext/Pretext.csproj -c Release
dotnet pack src/Pretext.Uno/Pretext.Uno.csproj -c Release
Docs and CI
The repository includes:
ci.ymlfor multi-platform build, test, docs validation, and preview package generationdocs.ymlfor GitHub Pages deploymentrelease.ymlfor tag-driven packing, optional NuGet publication, and GitHub release creation- a Lunet docs site in
site/
The docs cover:
- installation and namespace/package selection
- font strings, measurement, and prepared-text lifecycle
- whitespace and break behavior, locale-aware segmentation, and bidi
- practical Uno and generic SkiaSharp integration patterns
- full reference coverage for the public core API and
Pretext.Unohelpers
Project Structure
src/
Pretext/
Pretext.Uno/
tests/
Pretext.Uno.Tests/
samples/
PretextSamples/
site/
Attribution
The core Pretext implementation in this repository is ported from the original pretext project by Cheng Lou. This repository adapts that work to .NET, SkiaSharp, packaging, tests, samples, and companion Uno helpers.
License
MIT. See LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0-desktop1.0 is compatible. |
-
net10.0-desktop1.0
- Pretext (>= 0.1.0-preview.1)
- SkiaSharp.Views.Uno.WinUI (>= 3.119.1)
- Uno.WinUI (>= 6.5.153)
- Uno.WinUI.Graphics2DSK (>= 6.5.153)
- Uno.WinUI.Lottie (>= 6.5.153)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Pretext.Uno:
| Package | Downloads |
|---|---|
|
LeXtudio.RichText
LeXtudio.RichText — a rich text layout control for Uno Platform, providing RichTextBlock, Paragraph, Span, Bold, Italic, Hyperlink, InlineUIContainer and related document types backed by PretextSharp. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0 | 172 | 5/1/2026 |
| 0.1.0-preview.5 | 159 | 4/28/2026 |
| 0.1.0-preview.4 | 53 | 4/20/2026 |
| 0.1.0-preview.3 | 68 | 4/15/2026 |
| 0.1.0-preview.2 | 56 | 4/14/2026 |
| 0.1.0-preview.1 | 62 | 4/12/2026 |
Initial public packaging of the Uno-specific companion controls and layout helpers for Pretext.