Skip to content
Open
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
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ qrcode-rust
[![crates.io](https://img.shields.io/crates/v/qrcode.svg)](https://crates.io/crates/qrcode)
[![MIT OR Apache 2.0](https://img.shields.io/badge/license-MIT%20%2f%20Apache%202.0-blue.svg)](./LICENSE-APACHE.txt)

QR code and Micro QR code encoder in Rust. [Documentation](https://docs.rs/qrcode).
QR code, Micro QR code and rMQR code encoder in Rust. [Documentation](https://docs.rs/qrcode).

Cargo.toml
----------
Expand All @@ -25,7 +25,7 @@ qrcode = { version = "0.14.1", default-features = false, features = ["std"] }
Example
-------

## Image generation
### Image generation

```rust
use qrcode::QrCode;
Expand All @@ -47,7 +47,7 @@ Generates this image:

![Output](src/test_annex_i_qr_as_image.png)

## String generation
### String generation

```rust
use qrcode::QrCode;
Expand Down Expand Up @@ -89,7 +89,7 @@ Generates this output:
############## #### ## ## ##
```

## SVG generation
### SVG generation

```rust
use qrcode::{QrCode, Version, EcLevel};
Expand All @@ -110,7 +110,7 @@ Generates this SVG:

[![Output](src/test_annex_i_micro_qr_as_svg.svg)](src/test_annex_i_micro_qr_as_svg.svg)

## Unicode string generation
### Unicode string generation

```rust
use qrcode::QrCode;
Expand Down Expand Up @@ -146,7 +146,7 @@ Generates this output:
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
```

## PIC generation
### PIC generation

```rust
use qrcode::render::pic;
Expand Down Expand Up @@ -179,7 +179,7 @@ p(9,4,1,1)
```
See [`test_annex_i_micro_qr_as_pic.pic`](src/test_annex_i_micro_qr_as_pic.pic) for a full example.

## EPS generation
### EPS generation

```rust
use qrcode::render::eps;
Expand Down Expand Up @@ -219,3 +219,17 @@ grestore
```
See [`test_annex_i_micro_qr_as_eps.eps`](src/test_annex_i_micro_qr_as_eps.eps) for a full example.

License
-------

Copyright (c) 2016 kennytm

This crate is licensed under either of the
[MIT License](https://spdx.org/licenses/MIT.html) or the
[Apache License 2.0](https://spdx.org/licenses/Apache-2.0.html) at your option.

The rMQR code encoder is based on the
[`qrqrpar`](https://crates.io/crates/qrqrpar) crate, which is a fork of this
crate. It is licensed under the
[BSD 3-Clause "New" or "Revised" License](https://spdx.org/licenses/BSD-3-Clause.html).
54 changes: 50 additions & 4 deletions src/bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ impl Bits {
(Version::Micro(_), ExtendedMode::Data(Mode::Byte)) => 0b10,
(Version::Micro(_), ExtendedMode::Data(Mode::Kanji)) => 0b11,
(Version::Micro(_), _) => return Err(QrError::UnsupportedCharacterSet),
(Version::RectMicro(..), ExtendedMode::Data(Mode::Numeric)) => 0b001,
(Version::RectMicro(..), ExtendedMode::Data(Mode::Alphanumeric)) => 0b010,
(Version::RectMicro(..), ExtendedMode::Data(Mode::Byte)) => 0b011,
(Version::RectMicro(..), ExtendedMode::Data(Mode::Kanji)) => 0b100,
(Version::RectMicro(..), ExtendedMode::Eci) => 0b111,
(Version::RectMicro(..), ExtendedMode::Fnc1First) => 0b101,
(Version::RectMicro(..), ExtendedMode::Fnc1Second) => 0b110,
(Version::RectMicro(..), _) => return Err(QrError::UnsupportedCharacterSet),
(_, ExtendedMode::Data(Mode::Numeric)) => 0b0001,
(_, ExtendedMode::Data(Mode::Alphanumeric)) => 0b0010,
(_, ExtendedMode::Data(Mode::Byte)) => 0b0100,
Expand Down Expand Up @@ -669,8 +677,9 @@ impl Bits {
//------------------------------------------------------------------------------
//{{{ Finish

// This table is copied from ISO/IEC 18004:2006 §6.4.10, Table 7.
static DATA_LENGTHS: [[usize; 4]; 44] = [
// This table is copied from ISO/IEC 18004:2006 §6.4.10, Table 7, and ISO/IEC
// 23941:2022 Table 6.
static DATA_LENGTHS: [[usize; 4]; 76] = [
// Normal versions
[152, 128, 104, 72],
[272, 224, 176, 128],
Expand Down Expand Up @@ -717,6 +726,39 @@ static DATA_LENGTHS: [[usize; 4]; 44] = [
[40, 32, 0, 0],
[84, 68, 0, 0],
[128, 112, 80, 0],
// rMQR versions
[0, 48, 0, 24],
[0, 96, 0, 56],
[0, 160, 0, 80],
[0, 224, 0, 112],
[0, 352, 0, 192],
[0, 96, 0, 56],
[0, 168, 0, 88],
[0, 248, 0, 136],
[0, 336, 0, 176],
[0, 504, 0, 264],
[0, 56, 0, 40],
[0, 152, 0, 88],
[0, 248, 0, 120],
[0, 344, 0, 184],
[0, 456, 0, 232],
[0, 672, 0, 336],
[0, 96, 0, 56],
[0, 216, 0, 104],
[0, 304, 0, 160],
[0, 424, 0, 232],
[0, 584, 0, 280],
[0, 848, 0, 432],
[0, 264, 0, 120],
[0, 384, 0, 208],
[0, 536, 0, 248],
[0, 704, 0, 384],
[0, 1016, 0, 552],
[0, 312, 0, 168],
[0, 448, 0, 224],
[0, 624, 0, 304],
[0, 800, 0, 448],
[0, 1216, 0, 608],
];

impl Bits {
Expand All @@ -730,7 +772,11 @@ impl Bits {
/// `ec_level` for the given version (e.g. `Version::Micro(1)` with
/// `EcLevel::H`).
pub fn push_terminator(&mut self, ec_level: EcLevel) -> QrResult<()> {
let terminator_size = if let Version::Micro(a) = self.version { a.as_usize() * 2 + 1 } else { 4 };
let terminator_size = match self.version {
Version::Micro(a) => a.as_usize() * 2 + 1,
Version::RectMicro(..) => 3,
Version::Normal(_) => 4,
};

let cur_length = self.len();
let data_length = self.max_len(ec_level)?;
Expand Down Expand Up @@ -907,7 +953,7 @@ mod encode_tests {
/// Automatically determines the minimum version to store the data, and encode
/// the result.
///
/// This method will not consider any Micro QR code versions.
/// This method will not consider any Micro QR code or rMQR code versions.
///
/// # Errors
///
Expand Down
Loading
Loading