From ddbc390bad82320c350f45f1ac8eba228c4ef668 Mon Sep 17 00:00:00 2001 From: bvanroll Date: Sun, 5 Dec 2021 00:20:02 +0100 Subject: [PATCH] Initial commit --- .gitignore | 1 + Cargo.lock | 85 +++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 10 +++++ fontDataGenerator.iml | 12 ++++++ src/main.rs | 45 +++++++++++++++++++++++ 5 files changed, 153 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 fontDataGenerator.iml create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..9e03e14 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,85 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "asciiGenerator" +version = "0.1.0" +dependencies = [ + "fontdue", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "fontdue" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8669141fd879e023ac6fcfe1d90dfe3f83ca7e322781ddf3f5be59147e4b8113" +dependencies = [ + "hashbrown", + "ttf-parser", +] + +[[package]] +name = "getrandom" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +dependencies = [ + "ahash", +] + +[[package]] +name = "libc" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" + +[[package]] +name = "once_cell" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" + +[[package]] +name = "ttf-parser" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ae2f58a822f08abdaf668897e96a5656fe72f5a9ce66422423e8849384872e6" + +[[package]] +name = "version_check" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..4e53078 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "asciiGenerator" +version = "0.1.0" +authors = ["bvanroll "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +fontdue = "0.6.2" \ No newline at end of file diff --git a/fontDataGenerator.iml b/fontDataGenerator.iml new file mode 100644 index 0000000..2fecef3 --- /dev/null +++ b/fontDataGenerator.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..ed120fa --- /dev/null +++ b/src/main.rs @@ -0,0 +1,45 @@ +use std::env; +use std::fs; +use std::io; +use fontdue; +use std::collections::HashMap; +use std::ops::Add; + + +fn main() { + let args: Vec = env::args().collect(); + //let path = &args[1]; + //let path2 = &String::from("/Users/beppe/Git/asciiGenerator/fonts/Lucida Console.ttf"); + let data = include_bytes!("/Users/beppe/Git/asciiGenerator/fonts/Lucida Console.ttf") as &[u8]; + let font = fontdue::Font::from_bytes(data, fontdue::FontSettings::default()).expect("yessir"); + let mut output: HashMap = HashMap::new(); //todo Second value should be bitmap type??? + let mut char_index:u32 = 0; + //NOTE this starts at 0 + const RASTER_FACTOR: f32 = 15.0; + while char_index < 1000000 { + let char = std::char::from_u32(char_index).expect("yessiiiiiir"); + char_index += 1; + let (metrics, mut unsorted_raster) = font.rasterize(char, RASTER_FACTOR); + if (unsorted_raster.len() > 0) { + + + (chunks, remainder) = unsorted_raster.as_chunks(RASTER_FACTOR as usize); + output.insert(char, chunks.clone()); + } + } + //println!("{}", convertData(data)); +} + +//returns remainder, chunk +fn rasterize_chunk_recursive(mut source: Vec, mut chunk_size: usize) -> Vec { + if (source.len() < chunk_size) { + let mut chunk: Vec = Vec::with_capacity(chunk_size); + chunk = source.split_off(chunk_size); + return chunk; + } else { + let remainder: Vec = Vec::with_capacity(0); + let chunk = source.clone(); + return chunk; + + } +} \ No newline at end of file