Skip to content

Commit f208735

Browse files
committed
feat: Add rMQR Code encoder
This implementation is based on the [`qrqrpar`](https://crates.io/crates/qrqrpar) crate.
1 parent 0dc4ae0 commit f208735

15 files changed

+1551
-79
lines changed

README.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ qrcode-rust
55
[![crates.io](https://img.shields.io/crates/v/qrcode.svg)](https://crates.io/crates/qrcode)
66
[![MIT OR Apache 2.0](https://img.shields.io/badge/license-MIT%20%2f%20Apache%202.0-blue.svg)](./LICENSE-APACHE.txt)
77

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

1010
Cargo.toml
1111
----------
@@ -25,7 +25,7 @@ qrcode = { version = "0.14.1", default-features = false, features = ["std"] }
2525
Example
2626
-------
2727

28-
## Image generation
28+
### Image generation
2929

3030
```rust
3131
use qrcode::QrCode;
@@ -47,7 +47,7 @@ Generates this image:
4747

4848
![Output](src/test_annex_i_qr_as_image.png)
4949

50-
## String generation
50+
### String generation
5151

5252
```rust
5353
use qrcode::QrCode;
@@ -89,7 +89,7 @@ Generates this output:
8989
############## #### ## ## ##
9090
```
9191

92-
## SVG generation
92+
### SVG generation
9393

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

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

113-
## Unicode string generation
113+
### Unicode string generation
114114

115115
```rust
116116
use qrcode::QrCode;
@@ -146,7 +146,7 @@ Generates this output:
146146
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
147147
```
148148

149-
## PIC generation
149+
### PIC generation
150150

151151
```rust
152152
use qrcode::render::pic;
@@ -179,7 +179,7 @@ p(9,4,1,1)
179179
```
180180
See [`test_annex_i_micro_qr_as_pic.pic`](src/test_annex_i_micro_qr_as_pic.pic) for a full example.
181181

182-
## EPS generation
182+
### EPS generation
183183

184184
```rust
185185
use qrcode::render::eps;
@@ -219,3 +219,17 @@ grestore
219219
220220
```
221221
See [`test_annex_i_micro_qr_as_eps.eps`](src/test_annex_i_micro_qr_as_eps.eps) for a full example.
222+
223+
License
224+
-------
225+
226+
Copyright (c) 2016 kennytm
227+
228+
This crate is licensed under either of the
229+
[MIT License](https://spdx.org/licenses/MIT.html) or the
230+
[Apache License 2.0](https://spdx.org/licenses/Apache-2.0.html) at your option.
231+
232+
The rMQR code encoder is based on the
233+
[`qrqrpar`](https://crates.io/crates/qrqrpar) crate, which is a fork of this
234+
crate. It is licensed under the
235+
[BSD 3-Clause "New" or "Revised" License](https://spdx.org/licenses/BSD-3-Clause.html).

src/bits.rs

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,14 @@ impl Bits {
200200
(Version::Micro(_), ExtendedMode::Data(Mode::Byte)) => 0b10,
201201
(Version::Micro(_), ExtendedMode::Data(Mode::Kanji)) => 0b11,
202202
(Version::Micro(_), _) => return Err(QrError::UnsupportedCharacterSet),
203+
(Version::RectMicro(..), ExtendedMode::Data(Mode::Numeric)) => 0b001,
204+
(Version::RectMicro(..), ExtendedMode::Data(Mode::Alphanumeric)) => 0b010,
205+
(Version::RectMicro(..), ExtendedMode::Data(Mode::Byte)) => 0b011,
206+
(Version::RectMicro(..), ExtendedMode::Data(Mode::Kanji)) => 0b100,
207+
(Version::RectMicro(..), ExtendedMode::Eci) => 0b111,
208+
(Version::RectMicro(..), ExtendedMode::Fnc1First) => 0b101,
209+
(Version::RectMicro(..), ExtendedMode::Fnc1Second) => 0b110,
210+
(Version::RectMicro(..), _) => return Err(QrError::UnsupportedCharacterSet),
203211
(_, ExtendedMode::Data(Mode::Numeric)) => 0b0001,
204212
(_, ExtendedMode::Data(Mode::Alphanumeric)) => 0b0010,
205213
(_, ExtendedMode::Data(Mode::Byte)) => 0b0100,
@@ -669,8 +677,9 @@ impl Bits {
669677
//------------------------------------------------------------------------------
670678
//{{{ Finish
671679

672-
// This table is copied from ISO/IEC 18004:2006 §6.4.10, Table 7.
673-
static DATA_LENGTHS: [[usize; 4]; 44] = [
680+
// This table is copied from ISO/IEC 18004:2006 §6.4.10, Table 7, and ISO/IEC
681+
// 23941:2022 Table 6.
682+
static DATA_LENGTHS: [[usize; 4]; 76] = [
674683
// Normal versions
675684
[152, 128, 104, 72],
676685
[272, 224, 176, 128],
@@ -717,6 +726,39 @@ static DATA_LENGTHS: [[usize; 4]; 44] = [
717726
[40, 32, 0, 0],
718727
[84, 68, 0, 0],
719728
[128, 112, 80, 0],
729+
// rMQR versions
730+
[0, 48, 0, 24],
731+
[0, 96, 0, 56],
732+
[0, 160, 0, 80],
733+
[0, 224, 0, 112],
734+
[0, 352, 0, 192],
735+
[0, 96, 0, 56],
736+
[0, 168, 0, 88],
737+
[0, 248, 0, 136],
738+
[0, 336, 0, 176],
739+
[0, 504, 0, 264],
740+
[0, 56, 0, 40],
741+
[0, 152, 0, 88],
742+
[0, 248, 0, 120],
743+
[0, 344, 0, 184],
744+
[0, 456, 0, 232],
745+
[0, 672, 0, 336],
746+
[0, 96, 0, 56],
747+
[0, 216, 0, 104],
748+
[0, 304, 0, 160],
749+
[0, 424, 0, 232],
750+
[0, 584, 0, 280],
751+
[0, 848, 0, 432],
752+
[0, 264, 0, 120],
753+
[0, 384, 0, 208],
754+
[0, 536, 0, 248],
755+
[0, 704, 0, 384],
756+
[0, 1016, 0, 552],
757+
[0, 312, 0, 168],
758+
[0, 448, 0, 224],
759+
[0, 624, 0, 304],
760+
[0, 800, 0, 448],
761+
[0, 1216, 0, 608],
720762
];
721763

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

735781
let cur_length = self.len();
736782
let data_length = self.max_len(ec_level)?;
@@ -907,7 +953,7 @@ mod encode_tests {
907953
/// Automatically determines the minimum version to store the data, and encode
908954
/// the result.
909955
///
910-
/// This method will not consider any Micro QR code versions.
956+
/// This method will not consider any Micro QR code or rMQR code versions.
911957
///
912958
/// # Errors
913959
///

0 commit comments

Comments
 (0)