Skip to main content

leaf_raster/
lib.rs

1//! CPU rasterization shared by leaf frontends — the pieces of pixel rendering
2//! that are the same whatever the pixels end up painted with.
3//!
4//! Each leaf frontend has its own paint path (terminal cells, a gpui scene,
5//! Core Text, the DOM), but several of them also need actual pixels: the
6//! terminal ships graphics-protocol images for block media and oversized
7//! headings, and a headless consumer wants a frame with no toolkit at all.
8//! What those uses share lives here, in backend-neutral units:
9//!
10//! - [`resolve_image_path`] — which image destinations a synchronous local
11//!   loader handles, and where a relative one anchors. One policy, because two
12//!   frontends disagreeing about what loads is a bug report.
13//! - [`load_image`] / [`load_svg`] — file bytes to a decoded [`image`] raster,
14//!   vector pictures included.
15//! - [`fit_within`] — aspect-preserving containment in pixels, so frontends
16//!   with different display units (cells, points) share the sizing policy and
17//!   only round differently.
18//! - [`Rasterizer`] — shape and rasterize oversized heading text to an RGBA
19//!   frame, with the *editing UI* — caret and selection — painted into the
20//!   pixels. That last part is the reason this is a crate and not a helper: a
21//!   terminal cannot composite cells over a graphics-protocol image, so the
22//!   only way a rasterized heading stays editable is for the raster itself to
23//!   carry the caret. [`Rasterizer::heading_hit`] is the reverse mapping, so a
24//!   click on the raster lands on the glyph it visually hit.
25//!
26//! Everything here is CPU-side (cosmic-text, resvg, `image`): the consumers
27//! are terminals reading escape sequences and headless frames, none of which
28//! are latency-bound enough to want a GPU pipeline — and the one leaf backend
29//! that is (gpui) has its own. The contract is "hand me RGBA", so a GPU
30//! implementation could slot in behind it without callers changing.
31
32pub use image;
33
34mod fit;
35mod load;
36mod path;
37mod text;
38
39pub use fit::fit_within;
40pub use load::{load_image, load_svg};
41pub use path::resolve_image_path;
42pub use text::{EditingUi, HeadingSpec, Rasterizer};