From c65813d4278ffe3f216242534b3dbee560102356 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 16 May 2022 14:21:05 -0700 Subject: [PATCH] Add a program to generate diagram of the uncompressed bitmap --- Cargo.toml | 2 +- diagram/.gitignore | 1 + diagram/Cargo.toml | 9 +++++++++ diagram/src/main.rs | 25 +++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 diagram/.gitignore create mode 100644 diagram/Cargo.toml create mode 100644 diagram/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index c2ad726..75c84ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" publish = false [workspace] -members = ["generate"] +members = ["diagram", "generate"] diff --git a/diagram/.gitignore b/diagram/.gitignore new file mode 100644 index 0000000..e33609d --- /dev/null +++ b/diagram/.gitignore @@ -0,0 +1 @@ +*.png diff --git a/diagram/Cargo.toml b/diagram/Cargo.toml new file mode 100644 index 0000000..e3fda40 --- /dev/null +++ b/diagram/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "unicode-ident-diagram" +version = "0.0.0" +edition = "2021" +publish = false + +[dependencies] +image = "0.24" +unicode-ident = { path = ".." } diff --git a/diagram/src/main.rs b/diagram/src/main.rs new file mode 100644 index 0000000..3afa7d2 --- /dev/null +++ b/diagram/src/main.rs @@ -0,0 +1,25 @@ +use image::{ImageBuffer, Rgb}; +use std::process; + +fn main() { + let width = 512; + let height = 400; + let diagrams: [(&str, fn(char) -> bool); 2] = [ + ("xid_start.png", unicode_ident::is_xid_start), + ("xid_continue.png", unicode_ident::is_xid_continue), + ]; + for (name, f) in diagrams { + let mut imgbuf = ImageBuffer::new(width, height); + for (col, row, pixel) in imgbuf.enumerate_pixels_mut() { + *pixel = if char::from_u32(row * width + col).map_or(false, f) { + Rgb([0u8, 0, 0]) + } else { + Rgb([255, 255, 255]) + }; + } + if let Err(err) = imgbuf.save(name) { + eprintln!("Error: {}", err); + process::exit(1); + } + } +}