Skip to main content

densa_text/
lib.rs

1//! Real text for densa: fonts, glyph rasterization and a glyph atlas cache.
2//!
3//! Domain-agnostic: any widget that draws text goes through these three pieces.
4//!
5//! - [`Font`] wraps an OpenType/TrueType font (skrifa): character mapping, advances, line
6//!   metrics. [`Font::bundled_mono`] is JetBrains Mono, shipped under the SIL OFL 1.1.
7//! - [`rasterize`] turns a glyph outline into an 8-bit coverage bitmap (zeno), optionally
8//!   shifted by a fraction of a pixel.
9//! - [`GlyphCache`] packs rasterized glyphs into a paged texture atlas (etagere) that grows a
10//!   page at a time and, once at its limit, evicts the least recently used glyphs (never the
11//!   current frame's); it queues the [`AtlasUpdate`]s the GPU texture must follow.
12//!
13//! A warm cache answers lookups without allocating, so per-frame text drawing stays
14//! allocation-free; rasterizing a glyph seen for the first time allocates, once.
15
16mod cache;
17mod font;
18mod glyph_map;
19mod raster;
20mod run;
21
22pub use cache::{
23    quantize_x, AtlasConfig, AtlasLimitError, AtlasUpdate, CacheStats, CachedGlyph, GlyphCache,
24    GlyphUnavailable, GlyphUpload, SUBPIXEL_STEPS,
25};
26pub use font::{Font, FontBytes, FontError, FontId, GlyphId, LineMetrics, BUNDLED_MONO};
27pub use glyph_map::{GlyphMap, MappedGlyph, MAX_CACHED_CHARS};
28pub use raster::{rasterize, GlyphBitmap};
29pub use run::{GlyphRun, PositionedGlyph};