From 0085199914f64098dc3b93d31d2a3980d99bd587 Mon Sep 17 00:00:00 2001 From: Vladimir Serov Date: Sun, 9 Feb 2020 15:51:37 +0300 Subject: [PATCH 01/16] utf-8: initial support --- src/render/utf8.rs | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/render/utf8.rs diff --git a/src/render/utf8.rs b/src/render/utf8.rs new file mode 100644 index 0000000..c01aaf7 --- /dev/null +++ b/src/render/utf8.rs @@ -0,0 +1,74 @@ +//! UTF-8 rendering, with 2 pixels per symbol. + +use crate::render::{Canvas as RenderCanvas, Pixel, Color}; + +impl Pixel for u8 { + type Image = String; + type Canvas = Canvas; + fn default_color(color: Color) -> u8 {if color == Color::Dark {1} else {0}} + fn default_unit_size() -> (u32, u32) { (1, 1) } +} + +pub struct Canvas { + canvas: Vec, + width: u32, + dark_pixel: u8 +} + +impl RenderCanvas for Canvas { + + type Pixel = u8; + type Image = String; + + + fn new(width: u32, height: u32, dark_pixel: u8, light_pixel: u8) -> Self { + let a = vec![light_pixel; (width * height) as usize]; + Canvas { + width: width, + canvas: a, + dark_pixel: dark_pixel + } + } + + fn draw_dark_pixel(&mut self, x: u32, y: u32) { + self.canvas[(x + y * self.width) as usize] = self.dark_pixel; + } + + fn into_image(self) -> String { + self.canvas + // Chopping array into 1-line sized fragments + .chunks_exact(self.width as usize) + .collect::>() + // And then glueing every 2 lines. + .chunks(2) + .map(|rows| + { + // Then zipping those 2 lines together into a single 2-bit number list. + if rows.len() == 2 { + rows[0].iter().zip(rows[1]).map(|(top,bot)| (top * 2 + bot)).collect::>() + } else { + rows[0].iter().map(|a| (a * 2)).collect::>() + } + }.iter() + // Mapping those 2-bit numbers to corresponding pixels. + .map(|sym| [" ","\u{2584}","\u{2580}","\u{2588}"][*sym as usize]) + .collect::>() + .concat() + ) + .collect::>() + .join("\n") + } +} + +#[test] +fn test_render_to_utf8_string() { + use crate::render::Renderer; + let colors = &[Color::Dark, Color::Light, Color::Light, Color::Dark]; + let image: String = Renderer::::new(colors, 2, 1).build(); + + assert_eq!(&image, " ▄ \n ▀ "); + + let image2 = Renderer::::new(colors, 2, 1).module_dimensions(2, 2).build(); + + assert_eq!(&image2, " \n ██ \n ██ \n "); +} From d8262b278ac3fc615d4d271f014ea1b631a95f4a Mon Sep 17 00:00:00 2001 From: Vladimir Serov Date: Sun, 9 Feb 2020 16:04:45 +0300 Subject: [PATCH 02/16] utf-8: included into mod.rs --- src/render/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/render/mod.rs b/src/render/mod.rs index ab5e71c..3915661 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -7,6 +7,7 @@ use std::cmp::max; pub mod image; pub mod string; pub mod svg; +pub mod utf8; //------------------------------------------------------------------------------ //{{{ Pixel trait From fdc37548f55f5d74f0a9095c76a50136f6b02822 Mon Sep 17 00:00:00 2001 From: Vladimir Serov Date: Sun, 9 Feb 2020 16:24:59 +0300 Subject: [PATCH 03/16] utf-8: added README section --- README.md | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e075f7b..7138798 100644 --- a/README.md +++ b/README.md @@ -108,4 +108,39 @@ fn main() { Generates this SVG: -[![Output](src/test_annex_i_micro_qr_as_svg.svg)](src/test_annex_i_micro_qr_as_svg.svg) \ No newline at end of file +[![Output](src/test_annex_i_micro_qr_as_svg.svg)](src/test_annex_i_micro_qr_as_svg.svg) + +## Unicode string generation + +```rust +use qrcode::QrCode; + +fn main() { + let code = QrCode::new("mow mow").unwrap(); + let image = code.render::() + .dark_color(0) + .light_color(1) + .build(); + println!("{}", image); +} +``` + +Generates this output: + +``` +█████████████████████████████ +█████████████████████████████ +████ ▄▄▄▄▄ █ ▀▀▀▄█ ▄▄▄▄▄ ████ +████ █ █ █▀ ▀ ▀█ █ █ ████ +████ █▄▄▄█ ██▄ ▀█ █▄▄▄█ ████ +████▄▄▄▄▄▄▄█ ▀▄▀ █▄▄▄▄▄▄▄████ +████▄▀ ▄▀ ▄ █▄█ ▀ ▀█ █▄ ████ +████▄██▄▄▀▄▄▀█▄ ██▀▀█▀▄▄▄████ +█████▄▄▄█▄▄█ ▀▀▄█▀▀▀▄█▄▄████ +████ ▄▄▄▄▄ █ ▄▄██▄ ▄ ▀▀████ +████ █ █ █▀▄▄▀▄▄ ▄▄▄▄ ▄████ +████ █▄▄▄█ █▄ █▄▀▄▀██▄█▀████ +████▄▄▄▄▄▄▄█▄████▄█▄██▄██████ +█████████████████████████████ +▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ +``` \ No newline at end of file From d5a27c99e68eef8e7afe8eb208ab4c8bebf9e47b Mon Sep 17 00:00:00 2001 From: Vladimir Serov Date: Sun, 9 Feb 2020 17:31:10 +0300 Subject: [PATCH 04/16] utf-8: better variable name for lambda --- src/render/utf8.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/render/utf8.rs b/src/render/utf8.rs index c01aaf7..d48587f 100644 --- a/src/render/utf8.rs +++ b/src/render/utf8.rs @@ -47,7 +47,7 @@ impl RenderCanvas for Canvas { if rows.len() == 2 { rows[0].iter().zip(rows[1]).map(|(top,bot)| (top * 2 + bot)).collect::>() } else { - rows[0].iter().map(|a| (a * 2)).collect::>() + rows[0].iter().map(|top| (top * 2)).collect::>() } }.iter() // Mapping those 2-bit numbers to corresponding pixels. From 4f2422ede6313e7564536d6129f95cff9723ce93 Mon Sep 17 00:00:00 2001 From: Vladimir Serov Date: Sun, 9 Feb 2020 17:33:42 +0300 Subject: [PATCH 05/16] utf-8: changed pixel type to Unicode1x2 --- src/render/utf8.rs | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/render/utf8.rs b/src/render/utf8.rs index d48587f..2f17aa3 100644 --- a/src/render/utf8.rs +++ b/src/render/utf8.rs @@ -2,13 +2,28 @@ use crate::render::{Canvas as RenderCanvas, Pixel, Color}; -impl Pixel for u8 { + +#[derive(Copy, Clone, PartialEq)] +pub enum Unicode1x2 { + Dark, Light +} + +impl Pixel for Unicode1x2 { type Image = String; type Canvas = Canvas; - fn default_color(color: Color) -> u8 {if color == Color::Dark {1} else {0}} + fn default_color(color: Color) -> Unicode1x2 { color.select(Unicode1x2::Dark, Unicode1x2::Light) } fn default_unit_size() -> (u32, u32) { (1, 1) } } +impl Unicode1x2 { + fn value(&self) -> u8 { + match self { + Unicode1x2::Dark => {1} + Unicode1x2::Light => {0} + } + } +} + pub struct Canvas { canvas: Vec, width: u32, @@ -17,16 +32,16 @@ pub struct Canvas { impl RenderCanvas for Canvas { - type Pixel = u8; + type Pixel = Unicode1x2; type Image = String; - fn new(width: u32, height: u32, dark_pixel: u8, light_pixel: u8) -> Self { - let a = vec![light_pixel; (width * height) as usize]; + fn new(width: u32, height: u32, dark_pixel: Unicode1x2, light_pixel: Unicode1x2) -> Self { + let a = vec![light_pixel.value(); (width * height) as usize]; Canvas { width: width, canvas: a, - dark_pixel: dark_pixel + dark_pixel: dark_pixel.value() } } @@ -64,11 +79,11 @@ impl RenderCanvas for Canvas { fn test_render_to_utf8_string() { use crate::render::Renderer; let colors = &[Color::Dark, Color::Light, Color::Light, Color::Dark]; - let image: String = Renderer::::new(colors, 2, 1).build(); + let image: String = Renderer::::new(colors, 2, 1).build(); assert_eq!(&image, " ▄ \n ▀ "); - let image2 = Renderer::::new(colors, 2, 1).module_dimensions(2, 2).build(); + let image2 = Renderer::::new(colors, 2, 1).module_dimensions(2, 2).build(); assert_eq!(&image2, " \n ██ \n ██ \n "); } From 9eed3f630547b35f4a415b872b6f8c53b8a2625b Mon Sep 17 00:00:00 2001 From: Vladimir Serov Date: Sun, 9 Feb 2020 17:34:14 +0300 Subject: [PATCH 06/16] utf-8: moved codepage into a constant, and encoder into pixel impl --- src/render/utf8.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/render/utf8.rs b/src/render/utf8.rs index 2f17aa3..6c485bb 100644 --- a/src/render/utf8.rs +++ b/src/render/utf8.rs @@ -2,6 +2,7 @@ use crate::render::{Canvas as RenderCanvas, Pixel, Color}; +const CODEPAGE: [&str; 4] = [" ","\u{2584}","\u{2580}","\u{2588}"]; #[derive(Copy, Clone, PartialEq)] pub enum Unicode1x2 { @@ -22,6 +23,10 @@ impl Unicode1x2 { Unicode1x2::Light => {0} } } + #[doc(hidden)] + fn parse_2_bits(sym: &u8) -> &'static str { + CODEPAGE[*sym as usize] + } } pub struct Canvas { @@ -66,7 +71,7 @@ impl RenderCanvas for Canvas { } }.iter() // Mapping those 2-bit numbers to corresponding pixels. - .map(|sym| [" ","\u{2584}","\u{2580}","\u{2588}"][*sym as usize]) + .map(Unicode1x2::parse_2_bits) .collect::>() .concat() ) From ebd18655457cd396fbce51bac804649704c8b457 Mon Sep 17 00:00:00 2001 From: Vladimir Serov Date: Sun, 9 Feb 2020 17:35:31 +0300 Subject: [PATCH 07/16] utf-8: minor reformatting --- src/render/utf8.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/render/utf8.rs b/src/render/utf8.rs index 6c485bb..ffc8530 100644 --- a/src/render/utf8.rs +++ b/src/render/utf8.rs @@ -69,7 +69,8 @@ impl RenderCanvas for Canvas { } else { rows[0].iter().map(|top| (top * 2)).collect::>() } - }.iter() + } + .iter() // Mapping those 2-bit numbers to corresponding pixels. .map(Unicode1x2::parse_2_bits) .collect::>() From b61e7656c29b524316cb2e9498a795b532da4abd Mon Sep 17 00:00:00 2001 From: Vladimir Serov Date: Sun, 9 Feb 2020 17:39:51 +0300 Subject: [PATCH 08/16] utf-8: updated README --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7138798..423bc7d 100644 --- a/README.md +++ b/README.md @@ -114,12 +114,13 @@ Generates this SVG: ```rust use qrcode::QrCode; +use qrcode::render::utf8; fn main() { let code = QrCode::new("mow mow").unwrap(); - let image = code.render::() - .dark_color(0) - .light_color(1) + let image = code.render::() + .dark_color(utf8::Unicode1x2::Light) + .light_color(utf8::Unicode1x2::Dark) .build(); println!("{}", image); } From 59980a3b6b2eb0b5e012148334cce8e6533e8ffd Mon Sep 17 00:00:00 2001 From: Vladimir Serov Date: Sun, 9 Feb 2020 17:53:40 +0300 Subject: [PATCH 09/16] utf-8: added integration test --- src/render/utf8.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/render/utf8.rs b/src/render/utf8.rs index ffc8530..6d790d7 100644 --- a/src/render/utf8.rs +++ b/src/render/utf8.rs @@ -93,3 +93,18 @@ fn test_render_to_utf8_string() { assert_eq!(&image2, " \n ██ \n ██ \n "); } + +#[test] +fn integration_render_utf8_1x2() { + use crate::{QrCode, Version, EcLevel}; + use crate::render::utf8::Unicode1x2; + + let code = QrCode::with_version(b"12345678", Version::Micro(2), EcLevel::L).unwrap(); + let image = code.render::() + .dark_color(Unicode1x2::Light) + .light_color(Unicode1x2::Dark) + .module_dimensions(1, 1) + .build(); + assert_eq!("█████████████████\n██ ▄▄▄▄▄ █▄▀▄█▄██\n██ █ █ █ █ ██\n██ █▄▄▄█ █▄▄██▀██\n██▄▄▄▄▄▄▄█▄▄▄▀ ██\n██▄ ▀ ▀ ▀▄▄ ████\n██▄▄▀▄█ ▀▀▀ ▀▄▄██\n██▄▄▄█▄▄█▄██▄█▄██\n▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀", image); + +} \ No newline at end of file From 627ad65b048975c5c23afaa97555397262a32cf1 Mon Sep 17 00:00:00 2001 From: Cabia Rangris Date: Sun, 9 Feb 2020 18:07:44 +0100 Subject: [PATCH 10/16] Update README.md Co-Authored-By: kennytm --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 423bc7d..553d7fd 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ fn main() { Generates this output: -``` +```text █████████████████████████████ █████████████████████████████ ████ ▄▄▄▄▄ █ ▀▀▀▄█ ▄▄▄▄▄ ████ @@ -144,4 +144,4 @@ Generates this output: ████▄▄▄▄▄▄▄█▄████▄█▄██▄██████ █████████████████████████████ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ -``` \ No newline at end of file +``` From e8a2c66b274fef24798b8778b88ae88d4eb090d6 Mon Sep 17 00:00:00 2001 From: Vladimir Serov Date: Mon, 10 Feb 2020 14:16:18 +0300 Subject: [PATCH 11/16] utf8: removed redundant doc(hidden) annotation --- src/render/utf8.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/render/utf8.rs b/src/render/utf8.rs index 6d790d7..7c6aba8 100644 --- a/src/render/utf8.rs +++ b/src/render/utf8.rs @@ -23,7 +23,6 @@ impl Unicode1x2 { Unicode1x2::Light => {0} } } - #[doc(hidden)] fn parse_2_bits(sym: &u8) -> &'static str { CODEPAGE[*sym as usize] } From b9d27ef174ce64f2649f9150f4421a020969425d Mon Sep 17 00:00:00 2001 From: Vladimir Serov Date: Tue, 11 Feb 2020 10:55:05 +0300 Subject: [PATCH 12/16] utf-8: renamed canvas and pixel --- src/render/utf8.rs | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/render/utf8.rs b/src/render/utf8.rs index 7c6aba8..f886f8d 100644 --- a/src/render/utf8.rs +++ b/src/render/utf8.rs @@ -5,22 +5,22 @@ use crate::render::{Canvas as RenderCanvas, Pixel, Color}; const CODEPAGE: [&str; 4] = [" ","\u{2584}","\u{2580}","\u{2588}"]; #[derive(Copy, Clone, PartialEq)] -pub enum Unicode1x2 { +pub enum Dense1x2 { Dark, Light } -impl Pixel for Unicode1x2 { +impl Pixel for Dense1x2 { type Image = String; - type Canvas = Canvas; - fn default_color(color: Color) -> Unicode1x2 { color.select(Unicode1x2::Dark, Unicode1x2::Light) } + type Canvas = Canvas1x2; + fn default_color(color: Color) -> Dense1x2 { color.select(Dense1x2::Dark, Dense1x2::Light) } fn default_unit_size() -> (u32, u32) { (1, 1) } } -impl Unicode1x2 { +impl Dense1x2 { fn value(&self) -> u8 { match self { - Unicode1x2::Dark => {1} - Unicode1x2::Light => {0} + Dense1x2::Dark => {1} + Dense1x2::Light => {0} } } fn parse_2_bits(sym: &u8) -> &'static str { @@ -28,21 +28,21 @@ impl Unicode1x2 { } } -pub struct Canvas { +pub struct Canvas1x2 { canvas: Vec, width: u32, dark_pixel: u8 } -impl RenderCanvas for Canvas { +impl RenderCanvas for Canvas1x2 { - type Pixel = Unicode1x2; + type Pixel = Dense1x2; type Image = String; - fn new(width: u32, height: u32, dark_pixel: Unicode1x2, light_pixel: Unicode1x2) -> Self { + fn new(width: u32, height: u32, dark_pixel: Dense1x2, light_pixel: Dense1x2) -> Self { let a = vec![light_pixel.value(); (width * height) as usize]; - Canvas { + Canvas1x2 { width: width, canvas: a, dark_pixel: dark_pixel.value() @@ -71,7 +71,7 @@ impl RenderCanvas for Canvas { } .iter() // Mapping those 2-bit numbers to corresponding pixels. - .map(Unicode1x2::parse_2_bits) + .map(Dense1x2::parse_2_bits) .collect::>() .concat() ) @@ -84,11 +84,11 @@ impl RenderCanvas for Canvas { fn test_render_to_utf8_string() { use crate::render::Renderer; let colors = &[Color::Dark, Color::Light, Color::Light, Color::Dark]; - let image: String = Renderer::::new(colors, 2, 1).build(); + let image: String = Renderer::::new(colors, 2, 1).build(); assert_eq!(&image, " ▄ \n ▀ "); - let image2 = Renderer::::new(colors, 2, 1).module_dimensions(2, 2).build(); + let image2 = Renderer::::new(colors, 2, 1).module_dimensions(2, 2).build(); assert_eq!(&image2, " \n ██ \n ██ \n "); } @@ -96,12 +96,12 @@ fn test_render_to_utf8_string() { #[test] fn integration_render_utf8_1x2() { use crate::{QrCode, Version, EcLevel}; - use crate::render::utf8::Unicode1x2; + use crate::render::unicode::Dense1x2; let code = QrCode::with_version(b"12345678", Version::Micro(2), EcLevel::L).unwrap(); - let image = code.render::() - .dark_color(Unicode1x2::Light) - .light_color(Unicode1x2::Dark) + let image = code.render::() + .dark_color(Dense1x2::Light) + .light_color(Dense1x2::Dark) .module_dimensions(1, 1) .build(); assert_eq!("█████████████████\n██ ▄▄▄▄▄ █▄▀▄█▄██\n██ █ █ █ █ ██\n██ █▄▄▄█ █▄▄██▀██\n██▄▄▄▄▄▄▄█▄▄▄▀ ██\n██▄ ▀ ▀ ▀▄▄ ████\n██▄▄▀▄█ ▀▀▀ ▀▄▄██\n██▄▄▄█▄▄█▄██▄█▄██\n▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀", image); From 849c6c8bea14a6393cd613b1018c79a0d31d0625 Mon Sep 17 00:00:00 2001 From: Vladimir Serov Date: Tue, 11 Feb 2020 10:55:29 +0300 Subject: [PATCH 13/16] utf-8: better formatted qr code in test --- src/render/utf8.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/render/utf8.rs b/src/render/utf8.rs index f886f8d..5768184 100644 --- a/src/render/utf8.rs +++ b/src/render/utf8.rs @@ -104,6 +104,15 @@ fn integration_render_utf8_1x2() { .light_color(Dense1x2::Dark) .module_dimensions(1, 1) .build(); - assert_eq!("█████████████████\n██ ▄▄▄▄▄ █▄▀▄█▄██\n██ █ █ █ █ ██\n██ █▄▄▄█ █▄▄██▀██\n██▄▄▄▄▄▄▄█▄▄▄▀ ██\n██▄ ▀ ▀ ▀▄▄ ████\n██▄▄▀▄█ ▀▀▀ ▀▄▄██\n██▄▄▄█▄▄█▄██▄█▄██\n▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀", image); + assert_eq!(image, + "█████████████████\n\ + ██ ▄▄▄▄▄ █▄▀▄█▄██\n\ + ██ █ █ █ █ ██\n\ + ██ █▄▄▄█ █▄▄██▀██\n\ + ██▄▄▄▄▄▄▄█▄▄▄▀ ██\n\ + ██▄ ▀ ▀ ▀▄▄ ████\n\ + ██▄▄▀▄█ ▀▀▀ ▀▄▄██\n\ + ██▄▄▄█▄▄█▄██▄█▄██\n\ + ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀"); } \ No newline at end of file From 3d1d6883f2e68618cb00fc7040e82fcf27d432a8 Mon Sep 17 00:00:00 2001 From: Vladimir Serov Date: Tue, 11 Feb 2020 10:57:02 +0300 Subject: [PATCH 14/16] =?UTF-8?q?rename=20utf8=20=E2=86=92=20unicode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/render/mod.rs | 2 +- src/render/{utf8.rs => unicode.rs} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/render/{utf8.rs => unicode.rs} (100%) diff --git a/src/render/mod.rs b/src/render/mod.rs index 3915661..32fff6e 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -7,7 +7,7 @@ use std::cmp::max; pub mod image; pub mod string; pub mod svg; -pub mod utf8; +pub mod unicode; //------------------------------------------------------------------------------ //{{{ Pixel trait diff --git a/src/render/utf8.rs b/src/render/unicode.rs similarity index 100% rename from src/render/utf8.rs rename to src/render/unicode.rs From 6f407492eca4246188d767260534debb7d90a8ce Mon Sep 17 00:00:00 2001 From: Vladimir Serov Date: Tue, 11 Feb 2020 11:05:22 +0300 Subject: [PATCH 15/16] unicode: updated readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 553d7fd..f61be27 100644 --- a/README.md +++ b/README.md @@ -114,13 +114,13 @@ Generates this SVG: ```rust use qrcode::QrCode; -use qrcode::render::utf8; +use qrcode::render::unicode; fn main() { let code = QrCode::new("mow mow").unwrap(); - let image = code.render::() - .dark_color(utf8::Unicode1x2::Light) - .light_color(utf8::Unicode1x2::Dark) + let image = code.render::() + .dark_color(unicode::Dense1x2::Light) + .light_color(unicode::Dense1x2::Dark) .build(); println!("{}", image); } From 181acf64a7957f7a09f9ffa585e37bd285dde1d4 Mon Sep 17 00:00:00 2001 From: Vladimir Serov Date: Tue, 11 Feb 2020 11:05:53 +0300 Subject: [PATCH 16/16] unicode: non-inverted test --- src/render/unicode.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/render/unicode.rs b/src/render/unicode.rs index 5768184..066a75d 100644 --- a/src/render/unicode.rs +++ b/src/render/unicode.rs @@ -98,6 +98,28 @@ fn integration_render_utf8_1x2() { use crate::{QrCode, Version, EcLevel}; use crate::render::unicode::Dense1x2; + let code = QrCode::with_version(b"09876542", Version::Micro(2), EcLevel::L).unwrap(); + let image = code.render::() + .module_dimensions(1, 1) + .build(); + assert_eq!(image, + " \n".to_owned() + + " █▀▀▀▀▀█ ▀ █ ▀ \n" + + " █ ███ █ ▀ █ \n" + + " █ ▀▀▀ █ ▀█ █ \n" + + " ▀▀▀▀▀▀▀ ▄▀▀ █ \n" + + " ▀█ ▀▀▀▀▀██▀▀▄ \n" + + " ▀███▄ ▀▀ █ ██ \n" + + " ▀▀▀ ▀ ▀▀ ▀ ▀ \n" + + " ") + +} + +#[test] +fn integration_render_utf8_1x2_inverted() { + use crate::{QrCode, Version, EcLevel}; + use crate::render::unicode::Dense1x2; + let code = QrCode::with_version(b"12345678", Version::Micro(2), EcLevel::L).unwrap(); let image = code.render::() .dark_color(Dense1x2::Light)