Expand description
oxitext-sdf — Signed Distance Field glyph atlas generation for OxiText.
Provides a pure-Rust implementation of the Felzenszwalb-Huttenlocher EDT for computing signed distance fields from glyph coverage bitmaps, an atlas packer for producing GPU-ready SDF texture atlases, and a multi-channel SDF (MSDF) pipeline that generates 3-channel distance fields directly from glyph outlines for sharper rendering at large magnifications.
§Quick start (single-channel SDF)
use oxitext_sdf::{compute_sdf, SdfAtlas, SdfTile};
// A solid 32×32 square (inside everywhere).
let coverage = vec![255u8; 32 * 32];
let sdf = compute_sdf(&coverage, 32, 32, 8.0, 0).expect("compute_sdf");
assert_eq!(sdf.len(), 32 * 32);
// Pack a single tile into an atlas.
let tile = SdfTile {
glyph_id: 0,
width: 32,
height: 32,
data: sdf,
bearing_x: 0,
bearing_y: 0,
advance_x: 32.0,
};
let atlas = SdfAtlas::pack(&[tile]);
assert!(atlas.uv_map.contains_key(&0));Re-exports§
pub use analytic::glyph_to_sdf_tile_analytic;pub use build_helper::generate_ascii_atlas;pub use build_helper::generate_atlas_binary;pub use msdf::color_edges;pub use msdf::compute_msdf;pub use msdf::compute_mtsdf;pub use msdf::extract_glyph_shape;pub use msdf::glyph_to_msdf_tile;pub use msdf::glyph_to_mtsdf_tile;pub use msdf::EdgeColor;pub use msdf::GlyphShape;pub use msdf::MsdfTile;pub use msdf::MtsdfTile;pub use psdf::glyph_to_psdf_tile;pub use psdf::PsdfTile;
Modules§
- analytic
- Direct bezier-to-SDF pipeline using analytic (Newton-Raphson refined) distance.
- build_
helper - Build-time SDF atlas generation helpers.
- msdf
- Multi-channel signed distance field (MSDF) generation.
- psdf
- Signed Pseudo-Distance Field (PSDF) generation.
Structs§
- Atlas
Glyph Metrics - Per-glyph metrics stored alongside the atlas for rendering.
- Atlas
Options - Options for atlas packing.
- Atlas
Stats - Statistics returned from an atlas packing operation.
- GpuAtlas
Descriptor - A GPU-ready atlas descriptor: all the information needed to upload the atlas to a GPU texture (wgpu, Vulkan, Metal, OpenGL) without depending on any GPU crate.
- Msdf
Atlas - A packed atlas of MSDF glyph tiles, ready for GPU upload.
- Multi
Page Atlas - An atlas that spans multiple pages when a single texture is not large enough.
- Normalized
UvRect - UV rectangle in normalized [0, 1] texture coordinates.
- SdfAtlas
- A packed atlas of SDF glyph tiles, ready for GPU upload.
- SdfTile
- A single SDF glyph tile produced by the SDF pipeline.
- UvRect
- A UV rectangle within the atlas texture (all values in [0, 1]).
Enums§
- GpuAtlas
Format - Pixel format for GPU atlas texture upload.
- Packing
Algorithm - Packing algorithm selection.
- SdfError
- Error type for SDF computation failures.
Functions§
- bitmap_
to_ sdf_ tile - Convert a greyscale coverage bitmap (from
oxitext-raster) to a signed distance field tile. - compute_
sdf - Compute a signed SDF from a grayscale coverage map.
- glyph_
to_ sdf_ tile - Generate a signed-distance-field tile for a single glyph.
- pack_
growing - Pack tiles into an atlas that grows automatically until all tiles fit or
max_sizeis reached.