Expand description
§text-typeset
Turns rich text documents into GPU-ready glyph quads.
Typesetting crate for the text-document ecosystem. Takes a rich
text document model (styled paragraphs, tables, lists, frames)
and produces positioned glyph quads, decoration rectangles, and a
glyph atlas texture that any GPU framework can render in a few
draw calls.
text-document (model) --> text-typeset (shaping + layout) --> framework adapter (rendering)§Architecture: shared service, owned flows
text-typeset is split along the axis of “what is shareable”:
-
TextFontServiceowns the font registry, the glyph atlas, the glyph cache, theswashscale context, and the HiDPI scale factor. It is the expensive-to-build, expensive-to-share part. Construct one per process (or one per window) and share it by reference across every widget that emits text. -
DocumentFlowowns the per-widget view state: viewport, zoom, scroll offset, content-width mode, flow layout, cursor, and default colors. Every widget that shows a document holds its ownDocumentFlow. Layout and render methods take the service by reference, so many flows can render into one shared atlas — which means one GPU upload per frame, one shaped glyph rasterized at most once, and no cross-widget contamination of viewport / zoom / scroll state.
§Quick start
use text_typeset::{DocumentFlow, TextFontService};
let mut service = TextFontService::new();
let face = service.register_font(include_bytes!("../test-fonts/NotoSans-Variable.ttf"));
service.set_default_font(face, 16.0);
let mut flow = DocumentFlow::new();
flow.set_viewport(800.0, 600.0);
let doc = text_document::TextDocument::new();
doc.set_plain_text("Hello, world!").unwrap();
flow.layout_full(&service, &doc.snapshot_flow());
let frame = flow.render(&mut service);
// frame.glyphs -> glyph quads (textured rects from the shared atlas)
// frame.atlas_pixels -> RGBA texture to upload (or skip via service.atlas_pixels())
// frame.decorations -> cursor, selection, underlines, borders§Sharing between widgets
Put the service behind whatever smart pointer the host framework
uses — an Rc<RefCell<TextFontService>> for single-threaded UIs,
a plain &mut in render loops that already have exclusive
access. Every widget owns its own DocumentFlow and calls
flow.render(&mut *service.borrow_mut()) when it paints.
Because the service does not store any per-widget state,
“widget A rendered last” cannot break widget B. A changes to
set_viewport, set_zoom, set_scroll_offset, or set_cursor
live on A’s flow and never touch B’s.
§Features
text-document(default): enablesbridgemodule andDocumentFlow::layout_fullfor direct integration with text-document’sFlowSnapshot.
Re-exports§
pub use layout::inline_markup::InlineAttrs;pub use layout::inline_markup::InlineMarkup;pub use layout::inline_markup::InlineSpan;
Modules§
- atlas
- bridge
- Bridge between text-document snapshot types and text-typeset layout params.
- font
- layout
- shaping
Structs§
- Atlas
Snapshot - Outcome of a call to
TextFontService::atlas_snapshot. - Block
Visual Info - Visual position and size of a laid-out block.
- Character
Geometry - Per-character advance geometry for a laid-out text run.
- Cursor
Display - Cursor display state for rendering.
- Decoration
Rect - A colored rectangle for decorations (underlines, selections, borders, etc.).
- Document
Flow - Per-widget document flow state.
- Font
Face Id - Opaque handle to a registered font face.
- Glyph
Quad - A positioned glyph to draw as a textured quad from the atlas.
- HitTest
Result - Result of [
crate::Typesetter::hit_test] - maps a screen-space point to a document position. - Image
Quad - An inline image placeholder.
- Laid
OutSpan - A single laid-out span produced by the markup-aware layout path.
- Paragraph
Result - Result of [
crate::Typesetter::layout_paragraph]. - Render
Frame - Everything needed to draw one frame.
- Single
Line Result - Result of [
crate::Typesetter::layout_single_line]. - Text
Font Service - Shared font resources for a text-typeset session.
- Text
Format - Text formatting parameters for the single-line layout API.
Enums§
- Content
Width Mode - How the content (layout) width is determined.
- Decoration
Kind - The type of a
DecorationRect. - HitRegion
- What region of the layout a hit test landed in.
- Laid
OutSpan Kind - Kind discriminator for
LaidOutSpan. - Relayout
Error - Reasons
DocumentFlow::relayout_blockmay refuse an incremental update. - Underline
Style - Underline style for text decorations.
- Vertical
Alignment - Vertical alignment for characters (superscript, subscript, etc.).