diff --git a/src/font_build.rs b/src/font_build.rs index 1c82ad9..042a11c 100644 --- a/src/font_build.rs +++ b/src/font_build.rs @@ -1,7 +1,10 @@ use std::{fs::File, path::Path, io::Read}; +const GLYPH_WIDTH: usize = 8; +const GLYPH_HEIGHT: usize = 14; +const GLYPH_AREA: usize = GLYPH_WIDTH * GLYPH_HEIGHT; #[allow(dead_code)] -type Character = [[bool; 8]; 14]; +type Glyph = [[bool; GLYPH_WIDTH]; GLYPH_HEIGHT]; /// Reads the file and turns it into a Vec of u8s fn read_file(file_name: String) -> Vec { @@ -28,7 +31,39 @@ pub fn get_font() { let width_left_byte = contents[0]; let width_right_byte = contents[1]; let number = [width_left_byte, width_right_byte]; - let width = i16::from_be_bytes(number); + let width = u16::from_be_bytes(number); - println!("Left Byte: {width_left_byte}, Right Byte: {width_right_byte}, Byte Pair {width}") + println!("Left Byte: {width_left_byte}, Right Byte: {width_right_byte}, Byte Pair {width}"); + + /* + let gtable_prune = contents[2..].iter() + .filter(|x| **x % 3 == 0) + .collect::>(); + */ + // Remove useless Green and Blue data + let gtable_prune: Vec = contents[2..].iter() + .enumerate() + .filter(|x| x.0 % 3 == 0) + .map(|(_, x)| *x) + .collect(); + + println!("Pruned Glyph Table is {} long; it should be {}.", + gtable_prune.len(), + (contents.len() - 2) / 3 + ); + + let glyph_atlas: Vec; + for glyph in 0..95 { + let new_glyph: Glyph = [[false; GLYPH_WIDTH]; GLYPH_HEIGHT]; + for p in 0..GLYPH_AREA as u16 { + let multiplier = p / GLYPH_WIDTH as u16 * width; + let offset = glyph * GLYPH_WIDTH as u16; + let position = (p % GLYPH_WIDTH as u16 + multiplier + offset) as usize; + + println!("Glyph num: {glyph:2.} | Addr: {p:3.} | Line: {multiplier:5.} | Pos: {position:5.}"); + + if gtable_prune[position] == 255 { + } + } + } }