chore: version update and cargo fmt

This commit is contained in:
Henry Schimke
2024-01-02 17:10:56 -06:00
parent e04354cb4a
commit c3618919d7
10 changed files with 89 additions and 93 deletions

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "rxing" name = "rxing"
version = "0.4.12" version = "0.5.0"
description="A rust port of the zxing barcode library." description="A rust port of the zxing barcode library."
license="Apache-2.0" license="Apache-2.0"
repository="https://github.com/rxing-core/rxing" repository="https://github.com/rxing-core/rxing"

View File

@@ -39,6 +39,7 @@ All barcode formats are tested and functioning in their current state against cu
| upc e | complete | yes | yes | | upc e | complete | yes | yes |
| rss-14 | complete | no | yes | | rss-14 | complete | no | yes |
| rss-expanded | complete | no | yes| | rss-expanded | complete | no | yes|
| telepen | complete | yes | yes |
Please note that currently UPC/EAN Extension 2/5 is supported. Please note that currently UPC/EAN Extension 2/5 is supported.
@@ -81,6 +82,13 @@ fn main() {
``` ```
## Latest Release Notes ## Latest Release Notes
* *v0.5.0* -> Added support for [telepen](https://advanova.co.uk/wp-content/uploads/2022/05/Barcode-Symbology-information-and-History.pdf) thanks to the work of first time contributor [cpwood](https://github.com/cpwood).
This release also adds the ability to exclude building the "client" result parsing features. Currently part of the default
feature set, they can be disabled through the `client_support` feature.
This release fixes several build issues associated with the `chrono` crate and some deprecated function messages. This change
only impacts users building with the `client_support` feature.
* *v0.4.6* -> Fixed an issue with pdf417 whitespace, rotation, and compaction. Fix courtesy of first time contribution from GitHub user agkyunromb. * *v0.4.6* -> Fixed an issue with pdf417 whitespace, rotation, and compaction. Fix courtesy of first time contribution from GitHub user agkyunromb.
* *v0.4.4* -> Major update of QRCode support. * *v0.4.4* -> Major update of QRCode support.

View File

@@ -7,8 +7,8 @@ use rxing::multi::{GenericMultipleBarcodeReader, MultipleBarcodeReader};
use rxing::oned::rss::expanded::RSSExpandedReader; use rxing::oned::rss::expanded::RSSExpandedReader;
use rxing::oned::rss::RSS14Reader; use rxing::oned::rss::RSS14Reader;
use rxing::oned::{ use rxing::oned::{
CodaBarReader, Code39Reader, Code93Reader, EAN13Reader, EAN8Reader, TelepenReader, ITFReader, UPCAReader, CodaBarReader, Code39Reader, Code93Reader, EAN13Reader, EAN8Reader, ITFReader, TelepenReader,
UPCEReader, UPCAReader, UPCEReader,
}; };
use rxing::pdf417::PDF417Reader; use rxing::pdf417::PDF417Reader;
use rxing::qrcode::QRCodeReader; use rxing::qrcode::QRCodeReader;

View File

@@ -11,4 +11,4 @@ keywords = ["barcode", "2d_barcode", "1d_barcode", "barcode_reader", "barcode_wr
[dependencies] [dependencies]
clap = { version = "4.2.0", features = ["derive"] } clap = { version = "4.2.0", features = ["derive"] }
rxing = {path = "../../", version = "~0.4.9", features = ["image", "svg_read", "svg_write"] } rxing = {path = "../../", version = "~0.5.0", features = ["image", "svg_read", "svg_write"] }

View File

@@ -126,7 +126,6 @@ pub enum DecodeHintType {
* Will translate the ASCII values parsed by the Telepen reader into the Telepen Numeric form. * Will translate the ASCII values parsed by the Telepen reader into the Telepen Numeric form.
*/ */
TELEPEN_AS_NUMERIC, TELEPEN_AS_NUMERIC,
/* /*
* Data type the hint is expecting. * Data type the hint is expecting.
* Among the possible values the {@link Void} stands out as being used for * Among the possible values the {@link Void} stands out as being used for

View File

@@ -1,5 +1,5 @@
use crate::Exceptions;
use crate::common::Result; use crate::common::Result;
use crate::Exceptions;
pub fn calculate_checksum(contents: &str) -> char { pub fn calculate_checksum(contents: &str) -> char {
let mut sum = 0; let mut sum = 0;
@@ -12,8 +12,7 @@ pub fn calculate_checksum(contents: &str) -> char {
let diff = 127 - remainder; let diff = 127 - remainder;
return if diff != 127 { return if diff != 127 {
diff as u8 as char diff as u8 as char
} } else {
else {
0 as char 0 as char
}; };
} }
@@ -24,8 +23,7 @@ pub fn ascii_to_numeric(contents: &str) -> String {
for c in contents.chars().map(|x| x as u32) { for c in contents.chars().map(|x| x as u32) {
if c >= 27 { if c >= 27 {
number.push_str(&format!("{:0>2}", (c - 27))); number.push_str(&format!("{:0>2}", (c - 27)));
} } else {
else {
number.push_str(&format!("{:0>2}", (c - 17))); number.push_str(&format!("{:0>2}", (c - 17)));
} }
} }
@@ -35,7 +33,9 @@ pub fn ascii_to_numeric(contents: &str) -> String {
pub fn numeric_to_ascii(contents: &str) -> Result<String> { pub fn numeric_to_ascii(contents: &str) -> Result<String> {
if contents.len() % 2 != 0 { if contents.len() % 2 != 0 {
return Err(Exceptions::illegal_argument_with("Input must contain an even number of characters.")); return Err(Exceptions::illegal_argument_with(
"Input must contain an even number of characters.",
));
} }
let mut ascii = String::new(); let mut ascii = String::new();
@@ -47,12 +47,13 @@ pub fn numeric_to_ascii(contents: &str) -> Result<String> {
if second == 88 && first >= 48 && first <= 57 { if second == 88 && first >= 48 && first <= 57 {
ascii.push((17 + first - 48) as char); ascii.push((17 + first - 48) as char);
} } else if second >= 48 && second <= 57 && first >= 48 && first <= 57 {
else if second >= 48 && second <= 57 && first >= 48 && first <= 57 {
ascii.push((27 + (first - 48) * 10 + (second - 48)) as char); ascii.push((27 + (first - 48) * 10 + (second - 48)) as char);
} } else {
else { return Err(Exceptions::illegal_argument_with(format!(
return Err(Exceptions::illegal_argument_with(format!("Input contains an invalid character around position {}.", i.to_string()))); "Input contains an invalid character around position {}.",
i.to_string()
)));
} }
i += 2; i += 2;

View File

@@ -17,10 +17,10 @@
use rxing_one_d_proc_derive::OneDReader; use rxing_one_d_proc_derive::OneDReader;
use crate::common::{BitArray, Result}; use crate::common::{BitArray, Result};
use crate::oned::telepen_common;
use crate::DecodeHintValue;
use crate::Exceptions; use crate::Exceptions;
use crate::RXingResult; use crate::RXingResult;
use crate::DecodeHintValue;
use crate::oned::telepen_common;
use crate::{point_f, BarcodeFormat}; use crate::{point_f, BarcodeFormat};
use bit_reverse::ParallelReverse; use bit_reverse::ParallelReverse;
@@ -118,19 +118,15 @@ impl OneDReader for TelepenReader {
if isBlack { if isBlack {
// Narrow black: B // Narrow black: B
pattern[patternLength] = 1; pattern[patternLength] = 1;
} } else {
else {
// Narrow white: . // Narrow white: .
pattern[patternLength] = 0; pattern[patternLength] = 0;
} }
} else {
}
else {
if isBlack { if isBlack {
// Wide black: BBB // Wide black: BBB
pattern[patternLength] = 3; pattern[patternLength] = 3;
} } else {
else {
// Wide white: ... // Wide white: ...
pattern[patternLength] = 2; pattern[patternLength] = 2;
} }
@@ -147,31 +143,26 @@ impl OneDReader for TelepenReader {
// Convert narrow-wide sequence into bit array. // Convert narrow-wide sequence into bit array.
while j < patternLength - 1 { while j < patternLength - 1 {
if pattern[j] == 3 && pattern[j + 1] == 2 { if pattern[j] == 3 && pattern[j + 1] == 2 {
// BBB... = 010 // BBB... = 010
bits.appendBit(false); bits.appendBit(false);
bits.appendBit(true); bits.appendBit(true);
bits.appendBit(false); bits.appendBit(false);
} } else if pattern[j] == 3 && pattern[j + 1] == 0 {
else if pattern[j] == 3 && pattern[j + 1] == 0 {
// BBB. = 00 // BBB. = 00
bits.appendBit(false); bits.appendBit(false);
bits.appendBit(false); bits.appendBit(false);
} } else if pattern[j] == 1 && pattern[j + 1] == 2 && state == 0 {
else if pattern[j] == 1 && pattern[j + 1] == 2 && state == 0 {
// B... = 01 // B... = 01
bits.appendBit(false); bits.appendBit(false);
bits.appendBit(true); bits.appendBit(true);
state = 1; state = 1;
} } else if pattern[j] == 1 && pattern[j + 1] == 2 && state == 1 {
else if pattern[j] == 1 && pattern[j + 1] == 2 && state == 1 {
// B... = 10 // B... = 10
bits.appendBit(true); bits.appendBit(true);
bits.appendBit(false); bits.appendBit(false);
state = 0; state = 0;
} } else if pattern[j] == 1 && pattern[j + 1] == 0 {
else if pattern[j] == 1 && pattern[j + 1] == 0 {
// B. = 1 // B. = 1
bits.appendBit(true); bits.appendBit(true);
} }
@@ -192,7 +183,7 @@ impl OneDReader for TelepenReader {
j = 0; j = 0;
// Tweak our byte array to clean things up a little. // Tweak our byte array to clean things up a little.
while j < byteLength { while j < byteLength {
// Telepen is little-endian, so need to swap the // Telepen is little-endian, so need to swap the
// bits around for each byte to be correct. // bits around for each byte to be correct.
bytes[j] = bytes[j].swap_bits(); bytes[j] = bytes[j].swap_bits();
@@ -220,7 +211,7 @@ impl OneDReader for TelepenReader {
} }
// Content bytes // Content bytes
let contentBytes = bytes[1 .. byteLength - 2].to_vec(); let contentBytes = bytes[1..byteLength - 2].to_vec();
let mut contentString = String::from_utf8_lossy(&contentBytes).to_string(); let mut contentString = String::from_utf8_lossy(&contentBytes).to_string();
// Penultimate byte is a block check character. // Penultimate byte is a block check character.
@@ -272,7 +263,6 @@ impl OneDReader for TelepenReader {
} }
} }
impl TelepenReader { impl TelepenReader {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
counters: vec![0; 80], //Vec::with_capacity(80), counters: vec![0; 80], //Vec::with_capacity(80),
@@ -302,12 +292,10 @@ impl TelepenReader {
while i < end { while i < end {
if row.get(i) == currentColor { if row.get(i) == currentColor {
count += 1; count += 1;
} } else {
else {
if count >= minToleratedWidth || self.counterLength == 0 { if count >= minToleratedWidth || self.counterLength == 0 {
self.counterAppend(count); self.counterAppend(count);
} } else {
else {
// Noise from previous bar. Treat it as the // Noise from previous bar. Treat it as the
// previous colour. // previous colour.
self.counters[self.counterLength - 1] += count; self.counters[self.counterLength - 1] += count;
@@ -322,8 +310,7 @@ impl TelepenReader {
if count >= minToleratedWidth { if count >= minToleratedWidth {
self.counterAppend(count); self.counterAppend(count);
} } else {
else {
// Noise from previous bar. Treat it as the // Noise from previous bar. Treat it as the
// previous colour. // previous colour.
self.counters[self.counterLength - 1] += count; self.counters[self.counterLength - 1] += count;
@@ -355,13 +342,13 @@ impl TelepenReader {
let mut maxBar: f32 = 0.0; let mut maxBar: f32 = 0.0;
let mut minBar: f32 = f32::MAX; let mut minBar: f32 = f32::MAX;
while i + j < self.counterLength && j < 20 { while i + j < self.counterLength && j < 20 {
if (self.counters[i + j] as f32) > maxBar { if (self.counters[i + j] as f32) > maxBar {
maxBar = self.counters[i + j] as f32; maxBar = self.counters[i + j] as f32;
} }
if (self.counters[ i + j] as f32) < minBar { if (self.counters[i + j] as f32) < minBar {
minBar = self.counters[ i + j] as f32; minBar = self.counters[i + j] as f32;
} }
j += 1; j += 1;
@@ -374,14 +361,13 @@ impl TelepenReader {
// First 10 items must be: // First 10 items must be:
// N-N-N-N-N-N-N-N-N-N-W // N-N-N-N-N-N-N-N-N-N-W
while i + j < self.counterLength && j < 11 { while i + j < self.counterLength && j < 11 {
if j < 10 { if j < 10 {
// Narrow // Narrow
if (self.counters[i + j] as f32) > median { if (self.counters[i + j] as f32) > median {
passed = false; passed = false;
break; break;
} } else if j == 10 {
else if j == 10 {
// Wide // Wide
if (self.counters[i + j] as f32) < median { if (self.counters[i + j] as f32) < median {
passed = false; passed = false;
@@ -413,7 +399,7 @@ impl TelepenReader {
let mut j = 0; let mut j = 0;
let mut maxBar: f32 = 0.0; let mut maxBar: f32 = 0.0;
while i + j < self.counterLength && j < 20 { while i + j < self.counterLength && j < 20 {
if (self.counters[i + j] as f32) > maxBar { if (self.counters[i + j] as f32) > maxBar {
maxBar = self.counters[i + j] as f32; maxBar = self.counters[i + j] as f32;
} }

View File

@@ -14,11 +14,11 @@
* limitations under the License. * limitations under the License.
*/ */
use rxing_one_d_proc_derive::OneDWriter;
use regex::Regex;
use crate::common::Result; use crate::common::Result;
use crate::BarcodeFormat;
use crate::oned::telepen_common; use crate::oned::telepen_common;
use crate::BarcodeFormat;
use regex::Regex;
use rxing_one_d_proc_derive::OneDWriter;
use super::OneDimensionalCodeWriter; use super::OneDimensionalCodeWriter;
@@ -35,9 +35,11 @@ impl OneDimensionalCodeWriter for TelepenWriter {
self.encode_oned_with_hints(contents, &HashMap::new()) self.encode_oned_with_hints(contents, &HashMap::new())
} }
fn encode_oned_with_hints(&self, contents: &str, fn encode_oned_with_hints(
hints: &crate::EncodingHintDictionary) -> Result<Vec<bool>> { &self,
contents: &str,
hints: &crate::EncodingHintDictionary,
) -> Result<Vec<bool>> {
let mut decodedContents = contents.to_string(); let mut decodedContents = contents.to_string();
if matches!( if matches!(
@@ -91,7 +93,7 @@ impl OneDimensionalCodeWriter for TelepenWriter {
result[resultPosition + 5] = false; result[resultPosition + 5] = false;
resultPosition += 6; resultPosition += 6;
}, }
"00" => { "00" => {
// BBB. // BBB.
result[resultPosition] = true; result[resultPosition] = true;
@@ -100,14 +102,14 @@ impl OneDimensionalCodeWriter for TelepenWriter {
result[resultPosition + 3] = false; result[resultPosition + 3] = false;
resultPosition += 4; resultPosition += 4;
}, }
"1" => { "1" => {
// B. // B.
result[resultPosition] = true; result[resultPosition] = true;
result[resultPosition + 1] = false; result[resultPosition + 1] = false;
resultPosition += 2; resultPosition += 2;
}, }
"01" => { "01" => {
// B... // B...
result[resultPosition] = true; result[resultPosition] = true;
@@ -116,7 +118,7 @@ impl OneDimensionalCodeWriter for TelepenWriter {
result[resultPosition + 3] = false; result[resultPosition + 3] = false;
resultPosition += 4; resultPosition += 4;
}, }
"10" => { "10" => {
// B... // B...
result[resultPosition] = true; result[resultPosition] = true;
@@ -125,12 +127,12 @@ impl OneDimensionalCodeWriter for TelepenWriter {
result[resultPosition + 3] = false; result[resultPosition + 3] = false;
resultPosition += 4; resultPosition += 4;
}, }
"0" => { "0" => {
return Err(Exceptions::illegal_argument_with(format!( return Err(Exceptions::illegal_argument_with(format!(
"Invalid bit combination!" "Invalid bit combination!"
))); )));
}, }
_ => { _ => {
// B... (B.)* B... // B... (B.)* B...
result[resultPosition] = true; result[resultPosition] = true;
@@ -140,7 +142,7 @@ impl OneDimensionalCodeWriter for TelepenWriter {
resultPosition += 4; resultPosition += 4;
for _j in 2 .. b.len() - 2 { for _j in 2..b.len() - 2 {
result[resultPosition] = true; result[resultPosition] = true;
result[resultPosition + 1] = false; result[resultPosition + 1] = false;
@@ -157,7 +159,7 @@ impl OneDimensionalCodeWriter for TelepenWriter {
} }
} }
Ok(result[0 .. resultPosition - 1].to_vec()) Ok(result[0..resultPosition - 1].to_vec())
} }
fn getSupportedWriteFormats(&self) -> Option<Vec<crate::BarcodeFormat>> { fn getSupportedWriteFormats(&self) -> Option<Vec<crate::BarcodeFormat>> {
@@ -191,12 +193,7 @@ impl TelepenWriter {
let bits = self.get_bits(byte); let bits = self.get_bits(byte);
for i in 0..8 { for i in 0..8 {
binary.push(if bits[i] { binary.push(if bits[i] { '1' } else { '0' });
'1'
}
else {
'0'
});
} }
return binary; return binary;
@@ -212,7 +209,7 @@ mod TelepenWriterTestCase {
use crate::{ use crate::{
common::{bit_matrix_test_case, BitMatrix}, common::{bit_matrix_test_case, BitMatrix},
BarcodeFormat, Writer, EncodeHintType, EncodeHintValue, BarcodeFormat, EncodeHintType, EncodeHintValue, Writer,
}; };
use super::TelepenWriter; use super::TelepenWriter;
@@ -251,8 +248,7 @@ mod TelepenWriterTestCase {
if numeric { if numeric {
result = encode_with_hints(input); result = encode_with_hints(input);
} } else {
else {
result = encode(input); result = encode(input);
}; };
@@ -267,7 +263,10 @@ mod TelepenWriterTestCase {
fn encode_with_hints(input: &str) -> BitMatrix { fn encode_with_hints(input: &str) -> BitMatrix {
let mut hints = HashMap::new(); let mut hints = HashMap::new();
hints.insert(EncodeHintType::TELEPEN_AS_NUMERIC, EncodeHintValue::TelepenAsNumeric(true)); hints.insert(
EncodeHintType::TELEPEN_AS_NUMERIC,
EncodeHintValue::TelepenAsNumeric(true),
);
TelepenWriter TelepenWriter
.encode_with_hints(input, &BarcodeFormat::TELEPEN, 0, 0, &hints) .encode_with_hints(input, &BarcodeFormat::TELEPEN, 0, 0, &hints)

View File

@@ -46,7 +46,10 @@ fn telepen_numeric_test_case() {
); );
tester.add_test_complex(7, 1, 0, 0, 0.0); tester.add_test_complex(7, 1, 0, 0, 0.0);
tester.add_hint(rxing::DecodeHintType::TELEPEN_AS_NUMERIC, rxing::DecodeHintValue::TelepenAsNumeric(true)); tester.add_hint(
rxing::DecodeHintType::TELEPEN_AS_NUMERIC,
rxing::DecodeHintValue::TelepenAsNumeric(true),
);
tester.ignore_pure = true; tester.ignore_pure = true;
tester.test_black_box(); tester.test_black_box();