-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
089da3a
commit 0f7ced4
Showing
4 changed files
with
250 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,8 @@ pub mod parser { | |
pub mod theme_txt; | ||
} | ||
|
||
pub mod render { | ||
pub mod pff2; | ||
} | ||
|
||
pub type OwnedSlice<T> = Rc<T>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//! PFF2 font rendering functionality | ||
use crate::parser::pff2::{Font, Glyph}; | ||
|
||
impl Font { | ||
// TODO: make an abstraction over the bitmap | ||
|
||
pub fn render(&self, s: &str) -> () {} | ||
} | ||
|
||
impl Glyph { | ||
pub const FILLED_PIXEL: bool = true; | ||
pub const TRANSPARENT_PIXEL: bool = false; | ||
|
||
pub fn pixel(&self, x: usize, y: usize) -> Option<bool> { | ||
// dbg!(self.x_offset, self.y_offset); | ||
|
||
// let x = isize::try_from(x).ok()?; | ||
// let x = x.checked_add(self.x_offset)?; | ||
// let x = usize::try_from(x).ok()?; | ||
|
||
// let y = isize::try_from(y).ok()?; | ||
// let y = y.checked_sub(self.y_offset)?; | ||
// let y = usize::try_from(y).ok()?; | ||
|
||
if !(x < self.width && y < self.height) { | ||
return None; | ||
} | ||
|
||
let index = y * self.width + x; | ||
let byte_index = index / 8; | ||
let bit_index = 7 - (index % 8); | ||
let mask =1 << bit_index; | ||
|
||
Some((self.bitmap[byte_index] & mask) != 0) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::parser::pff2::Glyph; | ||
|
||
#[test_case( | ||
8, 1, &[0b00000001], | ||
7, 0 => 1; | ||
"right bit one line" | ||
)] | ||
#[test_case( | ||
8, 1, &[0b10000000], | ||
0, 0 => 1; | ||
"left bit one line" | ||
)] | ||
fn foo(width: usize, height: usize, bitmap: &[u8], x: usize, y: usize) -> u8 { | ||
let glyph = Glyph { | ||
width, | ||
height, | ||
bitmap: bitmap.into(), | ||
..Default::default() | ||
}; | ||
|
||
for (i, x) in (0..width).enumerate() { | ||
//println!("{i}: {:?}", glyph.pixel(x, 0)); | ||
} | ||
|
||
glyph.pixel(x, y).unwrap() as u8 | ||
} | ||
} |