Skip to content

Commit

Permalink
doc: added example for svg and fix stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanvivien committed Nov 8, 2022
1 parent 93a7889 commit 8e80701
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 24 deletions.
39 changes: 37 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,43 @@ let qrcode = QRBuilder::new("https://example.com/".into())
qrcode.unwrap().print();
```

<div style="display: flex; justify-content: center">
<img src="assets/example.com.svg" alt="Example qr for website example.com"/>
```
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
█ ▄▄▄▄▄ █ ▀██ █ ██ ▀▄█ ▄▄▄▄▄ █
█ █ █ █▄▀▄▀▄█ ▄█▀█ ▄█ █ █ █
█ █▄▄▄█ █▀▀▀▀ ▄▄ ▄█ ▄▄█ █▄▄▄█ █
█▄▄▄▄▄▄▄█ ▀▄▀ ▀ ▀▄█▄█▄█▄▄▄▄▄▄▄█
███▄▄▄▀▄▀ ▀▀▀▀█▀█ █▄▄▄ ▀▀ ▄ █
█ █ ▄▀ ▄▀ ▄ ▄ ▄ ▀ █▄ █▀█▀██
██ ▀▄▀ ▄▄ █▄█▀▄▀█▀██▀ ▀▄▀▀▄ █
█ ▄▀ ▀▄▄█ ▄█ ██▄▄▀ █ █▄▄▀▀█▀██
█▀▄ ▀ ▄▄█▀▄ █ ▀█ ███▀ ▀▀▀ ▄ ▀█
█ █▀▄▄▀▄▀█ ▀ ▀▄█ █ ▀█ ▄▀▄█▀██
█▄█▄▄█▄▄█ █▄▄ ▄ ▄ ▀ ▄ ▄▄▄ ▀▄█▀█
█ ▄▄▄▄▄ ██▀ ▀ ▄ ▀▄ █▄█ ▀████
█ █ █ █ █▀ ▀▀█▄▄ ▀ ▄ ▄ █▄█
█ █▄▄▄█ █▄ ▄█▄█ ▀ ▄▄▄▄ ▄ ▀▄ ██
█▄▄▄▄▄▄▄███▄▄▄▄▄▄██▄███▄█▄█▄███
```

# Example SVG

```rust
use fast_qr::{ECL, Version, QRBuilder};
use fast_qr::convert::svg::{SvgBuilder, Shape};

let qrcode = QRBuilder::new("https://example.com/".into())
.ecl(ECL::H)
.version(Version::V03)
.build();

let _ = SvgBuilder::default()
.shape(Shape::RoundedSquare)
.to_file(&qrcode.unwrap(), "out.svg");
```

<div style="display: flex; justify-content: center; max-width: 360px">
<img src="assets/example.com.round.svg" alt="Example round qr for website example.com"/>
</div>

## Build WASM
Expand Down
1 change: 1 addition & 0 deletions assets/example.com.round.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn print_matrix_with_margin(qr: &QRCode) {
}

#[cfg(test)]
use crate::{Version, compact::CompactQR};
use crate::{compact::CompactQR, Version};

#[cfg(test)]
#[allow(dead_code)]
Expand All @@ -61,7 +61,6 @@ use crate::{Version, compact::CompactQR};
* Example: { 101 } => "01100101"
*/
pub fn binary_to_binarystring_version(binary: [u8; 5430], version: Version) -> CompactQR {

let max = version.max_bytes() * 8;
CompactQR::from_array(&binary, max + version.missing_bits())
}
33 changes: 26 additions & 7 deletions src/lib.rs

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use fast_qr::convert::svg::{SvgBuilder, SvgError};
use fast_qr::convert::svg::{Shape, SvgBuilder, SvgError};
use fast_qr::qr::{QRBuilder, QRCodeError};
use fast_qr::{Version, ECL};

Expand All @@ -24,13 +24,11 @@ fn main() -> Result<(), Error> {
let qrcode = QRBuilder::new("https://example.com/".into())
.ecl(ECL::H)
.version(Version::V03)
.build()?;
.build();

qrcode.print();

// SvgBuilder::new().to_file(qrcode, "qrcode.svg")?;
let _svg = SvgBuilder::default().to_str(&qrcode);
// println!("{}", _svg);
let svg = SvgBuilder::default()
.shape(Shape::RoundedSquare)
.to_file(&qrcode.unwrap(), "out.svg");

Ok(())
}
41 changes: 37 additions & 4 deletions src/qr.rs

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#[cfg(test)]
use crate::default::transpose;
use crate::module::{Module, ModuleType};
use crate::{QRCode};
use crate::QRCode;

use super::hardcode;

Expand Down Expand Up @@ -194,7 +194,6 @@ fn dark_module_score(qr: &QRCode) -> u32 {

let percent = (dark_modules * 100) / (n * n);


hardcode::PERCENT_SCORE[percent as usize] as u32
}

Expand Down

0 comments on commit 8e80701

Please sign in to comment.