pub struct BitmapFont {
pub glyph_width: u8,
pub glyph_height: u8,
/* private fields */
}Expand description
A 1-bit-per-pixel bitmap glyph font.
Copy because it is just a static reference plus three small integers.
Fields§
§glyph_width: u8Width of each glyph in pixels (≤ 8 for single-byte rows).
glyph_height: u8Height of each glyph in pixels; also bytes per glyph.
Implementations§
Source§impl BitmapFont
impl BitmapFont
Sourcepub const fn new(
data: &'static [u8],
glyph_width: u8,
glyph_height: u8,
glyph_count: u16,
) -> Self
pub const fn new( data: &'static [u8], glyph_width: u8, glyph_height: u8, glyph_count: u16, ) -> Self
Constructs a bitmap font from a static byte slice.
data must contain exactly glyph_count * glyph_height bytes.
Sourcepub fn rows(&self, index: u8) -> &[u8] ⓘ
pub fn rows(&self, index: u8) -> &[u8] ⓘ
Returns the row bytes for glyph index.
Each byte is one row; bit 7 (MSB) is the leftmost pixel.
§Panics
Panics if index as u16 >= self.glyph_count.
Sourcepub fn glyph_pixels(&self, index: u8) -> impl Iterator<Item = (u8, u8)> + '_
pub fn glyph_pixels(&self, index: u8) -> impl Iterator<Item = (u8, u8)> + '_
Iterates the set (“on”) pixels of glyph index as (x, y) coordinates, row-major from the
top: x in 0..glyph_width, y in 0..glyph_height.
This is the single place the 1-bit format’s MSB-first bit order lives – pixel x of a row
is bit glyph_width - 1 - x of that row’s byte – so consumers (the GL atlas builder, the
software rasterizer’s glyph blit) decode through it instead of each re-deriving the shift
and risking disagreement. It is also the one seam that has to change for wider-than-8px
glyphs (multi-byte rows, #164): today a row is a single byte (glyph_width <= 8), so its
bits are read straight out of that byte.
§Panics
Panics if index as u16 >= self.glyph_count (via rows).
Sourcepub const fn glyph_count(&self) -> u16
pub const fn glyph_count(&self) -> u16
The total number of glyphs stored in this font.
Glyph indices 0..glyph_count() are valid arguments to rows. A GPU
backend uses this to size its glyph atlas (one texture-array layer per glyph).
Sourcepub const fn char_to_index(&self, ch: char) -> u8
pub const fn char_to_index(&self, ch: char) -> u8
Maps a Unicode char to a glyph index in this font using the CP437
encoding, falling back to a solid-block glyph for unmapped characters.
Sourcepub const fn try_char_to_index(&self, ch: char) -> Option<u8>
pub const fn try_char_to_index(&self, ch: char) -> Option<u8>
Attempts to map a Unicode char to a glyph index in this font, returning None
instead of substituting the solid-block fallback glyph on a miss.
A miss is either ch not being in the CP437 mapping table at all, or its mapped
index falling outside this font’s glyph_count (e.g. a font built with fewer than
256 glyphs). FallbackFontChain::resolve uses this to keep trying further fonts
in the chain rather than settling for char_to_index’s
unconditional solid-block substitution.
Trait Implementations§
Source§impl Clone for BitmapFont
impl Clone for BitmapFont
Source§fn clone(&self) -> BitmapFont
fn clone(&self) -> BitmapFont
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for BitmapFont
Source§impl Debug for BitmapFont
impl Debug for BitmapFont
impl Eq 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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.