You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.3 KiB

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 Glyph = [[bool; GLYPH_WIDTH]; GLYPH_HEIGHT];
/// Reads the file and turns it into a Vec of u8s
fn read_file(file_name: String) -> Vec<u8> {
let path = Path::new(&file_name);
if !path.exists() {
return String::from("Not Found!").into();
}
let mut file_content = Vec::new();
let mut file = File::open(&file_name).expect("Unable to open file");
file.read_to_end(&mut file_content).expect("Unable to read");
file_content
}
pub fn get_font() {
// Retrieve font data from file
let file_path = String::from("./fonts/Terminus14x8.data");
println!("In file {file_path}");
let contents = read_file(file_path);
let width_left_byte = contents[0];
let width_right_byte = contents[1];
let number = [width_left_byte, width_right_byte];
let width = u16::from_be_bytes(number);
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::<Vec<_>>();
*/
// Remove useless Green and Blue data
let gtable_prune: Vec<u8> = 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<Glyph>;
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 {
}
}
}
}