Struct Bitmap

Source
pub struct Bitmap<'a> { /* private fields */ }
Expand description

A single 8x16 or 16x16 bitmap, corresponding to a single displayed glyph. See the module documentation for a cryptic warning about combining characters, invisible characters, etc.

Implementations§

Source§

impl<'a> Bitmap<'a>

Source

pub fn get_bytes(&self) -> &'a [u8]

Returns the bytes that make up the given bitmap. Each byte contains 8 pixels. The highest order bit of the byte is the leftmost pixel, the next highest order bit is the next pixel, and so on. If the glyph is wide (see is_wide) then there are two bytes per row, otherwise there is one byte per row.

Examples found in repository?
examples/banner.rs (line 16)
6fn banner_print(unifont: &mut Unifont, ink: char, wat: &str) {
7    for c in wat.chars() {
8	let bitmap = unifont.load_bitmap(c as u32);
9	let pitch = if bitmap.is_wide() { 2 } else { 1 };
10	for x in 0..bitmap.get_dimensions().0 {
11	    for _ in 0 .. 2 {
12		for y in (0..16).rev() {
13		    for _ in 0 .. 2 {
14			let bi = (x/8) + y*pitch;
15			let shift = x%8;
16			let b = bitmap.get_bytes()[bi];
17			if (128 >> shift) & b == 0 {
18			    print!(" ");
19			}
20			else {
21			    print!("{}", ink);
22			}
23		    }
24		}
25		println!("");
26	    }
27	}
28    }
29}
Source

pub fn is_wide(&self) -> bool

Returns true if the bitmap is wide (16x16), false if it is narrow (8x16).

Examples found in repository?
examples/banner.rs (line 9)
6fn banner_print(unifont: &mut Unifont, ink: char, wat: &str) {
7    for c in wat.chars() {
8	let bitmap = unifont.load_bitmap(c as u32);
9	let pitch = if bitmap.is_wide() { 2 } else { 1 };
10	for x in 0..bitmap.get_dimensions().0 {
11	    for _ in 0 .. 2 {
12		for y in (0..16).rev() {
13		    for _ in 0 .. 2 {
14			let bi = (x/8) + y*pitch;
15			let shift = x%8;
16			let b = bitmap.get_bytes()[bi];
17			if (128 >> shift) & b == 0 {
18			    print!(" ");
19			}
20			else {
21			    print!("{}", ink);
22			}
23		    }
24		}
25		println!("");
26	    }
27	}
28    }
29}
Source

pub fn get_dimensions<T: From<u8>>(&self) -> (T, T)

Returns the dimensions of the bitmap, width then height. Always returns (8,16) or (16,16).

Examples found in repository?
examples/banner.rs (line 10)
6fn banner_print(unifont: &mut Unifont, ink: char, wat: &str) {
7    for c in wat.chars() {
8	let bitmap = unifont.load_bitmap(c as u32);
9	let pitch = if bitmap.is_wide() { 2 } else { 1 };
10	for x in 0..bitmap.get_dimensions().0 {
11	    for _ in 0 .. 2 {
12		for y in (0..16).rev() {
13		    for _ in 0 .. 2 {
14			let bi = (x/8) + y*pitch;
15			let shift = x%8;
16			let b = bitmap.get_bytes()[bi];
17			if (128 >> shift) & b == 0 {
18			    print!(" ");
19			}
20			else {
21			    print!("{}", ink);
22			}
23		    }
24		}
25		println!("");
26	    }
27	}
28    }
29}

Trait Implementations§

Source§

impl<'a> Debug for Bitmap<'a>

Source§

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

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

impl<'a> PartialEq for Bitmap<'a>

Source§

fn eq(&self, other: &Bitmap<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Eq for Bitmap<'a>

Source§

impl<'a> StructuralPartialEq for Bitmap<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Bitmap<'a>

§

impl<'a> RefUnwindSafe for Bitmap<'a>

§

impl<'a> Send for Bitmap<'a>

§

impl<'a> Sync for Bitmap<'a>

§

impl<'a> Unpin for Bitmap<'a>

§

impl<'a> UnwindSafe for Bitmap<'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> 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<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, 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.