type-render

type-render
korin 3 years ago
parent 289c318804
commit 624a56cc97
  1. 33
      src/font_build.rs
  2. 3
      src/main.rs

@ -1,14 +1,35 @@
use std::fs; use std::{fs::{self, File}, path::Path, io::Read};
struct TypeFace { type Character = [[bool; 8]; 14];
type_char: [[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");
}
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"; let file_path = "./fonts/Terminus14x8.data";
println!("In file {}", file_path); println!("In file {}", file_path);
let contents = fs::read_to_string(file_path) let contents = fs::read_to_string(file_path)
.expect("File could not be read"); .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}")
} }

@ -12,6 +12,7 @@ use sdl2::render::TextureQuery;
//use _catlas::*; //use _catlas::*;
mod font_build; mod font_build;
#[allow(unused_imports)]
use font_build::*; use font_build::*;
static SCREEN_WIDTH: u32 = 1680; 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> { pub fn main() -> Result<(), String> {
font_build::get_font();
let font_path: &Path = Path::new("./fonts/Monoid-Regular.ttf"); let font_path: &Path = Path::new("./fonts/Monoid-Regular.ttf");
let sdl_context = sdl2::init()?; let sdl_context = sdl2::init()?;

Loading…
Cancel
Save