diff --git a/src/font_build.rs b/src/font_build.rs index 0abfdef..4e386ab 100644 --- a/src/font_build.rs +++ b/src/font_build.rs @@ -1,14 +1,35 @@ -use std::fs; +use std::{fs::{self, File}, path::Path, io::Read}; -struct TypeFace { - type_char: [[bool; 8]; 14], +type Character = [[bool; 8]; 14]; + +fn read_file(mut file_name: String) -> Vec { + file_name = file_name.replace("/", ""); + if file_name.is_empty() { + file_name = String::from("index.html"); + } + + 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 } -fn get_font() { +pub fn get_font() { + // Retrieve font data from file let file_path = "./fonts/Terminus14x8.data"; - println!("In file {}", file_path); - let contents = fs::read_to_string(file_path) .expect("File could not be read"); + let width_left_byte = &contents[0..0]; + let width_right_byte = &contents[1..1]; + let number_left = width_left_byte.chars().nth(0).unwrap(); + let number_right = width_right_byte.chars().nth(0).unwrap(); + let number = [number_left as u8, number_right as u8]; + let width = i16::from_ne_bytes(number); + + println!("{width}") } diff --git a/src/main.rs b/src/main.rs index 15e50c7..6454b8f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ use sdl2::render::TextureQuery; //use _catlas::*; mod font_build; +#[allow(unused_imports)] use font_build::*; static SCREEN_WIDTH: u32 = 1680; @@ -65,6 +66,8 @@ fn get_corner_rect(rect_width: u32, rect_height: u32) -> Rect { pub fn main() -> Result<(), String> { + font_build::get_font(); + let font_path: &Path = Path::new("./fonts/Monoid-Regular.ttf"); let sdl_context = sdl2::init()?;