Skip to main content

FontAtlas

Struct FontAtlas 

Source
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

Source

pub fn built_in() -> FontAtlas

Create the built-in monospace font atlas.

Source

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.

Source

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.

Source

pub fn line_count(&self, text: &str) -> usize

Number of lines a string lays out to (always at least one).

Source

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.

Source

pub fn len(&self) -> usize

Number of glyphs in the atlas.

Source

pub fn is_empty(&self) -> bool

Whether the atlas is empty.

Source

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].

Source

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].

Source

pub fn glyph_bitmap(&self) -> (u32, u32, Vec<u8>)

Generate the atlas texture pixel data as R8_UNORM bytes.

Returns (width, height, data) where data is row-major, one byte per pixel. 0 = transparent, 255 = fully opaque glyph.

Trait Implementations§

Source§

impl Debug for FontAtlas

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for FontAtlas

Source§

fn default() -> FontAtlas

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> HalThreadSafe for T
where T: Send + Sync,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.