mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-25 20:02:34 +00:00
chore: version update and cargo fmt
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rxing"
|
||||
version = "0.4.12"
|
||||
version = "0.5.0"
|
||||
description="A rust port of the zxing barcode library."
|
||||
license="Apache-2.0"
|
||||
repository="https://github.com/rxing-core/rxing"
|
||||
|
||||
@@ -39,6 +39,7 @@ All barcode formats are tested and functioning in their current state against cu
|
||||
| upc e | complete | yes | yes |
|
||||
| rss-14 | complete | no | yes |
|
||||
| rss-expanded | complete | no | yes|
|
||||
| telepen | complete | yes | yes |
|
||||
|
||||
Please note that currently UPC/EAN Extension 2/5 is supported.
|
||||
|
||||
@@ -81,6 +82,13 @@ fn main() {
|
||||
```
|
||||
|
||||
## 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.4* -> Major update of QRCode support.
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ use rxing::multi::{GenericMultipleBarcodeReader, MultipleBarcodeReader};
|
||||
use rxing::oned::rss::expanded::RSSExpandedReader;
|
||||
use rxing::oned::rss::RSS14Reader;
|
||||
use rxing::oned::{
|
||||
CodaBarReader, Code39Reader, Code93Reader, EAN13Reader, EAN8Reader, TelepenReader, ITFReader, UPCAReader,
|
||||
UPCEReader,
|
||||
CodaBarReader, Code39Reader, Code93Reader, EAN13Reader, EAN8Reader, ITFReader, TelepenReader,
|
||||
UPCAReader, UPCEReader,
|
||||
};
|
||||
use rxing::pdf417::PDF417Reader;
|
||||
use rxing::qrcode::QRCodeReader;
|
||||
|
||||
@@ -11,4 +11,4 @@ keywords = ["barcode", "2d_barcode", "1d_barcode", "barcode_reader", "barcode_wr
|
||||
|
||||
[dependencies]
|
||||
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"] }
|
||||
|
||||
@@ -126,7 +126,6 @@ pub enum DecodeHintType {
|
||||
* Will translate the ASCII values parsed by the Telepen reader into the Telepen Numeric form.
|
||||
*/
|
||||
TELEPEN_AS_NUMERIC,
|
||||
|
||||
/*
|
||||
* Data type the hint is expecting.
|
||||
* Among the possible values the {@link Void} stands out as being used for
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::Exceptions;
|
||||
use crate::common::Result;
|
||||
use crate::Exceptions;
|
||||
|
||||
pub fn calculate_checksum(contents: &str) -> char {
|
||||
let mut sum = 0;
|
||||
@@ -12,8 +12,7 @@ pub fn calculate_checksum(contents: &str) -> char {
|
||||
let diff = 127 - remainder;
|
||||
return if diff != 127 {
|
||||
diff as u8 as char
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
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) {
|
||||
if c >= 27 {
|
||||
number.push_str(&format!("{:0>2}", (c - 27)));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
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> {
|
||||
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();
|
||||
@@ -47,12 +47,13 @@ pub fn numeric_to_ascii(contents: &str) -> Result<String> {
|
||||
|
||||
if second == 88 && first >= 48 && first <= 57 {
|
||||
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);
|
||||
}
|
||||
else {
|
||||
return Err(Exceptions::illegal_argument_with(format!("Input contains an invalid character around position {}.", i.to_string())));
|
||||
} else {
|
||||
return Err(Exceptions::illegal_argument_with(format!(
|
||||
"Input contains an invalid character around position {}.",
|
||||
i.to_string()
|
||||
)));
|
||||
}
|
||||
|
||||
i += 2;
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
use rxing_one_d_proc_derive::OneDReader;
|
||||
|
||||
use crate::common::{BitArray, Result};
|
||||
use crate::oned::telepen_common;
|
||||
use crate::DecodeHintValue;
|
||||
use crate::Exceptions;
|
||||
use crate::RXingResult;
|
||||
use crate::DecodeHintValue;
|
||||
use crate::oned::telepen_common;
|
||||
use crate::{point_f, BarcodeFormat};
|
||||
use bit_reverse::ParallelReverse;
|
||||
|
||||
@@ -118,19 +118,15 @@ impl OneDReader for TelepenReader {
|
||||
if isBlack {
|
||||
// Narrow black: B
|
||||
pattern[patternLength] = 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Narrow white: .
|
||||
pattern[patternLength] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if isBlack {
|
||||
// Wide black: BBB
|
||||
pattern[patternLength] = 3;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Wide white: ...
|
||||
pattern[patternLength] = 2;
|
||||
}
|
||||
@@ -147,31 +143,26 @@ impl OneDReader for TelepenReader {
|
||||
|
||||
// Convert narrow-wide sequence into bit array.
|
||||
while j < patternLength - 1 {
|
||||
|
||||
if pattern[j] == 3 && pattern[j + 1] == 2 {
|
||||
// BBB... = 010
|
||||
bits.appendBit(false);
|
||||
bits.appendBit(true);
|
||||
bits.appendBit(false);
|
||||
}
|
||||
else if pattern[j] == 3 && pattern[j + 1] == 0 {
|
||||
} else if pattern[j] == 3 && pattern[j + 1] == 0 {
|
||||
// BBB. = 00
|
||||
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
|
||||
bits.appendBit(false);
|
||||
bits.appendBit(true);
|
||||
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
|
||||
bits.appendBit(true);
|
||||
bits.appendBit(false);
|
||||
state = 0;
|
||||
}
|
||||
else if pattern[j] == 1 && pattern[j + 1] == 0 {
|
||||
} else if pattern[j] == 1 && pattern[j + 1] == 0 {
|
||||
// B. = 1
|
||||
bits.appendBit(true);
|
||||
}
|
||||
@@ -220,7 +211,7 @@ impl OneDReader for TelepenReader {
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
// Penultimate byte is a block check character.
|
||||
@@ -272,7 +263,6 @@ impl OneDReader for TelepenReader {
|
||||
}
|
||||
}
|
||||
impl TelepenReader {
|
||||
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
counters: vec![0; 80], //Vec::with_capacity(80),
|
||||
@@ -302,12 +292,10 @@ impl TelepenReader {
|
||||
while i < end {
|
||||
if row.get(i) == currentColor {
|
||||
count += 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if count >= minToleratedWidth || self.counterLength == 0 {
|
||||
self.counterAppend(count);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Noise from previous bar. Treat it as the
|
||||
// previous colour.
|
||||
self.counters[self.counterLength - 1] += count;
|
||||
@@ -322,8 +310,7 @@ impl TelepenReader {
|
||||
|
||||
if count >= minToleratedWidth {
|
||||
self.counterAppend(count);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Noise from previous bar. Treat it as the
|
||||
// previous colour.
|
||||
self.counters[self.counterLength - 1] += count;
|
||||
@@ -360,8 +347,8 @@ impl TelepenReader {
|
||||
maxBar = self.counters[i + j] as f32;
|
||||
}
|
||||
|
||||
if (self.counters[ i + j] as f32) < minBar {
|
||||
minBar = self.counters[ i + j] as f32;
|
||||
if (self.counters[i + j] as f32) < minBar {
|
||||
minBar = self.counters[i + j] as f32;
|
||||
}
|
||||
|
||||
j += 1;
|
||||
@@ -380,8 +367,7 @@ impl TelepenReader {
|
||||
if (self.counters[i + j] as f32) > median {
|
||||
passed = false;
|
||||
break;
|
||||
}
|
||||
else if j == 10 {
|
||||
} else if j == 10 {
|
||||
// Wide
|
||||
if (self.counters[i + j] as f32) < median {
|
||||
passed = false;
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use rxing_one_d_proc_derive::OneDWriter;
|
||||
use regex::Regex;
|
||||
use crate::common::Result;
|
||||
use crate::BarcodeFormat;
|
||||
use crate::oned::telepen_common;
|
||||
use crate::BarcodeFormat;
|
||||
use regex::Regex;
|
||||
use rxing_one_d_proc_derive::OneDWriter;
|
||||
|
||||
use super::OneDimensionalCodeWriter;
|
||||
|
||||
@@ -35,9 +35,11 @@ impl OneDimensionalCodeWriter for TelepenWriter {
|
||||
self.encode_oned_with_hints(contents, &HashMap::new())
|
||||
}
|
||||
|
||||
fn encode_oned_with_hints(&self, contents: &str,
|
||||
hints: &crate::EncodingHintDictionary) -> Result<Vec<bool>> {
|
||||
|
||||
fn encode_oned_with_hints(
|
||||
&self,
|
||||
contents: &str,
|
||||
hints: &crate::EncodingHintDictionary,
|
||||
) -> Result<Vec<bool>> {
|
||||
let mut decodedContents = contents.to_string();
|
||||
|
||||
if matches!(
|
||||
@@ -91,7 +93,7 @@ impl OneDimensionalCodeWriter for TelepenWriter {
|
||||
result[resultPosition + 5] = false;
|
||||
|
||||
resultPosition += 6;
|
||||
},
|
||||
}
|
||||
"00" => {
|
||||
// BBB.
|
||||
result[resultPosition] = true;
|
||||
@@ -100,14 +102,14 @@ impl OneDimensionalCodeWriter for TelepenWriter {
|
||||
result[resultPosition + 3] = false;
|
||||
|
||||
resultPosition += 4;
|
||||
},
|
||||
}
|
||||
"1" => {
|
||||
// B.
|
||||
result[resultPosition] = true;
|
||||
result[resultPosition + 1] = false;
|
||||
|
||||
resultPosition += 2;
|
||||
},
|
||||
}
|
||||
"01" => {
|
||||
// B...
|
||||
result[resultPosition] = true;
|
||||
@@ -116,7 +118,7 @@ impl OneDimensionalCodeWriter for TelepenWriter {
|
||||
result[resultPosition + 3] = false;
|
||||
|
||||
resultPosition += 4;
|
||||
},
|
||||
}
|
||||
"10" => {
|
||||
// B...
|
||||
result[resultPosition] = true;
|
||||
@@ -125,12 +127,12 @@ impl OneDimensionalCodeWriter for TelepenWriter {
|
||||
result[resultPosition + 3] = false;
|
||||
|
||||
resultPosition += 4;
|
||||
},
|
||||
}
|
||||
"0" => {
|
||||
return Err(Exceptions::illegal_argument_with(format!(
|
||||
"Invalid bit combination!"
|
||||
)));
|
||||
},
|
||||
}
|
||||
_ => {
|
||||
// B... (B.)* B...
|
||||
result[resultPosition] = true;
|
||||
@@ -140,7 +142,7 @@ impl OneDimensionalCodeWriter for TelepenWriter {
|
||||
|
||||
resultPosition += 4;
|
||||
|
||||
for _j in 2 .. b.len() - 2 {
|
||||
for _j in 2..b.len() - 2 {
|
||||
result[resultPosition] = true;
|
||||
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>> {
|
||||
@@ -191,12 +193,7 @@ impl TelepenWriter {
|
||||
let bits = self.get_bits(byte);
|
||||
|
||||
for i in 0..8 {
|
||||
binary.push(if bits[i] {
|
||||
'1'
|
||||
}
|
||||
else {
|
||||
'0'
|
||||
});
|
||||
binary.push(if bits[i] { '1' } else { '0' });
|
||||
}
|
||||
|
||||
return binary;
|
||||
@@ -212,7 +209,7 @@ mod TelepenWriterTestCase {
|
||||
|
||||
use crate::{
|
||||
common::{bit_matrix_test_case, BitMatrix},
|
||||
BarcodeFormat, Writer, EncodeHintType, EncodeHintValue,
|
||||
BarcodeFormat, EncodeHintType, EncodeHintValue, Writer,
|
||||
};
|
||||
|
||||
use super::TelepenWriter;
|
||||
@@ -251,8 +248,7 @@ mod TelepenWriterTestCase {
|
||||
|
||||
if numeric {
|
||||
result = encode_with_hints(input);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
result = encode(input);
|
||||
};
|
||||
|
||||
@@ -267,7 +263,10 @@ mod TelepenWriterTestCase {
|
||||
|
||||
fn encode_with_hints(input: &str) -> BitMatrix {
|
||||
let mut hints = HashMap::new();
|
||||
hints.insert(EncodeHintType::TELEPEN_AS_NUMERIC, EncodeHintValue::TelepenAsNumeric(true));
|
||||
hints.insert(
|
||||
EncodeHintType::TELEPEN_AS_NUMERIC,
|
||||
EncodeHintValue::TelepenAsNumeric(true),
|
||||
);
|
||||
|
||||
TelepenWriter
|
||||
.encode_with_hints(input, &BarcodeFormat::TELEPEN, 0, 0, &hints)
|
||||
|
||||
@@ -46,7 +46,10 @@ fn telepen_numeric_test_case() {
|
||||
);
|
||||
|
||||
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.test_black_box();
|
||||
|
||||
Reference in New Issue
Block a user