diff --git a/Readme.markdown b/Readme.markdown index a060ca7..6fe5a38 100644 --- a/Readme.markdown +++ b/Readme.markdown @@ -158,7 +158,7 @@ Rust language: // Simple operation let qr = QrCode::encode_text("Hello, world!", QrCodeEcc::Medium).unwrap(); - let svg = qr.to_svg_string(4); + let svg = to_svg_string(&qr, 4); // See qrcodegen-demo // Manual operation let chrs: Vec = "3141592653589793238462643383".chars().collect(); diff --git a/rust/Readme.markdown b/rust/Readme.markdown index 7a20c4a..8c5309b 100644 --- a/rust/Readme.markdown +++ b/rust/Readme.markdown @@ -18,7 +18,7 @@ Core features: * Available in 6 programming languages, all with nearly equal functionality: Java, TypeScript/JavaScript, Python, Rust, C++, C * Significantly shorter code but more documentation comments compared to competing libraries * Supports encoding all 40 versions (sizes) and all 4 error correction levels, as per the QR Code Model 2 standard -* Output formats: Raw modules/pixels of the QR symbol, SVG XML string +* Output format: Raw modules/pixels of the QR symbol * Detects finder-like penalty patterns more accurately than other implementations * Encodes numeric and special-alphanumeric text in less space than general text * Open source code under the permissive MIT License @@ -42,7 +42,7 @@ Examples // Simple operation let qr = QrCode::encode_text("Hello, world!", QrCodeEcc::Medium).unwrap(); - let svg = qr.to_svg_string(4); + let svg = to_svg_string(&qr, 4); // See qrcodegen-demo // Manual operation let chrs: Vec = "3141592653589793238462643383".chars().collect(); diff --git a/rust/examples/qrcodegen-demo.rs b/rust/examples/qrcodegen-demo.rs index 91fee9d..ed37c65 100644 --- a/rust/examples/qrcodegen-demo.rs +++ b/rust/examples/qrcodegen-demo.rs @@ -52,7 +52,7 @@ fn do_basic_demo() { // Make and print the QR Code symbol let qr: QrCode = QrCode::encode_text(text, errcorlvl).unwrap(); print_qr(&qr); - println!("{}", qr.to_svg_string(4)); + println!("{}", to_svg_string(&qr, 4)); } @@ -163,6 +163,35 @@ fn do_mask_demo() { /*---- Utilities ----*/ +// Returns a string of SVG code for an image depicting +// the given QR Code, with the given number of border modules. +// The string always uses Unix newlines (\n), regardless of the platform. +fn to_svg_string(qr: &QrCode, border: i32) -> String { + assert!(border >= 0, "Border must be non-negative"); + let mut result = String::new(); + result += "\n"; + result += "\n"; + let dimension = qr.size().checked_add(border.checked_mul(2).unwrap()).unwrap(); + result += &format!( + "\n", dimension); + result += "\t\n"; + result += "\t\n"; + result += "\n"; + result +} + + // Prints the given QrCode object to the console. fn print_qr(qr: &QrCode) { let border: i32 = 4; diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 2999e29..546f0a8 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -38,7 +38,7 @@ //! - Available in 6 programming languages, all with nearly equal functionality: Java, TypeScript/JavaScript, Python, Rust, C++, C //! - Significantly shorter code but more documentation comments compared to competing libraries //! - Supports encoding all 40 versions (sizes) and all 4 error correction levels, as per the QR Code Model 2 standard -//! - Output formats: Raw modules/pixels of the QR symbol, SVG XML string +//! - Output format: Raw modules/pixels of the QR symbol //! - Detects finder-like penalty patterns more accurately than other implementations //! - Encodes numeric and special-alphanumeric text in less space than general text //! - Open source code under the permissive MIT License @@ -64,7 +64,7 @@ //! ``` //! let qr = QrCode::encode_text("Hello, world!", //! QrCodeEcc::Medium).unwrap(); -//! let svg = qr.to_svg_string(4); +//! let svg = to_svg_string(&qr, 4); // See qrcodegen-demo //! ``` //! //! Manual operation: @@ -368,36 +368,6 @@ impl QrCode { } - /// Returns a string of SVG code for an image depicting - /// this QR Code, with the given number of border modules. - /// - /// The string always uses Unix newlines (\n), regardless of the platform. - pub fn to_svg_string(&self, border: i32) -> String { - assert!(border >= 0, "Border must be non-negative"); - let mut result = String::new(); - result += "\n"; - result += "\n"; - let dimension = self.size.checked_add(border.checked_mul(2).unwrap()).unwrap(); - result += &format!( - "\n", dimension); - result += "\t\n"; - result += "\t\n"; - result += "\n"; - result - } - - /*---- Private helper methods for constructor: Drawing function modules ----*/ // Reads this object's version field, and draws and marks all function modules.