pub struct FontAtlas {
pub texture_size: (u32, u32),
/* private fields */
}Expand description
A simple monospace bitmap font atlas.
The built-in engine font is a fixed-pitch 8×13 px bitmap covering ASCII
32–126, plus a trailing .notdef box. Glyphs are arranged in a single row
in the atlas texture.
§Atlas layout
Each glyph is GLYPH_WIDTH × GLYPH_HEIGHT pixels. They are packed
left-to-right, one row, in ASCII order, with .notdef last. The total atlas
width is GLYPH_WIDTH * GLYPH_COUNT pixels.
Fields§
§texture_size: (u32, u32)Atlas texture dimensions in pixels (width, height).
Implementations§
Source§impl FontAtlas
impl FontAtlas
Sourcepub fn glyph(&self, c: char) -> &GlyphMetrics
pub fn glyph(&self, c: char) -> &GlyphMetrics
Look up the metrics for a character.
Any codepoint outside ASCII 32–126 — including control characters and
everything non-Latin — resolves to the .notdef box.
Sourcepub fn text_width(&self, text: &str, scale: f32) -> f32
pub fn text_width(&self, text: &str, scale: f32) -> f32
Measure the width of a string in pixels at the given scale.
scale is a multiplier relative to the baked-in glyph size (1.0 =
natural pixel size). Multi-line text measures as its widest line, not
as the sum of every line.
Sourcepub fn line_count(&self, text: &str) -> usize
pub fn line_count(&self, text: &str) -> usize
Number of lines a string lays out to (always at least one).
Sourcepub fn layout_line(
&self,
text: &str,
pos: Vec2,
scale: f32,
) -> Vec<(char, Vec2, Vec2)>
pub fn layout_line( &self, text: &str, pos: Vec2, scale: f32, ) -> Vec<(char, Vec2, Vec2)>
Layout text into screen-space glyph positions.
pos is the top-left anchor of the first line’s em box — the same
anchor DrawCommand::Text::pos documents — not a baseline. The
baseline is derived from it as pos.y + ASCENDER * scale.
Returns a list of (char, min, max) quads where min/max are the
screen-space corners of each glyph, with min the top-left corner in
the Y-down screen convention.
Sourcepub fn glyph_u_min(&self, c: char) -> f32
pub fn glyph_u_min(&self, c: char) -> f32
UV u-coordinate of the left edge of the given glyph in the atlas texture (range [0, 1]).
Codepoints with no glyph resolve to .notdef, so the result is always
inside [0, 1].
Sourcepub fn glyph_u_max(&self, c: char) -> f32
pub fn glyph_u_max(&self, c: char) -> f32
UV u-coordinate of the right edge of the given glyph in the atlas texture (range [0, 1]).
Codepoints with no glyph resolve to .notdef, so the result is always
inside [0, 1].