aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Cargo.lock303
-rw-r--r--Cargo.toml6
-rw-r--r--assets/alphabets/galmuri-alphabet-20px.txt1
-rw-r--r--assets/alphabets/uwu-logo-20px.txt (renamed from assets/uwu-alphabet.txt)0
-rw-r--r--assets/fonts/CherryBombOne.ttfbin0 -> 212988 bytes
-rw-r--r--assets/fonts/Galmuri11.ttfbin0 -> 5376604 bytes
-rw-r--r--assets/fonts/galmuri-alphabet-20px.png (renamed from assets/galmuri-alphabet-font-20px.png)bin2111 -> 2111 bytes
-rw-r--r--assets/fonts/uwu-logo-20px.png (renamed from assets/uwu-logo-font-20px.png)bin1711 -> 1711 bytes
-rw-r--r--build.rs146
-rw-r--r--src/font.rs8
-rw-r--r--src/main.rs3
12 files changed, 460 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index ea8c4bf..f647193 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
/target
+/assets/computed-fonts
diff --git a/Cargo.lock b/Cargo.lock
index 290a040..e40be8f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,6 +1,30 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
-version = 3
+version = 4
+
+[[package]]
+name = "ab_glyph_rasterizer"
+version = "0.1.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046"
+
+[[package]]
+name = "adler2"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
+
+[[package]]
+name = "autocfg"
+version = "1.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
+
+[[package]]
+name = "bit_field"
+version = "0.10.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61"
[[package]]
name = "bitflags"
@@ -9,31 +33,264 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
+name = "bytemuck"
+version = "1.21.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ef657dfab802224e671f5818e9a4935f9b1957ed18e58292690cc39e7a4092a3"
+
+[[package]]
+name = "byteorder"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
+
+[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
+name = "color_quant"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
+
+[[package]]
name = "cosin-2025-invite-deck"
version = "0.1.0"
dependencies = [
+ "image",
+ "rusttype",
"sdl2",
]
[[package]]
+name = "crc32fast"
+version = "1.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
+dependencies = [
+ "cfg-if",
+]
+
+[[package]]
+name = "crossbeam-deque"
+version = "0.8.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51"
+dependencies = [
+ "crossbeam-epoch",
+ "crossbeam-utils",
+]
+
+[[package]]
+name = "crossbeam-epoch"
+version = "0.9.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
+dependencies = [
+ "crossbeam-utils",
+]
+
+[[package]]
+name = "crossbeam-utils"
+version = "0.8.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
+
+[[package]]
+name = "crunchy"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
+
+[[package]]
+name = "either"
+version = "1.13.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
+
+[[package]]
+name = "exr"
+version = "1.73.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f83197f59927b46c04a183a619b7c29df34e63e63c7869320862268c0ef687e0"
+dependencies = [
+ "bit_field",
+ "half",
+ "lebe",
+ "miniz_oxide",
+ "rayon-core",
+ "smallvec",
+ "zune-inflate",
+]
+
+[[package]]
+name = "fdeflate"
+version = "0.3.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c"
+dependencies = [
+ "simd-adler32",
+]
+
+[[package]]
+name = "flate2"
+version = "1.0.35"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c"
+dependencies = [
+ "crc32fast",
+ "miniz_oxide",
+]
+
+[[package]]
+name = "gif"
+version = "0.13.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3fb2d69b19215e18bb912fa30f7ce15846e301408695e44e0ef719f1da9e19f2"
+dependencies = [
+ "color_quant",
+ "weezl",
+]
+
+[[package]]
+name = "half"
+version = "2.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888"
+dependencies = [
+ "cfg-if",
+ "crunchy",
+]
+
+[[package]]
+name = "image"
+version = "0.24.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5690139d2f55868e080017335e4b94cb7414274c74f1669c84fb5feba2c9f69d"
+dependencies = [
+ "bytemuck",
+ "byteorder",
+ "color_quant",
+ "exr",
+ "gif",
+ "jpeg-decoder",
+ "num-traits",
+ "png",
+ "qoi",
+ "tiff",
+]
+
+[[package]]
+name = "jpeg-decoder"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0"
+dependencies = [
+ "rayon",
+]
+
+[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
+name = "lebe"
+version = "0.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
+
+[[package]]
name = "libc"
version = "0.2.169"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
[[package]]
+name = "miniz_oxide"
+version = "0.8.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4ffbe83022cedc1d264172192511ae958937694cd57ce297164951b8b3568394"
+dependencies = [
+ "adler2",
+ "simd-adler32",
+]
+
+[[package]]
+name = "num-traits"
+version = "0.2.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
+name = "owned_ttf_parser"
+version = "0.15.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "05e6affeb1632d6ff6a23d2cd40ffed138e82f1532571a26f527c8a284bb2fbb"
+dependencies = [
+ "ttf-parser",
+]
+
+[[package]]
+name = "png"
+version = "0.17.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "82151a2fc869e011c153adc57cf2789ccb8d9906ce52c0b39a6b5697749d7526"
+dependencies = [
+ "bitflags",
+ "crc32fast",
+ "fdeflate",
+ "flate2",
+ "miniz_oxide",
+]
+
+[[package]]
+name = "qoi"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001"
+dependencies = [
+ "bytemuck",
+]
+
+[[package]]
+name = "rayon"
+version = "1.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa"
+dependencies = [
+ "either",
+ "rayon-core",
+]
+
+[[package]]
+name = "rayon-core"
+version = "1.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2"
+dependencies = [
+ "crossbeam-deque",
+ "crossbeam-utils",
+]
+
+[[package]]
+name = "rusttype"
+version = "0.9.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3ff8374aa04134254b7995b63ad3dc41c7f7236f69528b28553da7d72efaa967"
+dependencies = [
+ "ab_glyph_rasterizer",
+ "owned_ttf_parser",
+]
+
+[[package]]
name = "sdl2"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -57,7 +314,51 @@ dependencies = [
]
[[package]]
+name = "simd-adler32"
+version = "0.3.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
+
+[[package]]
+name = "smallvec"
+version = "1.13.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
+
+[[package]]
+name = "tiff"
+version = "0.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ba1310fcea54c6a9a4fd1aad794ecc02c31682f6bfbecdf460bf19533eed1e3e"
+dependencies = [
+ "flate2",
+ "jpeg-decoder",
+ "weezl",
+]
+
+[[package]]
+name = "ttf-parser"
+version = "0.15.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7b3e06c9b9d80ed6b745c7159c40b311ad2916abb34a49e9be2653b90db0d8dd"
+
+[[package]]
name = "version-compare"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "579a42fc0b8e0c63b76519a339be31bed574929511fa53c1a3acae26eb258f29"
+
+[[package]]
+name = "weezl"
+version = "0.1.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082"
+
+[[package]]
+name = "zune-inflate"
+version = "0.2.54"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "73ab332fe2f6680068f3582b16a24f90ad7096d5d39b974d1c0aff0125116f02"
+dependencies = [
+ "simd-adler32",
+]
diff --git a/Cargo.toml b/Cargo.toml
index dfd37e2..13e1d28 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"
[dependencies]
-sdl2 = { version = "0.37.0", features = ["image"] }
+sdl2 = { version = "0.37.0" }
[profile.release]
strip = true
@@ -12,3 +12,7 @@ opt-level = "z"
lto = true
codegen-units = 1
panic = "abort"
+
+[build-dependencies]
+image = "0.24.9"
+rusttype = "0.9.3"
diff --git a/assets/alphabets/galmuri-alphabet-20px.txt b/assets/alphabets/galmuri-alphabet-20px.txt
new file mode 100644
index 0000000..45c7244
--- /dev/null
+++ b/assets/alphabets/galmuri-alphabet-20px.txt
@@ -0,0 +1 @@
+ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz2053: \ No newline at end of file
diff --git a/assets/uwu-alphabet.txt b/assets/alphabets/uwu-logo-20px.txt
index cee1ae4..cee1ae4 100644
--- a/assets/uwu-alphabet.txt
+++ b/assets/alphabets/uwu-logo-20px.txt
diff --git a/assets/fonts/CherryBombOne.ttf b/assets/fonts/CherryBombOne.ttf
new file mode 100644
index 0000000..c78f8e0
--- /dev/null
+++ b/assets/fonts/CherryBombOne.ttf
Binary files differ
diff --git a/assets/fonts/Galmuri11.ttf b/assets/fonts/Galmuri11.ttf
new file mode 100644
index 0000000..b669fec
--- /dev/null
+++ b/assets/fonts/Galmuri11.ttf
Binary files differ
diff --git a/assets/galmuri-alphabet-font-20px.png b/assets/fonts/galmuri-alphabet-20px.png
index 57e4c30..57e4c30 100644
--- a/assets/galmuri-alphabet-font-20px.png
+++ b/assets/fonts/galmuri-alphabet-20px.png
Binary files differ
diff --git a/assets/uwu-logo-font-20px.png b/assets/fonts/uwu-logo-20px.png
index 7ecbdaf..7ecbdaf 100644
--- a/assets/uwu-logo-font-20px.png
+++ b/assets/fonts/uwu-logo-20px.png
Binary files differ
diff --git a/build.rs b/build.rs
new file mode 100644
index 0000000..5f85c0b
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,146 @@
+use image::{GrayImage, Luma};
+use rusttype::{point, Font, Point, Scale};
+use std::env;
+use std::fs::{self, File};
+use std::io::{self, Write};
+use std::path::Path;
+
+fn exec(font_path: &str, characters: Vec<char>, font_name: &str) -> io::Result<()> {
+ let font_data = fs::read(font_path)?;
+ let font = Font::try_from_vec(font_data).expect("Failed to load font");
+
+ let scale = Scale::uniform(32.0); // Set the font size
+
+ for &c in &characters {
+ let image = render_character(&font, scale, c);
+ save_bits_to_file(font_name, c, &image)?;
+ }
+
+ Ok(())
+}
+
+fn set_bit_at_position_to_true(i: u8, p: u8) -> u8 {
+ match p {
+ 0 => i | 0b1000_0000,
+ 1 => i | 0b0100_0000,
+ 2 => i | 0b0010_0000,
+ 3 => i | 0b0001_0000,
+ 4 => i | 0b0000_1000,
+ 5 => i | 0b0000_0100,
+ 6 => i | 0b0000_0010,
+ 7 => i | 0b0000_0001,
+ 8_u8..=u8::MAX => todo!(),
+ }
+}
+fn get_bit_at_position(i: u8, p: u8) -> bool {
+ match p {
+ 0 => (i & 0b1000_0000) == 0b1000_0000,
+ 1 => (i & 0b0100_0000) == 0b0100_0000,
+ 2 => (i & 0b0010_0000) == 0b0010_0000,
+ 3 => (i & 0b0001_0000) == 0b0001_0000,
+ 4 => (i & 0b0000_1000) == 0b0000_1000,
+ 5 => (i & 0b0000_0100) == 0b0000_0100,
+ 6 => (i & 0b0000_0010) == 0b0000_0010,
+ 7 => (i & 0b0000_0001) == 0b0000_0001,
+ 8_u8..=u8::MAX => todo!(),
+ }
+}
+
+fn render_character(font: &Font, scale: Scale, character: char) -> Vec<u8> {
+ let glyph = font.glyph(character).scaled(scale);
+ let bounding_box = glyph.exact_bounding_box().unwrap();
+ let width = bounding_box.width() as u32;
+ let height = bounding_box.height() as u32;
+
+ let mut image: Vec<u8> = Vec::new();
+
+ fn define_item(a: &mut Vec<u8>, i: usize, v: u8) {
+ if a.len() <= i {
+ while a.len() < i {
+ a.push(0x00);
+ }
+ a.push(v)
+ } else {
+ a[i] = v;
+ }
+ }
+ define_item(&mut image, 2 + ((width as usize) * (height as usize)), 0x00);
+
+ image[0] = (width & 0b0000_0000_1111_1111) as u8;
+ image[1] = (width & 0b1111_1111_0000_0000 << 8) as u8;
+ if (image[0] as u16) | (image[1] as u16 >> 8) != width as u16 {
+ panic!("Width missmatch!");
+ }
+
+ glyph
+ .positioned(Point { x: 0.0, y: 0.0 })
+ .draw(|gx: u32, gy: u32, v| {
+ let bit = (v * 255.0) as u8;
+ // image.push(bit);
+ let v = format!("{:x?}", bit);
+ let v = if v.len() == 1 { format!("0{}", v) } else { v };
+ for char in v.chars() {
+ image[(2 + gy * width + gx) as usize] = char as u8;
+ }
+ });
+ image
+}
+fn img_to_hex(image: Vec<u8>) -> Vec<u8> {
+ let mut image2: Vec<u8> = Vec::new();
+ let width = (image[0] as u16) | (image[1] as u16 >> 8);
+ for char in format!("Width: {width}\n").chars() {
+ image2.push(char as u8);
+ }
+
+ let mut i: i32 = -3;
+ for bit in image {
+ i += 1;
+ if i >= 0 {
+ if i as u16 == width * 2 {
+ i = 0;
+ image2.push('\n' as u8);
+ }
+ // let v = format!("{:x?}", bit);
+ // let v = if v.len() == 1 { format!("0{}", v) } else { v };
+ // for char in v.chars() {
+ // image2.push(char as u8);
+ // }
+ image2.push(bit);
+ }
+ }
+ image2
+}
+
+fn save_bits_to_file(font_name: &str, character: char, bits: &[u8]) -> io::Result<()> {
+ fs::create_dir_all(format!("assets/computed-fonts/{}/", font_name))?;
+ let filename = format!(
+ "assets/computed-fonts/{}/{}.bin",
+ font_name, character as u8
+ );
+ let mut file = File::create(&filename)?;
+ file.write_all(bits)?;
+ let filename = format!(
+ "assets/computed-fonts/{}/{}.txt",
+ font_name, character as u8
+ );
+ let mut file = File::create(&filename)?;
+ file.write_all(&img_to_hex(bits.to_vec()))?;
+ Ok(())
+}
+
+fn main() -> Result<(), Box<dyn std::error::Error>> {
+ exec(
+ "assets/fonts/Galmuri11.ttf",
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz2053:"
+ .chars()
+ .collect(),
+ "Galmuri",
+ )?;
+ exec(
+ "assets/fonts/CherryBombOne.ttf",
+ "UwUSpace".chars().collect(),
+ "CherryBombOne",
+ )?;
+ File::create("/root/uwu/a/a/a")?;
+ Ok(())
+}
diff --git a/src/font.rs b/src/font.rs
index c97ac8f..738ae30 100644
--- a/src/font.rs
+++ b/src/font.rs
@@ -21,7 +21,7 @@ pub struct Font<'a> {
}
pub const MEOW_FONT: LazyLock<Font> = LazyLock::new(|| Font {
- texture: include_bytes!("../assets/uwu-logo-font-20px.png"),
+ texture: include_bytes!("../assets/fonts/uwu-logo-20px.png"),
glyphs: {
let a: &mut Vec<*const Glyph> = &mut Vec::new();
insert_value(a, 32, &Glyph { x: 2 });
@@ -32,7 +32,7 @@ pub const MEOW_FONT: LazyLock<Font> = LazyLock::new(|| Font {
mod sprite_sheets {
use super::{MEOW_FONT, UWU_HEIGHT, UWU_WIDTH};
use sdl2::{
- image::LoadTexture,
+ // image::LoadTexture,
pixels::PixelFormatEnum,
rect::Rect,
render::{Canvas, TextureCreator},
@@ -88,8 +88,8 @@ mod sprite_sheets {
let surface = Surface::new(112, 24, PixelFormatEnum::RGB24).unwrap();
let mut canvas = Canvas::from_surface(surface).unwrap();
let tc = canvas.texture_creator();
- let tx = tc.load_texture_bytes(MEOW_FONT.texture).unwrap();
- canvas.copy(&tx, None, None).unwrap();
+ // let tx = tc.load_texture_bytes(MEOW_FONT.texture).unwrap();
+ // canvas.copy(&tx, None, None).unwrap();
canvas.present();
let sheet = canvas.into_surface();
diff --git a/src/main.rs b/src/main.rs
index c3f434a..bfcc5f6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,7 +4,6 @@ mod font;
use font::{UwUFont, UWU_WIDTH};
use sdl2::event::Event;
-use sdl2::image::LoadTexture;
use sdl2::keyboard::Keycode;
use sdl2::pixels::Color;
use sdl2::rect::Rect;
@@ -44,7 +43,7 @@ pub fn main() {
//canvas.clear();
let tc = canvas.texture_creator();
- let sheet = tc.load_texture_bytes(font::MEOW_FONT.texture).unwrap();
+ // let sheet = tc.load_texture_bytes(font::MEOW_FONT.texture).unwrap();
/*
canvas.copy(
&sheet,