parent
624a56cc97
commit
dea9d2fa54
1 changed files with 18 additions and 19 deletions
@ -1,35 +1,34 @@ |
||||
use std::{fs::{self, File}, path::Path, io::Read}; |
||||
use std::{fs::File, path::Path, io::Read}; |
||||
|
||||
#[allow(dead_code)] |
||||
type Character = [[bool; 8]; 14]; |
||||
|
||||
fn read_file(mut file_name: String) -> Vec<u8> { |
||||
file_name = file_name.replace("/", ""); |
||||
if file_name.is_empty() { |
||||
file_name = String::from("index.html"); |
||||
} |
||||
|
||||
/// 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 = "./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}") |
||||
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 = i16::from_be_bytes(number); |
||||
|
||||
println!("Left Byte: {width_left_byte}, Right Byte: {width_right_byte}, Byte Pair {width}") |
||||
} |
||||
|
||||
Loading…
Reference in new issue