emblema_text/lib.rs
1//! Packing rasterized glyph coverage into a texture, and placing the result.
2//!
3//! This crate takes coverage bitmaps and answers where each one sits. It does
4//! not produce them: turning an outline into coverage needs a font parser, and
5//! that is out of scope here -- bring `swash` or `ttf-parser` and hand the
6//! coverage over. Shaping and layout are out of scope for the same reason;
7//! bring `cosmic-text` or `parley`. The boundary is what lets the atlas be
8//! tested with no font anywhere in the tree, against bitmaps whose contents
9//! are known exactly.
10//!
11//! Subpixel positioning is a key, not a placement: [`GlyphKey::subpixel`] tells
12//! the atlas that coverage rasterized a quarter of a pixel along is a glyph of
13//! its own, and the caller who rasterized it there places it to match.
14//!
15//! Named here because this header claimed them and they would each change what
16//! a caller has to do: signed-distance-field coverage above a threshold size,
17//! and color glyphs drawn as image quads are **not implemented**. Nor is paging -- a full atlas is repacked and then doubled,
18//! which [`atlas`] explains and which was chosen over pages because a page
19//! boundary splits a glyph run into more than one draw.
20
21pub mod atlas;
22
23pub use atlas::{Atlas, AtlasError, AtlasRect, Coverage, GlyphKey};
24
25/// One glyph, placed.
26///
27/// The position is the glyph's top-left corner in user space, and the size is
28/// what it covers there. Both come from the caller: shaping decides where
29/// glyphs go and this does not shape. Keeping the destination separate from the
30/// atlas rectangle is what lets a glyph be drawn at a size other than the one
31/// it was rasterized at, which a caller doing so knowingly may want.
32#[derive(Debug, Clone, Copy, PartialEq)]
33pub struct PositionedGlyph {
34 pub key: GlyphKey,
35 pub position: [f32; 2],
36 pub size: [f32; 2],
37}
38
39impl PositionedGlyph {
40 /// A glyph drawn at the size its coverage was rasterized at.
41 pub fn new(key: GlyphKey, position: [f32; 2], rect: AtlasRect) -> Self {
42 Self {
43 key,
44 position,
45 size: [rect.width as f32, rect.height as f32],
46 }
47 }
48}