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>
impl<'a> Bitmap<'a>
Sourcepub fn get_bytes(&self) -> &'a [u8] ⓘ
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}
Sourcepub fn is_wide(&self) -> bool
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}
Sourcepub fn get_dimensions<T: From<u8>>(&self) -> (T, T)
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§
impl<'a> Eq for Bitmap<'a>
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> 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
Mutably borrows from an owned value. Read more