Skip to main content
← PSoXide SDK guides and examples · SDK f2fec1c301f1 · All Cargo features enabled; check feature gates before use.

BitmapFont

Struct BitmapFont 

Source
pub struct BitmapFont {
    pub glyph_w: u8,
    pub glyph_h: u8,
    pub first_char: u16,
    pub glyph_count: u16,
    pub bitmap: &'static [u8],
    pub glyph_advances: Option<&'static [u8]>,
    pub advance_x: u8,
    pub line_height: u8,
    pub bit_order: BitOrder,
}
Expand description

A bitmap font as a static data descriptor.

All fields are compile-time constants so fonts can live in .rodata and a BitmapFont value can be declared as a const right next to its bitmap. The type stays size-agnostic – 6×8, 8×8, 8×16, 12×16 all work; the uploader reads glyph_w / glyph_h and lays out the atlas from there.

Glyph i in the bitmap slice occupies bitmap[i * row_bytes * glyph_h .. i * row_bytes * glyph_h + row_bytes * glyph_h], where row_bytes = ceil(glyph_w / 8). For 8-wide glyphs that’s one byte per row. Wider glyphs (12, 16 px) use multiple bytes per row, MSB-first within the row (i.e., byte 0 covers columns 0..=7, byte 1 covers columns 8..=15, regardless of BitOrder within each byte).

The first_char / glyph_count window is a codepoint range – code c is looked up at offset c - first_char in the bitmap as long as first_char <= c < first_char + glyph_count. Anything outside falls back to the missing-glyph box.

Fields§

§glyph_w: u8

Glyph cell width in pixels.

§glyph_h: u8

Glyph cell height in pixels.

§first_char: u16

First codepoint covered. For a basic-Latin font this is usually 0x00 (null) or 0x20 (space).

§glyph_count: u16

Number of glyphs in this font. The range first_char..first_char + glyph_count is the supported set.

§bitmap: &'static [u8]

Row-major bitmap bytes. glyph_count * glyph_h * ceil(glyph_w / 8) bytes total.

§glyph_advances: Option<&'static [u8]>

Optional per-glyph pixel advances. Proportional TTF imports fill this; fixed-cell bitmap fonts leave it None and use advance_x.

§advance_x: u8

Pixel step between adjacent characters on a text line. Usually == glyph_w for fixed-width fonts. Proportional fonts use this as the fallback for missing/out-of-range glyphs.

§line_height: u8

Pixel step between text lines. Usually == glyph_h.

§bit_order: BitOrder

Bit packing within each bitmap byte.

Implementations§

Source§

impl BitmapFont

Source

pub const fn row_bytes(&self) -> usize

Bytes per row of a single glyph in the source bitmap. Derived from BitmapFont::glyph_w – 1 byte for ≤ 8-wide fonts, 2 bytes for 9..16-wide, etc.

Source

pub const fn glyph_stride(&self) -> usize

Total bitmap bytes per glyph.

Source

pub fn glyph_index(&self, ch: char) -> Option<u16>

Glyph index for ch if the font covers its codepoint.

Source

pub fn glyph_advance(&self, ch: char) -> u8

Pixel advance for ch, falling back to BitmapFont::advance_x when the font has no per-glyph table or ch is outside the covered range.

Source

pub fn text_width(&self, text: &str) -> u16

Pixel width of text with this font’s advance metrics.

Source

pub fn text_width_with_spacing(&self, text: &str, letter_spacing: i8) -> u16

Pixel width of text with an extra signed spacing value inserted between adjacent characters. The spacing is in final screen pixels, so callers that scale glyphs can decide whether or not to scale the spacing separately.

Source

pub fn glyph_row_packed(&self, i: u16, r: u8) -> u32

Fetch row r of glyph i as 4 bytes LSB-packed little- endian – the row comes out as a u32 with pixel 0 in bit 0, pixel 1 in bit 1, … up to pixel 31 (enough for any realistic cell width). Handles BitOrder normalisation in one place so callers don’t have to branch.

Trait Implementations§

Source§

impl Clone for BitmapFont

Source§

fn clone(&self) -> BitmapFont

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BitmapFont

Source§

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

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

impl Copy for BitmapFont

Auto Trait Implementations§

§

impl Freeze for BitmapFont

§

impl RefUnwindSafe for BitmapFont

§

impl Send for BitmapFont

§

impl Sync for BitmapFont

§

impl Unpin for BitmapFont

§

impl UnsafeUnpin for BitmapFont

§

impl UnwindSafe for BitmapFont

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.