From 1e07a31f30ed67940ab5468ee26fb8ea8c4a961b Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Fri, 27 Oct 2023 18:17:51 +0200 Subject: [PATCH 01/23] added translations and help - added possibility to translate strings - added English language - added --help - added --version - made help more descriptive --- Cargo.lock | 143 ++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 + src/font_config.rs | 17 ++--- src/image_processing.rs | 7 +- src/main.rs | 40 ++++++++--- src/translations/en.rs | 57 ++++++++++++++++ src/translations/kk.rs | 57 ++++++++++++++++ src/translations/mod.rs | 43 ++++++++++++ 8 files changed, 346 insertions(+), 20 deletions(-) create mode 100644 src/translations/en.rs create mode 100644 src/translations/kk.rs create mode 100644 src/translations/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 05901c9..a0dc642 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,6 +14,15 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -31,11 +40,19 @@ name = "bitmap_type_tracer" version = "1.0.0" dependencies = [ "image", + "locale_config", + "once_cell", "serde", "serde_derive", "serde_json", ] +[[package]] +name = "block" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" + [[package]] name = "bytemuck" version = "1.14.0" @@ -162,6 +179,46 @@ dependencies = [ "rayon", ] +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" + +[[package]] +name = "locale_config" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d2c35b16f4483f6c26f0e4e9550717a2f6575bcd6f12a53ff0c490a94a6934" +dependencies = [ + "lazy_static", + "objc", + "objc-foundation", + "regex", + "winapi", +] + +[[package]] +name = "malloc_buf" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" +dependencies = [ + "libc", +] + +[[package]] +name = "memchr" +version = "2.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" + [[package]] name = "memoffset" version = "0.9.0" @@ -231,6 +288,41 @@ dependencies = [ "autocfg", ] +[[package]] +name = "objc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" +dependencies = [ + "malloc_buf", +] + +[[package]] +name = "objc-foundation" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" +dependencies = [ + "block", + "objc", + "objc_id", +] + +[[package]] +name = "objc_id" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" +dependencies = [ + "objc", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + [[package]] name = "png" version = "0.16.8" @@ -281,6 +373,35 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + [[package]] name = "ryu" version = "1.0.15" @@ -363,3 +484,25 @@ name = "weezl" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 05bffa6..88e40cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,3 +28,5 @@ image = "0.23.14" serde = { version = "1.0", features = [] } serde_json = "1.0" serde_derive = { version = "1.0", features = [] } +locale_config = "0.3" +once_cell = { version = "1.8", features = [] } diff --git a/src/font_config.rs b/src/font_config.rs index 58c8f02..05e95ff 100644 --- a/src/font_config.rs +++ b/src/font_config.rs @@ -1,3 +1,5 @@ +use crate::{TRANSLATION}; + use serde_derive::{Serialize, Deserialize}; use std::fs::File; use std::io::Read; @@ -16,19 +18,18 @@ pub struct FontConfig { } pub fn load_font_config(font_path: &str) -> FontConfig { - let config_name = font_path.strip_suffix(".png").expect("Invalid font path").to_owned() + ".json"; - let mut file = File::open(config_name).expect("Failed to open font config"); + let config_name = font_path.strip_suffix(".png").expect(TRANSLATION.err_invalid_font_path()).to_owned() + ".json"; + let mut file = File::open(config_name).expect(TRANSLATION.err_failed_to_open_config()); let mut contents = String::new(); - file.read_to_string(&mut contents).expect("Failed to read font config"); + file.read_to_string(&mut contents).expect(TRANSLATION.err_failed_to_read_config()); - serde_json::from_str(&contents).expect("Failed to parse font config") + serde_json::from_str(&contents).expect(TRANSLATION.err_failed_to_parse_config()) } pub fn save_font_config(font_path: &str, config: &FontConfig) { - let config_name = font_path.strip_suffix(".png").expect("Invalid font path").to_owned() + ".json"; + let config_name = font_path.strip_suffix(".png").expect(TRANSLATION.err_invalid_font_path()).to_owned() + ".json"; - // Use to_string_pretty for a prettified JSON format. - let json_content = serde_json::to_string_pretty(&config).expect("Failed to serialize font config"); + let json_content = serde_json::to_string_pretty(&config).expect(TRANSLATION.err_failed_to_serialize_config()); - write(&config_name, json_content).expect("Failed to save font config"); + write(&config_name, json_content).expect(TRANSLATION.err_failed_to_save_config()) } diff --git a/src/image_processing.rs b/src/image_processing.rs index 91937a9..c0ac2c8 100644 --- a/src/image_processing.rs +++ b/src/image_processing.rs @@ -1,4 +1,5 @@ use image::{ImageBuffer, GenericImageView, Rgba}; +use crate::TRANSLATION; pub fn generate_image( font_path: &str, @@ -32,7 +33,7 @@ pub fn generate_image( top_margin, idx ); } else if None == pos { - eprintln!("Character '{}' not found in sequence. Trying to use the background-color instead.", character); + eprintln!("{}", TRANSLATION.character_not_found(character)); fill_with_bg_color(&mut output_image, idx as u32 * char_width, 0, char_width, char_height); } } @@ -40,11 +41,11 @@ pub fn generate_image( remove_background(&mut output_image, threshold); } - output_image.save("output.png").expect("Failed to save output image"); + output_image.save("output.png").expect(TRANSLATION.err_failed_to_save_output_image()) } fn load_font_image(font_path: &str) -> image::DynamicImage { - image::open(font_path).expect("Failed to open font image") + image::open(font_path).expect(TRANSLATION.err_failed_to_open_font_image()) } fn calculate_character_dimensions( diff --git a/src/main.rs b/src/main.rs index 647cdb1..1eded38 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,14 +4,36 @@ extern crate serde_derive; use std::env; mod font_config; mod image_processing; +mod translations; use font_config::{FontConfig, load_font_config, save_font_config}; use image_processing::generate_image; +use locale_config::Locale; +use once_cell::sync::Lazy; +use crate::translations::Translation; +use std::sync::Arc; + +static TRANSLATION: Lazy> = Lazy::new(|| { + let locale = Locale::user_default().to_string(); + let boxed_translation = translations::get_translation_for_locale(&locale); + Arc::from(boxed_translation) +}); + fn main() { let args: Vec = env::args().collect(); + if args.len() < 3 || args[1] == "--help" { + eprintln!("{}", TRANSLATION.full_help()); + return; + } + + if args.len() < 3 || args[1] == "--version" { + eprintln!("{}", TRANSLATION.version()); + return; + } + if args.len() == 3 { // If only font and text are provided generate_image_from_config(&args) } else { @@ -40,7 +62,7 @@ fn generate_image_from_config(args: &[String]) { fn generate_image_from_args(args: &[String]) { if !validate_args(&args) { - eprintln!("Usage: bitmap_type_tracer [--top VALUE] [--bottom VALUE] [--left VALUE] [--right VALUE] [--threshold VALUE] [--save-json]"); + eprintln!("{}", TRANSLATION.full_help()); return; } @@ -93,7 +115,7 @@ fn parse_mandatory_args(args: &[String]) -> (&String, &String, &String, u32) { let chars_per_row = match args[4].parse() { Ok(val) => val, Err(_) => { - eprintln!("You need to provide a valid number of characters per row."); + eprintln!("{}", TRANSLATION.err_invalid_num_of_chars()); std::process::exit(1); } }; @@ -109,11 +131,11 @@ fn parse_optional_args(args: &[String]) -> (u32, u32, u32, u32, u8) { for i in 5..args.len() { match args[i].as_str() { - "--top" => top_margin = parse_argument(&args[i+1],"Failed to read the top margin argument. Please provide a valid value." ), - "--bottom" => bottom_margin = parse_argument(&args[i+1],"Failed to read the top margin argument. Please provide a valid value."), - "--left" => left_margin = parse_argument(&args[i+1],"Failed to read the left margin argument. Please provide a valid value." ), - "--right" => right_margin = parse_argument(&args[i+1],"Failed to read the right margin argument. Please provide a valid value." ), - "--threshold" => threshold = parse_argument(&args[i+1],"Failed to read the threshold argument. Please provide a valid value." ), + "--top" => top_margin = parse_argument(&args[i+1],TRANSLATION.err_invalid_top_margin()), + "--bottom" => bottom_margin = parse_argument(&args[i+1],TRANSLATION.err_invalid_bottom_margin()), + "--left" => left_margin = parse_argument(&args[i+1],TRANSLATION.err_invalid_left_margin()), + "--right" => right_margin = parse_argument(&args[i+1],TRANSLATION.err_invalid_right_margin()), + "--threshold" => threshold = parse_argument(&args[i+1],TRANSLATION.err_invalid_threshold()), _ => {} } } @@ -125,8 +147,8 @@ fn parse_argument(value: &str, error_message: &str) -> u32 { match value.parse::() { Ok(val) => val, Err(_) => { - eprintln!("{}", error_message); // print the error to the stderr - std::process::exit(1); // exit the process with a non-zero exit code + eprintln!("{}", error_message); + std::process::exit(1); } } } diff --git a/src/translations/en.rs b/src/translations/en.rs new file mode 100644 index 0000000..4cc2371 --- /dev/null +++ b/src/translations/en.rs @@ -0,0 +1,57 @@ +pub struct English; + +impl super::Translation for English { + fn help(&self) -> &'static str { + "Usage: \n \ + If your font already has a configuration file: \n \ + bitmap_type_tracer \n\n \ + If you want to generate a configuration file: \n \ + bitmap_type_tracer [--top VALUE] [--bottom VALUE] [--left VALUE] [--right VALUE] [--threshold VALUE] [--save-json]\n \ + path_to_bitmap_font literally the path to the bitmap.png containing the characters\n \ + sequence the sequence of characters that you see in the bitmap font e.x 'ABCDEF...'\n \ + text the text you want to write with the provided bitmap font\n \ + chars_per_row how many characters are in a row in the provided bitmap font\n \ + Margins: \n \ + --top VALUE the number of pixels to crop from the top of the image\n \ + --bottom VALUE the number of pixels to crop from the bottom of the image\n \ + --left VALUE the number of pixels to crop from the left of the image\n \ + --right VALUE the number of pixels to crop from the right of the image\n \ + Other options: \n \ + --threshold VALUE the value to determine the threshold for making the background transparent (0-255)\n \ + --save-json save the configuration to a json file\n \ + --help print this help message\n \ + --version print the version of the program\n\n \ + For example usage check out the README.md in the repository \n \ + " + } + fn version(&self) -> &'static str {env!("CARGO_PKG_VERSION")} + fn repository(&self) -> &'static str {env!("CARGO_PKG_REPOSITORY")} + fn name(&self) -> &'static str {env!("CARGO_PKG_NAME")} + fn author(&self) -> &'static str {env!("CARGO_PKG_AUTHORS")} + fn full_help(&self) -> String { + format!( + "{} by {}\nVersion: {}\nRepository: {}\n{}", + self.name(), self.author(), self.version(), self.repository(), self.help() + ) + } + fn character_not_found(&self, character: char) -> String { + format!("Character '{}' not found in sequence. Trying to use the background-color instead.", character) + } + + fn err_invalid_num_of_chars(&self) -> &'static str {"You need to provide a valid number of characters per row."} + fn err_invalid_threshold(&self) -> &'static str {"You need to provide a valid threshold value (0-255)."} + fn err_invalid_left_margin(&self) -> &'static str {"Failed to read the right margin argument. Please provide a valid value."} + fn err_invalid_right_margin(&self) -> &'static str {"Failed to read the right margin argument. Please provide a valid value."} + fn err_invalid_top_margin(&self) -> &'static str {"Failed to read the top margin argument. Please provide a valid value."} + fn err_invalid_bottom_margin(&self) -> &'static str {"Failed to read the bottom margin argument. Please provide a valid value."} + + fn err_failed_to_read_config(&self) -> &'static str {"Failed to read the font config (json) file."} + fn err_failed_to_parse_config(&self) -> &'static str {"Failed to parse the font config (json) file."} + fn err_failed_to_open_config(&self) -> &'static str {"Failed to open the font config (json) file."} + fn err_failed_to_serialize_config(&self) -> &'static str {"Failed to serialize the font config (json) file."} + fn err_failed_to_save_config(&self) -> &'static str {"Failed to save the font config (json) file."} + fn err_invalid_font_path(&self) -> &'static str {"Invalid font path"} + + fn err_failed_to_save_output_image(&self) -> &'static str {"Failed to save output image"} + fn err_failed_to_open_font_image(&self) -> &'static str {"Failed to open font image"} +} \ No newline at end of file diff --git a/src/translations/kk.rs b/src/translations/kk.rs new file mode 100644 index 0000000..a586577 --- /dev/null +++ b/src/translations/kk.rs @@ -0,0 +1,57 @@ +pub struct Kazakh; + +impl super::Translation for Kazakh { + fn help(&self) -> &'static str { + "Usage: \n \ + If your font already has a configuration file: \n \ + bitmap_type_tracer \n\n \ + If you want to generate a configuration file: \n \ + bitmap_type_tracer [--top VALUE] [--bottom VALUE] [--left VALUE] [--right VALUE] [--threshold VALUE] [--save-json]\n \ + path_to_bitmap_font literally the path to the bitmap.png containing the characters\n \ + sequence the sequence of characters that you see in the bitmap font e.x 'ABCDEF...'\n \ + text the text you want to write with the provided bitmap font\n \ + chars_per_row how many characters are in a row in the provided bitmap font\n \ + Margins: \n \ + --top VALUE the number of pixels to crop from the top of the image\n \ + --bottom VALUE the number of pixels to crop from the bottom of the image\n \ + --left VALUE the number of pixels to crop from the left of the image\n \ + --right VALUE the number of pixels to crop from the right of the image\n \ + Other options: \n \ + --threshold VALUE the value to determine the threshold for making the background transparent (0-255)\n \ + --save-json save the configuration to a json file\n \ + --help print this help message\n \ + --version print the version of the program\n\n \ + For example usage check out the README.md in the repository \n \ + " + } + fn version(&self) -> &'static str {env!("CARGO_PKG_VERSION")} + fn repository(&self) -> &'static str {env!("CARGO_PKG_REPOSITORY")} + fn name(&self) -> &'static str {env!("CARGO_PKG_NAME")} + fn author(&self) -> &'static str {env!("CARGO_PKG_AUTHORS")} + fn full_help(&self) -> String { + format!( + "{} by {}\nVersion: {}\nRepository: {}\n{}", + self.name(), self.author(), self.version(), self.repository(), self.help() + ) + } + fn character_not_found(&self, character: char) -> String { + format!("Character '{}' not found in sequence. Trying to use the background-color instead.", character) + } + + fn err_invalid_num_of_chars(&self) -> &'static str {"You need to provide a valid number of characters per row."} + fn err_invalid_threshold(&self) -> &'static str {"You need to provide a valid threshold value (0-255)."} + fn err_invalid_left_margin(&self) -> &'static str {"Failed to read the right margin argument. Please provide a valid value."} + fn err_invalid_right_margin(&self) -> &'static str {"Failed to read the right margin argument. Please provide a valid value."} + fn err_invalid_top_margin(&self) -> &'static str {"Failed to read the top margin argument. Please provide a valid value."} + fn err_invalid_bottom_margin(&self) -> &'static str {"Failed to read the bottom margin argument. Please provide a valid value."} + + fn err_failed_to_read_config(&self) -> &'static str {"Failed to read the font config (json) file."} + fn err_failed_to_parse_config(&self) -> &'static str {"Failed to parse the font config (json) file."} + fn err_failed_to_open_config(&self) -> &'static str {"Failed to open the font config (json) file."} + fn err_failed_to_serialize_config(&self) -> &'static str {"Failed to serialize the font config (json) file."} + fn err_failed_to_save_config(&self) -> &'static str {"Failed to save the font config (json) file."} + fn err_invalid_font_path(&self) -> &'static str {"Invalid font path"} + + fn err_failed_to_save_output_image(&self) -> &'static str {"Failed to save output image"} + fn err_failed_to_open_font_image(&self) -> &'static str {"Failed to open font image"} +} \ No newline at end of file diff --git a/src/translations/mod.rs b/src/translations/mod.rs new file mode 100644 index 0000000..33a8127 --- /dev/null +++ b/src/translations/mod.rs @@ -0,0 +1,43 @@ +use crate::translations::en::English; +use crate::translations::kk::Kazakh; + +mod en; +mod kk; + +pub fn get_translation_for_locale(locale: &str) -> Box { + match locale { + "kk" => Box::new(Kazakh), + "kz" => Box::new(Kazakh), + // ... other locales + _ => Box::new(English), + } +} + +pub trait Translation : Send + Sync { + fn help(&self) -> &'static str; + fn version(&self) -> &'static str; + fn repository(&self) -> &'static str; + fn name(&self) -> &'static str; + fn author(&self) -> &'static str; + fn full_help(&self) -> String; + fn character_not_found(&self, character: char) -> String; + + fn err_invalid_num_of_chars(&self) -> &'static str; + fn err_invalid_threshold(&self) -> &'static str; + fn err_invalid_left_margin(&self) -> &'static str; + fn err_invalid_right_margin(&self) -> &'static str; + fn err_invalid_top_margin(&self) -> &'static str; + fn err_invalid_bottom_margin(&self) -> &'static str; + + fn err_failed_to_read_config(&self) -> &'static str; + fn err_failed_to_parse_config(&self) -> &'static str; + fn err_failed_to_open_config(&self) -> &'static str; + fn err_failed_to_serialize_config(&self) -> &'static str; + fn err_failed_to_save_config(&self) -> &'static str; + fn err_invalid_font_path(&self) -> &'static str; + + fn err_failed_to_save_output_image(&self) -> &'static str; + fn err_failed_to_open_font_image(&self) -> &'static str; +} + + From da2a8722d7470007bedf6004c5323fd69f8ec7dc Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Fri, 27 Oct 2023 18:19:29 +0200 Subject: [PATCH 02/23] bumped the version up --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 88e40cc..9a6c406 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bitmap_type_tracer" authors = ["tolik518"] -version = "1.0.0" +version = "1.1.0" edition = "2021" rust-version = "1.65" description = "bitmap_type_trace is a utility tool to generate images from font bitmaps with customizable configurations" From eae711495ce3bc59ead469207dd5099aa47691ef Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Sat, 28 Oct 2023 19:24:05 +0200 Subject: [PATCH 03/23] removed "extern crate" --- Cargo.lock | 2 +- src/main.rs | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a0dc642..af74107 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,7 +37,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitmap_type_tracer" -version = "1.0.0" +version = "1.1.0" dependencies = [ "image", "locale_config", diff --git a/src/main.rs b/src/main.rs index 1eded38..5582b99 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,3 @@ -extern crate image; -extern crate serde_derive; - use std::env; mod font_config; mod image_processing; From f64854fb1beb914fcec8aa4a59025ebc2c1efd6d Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Sun, 29 Oct 2023 12:15:52 +0100 Subject: [PATCH 04/23] added turkish translation --- src/translations/en.rs | 39 ++++++++++++++-------------- src/translations/kk.rs | 57 ----------------------------------------- src/translations/mod.rs | 12 +++++---- src/translations/tr.rs | 56 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 82 deletions(-) delete mode 100644 src/translations/kk.rs create mode 100644 src/translations/tr.rs diff --git a/src/translations/en.rs b/src/translations/en.rs index 4cc2371..0e8dfd3 100644 --- a/src/translations/en.rs +++ b/src/translations/en.rs @@ -3,26 +3,25 @@ pub struct English; impl super::Translation for English { fn help(&self) -> &'static str { "Usage: \n \ - If your font already has a configuration file: \n \ - bitmap_type_tracer \n\n \ - If you want to generate a configuration file: \n \ - bitmap_type_tracer [--top VALUE] [--bottom VALUE] [--left VALUE] [--right VALUE] [--threshold VALUE] [--save-json]\n \ - path_to_bitmap_font literally the path to the bitmap.png containing the characters\n \ - sequence the sequence of characters that you see in the bitmap font e.x 'ABCDEF...'\n \ - text the text you want to write with the provided bitmap font\n \ - chars_per_row how many characters are in a row in the provided bitmap font\n \ - Margins: \n \ - --top VALUE the number of pixels to crop from the top of the image\n \ - --bottom VALUE the number of pixels to crop from the bottom of the image\n \ - --left VALUE the number of pixels to crop from the left of the image\n \ - --right VALUE the number of pixels to crop from the right of the image\n \ - Other options: \n \ - --threshold VALUE the value to determine the threshold for making the background transparent (0-255)\n \ - --save-json save the configuration to a json file\n \ - --help print this help message\n \ - --version print the version of the program\n\n \ - For example usage check out the README.md in the repository \n \ - " + If your font already has a configuration file: \n \ + bitmap_type_tracer \n\n \ + If you want to generate a configuration file: \n \ + bitmap_type_tracer [--top VALUE] [--bottom VALUE] [--left VALUE] [--right VALUE] [--threshold VALUE] [--save-json]\n \ + path_to_bitmap_font literally the path to the bitmap.png containing the characters\n \ + sequence the sequence of characters that you see in the bitmap font e.x 'ABCDEF...'\n \ + text the text you want to write with the provided bitmap font\n \ + chars_per_row how many characters are in a row in the provided bitmap font\n \ + Margins: \n \ + --top VALUE the number of pixels to crop from the top of the image\n \ + --bottom VALUE the number of pixels to crop from the bottom of the image\n \ + --left VALUE the number of pixels to crop from the left of the image\n \ + --right VALUE the number of pixels to crop from the right of the image\n \ + Other options: \n \ + --threshold VALUE the value to determine the threshold for making the background transparent (0-255)\n \ + --save-json save the configuration to a json file\n \ + --help print this help message\n \ + --version print the version of the program\n\n \ + For example usage check out the README.md in the repository \n" } fn version(&self) -> &'static str {env!("CARGO_PKG_VERSION")} fn repository(&self) -> &'static str {env!("CARGO_PKG_REPOSITORY")} diff --git a/src/translations/kk.rs b/src/translations/kk.rs deleted file mode 100644 index a586577..0000000 --- a/src/translations/kk.rs +++ /dev/null @@ -1,57 +0,0 @@ -pub struct Kazakh; - -impl super::Translation for Kazakh { - fn help(&self) -> &'static str { - "Usage: \n \ - If your font already has a configuration file: \n \ - bitmap_type_tracer \n\n \ - If you want to generate a configuration file: \n \ - bitmap_type_tracer [--top VALUE] [--bottom VALUE] [--left VALUE] [--right VALUE] [--threshold VALUE] [--save-json]\n \ - path_to_bitmap_font literally the path to the bitmap.png containing the characters\n \ - sequence the sequence of characters that you see in the bitmap font e.x 'ABCDEF...'\n \ - text the text you want to write with the provided bitmap font\n \ - chars_per_row how many characters are in a row in the provided bitmap font\n \ - Margins: \n \ - --top VALUE the number of pixels to crop from the top of the image\n \ - --bottom VALUE the number of pixels to crop from the bottom of the image\n \ - --left VALUE the number of pixels to crop from the left of the image\n \ - --right VALUE the number of pixels to crop from the right of the image\n \ - Other options: \n \ - --threshold VALUE the value to determine the threshold for making the background transparent (0-255)\n \ - --save-json save the configuration to a json file\n \ - --help print this help message\n \ - --version print the version of the program\n\n \ - For example usage check out the README.md in the repository \n \ - " - } - fn version(&self) -> &'static str {env!("CARGO_PKG_VERSION")} - fn repository(&self) -> &'static str {env!("CARGO_PKG_REPOSITORY")} - fn name(&self) -> &'static str {env!("CARGO_PKG_NAME")} - fn author(&self) -> &'static str {env!("CARGO_PKG_AUTHORS")} - fn full_help(&self) -> String { - format!( - "{} by {}\nVersion: {}\nRepository: {}\n{}", - self.name(), self.author(), self.version(), self.repository(), self.help() - ) - } - fn character_not_found(&self, character: char) -> String { - format!("Character '{}' not found in sequence. Trying to use the background-color instead.", character) - } - - fn err_invalid_num_of_chars(&self) -> &'static str {"You need to provide a valid number of characters per row."} - fn err_invalid_threshold(&self) -> &'static str {"You need to provide a valid threshold value (0-255)."} - fn err_invalid_left_margin(&self) -> &'static str {"Failed to read the right margin argument. Please provide a valid value."} - fn err_invalid_right_margin(&self) -> &'static str {"Failed to read the right margin argument. Please provide a valid value."} - fn err_invalid_top_margin(&self) -> &'static str {"Failed to read the top margin argument. Please provide a valid value."} - fn err_invalid_bottom_margin(&self) -> &'static str {"Failed to read the bottom margin argument. Please provide a valid value."} - - fn err_failed_to_read_config(&self) -> &'static str {"Failed to read the font config (json) file."} - fn err_failed_to_parse_config(&self) -> &'static str {"Failed to parse the font config (json) file."} - fn err_failed_to_open_config(&self) -> &'static str {"Failed to open the font config (json) file."} - fn err_failed_to_serialize_config(&self) -> &'static str {"Failed to serialize the font config (json) file."} - fn err_failed_to_save_config(&self) -> &'static str {"Failed to save the font config (json) file."} - fn err_invalid_font_path(&self) -> &'static str {"Invalid font path"} - - fn err_failed_to_save_output_image(&self) -> &'static str {"Failed to save output image"} - fn err_failed_to_open_font_image(&self) -> &'static str {"Failed to open font image"} -} \ No newline at end of file diff --git a/src/translations/mod.rs b/src/translations/mod.rs index 33a8127..8cab891 100644 --- a/src/translations/mod.rs +++ b/src/translations/mod.rs @@ -1,15 +1,17 @@ use crate::translations::en::English; -use crate::translations::kk::Kazakh; +use crate::translations::tr::Turkish; mod en; -mod kk; +mod tr; pub fn get_translation_for_locale(locale: &str) -> Box { + eprintln!("{}", locale); + match locale { - "kk" => Box::new(Kazakh), - "kz" => Box::new(Kazakh), + "tr" => Box::new(Turkish), // ... other locales - _ => Box::new(English), + "en" => Box::new(English), + _ => Box::new(Turkish), } } diff --git a/src/translations/tr.rs b/src/translations/tr.rs new file mode 100644 index 0000000..063fd85 --- /dev/null +++ b/src/translations/tr.rs @@ -0,0 +1,56 @@ +pub struct Turkish; + +impl super::Translation for Turkish { + fn help(&self) -> &'static str { + "Usage: \n \ + Yazı tipinizde zaten bir yapılandırma dosyası varsa:\n \ + bitmap_type_tracer \n\n \ + Bir yapılandırma dosyası oluşturmak istiyorsanız: \n \ + bitmap_type_tracer [--top VALUE] [--bottom VALUE] [--left VALUE] [--right VALUE] [--threshold VALUE] [--save-json]\n \ + path_to_bitmap_font karakterleri içeren bitmap.png dosyasının yolu\n \ + sequence bit eşlem yazı tipinde gördüğünüz karakter dizisi, örneğin 'ABCÇDEF...'\n \ + text bitmap yazı tipiyle yazmak istediğiniz metin\n \ + chars_per_row bitmap yazı tipinde bir satırda kaç karakter olduğunu\n \ + Margins: \n \ + --top VALUE görüntünün üst kısmından kırpılacak piksel sayısı\n \ + --bottom VALUE görüntünün alt kısmından kırpılacak piksel sayısı\n \ + --left VALUE görüntünün solundan kırpılacak piksel sayısı\n \ + --right VALUE görüntünün sağından kırpılacak piksel sayısı\n \ + Other options: \n \ + --threshold VALUE arka planı saydam hale getirmeye yönelik eşiği belirleyen değer (0-255)\n \ + --save-json yapılandırmayı json dosyasına kaydedin\n \ + --help yardım mesajını yazdır\n \ + --version programın sürümünü yazdır\n\n \ + Nasıl kullanıldığını öğrenmek için README.md dosyasını okuyun. \n" + } + fn version(&self) -> &'static str {env!("CARGO_PKG_VERSION")} + fn repository(&self) -> &'static str {env!("CARGO_PKG_REPOSITORY")} + fn name(&self) -> &'static str {env!("CARGO_PKG_NAME")} + fn author(&self) -> &'static str {env!("CARGO_PKG_AUTHORS")} + fn full_help(&self) -> String { + format!( + "{} by {}\nVersion: {}\nRepository: {}\n{}", + self.name(), self.author(), self.version(), self.repository(), self.help() + ) + } + fn character_not_found(&self, character: char) -> String { + format!("Karakter '{}' bulunamadı. Onun yerine arka plan rengini kullanıyoruz.", character) + } + + fn err_invalid_num_of_chars(&self) -> &'static str {"Yetersiz karakter.."} + fn err_invalid_threshold(&self) -> &'static str {"Geçerli bir threshold girmelisiniz. (0-255)."} + fn err_invalid_left_margin(&self) -> &'static str {"Sağ margin ayarlanamadı, lütfen geçerli bir değer girin."} + fn err_invalid_right_margin(&self) -> &'static str {"Sol margin ayarlanamadı, lütfen geçerli bir değer girin."} + fn err_invalid_top_margin(&self) -> &'static str {"Üst margin ayarlanamadı, lütfen geçerli bir değer girin."} + fn err_invalid_bottom_margin(&self) -> &'static str {"Alt margin ayarlanamadı, lütfen geçerli bir değer girin."} + + fn err_failed_to_read_config(&self) -> &'static str {"Yazı tipi yapılandırma dosyası (json) okunamadı."} + fn err_failed_to_parse_config(&self) -> &'static str {"Yazı tipi yapılandırma dosyası (json) analiz edilemedi."} + fn err_failed_to_open_config(&self) -> &'static str {"Yazı tipi yapılandırma dosyası (json) analiz açılamadı."} + fn err_failed_to_serialize_config(&self) -> &'static str {"Yazı tipi yapılandırma dosyası (json) dizilemedi."} + fn err_failed_to_save_config(&self) -> &'static str {"Yazı tipi yapılandırma dosyası (json) kaydedilemedi."} + fn err_invalid_font_path(&self) -> &'static str {"Geçersiz yazı tipi dosyası yolu."} + + fn err_failed_to_save_output_image(&self) -> &'static str {"Çıktı görüntüsü kaydedilemedi."} + fn err_failed_to_open_font_image(&self) -> &'static str {"Yazı tipi görüntüsü açılamadı."} +} \ No newline at end of file From ab1c9a0120b0547b28987f5b62791ec4cb944552 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Sun, 29 Oct 2023 12:16:09 +0100 Subject: [PATCH 05/23] fixed examples in the readme --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index bf692c0..67dc951 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ This command will generate an image using a previously saved font configuration _/examples/4138906397_0dc616813b_o.png_ ![](./examples/4138906397_0dc616813b_o.png) ```bash -bitmap_font_tool examples/4138906397_0dc616813b_o.png " \!\" '()*+,-.\\0123456789:; = ? ABCDEFGHIJKLMNOPQRSTUVWXYZ " tolik518 10 +bitmap_type_tracer examples/4138906397_0dc616813b_o.png " \!\" '()*+,-.\\0123456789:; = ? ABCDEFGHIJKLMNOPQRSTUVWXYZ " tolik518 10 ``` ![](./examples/4138906397_0dc616813b_o.png_tolik518.png) @@ -96,7 +96,7 @@ bitmap_font_tool examples/4138906397_0dc616813b_o.png " \!\" '()*+,-.\\012345 _/examples/4138906425_29cbc92641_o.png_ ![](./examples/4138906425_29cbc92641_o.png) ```bash -bitmap_font_tool examples/4138906425_29cbc92641_o.png " \!\" '()*+,-.\\0123456789:; = ? ABCDEFGHIJKLMNOPQRSTUVWXYZ " tolik518 10 +bitmap_type_tracer examples/4138906425_29cbc92641_o.png " \!\" '()*+,-.\\0123456789:; = ? ABCDEFGHIJKLMNOPQRSTUVWXYZ " tolik518 10 ``` ![](./examples/4138906425_29cbc92641_o.png_tolik518.png) @@ -105,7 +105,7 @@ bitmap_font_tool examples/4138906425_29cbc92641_o.png " \!\" '()*+,-.\\012345 _/examples/FONT34.png_ ![](./examples/FONT34.png) ```bash -bitmap_font_tool examples/FONT34.png " \! () , . 0123456789:; - ? ABCDEFGHIJKLMNOPQRSTUVWXYZ " tolik518 20 --bottom 150 --threshold 20 +bitmap_type_tracer examples/FONT34.png " \! () , . 0123456789:; - ? ABCDEFGHIJKLMNOPQRSTUVWXYZ " tolik518 20 --bottom 150 --threshold 20 ``` ![](./examples/FONT34.png_tolik518.png) @@ -114,7 +114,7 @@ bitmap_font_tool examples/FONT34.png " \! () , . 0123456789:; - ? ABCDEFGH _/examples/font228.png_ ![](./examples/font228.png) ```bash -bitmap_font_tool examples/font228.png "ABCDEFGHIJKLMNOPQRSTUVWXYZ>.: " tolik518 10 --threshold 0 +bitmap_type_tracer examples/font228.png "ABCDEFGHIJKLMNOPQRSTUVWXYZ>.: " tolik518 10 --threshold 0 ``` Since the number are missing from the sequence, they are not generated in the image and it tries to fill the space with the background. The background was not recognized properly, so it was filled with the brown instead of black. @@ -125,7 +125,7 @@ The background was not recognized properly, so it was filled with the brown inst _/examples/font239r.png_ ![](./examples/font239r.png) ```bash -bitmap_font_tool examples/font239r.png "ABCDEFGHIJKLMNOPQRSTUVWXYZ()\!?.,’ " tolik518 7 --bottom 4 --threshold 1 +bitmap_type_tracer examples/font239r.png "ABCDEFGHIJKLMNOPQRSTUVWXYZ()\!?.,’ " tolik518 7 --bottom 4 --threshold 1 ``` Since the number are missing from the sequence, they are not generated in the image and it tries to fill the space with the background, but the threshold is set to 1, so it doesn't fill the space with the transparent background since it recognized the black background. ![](./examples/font239r.png_tolik518.png) @@ -135,7 +135,7 @@ Since the number are missing from the sequence, they are not generated in the im _/examples/font244r.png_ ![](./examples/font244r.png) ```bash -bitmap_font_tool examples/font244r.png "ALW6BMX7CNY8DOZ9EP*\!FQ0?GR1.HS2 IT3 JU4 KV5 " tolik518 4 --threshold 30 +bitmap_type_tracer examples/font244r.png "ALW6BMX7CNY8DOZ9EP*\!FQ0?GR1.HS2 IT3 JU4 KV5 " tolik518 4 --threshold 30 ``` We needed a threshold of 30 to remove the black background. ![](./examples/font244r.png_tolik518.png) @@ -145,7 +145,7 @@ We needed a threshold of 30 to remove the black background. _/examples/font248r.png_ ![](./examples/font248r.png) ```bash -bitmap_font_tool examples/font248r.png "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 \!?." tolik518 20 --threshold 60 +bitmap_type_tracer examples/font248r.png "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 \!?." tolik518 20 --threshold 60 ``` To have a better result, we needed a threshold of 60 to remove the black background. ![](./examples/font248r.png_tolik518.png) @@ -155,7 +155,7 @@ To have a better result, we needed a threshold of 60 to remove the black backgro _/examples/MEGAD.png_ ![](./examples/MEGAD.png) ```bash -bitmap_font_tool examples/MEGAD.png "'() +,-. 0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ ! =? " tolik518 10 --bottom 10 --threshold 1 +bitmap_type_tracer examples/MEGAD.png "'() +,-. 0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ ! =? " tolik518 10 --bottom 10 --threshold 1 ``` In this example, we needed to add a bottom margin of 10 for the characters to align properly. ![](./examples/MEGAD.png_tolik518.png) @@ -165,7 +165,7 @@ In this example, we needed to add a bottom margin of 10 for the characters to al _/examples/MEGAD2.png_ ![](./examples/MEGAD2.png) ```bash -bitmap_font_tool examples/MEGAD2.png "AGMSY+:4BHNTZ\!;5CIOU.?06DJPV;(17EKQW\")28FLRX-'39" tolik518 8 --bottom 3 --threshold 1 +bitmap_type_tracer examples/MEGAD2.png "AGMSY+:4BHNTZ\!;5CIOU.?06DJPV;(17EKQW\")28FLRX-'39" tolik518 8 --bottom 3 --threshold 1 ``` ![](./examples/MEGAD2.png_tolik518.png) From 9b3dfc9dd3f38d5c2ee27d2d761e2220b5c11086 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Sun, 29 Oct 2023 12:17:56 +0100 Subject: [PATCH 06/23] use config internally --- src/font_config.rs | 3 +-- src/image_processing.rs | 34 ++++++++++------------------ src/main.rs | 49 +++++++++++++++++------------------------ 3 files changed, 33 insertions(+), 53 deletions(-) diff --git a/src/font_config.rs b/src/font_config.rs index 05e95ff..aa69ea5 100644 --- a/src/font_config.rs +++ b/src/font_config.rs @@ -7,7 +7,6 @@ use std::fs::write; #[derive(Serialize, Deserialize)] pub struct FontConfig { - pub font_name: String, pub sequence: String, pub chars_per_row: u32, pub top_margin: u32, @@ -31,5 +30,5 @@ pub fn save_font_config(font_path: &str, config: &FontConfig) { let json_content = serde_json::to_string_pretty(&config).expect(TRANSLATION.err_failed_to_serialize_config()); - write(&config_name, json_content).expect(TRANSLATION.err_failed_to_save_config()) + write(config_name, json_content).expect(TRANSLATION.err_failed_to_save_config()) } diff --git a/src/image_processing.rs b/src/image_processing.rs index c0ac2c8..95ffabc 100644 --- a/src/image_processing.rs +++ b/src/image_processing.rs @@ -1,25 +1,20 @@ use image::{ImageBuffer, GenericImageView, Rgba}; +use crate::font_config::FontConfig; use crate::TRANSLATION; pub fn generate_image( font_path: &str, - sequence: &str, text: &str, - chars_per_row: u32, - top_margin: u32, - bottom_margin: u32, - left_margin: u32, - right_margin: u32, - threshold: u8 + config: &FontConfig ) { let font_image = load_font_image(font_path); - let (char_width, char_height) = calculate_character_dimensions(&font_image, sequence, chars_per_row, top_margin, bottom_margin, left_margin, right_margin); + let (char_width, char_height) = calculate_character_dimensions(&font_image, config); let output_width = char_width * text.len() as u32; let mut output_image = ImageBuffer::new(output_width, char_height); for (idx, character) in text.chars().enumerate() { - let pos = find_character_position(character, sequence); + let pos = find_character_position(character, &config.sequence); if let Some(position) = pos { copy_character_to_output( @@ -28,17 +23,17 @@ pub fn generate_image( position, char_width, char_height, - chars_per_row, - left_margin, - top_margin, idx + config.chars_per_row, + config.left_margin, + config.top_margin, idx ); } else if None == pos { eprintln!("{}", TRANSLATION.character_not_found(character)); fill_with_bg_color(&mut output_image, idx as u32 * char_width, 0, char_width, char_height); } } - if threshold > 0 { - remove_background(&mut output_image, threshold); + if config.threshold > 0 { + remove_background(&mut output_image, config.threshold); } output_image.save("output.png").expect(TRANSLATION.err_failed_to_save_output_image()) @@ -50,15 +45,10 @@ fn load_font_image(font_path: &str) -> image::DynamicImage { fn calculate_character_dimensions( font_image: &image::DynamicImage, - sequence: &str, - chars_per_row: u32, - top_margin: u32, - bottom_margin: u32, - left_margin: u32, - right_margin: u32 + config: &FontConfig ) -> (u32, u32) { - let char_width = (font_image.width() - (left_margin + right_margin)) / chars_per_row; - let char_height = (font_image.height() - (top_margin + bottom_margin)) / (sequence.len() as u32 / chars_per_row); + let char_width = (font_image.width() - (config.left_margin + config.right_margin)) / config.chars_per_row; + let char_height = (font_image.height() - (config.top_margin + config.bottom_margin)) / (config.sequence.len() as u32 / config.chars_per_row); (char_width, char_height) } diff --git a/src/main.rs b/src/main.rs index 5582b99..1e7e179 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,50 +46,38 @@ fn generate_image_from_config(args: &[String]) { generate_image( font_path, - &config.sequence, text, - config.chars_per_row, - config.top_margin, - config.bottom_margin, - config.left_margin, - config.right_margin, - config.threshold + &config ); } fn generate_image_from_args(args: &[String]) { - if !validate_args(&args) { + if !validate_args(args) { eprintln!("{}", TRANSLATION.full_help()); return; } - let (font_path, sequence, text, chars_per_row) = parse_mandatory_args(&args); - let (top_margin, bottom_margin, left_margin, right_margin, threshold) = parse_optional_args(&args); + let (font_path, sequence, text, chars_per_row) = parse_mandatory_args(args); + let (top_margin, bottom_margin, left_margin, right_margin, threshold) = parse_optional_args(args); + + let config = FontConfig { + sequence: sequence.to_string(), + chars_per_row, + top_margin, + bottom_margin, + left_margin, + right_margin, + threshold + }; if args.contains(&"--save-json".to_string()) { - let config = FontConfig { - font_name: font_path.to_string(), - sequence: sequence.to_string(), - chars_per_row, - top_margin, - bottom_margin, - left_margin, - right_margin, - threshold - }; save_font_config(font_path, &config); } generate_image( font_path, - sequence, text, - chars_per_row, - top_margin, - bottom_margin, - left_margin, - right_margin, - threshold + &config ); } @@ -99,11 +87,14 @@ fn validate_args(args: &[String]) -> bool { return false; } - // Check if --save-json flag is present let save_json_flag = args.contains(&"--save-json".to_string()); // Calculate the number of expected arguments excluding the flag - let expected_args = if save_json_flag { args.len() - 1 } else { args.len() }; + let expected_args = if save_json_flag { + args.len() - 1 + } else { + args.len() + }; expected_args <= 5 || (expected_args - 5) % 2 == 0 } From 7f5787501aaa8e1d5a50c414ae34ec0d907bede3 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Sun, 29 Oct 2023 12:18:06 +0100 Subject: [PATCH 07/23] removed font_name from all configs --- examples/4138906397_0dc616813b_o.json | 1 - examples/4138906425_29cbc92641_o.json | 1 - examples/FONT34.json | 1 - examples/MEGAD.json | 1 - examples/MEGAD2.json | 1 - examples/font228.json | 1 - examples/font239r.json | 1 - examples/font244r.json | 1 - examples/font248r.json | 1 - 9 files changed, 9 deletions(-) diff --git a/examples/4138906397_0dc616813b_o.json b/examples/4138906397_0dc616813b_o.json index 4978932..ce134cf 100644 --- a/examples/4138906397_0dc616813b_o.json +++ b/examples/4138906397_0dc616813b_o.json @@ -1,5 +1,4 @@ { - "font_name": "4138906397_0dc616813b_o", "sequence": " !\" '()*+,-.\\0123456789:; = ? ABCDEFGHIJKLMNOPQRSTUVWXYZ ", "chars_per_row": 10, "top_margin": 0, diff --git a/examples/4138906425_29cbc92641_o.json b/examples/4138906425_29cbc92641_o.json index 903bd89..ce134cf 100644 --- a/examples/4138906425_29cbc92641_o.json +++ b/examples/4138906425_29cbc92641_o.json @@ -1,5 +1,4 @@ { - "font_name": "4138906425_29cbc92641_o", "sequence": " !\" '()*+,-.\\0123456789:; = ? ABCDEFGHIJKLMNOPQRSTUVWXYZ ", "chars_per_row": 10, "top_margin": 0, diff --git a/examples/FONT34.json b/examples/FONT34.json index 0c292a3..3245c90 100644 --- a/examples/FONT34.json +++ b/examples/FONT34.json @@ -1,5 +1,4 @@ { - "font_name": "FONT34", "sequence": " ! () , . 0123456789:; - ? ABCDEFGHIJKLMNOPQRSTUVWXYZ ", "chars_per_row": 20, "top_margin": 0, diff --git a/examples/MEGAD.json b/examples/MEGAD.json index 6d9e576..1166e03 100644 --- a/examples/MEGAD.json +++ b/examples/MEGAD.json @@ -1,5 +1,4 @@ { - "font_name": "MEGAD", "sequence": "'() +,-. 0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ ! =? ", "chars_per_row": 10, "top_margin": 0, diff --git a/examples/MEGAD2.json b/examples/MEGAD2.json index 13b9426..ea4eb0f 100644 --- a/examples/MEGAD2.json +++ b/examples/MEGAD2.json @@ -1,5 +1,4 @@ { - "font_name": "MEGAD", "sequence": "AGMSY+:4BHNTZ!;5CIOU.?06DJPV;(17EKQW\")28FLRX-'39", "chars_per_row": 8, "top_margin": 0, diff --git a/examples/font228.json b/examples/font228.json index 72ecf77..837dccb 100644 --- a/examples/font228.json +++ b/examples/font228.json @@ -1,5 +1,4 @@ { - "font_name": "font228", "sequence": "ABCDEFGHIJKLMNOPQRSTUVWXYZ>.: ", "chars_per_row": 10, "top_margin": 0, diff --git a/examples/font239r.json b/examples/font239r.json index e41a0eb..42994d1 100644 --- a/examples/font239r.json +++ b/examples/font239r.json @@ -1,5 +1,4 @@ { - "font_name": "font239r", "sequence": "ABCDEFGHIJKLMNOPQRSTUVWXYZ()!?.,' ", "chars_per_row": 7, "top_margin": 0, diff --git a/examples/font244r.json b/examples/font244r.json index 05f8421..1c43955 100644 --- a/examples/font244r.json +++ b/examples/font244r.json @@ -1,5 +1,4 @@ { - "font_name": "examples/font244r.png", "sequence": "ALW6BMX7CNY8DOZ9EP*!FQ0?GR1.HS2 IT3 JU4 KV5 ", "chars_per_row": 4, "top_margin": 0, diff --git a/examples/font248r.json b/examples/font248r.json index 468411d..92cd25b 100644 --- a/examples/font248r.json +++ b/examples/font248r.json @@ -1,5 +1,4 @@ { - "font_name": "font248r.png", "sequence": "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !?.", "chars_per_row": 20, "top_margin": 0, From f43166f03b01c7942ae15d20c0826d17a814c1a6 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Sun, 29 Oct 2023 12:24:58 +0100 Subject: [PATCH 08/23] #![allow(clippy::expect_fun_call)] --- src/font_config.rs | 1 + src/image_processing.rs | 7 +++++-- src/main.rs | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/font_config.rs b/src/font_config.rs index aa69ea5..38edbf4 100644 --- a/src/font_config.rs +++ b/src/font_config.rs @@ -1,3 +1,4 @@ +#![allow(clippy::expect_fun_call)] use crate::{TRANSLATION}; use serde_derive::{Serialize, Deserialize}; diff --git a/src/image_processing.rs b/src/image_processing.rs index 95ffabc..32d80b4 100644 --- a/src/image_processing.rs +++ b/src/image_processing.rs @@ -1,3 +1,5 @@ +#![allow(clippy::expect_fun_call)] + use image::{ImageBuffer, GenericImageView, Rgba}; use crate::font_config::FontConfig; use crate::TRANSLATION; @@ -25,9 +27,10 @@ pub fn generate_image( char_height, config.chars_per_row, config.left_margin, - config.top_margin, idx + config.top_margin, + idx ); - } else if None == pos { + } else if pos.is_none() { eprintln!("{}", TRANSLATION.character_not_found(character)); fill_with_bg_color(&mut output_image, idx as u32 * char_width, 0, char_width, char_height); } diff --git a/src/main.rs b/src/main.rs index 1e7e179..073f15a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +#![allow(clippy::expect_fun_call)] + use std::env; mod font_config; mod image_processing; From 4c660acacf3073fce9d767a54f345a34efc19091 Mon Sep 17 00:00:00 2001 From: Mattia Beccari <103275021+Tizzz-555@users.noreply.github.com> Date: Sun, 29 Oct 2023 19:10:12 +0100 Subject: [PATCH 09/23] feat(lang): add Italian language --- src/translations/it.rs | 56 +++++++++++++++++++++++++++++++++++++++++ src/translations/mod.rs | 3 +++ 2 files changed, 59 insertions(+) create mode 100644 src/translations/it.rs diff --git a/src/translations/it.rs b/src/translations/it.rs new file mode 100644 index 0000000..cf495fb --- /dev/null +++ b/src/translations/it.rs @@ -0,0 +1,56 @@ +pub struct Italian; + +impl super::Translation for Italian { + fn help(&self) -> &'static str { + "Usage: \n \ + Se il tuo font ha già un file di configurazione:\n \ + bitmap_type_tracer \n\n \ + Se vuoi generare un file di configurazione: \n \ + bitmap_type_tracer [--top VALUE] [--bottom VALUE] [--left VALUE] [--right VALUE] [--threshold VALUE] [--save-json]\n \ + path_to_bitmap_font letteralmente il percorso per il bitmap.png che contiene i caratteri\n \ + sequence la sequenza di caratteri che vedi nel font bitmap es. 'ABCDEF...'\n \ + text il testo che vuoi scrivere con il font bitmap fornito\n \ + chars_per_row quanti caratteri ci sono in una riga nel font bitmap fornito\n \ + Margins: \n \ + --top VALUE il numero di pixel da ritagliare dalla parte superiore dell'immagine\n \ + --bottom VALUE il numero di pixel da ritagliare dalla parte inferiore dell'immagine\n \ + --left VALUE numero di pixel da ritagliare dalla parte sinistra dell'immagine\n \ + --right VALUE numero di pixel da ritagliare dalla parte destra dell'immagine\n \ + Other options: \n \ + --threshold VALUE il valore per determinare la soglia per rendere trasparente lo sfondo (0-255)\n \ + --save-json salva la configurazione in un file json\n \ + --help stampa questo messaggio di aiuto\n \ + --version stampa la versione del programma\n\n \ + Per esempi di utilizzo consulta il README.md nel repository \n" + } + fn version(&self) -> &'static str {env!("CARGO_PKG_VERSION")} + fn repository(&self) -> &'static str {env!("CARGO_PKG_REPOSITORY")} + fn name(&self) -> &'static str {env!("CARGO_PKG_NAME")} + fn author(&self) -> &'static str {env!("CARGO_PKG_AUTHORS")} + fn full_help(&self) -> String { + format!( + "{} by {}\nVersion: {}\nRepository: {}\n{}", + self.name(), self.author(), self.version(), self.repository(), self.help() + ) + } + fn character_not_found(&self, character: char) -> String { + format!("Carattere '{}' non trovato nella sequenza. Si tenta di utilizzare il colore di sfondo in alternativa.", character) + } + + fn err_invalid_num_of_chars(&self) -> &'static str {"Devi fornire un numero valido di caratteri per riga."} + fn err_invalid_threshold(&self) -> &'static str {"Devi fornire un valore di soglia valido (0-255)."} + fn err_invalid_left_margin(&self) -> &'static str {"Lettura del margine sinistro non riuscita. Si prega di fornire un valore valido."} + fn err_invalid_right_margin(&self) -> &'static str {"Lettura del margine destro non riuscita. Si prega di fornire un valore valido."} + fn err_invalid_top_margin(&self) -> &'static str {"Lettura del margine superiore non riuscita. Si prega di fornire un valore valido."} + fn err_invalid_bottom_margin(&self) -> &'static str {"Lettura del margine inferiore non riuscita. Si prega di fornire un valore valido."} + + fn err_failed_to_read_config(&self) -> &'static str {"Lettura del file di configurazione del font (json) non riuscita."} + fn err_failed_to_parse_config(&self) -> &'static str {"Analisi del file di configurazione del font (json) non riuscita."} + fn err_failed_to_open_config(&self) -> &'static str {"Apertura del file di configurazione del font (json) non riuscita."} + fn err_failed_to_serialize_config(&self) -> &'static str {"Serializzazione del file di configurazione del font (json) non riuscita."} + fn err_failed_to_save_config(&self) -> &'static str {"Salvataggio del file di configurazione del font (json) non riuscito."} + fn err_invalid_font_path(&self) -> &'static str {"Percorso del font non valido"} + + fn err_failed_to_save_output_image(&self) -> &'static str {"Salvataggio dell'immagine di output non riuscito"} + fn err_failed_to_open_font_image(&self) -> &'static str {"Apertura dell'immagine del font non riuscita"} +} \ No newline at end of file diff --git a/src/translations/mod.rs b/src/translations/mod.rs index 8cab891..b79f135 100644 --- a/src/translations/mod.rs +++ b/src/translations/mod.rs @@ -1,14 +1,17 @@ use crate::translations::en::English; use crate::translations::tr::Turkish; +use crate::translations::it::Italian; mod en; mod tr; +mod it; pub fn get_translation_for_locale(locale: &str) -> Box { eprintln!("{}", locale); match locale { "tr" => Box::new(Turkish), + "it" => Box::new(Italian), // ... other locales "en" => Box::new(English), _ => Box::new(Turkish), From 21ae7f1d3b2b8141eae9e19e8b840cdf8ee3cc0b Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Mon, 30 Oct 2023 12:12:48 +0100 Subject: [PATCH 10/23] fixed translations - fixed detection of system language - split up "help" in translations --- src/image_processing.rs | 2 +- src/main.rs | 2 +- src/translations/en.rs | 66 +++++++++++++++++++++++++++-------------- src/translations/it.rs | 66 +++++++++++++++++++++++++++-------------- src/translations/mod.rs | 25 ++++++++++------ src/translations/tr.rs | 66 +++++++++++++++++++++++++++-------------- 6 files changed, 147 insertions(+), 80 deletions(-) diff --git a/src/image_processing.rs b/src/image_processing.rs index 32d80b4..d99f4d7 100644 --- a/src/image_processing.rs +++ b/src/image_processing.rs @@ -31,7 +31,7 @@ pub fn generate_image( idx ); } else if pos.is_none() { - eprintln!("{}", TRANSLATION.character_not_found(character)); + eprintln!("{}", TRANSLATION.warn_character_not_found(character)); fill_with_bg_color(&mut output_image, idx as u32 * char_width, 0, char_width, char_height); } } diff --git a/src/main.rs b/src/main.rs index 073f15a..b1064c8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ use crate::translations::Translation; use std::sync::Arc; static TRANSLATION: Lazy> = Lazy::new(|| { - let locale = Locale::user_default().to_string(); + let locale = Locale::user_default().to_string().split('-').next().unwrap().to_owned(); let boxed_translation = translations::get_translation_for_locale(&locale); Arc::from(boxed_translation) }); diff --git a/src/translations/en.rs b/src/translations/en.rs index 0e8dfd3..d1d662f 100644 --- a/src/translations/en.rs +++ b/src/translations/en.rs @@ -1,28 +1,48 @@ pub struct English; -impl super::Translation for English { - fn help(&self) -> &'static str { - "Usage: \n \ - If your font already has a configuration file: \n \ - bitmap_type_tracer \n\n \ - If you want to generate a configuration file: \n \ - bitmap_type_tracer [--top VALUE] [--bottom VALUE] [--left VALUE] [--right VALUE] [--threshold VALUE] [--save-json]\n \ - path_to_bitmap_font literally the path to the bitmap.png containing the characters\n \ - sequence the sequence of characters that you see in the bitmap font e.x 'ABCDEF...'\n \ - text the text you want to write with the provided bitmap font\n \ - chars_per_row how many characters are in a row in the provided bitmap font\n \ - Margins: \n \ - --top VALUE the number of pixels to crop from the top of the image\n \ - --bottom VALUE the number of pixels to crop from the bottom of the image\n \ - --left VALUE the number of pixels to crop from the left of the image\n \ - --right VALUE the number of pixels to crop from the right of the image\n \ - Other options: \n \ - --threshold VALUE the value to determine the threshold for making the background transparent (0-255)\n \ - --save-json save the configuration to a json file\n \ - --help print this help message\n \ - --version print the version of the program\n\n \ - For example usage check out the README.md in the repository \n" +impl super::Translation for English +{ + fn help_usage(&self) -> &'static str { + "Usage:\n\ + \u{20} If your font already has a configuration file: \n\ + \u{20} bitmap_type_tracer \n\n\ + \u{20} If you want to generate a configuration file: \n\ + \u{20} bitmap_type_tracer [--top VALUE] [--bottom VALUE] [--left VALUE] [--right VALUE] [--threshold VALUE] [--save-json]" } + + fn help_parameters(&self) -> &'static str { + "\n\ + \u{20}\u{20} path_to_bitmap_font literally the path to the bitmap.png containing the characters\n\ + \u{20}\u{20} sequence the sequence of characters that you see in the bitmap font e.x 'ABCDEF...'\n\ + \u{20}\u{20} text the text you want to write with the provided bitmap font\n\ + \u{20}\u{20} chars_per_row how many characters are in a row in the provided bitmap font\n" + } + + fn help_margins(&self) -> &'static str { + "Margins:\n\ + \u{20}\u{20} --top VALUE the number of pixels to crop from the top of the image\n\ + \u{20}\u{20} --bottom VALUE the number of pixels to crop from the bottom of the image\n\ + \u{20}\u{20} --left VALUE the number of pixels to crop from the left of the image\n\ + \u{20}\u{20} --right VALUE the number of pixels to crop from the right of the image" + } + + fn help_other_options(&self) -> &'static str { + "Other options:\n\ + \u{20}\u{20} --threshold VALUE the value to determine the threshold for making the background transparent (0-255)\n\ + \u{20}\u{20} --save-json save the configuration to a json file\n\ + \u{20}\u{20} --help print this help message\n\ + \u{20}\u{20} --version print the version of the program" + } + + fn help_example_usage(&self) -> &'static str {"For examples usage check out the README.md in the repository"} + + fn help(&self) -> String { + format!( + "{}\n\n{}\n\n{}\n\n{}\n", + self.help_usage(), self.help_margins(), self.help_other_options(), self.help_example_usage() + ) + } + fn version(&self) -> &'static str {env!("CARGO_PKG_VERSION")} fn repository(&self) -> &'static str {env!("CARGO_PKG_REPOSITORY")} fn name(&self) -> &'static str {env!("CARGO_PKG_NAME")} @@ -33,7 +53,7 @@ impl super::Translation for English { self.name(), self.author(), self.version(), self.repository(), self.help() ) } - fn character_not_found(&self, character: char) -> String { + fn warn_character_not_found(&self, character: char) -> String { format!("Character '{}' not found in sequence. Trying to use the background-color instead.", character) } diff --git a/src/translations/it.rs b/src/translations/it.rs index cf495fb..86e01d9 100644 --- a/src/translations/it.rs +++ b/src/translations/it.rs @@ -1,28 +1,48 @@ pub struct Italian; -impl super::Translation for Italian { - fn help(&self) -> &'static str { - "Usage: \n \ - Se il tuo font ha già un file di configurazione:\n \ - bitmap_type_tracer \n\n \ - Se vuoi generare un file di configurazione: \n \ - bitmap_type_tracer [--top VALUE] [--bottom VALUE] [--left VALUE] [--right VALUE] [--threshold VALUE] [--save-json]\n \ - path_to_bitmap_font letteralmente il percorso per il bitmap.png che contiene i caratteri\n \ - sequence la sequenza di caratteri che vedi nel font bitmap es. 'ABCDEF...'\n \ - text il testo che vuoi scrivere con il font bitmap fornito\n \ - chars_per_row quanti caratteri ci sono in una riga nel font bitmap fornito\n \ - Margins: \n \ - --top VALUE il numero di pixel da ritagliare dalla parte superiore dell'immagine\n \ - --bottom VALUE il numero di pixel da ritagliare dalla parte inferiore dell'immagine\n \ - --left VALUE numero di pixel da ritagliare dalla parte sinistra dell'immagine\n \ - --right VALUE numero di pixel da ritagliare dalla parte destra dell'immagine\n \ - Other options: \n \ - --threshold VALUE il valore per determinare la soglia per rendere trasparente lo sfondo (0-255)\n \ - --save-json salva la configurazione in un file json\n \ - --help stampa questo messaggio di aiuto\n \ - --version stampa la versione del programma\n\n \ - Per esempi di utilizzo consulta il README.md nel repository \n" +impl super::Translation for Italian +{ + fn help_usage(&self) -> &'static str { + "Usage: \n\ + \u{20} Se il tuo font ha già un file di configurazione:\n + \u{20} bitmap_type_tracer \n\n\ + \u{20} Se vuoi generare un file di configurazione:\n\ + \u{20} bitmap_type_tracer [--top VALUE] [--bottom VALUE] [--left VALUE] [--right VALUE] [--threshold VALUE] [--save-json]" } + + fn help_parameters(&self) -> &'static str { + "\n\ + \u{20}\u{20} path_to_bitmap_font letteralmente il percorso per il bitmap.png che contiene i caratteri\n\ + \u{20}\u{20} sequence la sequenza di caratteri che vedi nel font bitmap es. 'ABCDEF...'\n\ + \u{20}\u{20} text il testo che vuoi scrivere con il font bitmap fornito\n\ + \u{20}\u{20} chars_per_row quanti caratteri ci sono in una riga nel font bitmap fornito\n" + } + + fn help_margins(&self) -> &'static str { + "Margins:\n\ + \u{20}\u{20} --top VALUE il numero di pixel da ritagliare dalla parte superiore dell'immagine\n\ + \u{20}\u{20} --bottom VALUE il numero di pixel da ritagliare dalla parte inferiore dell'immagine\n\ + \u{20}\u{20} --left VALUE numero di pixel da ritagliare dalla parte sinistra dell'immagine\n\ + \u{20}\u{20} --right VALUE numero di pixel da ritagliare dalla parte destra dell'immagine" + } + + fn help_other_options(&self) -> &'static str { + "Other options:\n\ + \u{20}\u{20} --threshold VALUE il valore per determinare la soglia per rendere trasparente lo sfondo (0-255)\n\ + \u{20}\u{20} --save-json salva la configurazione in un file json\n\ + \u{20}\u{20} --help stampa questo messaggio di aiuto\n\ + \u{20}\u{20} --version stampa la versione del programma" + } + + fn help_example_usage(&self) -> &'static str {"Per esempi di utilizzo consulta il README.md nel repository"} + + fn help(&self) -> String { + format!( + "{}\n\n{}\n\n{}\n\n{}\n", + self.help_usage(), self.help_margins(), self.help_other_options(), self.help_example_usage() + ) + } + fn version(&self) -> &'static str {env!("CARGO_PKG_VERSION")} fn repository(&self) -> &'static str {env!("CARGO_PKG_REPOSITORY")} fn name(&self) -> &'static str {env!("CARGO_PKG_NAME")} @@ -33,7 +53,7 @@ impl super::Translation for Italian { self.name(), self.author(), self.version(), self.repository(), self.help() ) } - fn character_not_found(&self, character: char) -> String { + fn warn_character_not_found(&self, character: char) -> String { format!("Carattere '{}' non trovato nella sequenza. Si tenta di utilizzare il colore di sfondo in alternativa.", character) } diff --git a/src/translations/mod.rs b/src/translations/mod.rs index b79f135..8b46a62 100644 --- a/src/translations/mod.rs +++ b/src/translations/mod.rs @@ -1,32 +1,39 @@ -use crate::translations::en::English; -use crate::translations::tr::Turkish; -use crate::translations::it::Italian; +use crate::translations::{ + tr::Turkish, + en::English, + it::Italian +}; mod en; mod tr; mod it; pub fn get_translation_for_locale(locale: &str) -> Box { - eprintln!("{}", locale); - match locale { "tr" => Box::new(Turkish), "it" => Box::new(Italian), - // ... other locales "en" => Box::new(English), - _ => Box::new(Turkish), + _ => Box::new(English), } } pub trait Translation : Send + Sync { - fn help(&self) -> &'static str; + fn help_example_usage(&self) -> &'static str; + fn help_other_options(&self) -> &'static str; + fn help_parameters(&self) -> &'static str; + fn help_margins(&self) -> &'static str; + fn help_usage(&self) -> &'static str; + + fn help(&self) -> String; + fn version(&self) -> &'static str; fn repository(&self) -> &'static str; fn name(&self) -> &'static str; fn author(&self) -> &'static str; + fn full_help(&self) -> String; - fn character_not_found(&self, character: char) -> String; + fn warn_character_not_found(&self, character: char) -> String; fn err_invalid_num_of_chars(&self) -> &'static str; fn err_invalid_threshold(&self) -> &'static str; fn err_invalid_left_margin(&self) -> &'static str; diff --git a/src/translations/tr.rs b/src/translations/tr.rs index 063fd85..ce3972e 100644 --- a/src/translations/tr.rs +++ b/src/translations/tr.rs @@ -1,28 +1,48 @@ pub struct Turkish; -impl super::Translation for Turkish { - fn help(&self) -> &'static str { - "Usage: \n \ - Yazı tipinizde zaten bir yapılandırma dosyası varsa:\n \ - bitmap_type_tracer \n\n \ - Bir yapılandırma dosyası oluşturmak istiyorsanız: \n \ - bitmap_type_tracer [--top VALUE] [--bottom VALUE] [--left VALUE] [--right VALUE] [--threshold VALUE] [--save-json]\n \ - path_to_bitmap_font karakterleri içeren bitmap.png dosyasının yolu\n \ - sequence bit eşlem yazı tipinde gördüğünüz karakter dizisi, örneğin 'ABCÇDEF...'\n \ - text bitmap yazı tipiyle yazmak istediğiniz metin\n \ - chars_per_row bitmap yazı tipinde bir satırda kaç karakter olduğunu\n \ - Margins: \n \ - --top VALUE görüntünün üst kısmından kırpılacak piksel sayısı\n \ - --bottom VALUE görüntünün alt kısmından kırpılacak piksel sayısı\n \ - --left VALUE görüntünün solundan kırpılacak piksel sayısı\n \ - --right VALUE görüntünün sağından kırpılacak piksel sayısı\n \ - Other options: \n \ - --threshold VALUE arka planı saydam hale getirmeye yönelik eşiği belirleyen değer (0-255)\n \ - --save-json yapılandırmayı json dosyasına kaydedin\n \ - --help yardım mesajını yazdır\n \ - --version programın sürümünü yazdır\n\n \ - Nasıl kullanıldığını öğrenmek için README.md dosyasını okuyun. \n" +impl super::Translation for Turkish +{ + fn help_usage(&self) -> &'static str { + "Usage:\n\ + \u{20} Yazı tipinizde zaten bir yapılandırma dosyası varsa: \n\ + \u{20} bitmap_type_tracer \n\n\ + \u{20} Bir yapılandırma dosyası oluşturmak istiyorsanız:\n\ + \u{20} bitmap_type_tracer [--top VALUE] [--bottom VALUE] [--left VALUE] [--right VALUE] [--threshold VALUE] [--save-json]" } + + fn help_parameters(&self) -> &'static str { + "\n\ + \u{20}\u{20} path_to_bitmap_font karakterleri içeren bitmap.png dosyasının yolu\n\ + \u{20}\u{20} sequence bit eşlem yazı tipinde gördüğünüz karakter dizisi, örneğin 'ABCÇDEF...'\n\ + \u{20}\u{20} text bitmap yazı tipiyle yazmak istediğiniz metin\n\ + \u{20}\u{20} chars_per_row bitmap yazı tipinde bir satırda kaç karakter olduğunu\n" + } + + fn help_margins(&self) -> &'static str { + "Margins:\n\ + \u{20}\u{20} --top VALUE örüntünün üst kısmından kırpılacak piksel sayısı\n\ + \u{20}\u{20} --bottom VALUE örüntünün alt kısmından kırpılacak piksel sayısı\n\ + \u{20}\u{20} --left VALUE görüntünün solundan kırpılacak piksel sayısı\n\ + \u{20}\u{20} --right VALUE görüntünün sağından kırpılacak piksel sayısı" + } + + fn help_other_options(&self) -> &'static str { + "Other options:\n\ + \u{20}\u{20} --threshold VALUE arka planı saydam hale getirmeye yönelik eşiği belirleyen değer (0-255)\n\ + \u{20}\u{20} --save-json yapılandırmayı json dosyasına kaydedin\n\ + \u{20}\u{20} --help yardım mesajını yazdır\n\ + \u{20}\u{20} --version programın sürümünü yazdır" + } + + fn help_example_usage(&self) -> &'static str {"Nasıl kullanıldığını öğrenmek için README.md dosyasını okuyun"} + + fn help(&self) -> String { + format!( + "{}\n\n{}\n\n{}\n\n{}\n", + self.help_usage(), self.help_margins(), self.help_other_options(), self.help_example_usage() + ) + } + fn version(&self) -> &'static str {env!("CARGO_PKG_VERSION")} fn repository(&self) -> &'static str {env!("CARGO_PKG_REPOSITORY")} fn name(&self) -> &'static str {env!("CARGO_PKG_NAME")} @@ -33,7 +53,7 @@ impl super::Translation for Turkish { self.name(), self.author(), self.version(), self.repository(), self.help() ) } - fn character_not_found(&self, character: char) -> String { + fn warn_character_not_found(&self, character: char) -> String { format!("Karakter '{}' bulunamadı. Onun yerine arka plan rengini kullanıyoruz.", character) } From deae672f11b95f333e29235bef57dd281c410c74 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Mon, 30 Oct 2023 12:18:08 +0100 Subject: [PATCH 11/23] added author --- src/translations/en.rs | 4 ++++ src/translations/it.rs | 4 ++++ src/translations/tr.rs | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/src/translations/en.rs b/src/translations/en.rs index d1d662f..e916f46 100644 --- a/src/translations/en.rs +++ b/src/translations/en.rs @@ -1,5 +1,9 @@ pub struct English; +/* + * Author: Anatolij "tolik518" Vasilev + * Created: 2023-10-26 + */ impl super::Translation for English { fn help_usage(&self) -> &'static str { diff --git a/src/translations/it.rs b/src/translations/it.rs index 86e01d9..c3213bb 100644 --- a/src/translations/it.rs +++ b/src/translations/it.rs @@ -1,5 +1,9 @@ pub struct Italian; +/* + * Author: Mattia "Tizzz-555" Beccari + * Created: 2023-10-29 + */ impl super::Translation for Italian { fn help_usage(&self) -> &'static str { diff --git a/src/translations/tr.rs b/src/translations/tr.rs index ce3972e..d29848a 100644 --- a/src/translations/tr.rs +++ b/src/translations/tr.rs @@ -1,5 +1,9 @@ pub struct Turkish; +/* + * Author: ARDA KÖLEMENOĞLU + * Created: 2023-10-28 + */ impl super::Translation for Turkish { fn help_usage(&self) -> &'static str { From 36ae203be3bbd37b0541a6f29bead7356cb0585d Mon Sep 17 00:00:00 2001 From: Apoorv <103172763+Sam654123@users.noreply.github.com> Date: Mon, 30 Oct 2023 21:21:03 +0530 Subject: [PATCH 12/23] Create fr.rs for French translation --- src/translations/fr.rs | 80 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/translations/fr.rs diff --git a/src/translations/fr.rs b/src/translations/fr.rs new file mode 100644 index 0000000..31e61da --- /dev/null +++ b/src/translations/fr.rs @@ -0,0 +1,80 @@ +pub struct French; + +/* + * Author: Apoorv "Sam654123" + * Created: 2023-10-30 + */ +impl super::Translation for French +{ + fn help_usage(&self) -> &'static str { + "Usage:\n\ + \u{20} Si votre police possède déjà un fichier de configuration : \n\ + \u{20} bitmap_type_tracer \n\n\ + \u{20} Si vous souhaitez générer un fichier de configuration : \n\ + \u{20} bitmap_type_tracer [--top VALUE] [--bottom VALUE] [--left VALUE] [--right VALUE] [--threshold VALUE] [--save-json]" + } + + fn help_parameters(&self) -> &'static str { + "\n\ + \u{20}\u{20} path_to_bitmap_font littéralement le chemin vers le bitmap.png contenant les caractères\n\ + \u{20}\u{20} sequence la séquence de caractères que vous voyez dans la police bitmap e.x 'ABCDEF...'\n\ + \u{20}\u{20} text le texte que vous souhaitez écrire avec la police bitmap fournie\n\ + \u{20}\u{20} chars_per_row combien de caractères sont alignés dans la police bitmap fournie\n" + } + + fn help_margins(&self) -> &'static str { + "Margins:\n\ + \u{20}\u{20} --top VALUE le nombre de pixels à recadrer à partir du haut de l'image\n\ + \u{20}\u{20} --bottom VALUE le nombre de pixels à recadrer à partir du bas de l'image\n\ + \u{20}\u{20} --left VALUE le nombre de pixels à recadrer à gauche de l'image\n\ + \u{20}\u{20} --right VALUE le nombre de pixels à recadrer à droite de l'image" + } + + fn help_other_options(&self) -> &'static str { + "Other options:\n\ + \u{20}\u{20} --threshold VALUE la valeur pour déterminer le seuil de transparence du fond (0-255)\n\ + \u{20}\u{20} --save-json enregistrer la configuration dans un fichier json\n\ + \u{20}\u{20} --help imprimer ce message d'aide\n\ + \u{20}\u{20} --version imprimer la version du programme" + } + + fn help_example_usage(&self) -> &'static str {"Pour des exemples d'utilisation, consultez le README.md dans le référentiel"} + + fn help(&self) -> String { + format!( + "{}\n\n{}\n\n{}\n\n{}\n", + self.help_usage(), self.help_margins(), self.help_other_options(), self.help_example_usage() + ) + } + + fn version(&self) -> &'static str {env!("CARGO_PKG_VERSION")} + fn repository(&self) -> &'static str {env!("CARGO_PKG_REPOSITORY")} + fn name(&self) -> &'static str {env!("CARGO_PKG_NAME")} + fn author(&self) -> &'static str {env!("CARGO_PKG_AUTHORS")} + fn full_help(&self) -> String { + format!( + "{} by {}\nVersion: {}\nRepository: {}\n{}", + self.name(), self.author(), self.version(), self.repository(), self.help() + ) + } + fn warn_character_not_found(&self, character: char) -> String { + format!("Caractère '{}' introuvable dans la séquence. Essayer d'utiliser la couleur d'arrière-plan à la place.", character) + } + + fn err_invalid_num_of_chars(&self) -> &'static str {"Vous devez fournir un nombre valide de caractères par ligne."} + fn err_invalid_threshold(&self) -> &'static str {"Vous devez fournir une valeur seuil valide (0-255)."} + fn err_invalid_left_margin(&self) -> &'static str {"Échec de la lecture de l'argument de la marge gauche. Veuillez fournir une valeur valide."} + fn err_invalid_right_margin(&self) -> &'static str {"Échec de la lecture de l'argument de marge correct. Veuillez fournir une valeur valide."} + fn err_invalid_top_margin(&self) -> &'static str {"Échec de la lecture de l'argument de la marge supérieure. Veuillez fournir une valeur valide."} + fn err_invalid_bottom_margin(&self) -> &'static str {"Échec de la lecture de l'argument de la marge inférieure. Veuillez fournir une valeur valide."} + + fn err_failed_to_read_config(&self) -> &'static str {"Échec de la lecture du fichier de configuration de police (json)."} + fn err_failed_to_parse_config(&self) -> &'static str {"Échec de l'analyse du fichier de configuration de police (json)."} + fn err_failed_to_open_config(&self) -> &'static str {"Échec de l'ouverture du fichier de configuration de police (json)."} + fn err_failed_to_serialize_config(&self) -> &'static str {"Échec de la sérialisation du fichier de configuration de police (json)."} + fn err_failed_to_save_config(&self) -> &'static str {"Échec de l'enregistrement du fichier de configuration de police (json)."} + fn err_invalid_font_path(&self) -> &'static str {"Chemin de police invalide"} + + fn err_failed_to_save_output_image(&self) -> &'static str {"Échec de l'enregistrement de l'image de sortie"} + fn err_failed_to_open_font_image(&self) -> &'static str {"Échec de l'ouverture de l'image de la police"} +} From b10caba941edfe847e12e2e4c1d73e731cf1e283 Mon Sep 17 00:00:00 2001 From: Apoorv <103172763+Sam654123@users.noreply.github.com> Date: Mon, 30 Oct 2023 21:24:24 +0530 Subject: [PATCH 13/23] Update mod.rs added french --- src/translations/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/translations/mod.rs b/src/translations/mod.rs index 8b46a62..5a7d36a 100644 --- a/src/translations/mod.rs +++ b/src/translations/mod.rs @@ -1,15 +1,18 @@ use crate::translations::{ tr::Turkish, en::English, - it::Italian + it::Italian, + fr::French }; mod en; mod tr; mod it; +mod fr; pub fn get_translation_for_locale(locale: &str) -> Box { match locale { + "fr" => Box::new(French), "tr" => Box::new(Turkish), "it" => Box::new(Italian), "en" => Box::new(English), From ea98d0512f30fc2f26bb87087c5bf1c7d8917812 Mon Sep 17 00:00:00 2001 From: Apoorv <103172763+Sam654123@users.noreply.github.com> Date: Mon, 30 Oct 2023 21:33:34 +0530 Subject: [PATCH 14/23] Update fr.rs --- src/translations/fr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/translations/fr.rs b/src/translations/fr.rs index 31e61da..050773b 100644 --- a/src/translations/fr.rs +++ b/src/translations/fr.rs @@ -64,7 +64,7 @@ impl super::Translation for French fn err_invalid_num_of_chars(&self) -> &'static str {"Vous devez fournir un nombre valide de caractères par ligne."} fn err_invalid_threshold(&self) -> &'static str {"Vous devez fournir une valeur seuil valide (0-255)."} fn err_invalid_left_margin(&self) -> &'static str {"Échec de la lecture de l'argument de la marge gauche. Veuillez fournir une valeur valide."} - fn err_invalid_right_margin(&self) -> &'static str {"Échec de la lecture de l'argument de marge correct. Veuillez fournir une valeur valide."} + fn err_invalid_right_margin(&self) -> &'static str {"Échec de la lecture de l'argument de la marge droite. Veuillez fournir une valeur valide."} fn err_invalid_top_margin(&self) -> &'static str {"Échec de la lecture de l'argument de la marge supérieure. Veuillez fournir une valeur valide."} fn err_invalid_bottom_margin(&self) -> &'static str {"Échec de la lecture de l'argument de la marge inférieure. Veuillez fournir une valeur valide."} From e8dcef83a304e6d94a7ffb745e81522da8a64fd1 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Wed, 1 Nov 2023 21:14:31 +0100 Subject: [PATCH 15/23] language can be set with a --lang param --- README.md | 2 ++ src/main.rs | 20 +++++++++++++++++++- src/translations/en.rs | 5 +++-- src/translations/fr.rs | 3 ++- src/translations/it.rs | 3 ++- src/translations/tr.rs | 3 ++- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 67dc951..2c6819f 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,8 @@ This command will generate an image using a previously saved font configuration - `--save-json`: Save the provided configuration as a JSON file, making it easier to reuse in the future. +- `--lang en|it|fr|en`: Specify the language of the text. Default is en. + ## Modules - `main.rs`: The main driver of the application, handling command line arguments and invoking image generation. diff --git a/src/main.rs b/src/main.rs index b1064c8..11ddc41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,11 +10,17 @@ use image_processing::generate_image; use locale_config::Locale; use once_cell::sync::Lazy; +use once_cell::sync::OnceCell; use crate::translations::Translation; use std::sync::Arc; +static LANG_OVERRIDE: OnceCell> = OnceCell::new(); static TRANSLATION: Lazy> = Lazy::new(|| { - let locale = Locale::user_default().to_string().split('-').next().unwrap().to_owned(); + let locale = if let Some(override_lang) = LANG_OVERRIDE.get() { + override_lang.clone().unwrap_or("en".to_owned()) + } else { + Locale::user_default().to_string().split('-').next().unwrap_or("en").to_owned() + }; let boxed_translation = translations::get_translation_for_locale(&locale); Arc::from(boxed_translation) }); @@ -23,6 +29,18 @@ static TRANSLATION: Lazy> = Lazy::new(|| { fn main() { let args: Vec = env::args().collect(); + // Check for --lang argument and set it globally + let mut lang_override: Option = None; + + args.iter().enumerate().for_each(|(i, arg)| { + if arg == "--lang" && i + 1 < args.len() { + lang_override = Some(args[i + 1].clone()); + } + }); + + // Set the global LANG_OVERRIDE variable + let _ = LANG_OVERRIDE.set(lang_override); + if args.len() < 3 || args[1] == "--help" { eprintln!("{}", TRANSLATION.full_help()); return; diff --git a/src/translations/en.rs b/src/translations/en.rs index e916f46..ac580d8 100644 --- a/src/translations/en.rs +++ b/src/translations/en.rs @@ -11,7 +11,7 @@ impl super::Translation for English \u{20} If your font already has a configuration file: \n\ \u{20} bitmap_type_tracer \n\n\ \u{20} If you want to generate a configuration file: \n\ - \u{20} bitmap_type_tracer [--top VALUE] [--bottom VALUE] [--left VALUE] [--right VALUE] [--threshold VALUE] [--save-json]" + \u{20} bitmap_type_tracer [--top VALUE] [--bottom VALUE] [--left VALUE] [--right VALUE] [--threshold VALUE] [--save-json] [--lang en|it|fr|tr|...]" } fn help_parameters(&self) -> &'static str { @@ -35,7 +35,8 @@ impl super::Translation for English \u{20}\u{20} --threshold VALUE the value to determine the threshold for making the background transparent (0-255)\n\ \u{20}\u{20} --save-json save the configuration to a json file\n\ \u{20}\u{20} --help print this help message\n\ - \u{20}\u{20} --version print the version of the program" + \u{20}\u{20} --version print the version of the program\n\ + \u{20}\u{20} --lang Specify the language (en|it|fr|tr|...) of the application. Default is your system lang or en" } fn help_example_usage(&self) -> &'static str {"For examples usage check out the README.md in the repository"} diff --git a/src/translations/fr.rs b/src/translations/fr.rs index 050773b..5294041 100644 --- a/src/translations/fr.rs +++ b/src/translations/fr.rs @@ -35,7 +35,8 @@ impl super::Translation for French \u{20}\u{20} --threshold VALUE la valeur pour déterminer le seuil de transparence du fond (0-255)\n\ \u{20}\u{20} --save-json enregistrer la configuration dans un fichier json\n\ \u{20}\u{20} --help imprimer ce message d'aide\n\ - \u{20}\u{20} --version imprimer la version du programme" + \u{20}\u{20} --version imprimer la version du programme\n\ + \u{20}\u{20} --lang Specify the language (en|it|fr|tr|...) of the application. Default is your system lang or en" // needs translation } fn help_example_usage(&self) -> &'static str {"Pour des exemples d'utilisation, consultez le README.md dans le référentiel"} diff --git a/src/translations/it.rs b/src/translations/it.rs index c3213bb..0b9eb2a 100644 --- a/src/translations/it.rs +++ b/src/translations/it.rs @@ -35,7 +35,8 @@ impl super::Translation for Italian \u{20}\u{20} --threshold VALUE il valore per determinare la soglia per rendere trasparente lo sfondo (0-255)\n\ \u{20}\u{20} --save-json salva la configurazione in un file json\n\ \u{20}\u{20} --help stampa questo messaggio di aiuto\n\ - \u{20}\u{20} --version stampa la versione del programma" + \u{20}\u{20} --version stampa la versione del programma\n\ + \u{20}\u{20} --lang Specify the language (en|it|fr|tr|...) of the application. Default is your system lang or en" // needs translation } fn help_example_usage(&self) -> &'static str {"Per esempi di utilizzo consulta il README.md nel repository"} diff --git a/src/translations/tr.rs b/src/translations/tr.rs index d29848a..49010d8 100644 --- a/src/translations/tr.rs +++ b/src/translations/tr.rs @@ -35,7 +35,8 @@ impl super::Translation for Turkish \u{20}\u{20} --threshold VALUE arka planı saydam hale getirmeye yönelik eşiği belirleyen değer (0-255)\n\ \u{20}\u{20} --save-json yapılandırmayı json dosyasına kaydedin\n\ \u{20}\u{20} --help yardım mesajını yazdır\n\ - \u{20}\u{20} --version programın sürümünü yazdır" + \u{20}\u{20} --version programın sürümünü yazdır\n\ + \u{20}\u{20} --lang Specify the language (en|it|fr|tr|...) of the application. Default is your system lang or en" // needs translation } fn help_example_usage(&self) -> &'static str {"Nasıl kullanıldığını öğrenmek için README.md dosyasını okuyun"} From 978d8144345c6b09975d0f8580e953802b12b1c3 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Wed, 1 Nov 2023 21:14:49 +0100 Subject: [PATCH 16/23] added some comments to cargo --- Cargo.toml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9a6c406..3842a88 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,13 +20,14 @@ debug-assertions = false overflow-checks = false incremental = false opt-level = 3 -strip = true # Automatically strip symbols from the binary. -lto = true # Enable link-time optimization. +strip = true +lto = true [dependencies] -image = "0.23.14" -serde = { version = "1.0", features = [] } -serde_json = "1.0" -serde_derive = { version = "1.0", features = [] } -locale_config = "0.3" -once_cell = { version = "1.8", features = [] } +image = "0.23.14" # Image processing +serde = { version = "1.0", features = [] } # Serialization +serde_json = "1.0" # JSON +serde_derive = { version = "1.0", features = [] } # Serialization +locale_config = "0.3" # System locale +once_cell = { version = "1.8", features = [] } # Lazy statics + From d48f3130fd533e7566330c60761b0dc68d05d7d0 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Wed, 1 Nov 2023 21:20:06 +0100 Subject: [PATCH 17/23] moved generated example files to an extra folder --- README.md | 18 +++++++++--------- .../4138906397_0dc616813b_o.png_tolik518.png | Bin .../4138906425_29cbc92641_o.png_tolik518.png | Bin .../{ => outputs}/FONT34.png_tolik518.png | Bin examples/{ => outputs}/MEGAD.png_tolik518.png | Bin .../{ => outputs}/MEGAD2.png_tolik518.png | Bin .../{ => outputs}/font228.png_tolik518.png | Bin .../{ => outputs}/font239r.png_tolik518.png | Bin .../{ => outputs}/font244r.png_tolik518.png | Bin .../{ => outputs}/font248r.png_tolik518.png | Bin 10 files changed, 9 insertions(+), 9 deletions(-) rename examples/{ => outputs}/4138906397_0dc616813b_o.png_tolik518.png (100%) rename examples/{ => outputs}/4138906425_29cbc92641_o.png_tolik518.png (100%) rename examples/{ => outputs}/FONT34.png_tolik518.png (100%) rename examples/{ => outputs}/MEGAD.png_tolik518.png (100%) rename examples/{ => outputs}/MEGAD2.png_tolik518.png (100%) rename examples/{ => outputs}/font228.png_tolik518.png (100%) rename examples/{ => outputs}/font239r.png_tolik518.png (100%) rename examples/{ => outputs}/font244r.png_tolik518.png (100%) rename examples/{ => outputs}/font248r.png_tolik518.png (100%) diff --git a/README.md b/README.md index 2c6819f..8e732e3 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ _/examples/4138906397_0dc616813b_o.png_ ```bash bitmap_type_tracer examples/4138906397_0dc616813b_o.png " \!\" '()*+,-.\\0123456789:; = ? ABCDEFGHIJKLMNOPQRSTUVWXYZ " tolik518 10 ``` -![](./examples/4138906397_0dc616813b_o.png_tolik518.png) +![](examples/outputs/4138906397_0dc616813b_o.png_tolik518.png) --------------------------------------- @@ -100,7 +100,7 @@ _/examples/4138906425_29cbc92641_o.png_ ```bash bitmap_type_tracer examples/4138906425_29cbc92641_o.png " \!\" '()*+,-.\\0123456789:; = ? ABCDEFGHIJKLMNOPQRSTUVWXYZ " tolik518 10 ``` -![](./examples/4138906425_29cbc92641_o.png_tolik518.png) +![](examples/outputs/4138906425_29cbc92641_o.png_tolik518.png) --------------------------------------- @@ -109,7 +109,7 @@ _/examples/FONT34.png_ ```bash bitmap_type_tracer examples/FONT34.png " \! () , . 0123456789:; - ? ABCDEFGHIJKLMNOPQRSTUVWXYZ " tolik518 20 --bottom 150 --threshold 20 ``` -![](./examples/FONT34.png_tolik518.png) +![](examples/outputs/FONT34.png_tolik518.png) --------------------------------------- @@ -120,7 +120,7 @@ bitmap_type_tracer examples/font228.png "ABCDEFGHIJKLMNOPQRSTUVWXYZ>.: " tolik51 ``` Since the number are missing from the sequence, they are not generated in the image and it tries to fill the space with the background. The background was not recognized properly, so it was filled with the brown instead of black. -![](./examples/font228.png_tolik518.png) +![](examples/outputs/font228.png_tolik518.png) --------------------------------------- @@ -130,7 +130,7 @@ _/examples/font239r.png_ bitmap_type_tracer examples/font239r.png "ABCDEFGHIJKLMNOPQRSTUVWXYZ()\!?.,’ " tolik518 7 --bottom 4 --threshold 1 ``` Since the number are missing from the sequence, they are not generated in the image and it tries to fill the space with the background, but the threshold is set to 1, so it doesn't fill the space with the transparent background since it recognized the black background. -![](./examples/font239r.png_tolik518.png) +![](examples/outputs/font239r.png_tolik518.png) --------------------------------------- @@ -140,7 +140,7 @@ _/examples/font244r.png_ bitmap_type_tracer examples/font244r.png "ALW6BMX7CNY8DOZ9EP*\!FQ0?GR1.HS2 IT3 JU4 KV5 " tolik518 4 --threshold 30 ``` We needed a threshold of 30 to remove the black background. -![](./examples/font244r.png_tolik518.png) +![](examples/outputs/font244r.png_tolik518.png) --------------------------------------- @@ -150,7 +150,7 @@ _/examples/font248r.png_ bitmap_type_tracer examples/font248r.png "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 \!?." tolik518 20 --threshold 60 ``` To have a better result, we needed a threshold of 60 to remove the black background. -![](./examples/font248r.png_tolik518.png) +![](examples/outputs/font248r.png_tolik518.png) --------------------------------------- @@ -160,7 +160,7 @@ _/examples/MEGAD.png_ bitmap_type_tracer examples/MEGAD.png "'() +,-. 0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ ! =? " tolik518 10 --bottom 10 --threshold 1 ``` In this example, we needed to add a bottom margin of 10 for the characters to align properly. -![](./examples/MEGAD.png_tolik518.png) +![](examples/outputs/MEGAD.png_tolik518.png) --------------------------------------- @@ -169,7 +169,7 @@ _/examples/MEGAD2.png_ ```bash bitmap_type_tracer examples/MEGAD2.png "AGMSY+:4BHNTZ\!;5CIOU.?06DJPV;(17EKQW\")28FLRX-'39" tolik518 8 --bottom 3 --threshold 1 ``` -![](./examples/MEGAD2.png_tolik518.png) +![](examples/outputs/MEGAD2.png_tolik518.png) ## Contributions diff --git a/examples/4138906397_0dc616813b_o.png_tolik518.png b/examples/outputs/4138906397_0dc616813b_o.png_tolik518.png similarity index 100% rename from examples/4138906397_0dc616813b_o.png_tolik518.png rename to examples/outputs/4138906397_0dc616813b_o.png_tolik518.png diff --git a/examples/4138906425_29cbc92641_o.png_tolik518.png b/examples/outputs/4138906425_29cbc92641_o.png_tolik518.png similarity index 100% rename from examples/4138906425_29cbc92641_o.png_tolik518.png rename to examples/outputs/4138906425_29cbc92641_o.png_tolik518.png diff --git a/examples/FONT34.png_tolik518.png b/examples/outputs/FONT34.png_tolik518.png similarity index 100% rename from examples/FONT34.png_tolik518.png rename to examples/outputs/FONT34.png_tolik518.png diff --git a/examples/MEGAD.png_tolik518.png b/examples/outputs/MEGAD.png_tolik518.png similarity index 100% rename from examples/MEGAD.png_tolik518.png rename to examples/outputs/MEGAD.png_tolik518.png diff --git a/examples/MEGAD2.png_tolik518.png b/examples/outputs/MEGAD2.png_tolik518.png similarity index 100% rename from examples/MEGAD2.png_tolik518.png rename to examples/outputs/MEGAD2.png_tolik518.png diff --git a/examples/font228.png_tolik518.png b/examples/outputs/font228.png_tolik518.png similarity index 100% rename from examples/font228.png_tolik518.png rename to examples/outputs/font228.png_tolik518.png diff --git a/examples/font239r.png_tolik518.png b/examples/outputs/font239r.png_tolik518.png similarity index 100% rename from examples/font239r.png_tolik518.png rename to examples/outputs/font239r.png_tolik518.png diff --git a/examples/font244r.png_tolik518.png b/examples/outputs/font244r.png_tolik518.png similarity index 100% rename from examples/font244r.png_tolik518.png rename to examples/outputs/font244r.png_tolik518.png diff --git a/examples/font248r.png_tolik518.png b/examples/outputs/font248r.png_tolik518.png similarity index 100% rename from examples/font248r.png_tolik518.png rename to examples/outputs/font248r.png_tolik518.png From c807e784be49a22104b285a54ebb3a1f2088862f Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Wed, 1 Nov 2023 21:20:49 +0100 Subject: [PATCH 18/23] print --help and --version to stdout instead of stderr --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 11ddc41..f411080 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,12 +42,12 @@ fn main() { let _ = LANG_OVERRIDE.set(lang_override); if args.len() < 3 || args[1] == "--help" { - eprintln!("{}", TRANSLATION.full_help()); + println!("{}", TRANSLATION.full_help()); return; } if args.len() < 3 || args[1] == "--version" { - eprintln!("{}", TRANSLATION.version()); + println!("{}", TRANSLATION.version()); return; } From 67d6a92cde6d501e90bf590232ae4119033b5099 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Wed, 1 Nov 2023 21:26:57 +0100 Subject: [PATCH 19/23] updated readme with rust love --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e732e3..cc6a767 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,14 @@ +

+ # ![bitmap_type_tracer](./logo.png) ![Crates.io](https://img.shields.io/crates/v/bitmap_type_tracer) ![Crates.io](https://img.shields.io/crates/d/bitmap_type_tracer) +![GitHub issues](https://img.shields.io/github/issues/tolik518/bitmap_type_tracer) +![GitHub pull requests](https://img.shields.io/github/issues-pr/tolik518/bitmap_type_tracer) + +`bitmap_type_tracer` is a utility tool, written in Rust, for generating text-images using a provided bitmap-font (and a set of configuration parameters). -`bitmap_type_tracer` is a utility tool for generating text-images using a provided bitmap-font (and a set of configuration parameters). +

## Features - Generate images from a font bitmap using a custom sequence and text. @@ -175,3 +181,9 @@ bitmap_type_tracer examples/MEGAD2.png "AGMSY+:4BHNTZ\!;5CIOU.?06DJPV;(17EKQW\") ## Contributions Feel free to contribute by opening issues or pull requests. All feedback is welcome! + +

+ +![Rust love](https://www.gstatic.com/android/keyboard/emojikitchen/20220506/u1f498/u1f498_u1f980.png) + +

\ No newline at end of file From d2a66d11752f789d211a4865e315281680fcb7e2 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Wed, 1 Nov 2023 21:30:02 +0100 Subject: [PATCH 20/23] fixed readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cc6a767..95c3fd6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -

+

# ![bitmap_type_tracer](./logo.png) ![Crates.io](https://img.shields.io/crates/v/bitmap_type_tracer) @@ -8,7 +8,7 @@ `bitmap_type_tracer` is a utility tool, written in Rust, for generating text-images using a provided bitmap-font (and a set of configuration parameters). -

+
## Features - Generate images from a font bitmap using a custom sequence and text. @@ -182,8 +182,8 @@ bitmap_type_tracer examples/MEGAD2.png "AGMSY+:4BHNTZ\!;5CIOU.?06DJPV;(17EKQW\") Feel free to contribute by opening issues or pull requests. All feedback is welcome! -

+

![Rust love](https://www.gstatic.com/android/keyboard/emojikitchen/20220506/u1f498/u1f498_u1f980.png) -

\ No newline at end of file +
\ No newline at end of file From b9012c029372dd6148ca923fec2c4951ae6547cf Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Wed, 1 Nov 2023 21:32:16 +0100 Subject: [PATCH 21/23] updated the part about --lang --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 95c3fd6..84fa38c 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ This command will generate an image using a previously saved font configuration - `--save-json`: Save the provided configuration as a JSON file, making it easier to reuse in the future. -- `--lang en|it|fr|en`: Specify the language of the text. Default is en. +- `--lang en|it|fr|en`: Specify the language of the text. Default is your System language if supported, otherwise its set to en. ## Modules From b5c227ef42f87b91ad147b20bb4dc1f4bf5f3e67 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Wed, 1 Nov 2023 21:51:13 +0100 Subject: [PATCH 22/23] fixed lang not working when using config --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index f411080..ff0b62d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,7 +39,7 @@ fn main() { }); // Set the global LANG_OVERRIDE variable - let _ = LANG_OVERRIDE.set(lang_override); + let _ = LANG_OVERRIDE.set(lang_override.clone()); if args.len() < 3 || args[1] == "--help" { println!("{}", TRANSLATION.full_help()); @@ -51,7 +51,7 @@ fn main() { return; } - if args.len() == 3 { // If only font and text are provided + if args.len() == 3 || (args.len() == 5 && lang_override.is_some()) { // If only font and text are provided | lang override generate_image_from_config(&args) } else { generate_image_from_args(&args); From c4fd8764a10a86a5e699f9ccbae78cdb7968c663 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Wed, 1 Nov 2023 22:13:50 +0100 Subject: [PATCH 23/23] added allow clippy::too_many_arguments --- src/image_processing.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/image_processing.rs b/src/image_processing.rs index d99f4d7..7f04a2c 100644 --- a/src/image_processing.rs +++ b/src/image_processing.rs @@ -63,6 +63,7 @@ fn find_character_position(character: char, sequence: &str) -> Option { pos } +#[allow(clippy::too_many_arguments)] fn copy_character_to_output( font_image: &image::DynamicImage, output_image: &mut ImageBuffer, Vec>,