BitmapFont

Struct BitmapFont 

Source
pub struct BitmapFont<'a> {
    pub bitmap: ImageRaw<'a, BinaryColor>,
    pub glyph_mapping: &'a dyn GlyphMapping,
    pub size: Size,
    pub pixels: NonZeroU8,
}
Expand description

Stores the font bitmap and metadata for rendering.

Each BitmapFont contains the raw bitmap data for all glyphs arranged in a sprite sheet, along with information about glyph dimensions and character mapping.

§Pixel Doubling

The key feature of this crate is pixel-doubling support. You can call pixel_double() to get a font that renders at 2x size without any additional memory cost. This works by drawing each pixel as a 2x2 block.

use embedded_bitmap_fonts::tamzen::FONT_8x15;

// Original 8x15 font
let small = &FONT_8x15;
assert_eq!(small.width(), 8);
assert_eq!(small.height(), 15);

// Pixel-doubled 16x30 font (same bitmap data!)
let large = FONT_8x15.pixel_double();
assert_eq!(large.width(), 16);
assert_eq!(large.height(), 30);

Fields§

§bitmap: ImageRaw<'a, BinaryColor>

The raw bitmap data for the font sprite sheet.

§glyph_mapping: &'a dyn GlyphMapping

Maps characters to glyph indices in the sprite sheet.

§size: Size

The size of each glyph in the raw bitmap (before pixel multiplication).

§pixels: NonZeroU8

Pixel multiplier for scaling. 1 = normal, 2 = double, etc.

Implementations§

Source§

impl<'a> BitmapFont<'a>

Source

pub const fn new( bitmap: ImageRaw<'a, BinaryColor>, glyph_mapping: &'a dyn GlyphMapping, width: u32, height: u32, ) -> Self

Creates a new BitmapFont from raw bitmap data.

This is typically called by the generated font modules, not directly by users.

Source

pub const fn width(&self) -> u32

Returns the width of each character in pixels (after pixel multiplication).

Source

pub const fn height(&self) -> u32

Returns the height of each character in pixels (after pixel multiplication).

Source

pub const fn base_width(&self) -> u32

Returns the base (unmultiplied) width of each character.

Source

pub const fn base_height(&self) -> u32

Returns the base (unmultiplied) height of each character.

Source

pub const fn pixel_multiplier(&self) -> u8

Returns the current pixel multiplier.

Source

pub fn draw_glyph<D>( &self, idx: u32, target: &mut D, color: BinaryColor, pos: Point, ) -> Result<(), D::Error>
where D: DrawTarget<Color = BinaryColor>,

Draw a single glyph at the specified position.

Source

pub const fn pixel_double(self) -> Self

Returns a pixel-doubled version of this font.

The returned font renders at 2x the original size by drawing each pixel as a 2x2 block. This incurs no additional memory cost since it uses the same underlying bitmap data.

§Example
use embedded_bitmap_fonts::tamzen::FONT_8x15;

let doubled = FONT_8x15.pixel_double();
assert_eq!(doubled.width(), 16);
assert_eq!(doubled.height(), 30);
Source

pub const fn pixel_triple(self) -> Self

Returns a pixel-tripled version of this font.

The returned font renders at 3x the original size.

Source

pub const fn pixel_multiply(self, multiplier: u8) -> Self

Returns a version of this font with custom pixel multiplication.

§Panics

Panics if multiplier is 0.

Trait Implementations§

Source§

impl<'a> Clone for BitmapFont<'a>

Source§

fn clone(&self) -> BitmapFont<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for BitmapFont<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for BitmapFont<'a>

§

impl<'a> !RefUnwindSafe for BitmapFont<'a>

§

impl<'a> Send for BitmapFont<'a>

§

impl<'a> Sync for BitmapFont<'a>

§

impl<'a> Unpin for BitmapFont<'a>

§

impl<'a> !UnwindSafe for BitmapFont<'a>

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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

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

Source§

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
Source§

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

Source§

type Error = Infallible

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

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

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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.