Skip to main content

text_typeset/
lib.rs

1//! # text-typeset
2//!
3//! Turns rich text documents into GPU-ready glyph quads.
4//!
5//! Typesetting crate for the `text-document` ecosystem. Takes a rich text
6//! document model (styled paragraphs, tables, lists, frames) and produces
7//! positioned glyph quads, decoration rectangles, and a glyph atlas texture
8//! that any GPU framework can render in a few draw calls.
9//!
10//! ```text
11//! text-document (model) --> text-typeset (shaping + layout) --> framework adapter (rendering)
12//! ```
13//!
14//! # Quick start
15//!
16//! ```rust,no_run
17//! use text_typeset::Typesetter;
18//!
19//! let mut ts = Typesetter::new();
20//! let font = ts.register_font(include_bytes!("../test-fonts/NotoSans-Variable.ttf"));
21//! ts.set_default_font(font, 16.0);
22//! ts.set_viewport(800.0, 600.0);
23//!
24//! // With text-document (default feature):
25//! # #[cfg(feature = "text-document")]
26//! # {
27//! let doc = text_document::TextDocument::new();
28//! doc.set_plain_text("Hello, world!").unwrap();
29//! ts.layout_full(&doc.snapshot_flow());
30//! # }
31//!
32//! let frame = ts.render();
33//! // frame.glyphs     -> glyph quads (textured rects from atlas)
34//! // frame.atlas_pixels -> RGBA texture to upload
35//! // frame.decorations  -> cursor, selection, underlines, borders
36//! ```
37//!
38//! # Features
39//!
40//! - `text-document` (default) : enables [`bridge`] module and [`Typesetter::layout_full`]
41//!   for direct integration with text-document's `FlowSnapshot`.
42
43mod types;
44
45pub mod atlas;
46pub mod font;
47pub mod layout;
48mod render;
49pub mod shaping;
50
51#[cfg(feature = "text-document")]
52pub mod bridge;
53
54mod typesetter;
55
56// Public API
57pub use types::{
58    BlockVisualInfo, CursorDisplay, DecorationKind, DecorationRect, FontFaceId, GlyphQuad,
59    HitRegion, HitTestResult, ImageQuad, RenderFrame,
60};
61
62pub use typesetter::{ContentWidthMode, Typesetter};