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 GlyphMappingMaps characters to glyph indices in the sprite sheet.
size: SizeThe size of each glyph in the raw bitmap (before pixel multiplication).
pixels: NonZeroU8Pixel multiplier for scaling. 1 = normal, 2 = double, etc.
Implementations§
Source§impl<'a> BitmapFont<'a>
impl<'a> BitmapFont<'a>
Sourcepub const fn new(
bitmap: ImageRaw<'a, BinaryColor>,
glyph_mapping: &'a dyn GlyphMapping,
width: u32,
height: u32,
) -> Self
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.
Sourcepub const fn width(&self) -> u32
pub const fn width(&self) -> u32
Returns the width of each character in pixels (after pixel multiplication).
Sourcepub const fn height(&self) -> u32
pub const fn height(&self) -> u32
Returns the height of each character in pixels (after pixel multiplication).
Sourcepub const fn base_width(&self) -> u32
pub const fn base_width(&self) -> u32
Returns the base (unmultiplied) width of each character.
Sourcepub const fn base_height(&self) -> u32
pub const fn base_height(&self) -> u32
Returns the base (unmultiplied) height of each character.
Sourcepub const fn pixel_multiplier(&self) -> u8
pub const fn pixel_multiplier(&self) -> u8
Returns the current pixel multiplier.
Sourcepub fn draw_glyph<D>(
&self,
idx: u32,
target: &mut D,
color: BinaryColor,
pos: Point,
) -> Result<(), D::Error>where
D: DrawTarget<Color = BinaryColor>,
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.
Sourcepub const fn pixel_double(self) -> Self
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);Sourcepub const fn pixel_triple(self) -> Self
pub const fn pixel_triple(self) -> Self
Returns a pixel-tripled version of this font.
The returned font renders at 3x the original size.
Sourcepub const fn pixel_multiply(self, multiplier: u8) -> Self
pub const fn pixel_multiply(self, multiplier: u8) -> Self
Trait Implementations§
Source§impl<'a> Clone for BitmapFont<'a>
impl<'a> Clone for BitmapFont<'a>
Source§fn clone(&self) -> BitmapFont<'a>
fn clone(&self) -> BitmapFont<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more