mirror of
https://github.com/openharmony/third_party_rust_unicode-ident.git
synced 2026-07-01 20:44:13 -04:00
Add a program to generate diagram of the uncompressed bitmap
This commit is contained in:
+1
-1
@@ -6,4 +6,4 @@ edition = "2021"
|
||||
publish = false
|
||||
|
||||
[workspace]
|
||||
members = ["generate"]
|
||||
members = ["diagram", "generate"]
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
*.png
|
||||
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "unicode-ident-diagram"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
image = "0.24"
|
||||
unicode-ident = { path = ".." }
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user