pub struct BitmapFont { /* private fields */ }Expand description
A 1-bit-per-pixel bitmap glyph font.
Copy because it is just a static reference plus a few small fields.
Implementations§
Source§impl BitmapFont
impl BitmapFont
Sourcepub const fn new(
data: &'static [u8],
glyph_width: u8,
glyph_height: u8,
glyph_count: u16,
) -> BitmapFont
pub const fn new( data: &'static [u8], glyph_width: u8, glyph_height: u8, glyph_count: u16, ) -> BitmapFont
Constructs a bitmap font from a static byte slice, mapped through the built-in CP437
char encoding.
data must contain exactly glyph_count * glyph_height bytes.
Sourcepub const fn with_charset(
data: &'static [u8],
glyph_width: u8,
glyph_height: u8,
glyph_count: u16,
charset: &'static [(char, u8)],
) -> BitmapFont
pub const fn with_charset( data: &'static [u8], glyph_width: u8, glyph_height: u8, glyph_count: u16, charset: &'static [(char, u8)], ) -> BitmapFont
Constructs a bitmap font from a static byte slice, mapped through an explicit
char -> glyph-index charset instead of the built-in CP437 encoding.
This is how a font extends coverage past CP437: glyph_index looks a
char up in charset instead of the CP437 table, so a font built this way can answer for
codepoints (quadrants, sextants, braille, …) that CP437 has no mapping for at all.
data must contain exactly glyph_count * glyph_height bytes.
charset is scanned linearly, so it is meant for the focused repertoire a font actually
declares (a few dozen block or marker glyphs), not for a second general-purpose encoding
table.
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.
A glyph_width above 8 is out of this format’s contract (rows are one byte, so only bits
0..8 exist); it is clamped to 8 here rather than shifting past the byte’s width, so columns
8.. of an oversized font are simply never yielded instead of panicking.
§Panics
Panics if index as u16 >= self.glyph_count (via rows).
Sourcepub const fn glyph_width(&self) -> u8
pub const fn glyph_width(&self) -> u8
The width of each glyph in pixels (≤ 8 for single-byte rows).
Sourcepub const fn glyph_height(&self) -> u8
pub const fn glyph_height(&self) -> u8
The height of each glyph in pixels; also bytes per glyph.
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 glyph_index(&self, ch: char) -> Option<u8>
pub const fn glyph_index(&self, ch: char) -> Option<u8>
Maps a Unicode char to a glyph index in this font, or None if this font does not
cover ch.
If this font was built with with_charset, ch is looked up in
that explicit table; otherwise it goes through the built-in CP437 mapping. A miss is
either ch not being in this font’s repertoire at all, or its mapped index falling
outside this font’s glyph_count (e.g. a font built with fewer than 256 glyphs).
A returned index is always < glyph_count(), so it is always a valid argument to
rows and glyph_pixels.
Substituting something drawable for a miss is FontChain::resolve’s job, not this
one’s: a font cannot answer for a character it has no glyph for, and pretending otherwise
is what hides a chain’s later fonts from ever being consulted.
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 moreSource§impl Debug for BitmapFont
impl Debug for BitmapFont
Source§impl From<BitmapFont> for FontChain<'static>
impl From<BitmapFont> for FontChain<'static>
Source§fn from(font: BitmapFont) -> FontChain<'static>
fn from(font: BitmapFont) -> FontChain<'static>
Source§impl PartialEq for BitmapFont
impl PartialEq for BitmapFont
Source§fn eq(&self, other: &BitmapFont) -> bool
fn eq(&self, other: &BitmapFont) -> bool
self and other values to be equal, and is used by ==.impl Copy 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<C> WithAlpha for Cwhere
C: Copy,
impl<C> WithAlpha for Cwhere
C: Copy,
§fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
self with alpha, storing alpha before the color in memory
(see [AlphaFirst]).§fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
self with alpha, storing alpha after the color in memory
(see [AlphaLast]).