mirror of
https://github.com/bvanroll/ascii_generator.git
synced 2025-08-28 11:32:38 +00:00
Initial commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
85
Cargo.lock
generated
Normal file
85
Cargo.lock
generated
Normal file
@@ -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"
|
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "asciiGenerator"
|
||||
version = "0.1.0"
|
||||
authors = ["bvanroll <beppe.vanrolleghem@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
fontdue = "0.6.2"
|
12
fontDataGenerator.iml
Normal file
12
fontDataGenerator.iml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="RUST_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
45
src/main.rs
Normal file
45
src/main.rs
Normal file
@@ -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<String> = 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<char, [[u8]]> = 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<u8>, mut chunk_size: usize) -> Vec<u8> {
|
||||
if (source.len() < chunk_size) {
|
||||
let mut chunk: Vec<u8> = Vec::with_capacity(chunk_size);
|
||||
chunk = source.split_off(chunk_size);
|
||||
return chunk;
|
||||
} else {
|
||||
let remainder: Vec<u8> = Vec::with_capacity(0);
|
||||
let chunk = source.clone();
|
||||
return chunk;
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user