Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evi/fix svg inversion #49

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use crate::Module;
/// For the square shape, the svg is `M{x},{y}h1v1h-1`
///
/// ```rust
/// fn square(y: usize, x: usize) -> String {
/// # use fast_qr::Module;
/// fn square(y: usize, x: usize, _module: Module) -> String {
/// format!("M{x},{y}h1v1h-1")
/// }
/// ```
Expand Down
2 changes: 1 addition & 1 deletion src/convert/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl SvgBuilder {
}

for (i, command) in commands.iter().enumerate() {
paths[i].push_str(&command(x + self.margin, y + self.margin, cell));
paths[i].push_str(&command(y + self.margin, x + self.margin, cell));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn it_can_output_to_bytes_from_image() {
use crate::{QRBuilder, ECL};

// Expected
let image_base64 = "iVBORw0KGgoAAAANSUhEUgAAACUAAAAlCAYAAADFniADAAACsklEQVR4Ae2SUW4bQQxD8+5/6NQvAjsaza7rNB9NgRQgJFEUh96U98e/t2/27yfUq3+Q/+NLAbc/qP/3g9KFgzVD9TFSAzuXndW9NTi+FPA2RYrhnncvvIN7nXt1HXDqb0PB+mWaQR3DqprPnZwI3/vOTd45+FKoPJKq6VUfLlWdyGx1Dv46lAawvprGsL6uezmrgKV1Fu6heOfgNlQEqbCOYX88mvkIlG7y0Vth+TqLy1AurtDNoczg9XrlK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bTnsuTQMmtGfVB9k78cBWWC+pI02jRz6zvElzh9crPe5S+PcgBcj3PQTptcPEaoGebxzCg/cTlKEfq10iwfhDPKQfnNz4A6SC+0D4rXr2YMbo/SoBmq2VwOevCsoXioGM0YOAN6HnQej/FyFLQRagGsnI0iS4zWsPrk4TpD7ytsj8qwNFonh14sB7XUPID2wKrDvfbsPxYu/0tQgLVRThxewwes+o5/GD9/wP4w5fSaB2+9lIOgFsF6oIPVjQJKN5/QA6WZT+32KE3QTVBHhHcQFAcd1cXUrWE/S+2M26OgFtkAlUNH+cADzKEWm8tB1cln1AM1z3zi5VEaM2jmk5M/46u6vnOv9eUoyVeA9eugauiYfpdC8eGgX08OVv3BHY3Lvz6oJsUzDu+TghoGq18P7LloxuegTXJ5KahlZy80D+tSvS6C4mcezSigPdY73B4F1WxTliSGM0Ifm9oopt/6jOjGqf3VUdCHO3QOh6sG9QFQ2vTbH7x9lAMcCr0otdorTJ/52Xt71MX4uVwe6hDzAOrrU5+XQfVA+dShuPQkbo+KeI4OCgc1PHViPLAuhKphjemb8XLUFP9V/nPUV1/+W77Ub25RML9l49+tAAAAAElFTkSuQmCC";
let expected_data_uri = format!("data:image/png;base64,{image_base64}");

// Source
Expand Down
29 changes: 29 additions & 0 deletions src/tests/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,32 @@ fn it_embeds_an_image_via_data_uri() {
let expected_href = format!(r#"href="{data_uri}""#);
assert!(svg.contains(&expected_href));
}

#[cfg(feature = "svg")]
#[test]
fn check_svg_is_not_inverted() {
use crate::convert::svg::SvgBuilder;
use crate::convert::Builder;
use crate::{QRBuilder, Version, ECL};

let qrcode = QRBuilder::new("Test")
.ecl(ECL::M)
.version(Version::V01)
.build()
.unwrap();

const MARGIN: usize = 4;
let svg = SvgBuilder::default().margin(MARGIN).to_str(&qrcode);

let size = qrcode.size;
for y in 0..size {
for x in 0..size {
let index = y * size + x;
let expected = qrcode.data[index];
if expected.value() {
let expected = format!(r#"M{x},{y}"#, x = x + MARGIN, y = y + MARGIN);
assert!(svg.contains(&expected));
}
}
}
}