mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
fix issue with metadata testing
This commit is contained in:
@@ -39,6 +39,8 @@ pub struct DecoderRXingResult {
|
|||||||
structuredAppendParity: i32,
|
structuredAppendParity: i32,
|
||||||
structuredAppendSequenceNumber: i32,
|
structuredAppendSequenceNumber: i32,
|
||||||
symbologyModifier: u32,
|
symbologyModifier: u32,
|
||||||
|
contentType: String,
|
||||||
|
isMirrored: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DecoderRXingResult {
|
impl DecoderRXingResult {
|
||||||
@@ -48,7 +50,17 @@ impl DecoderRXingResult {
|
|||||||
byteSegments: Vec<Vec<u8>>,
|
byteSegments: Vec<Vec<u8>>,
|
||||||
ecLevel: String,
|
ecLevel: String,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::with_all(rawBytes, text, byteSegments, ecLevel, -2, -2, 0)
|
Self::with_all(
|
||||||
|
rawBytes,
|
||||||
|
text,
|
||||||
|
byteSegments,
|
||||||
|
ecLevel,
|
||||||
|
-2,
|
||||||
|
-2,
|
||||||
|
0,
|
||||||
|
String::default(),
|
||||||
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_symbology(
|
pub fn with_symbology(
|
||||||
@@ -66,6 +78,8 @@ impl DecoderRXingResult {
|
|||||||
-1,
|
-1,
|
||||||
-1,
|
-1,
|
||||||
symbologyModifier,
|
symbologyModifier,
|
||||||
|
String::default(),
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,6 +99,8 @@ impl DecoderRXingResult {
|
|||||||
saSequence,
|
saSequence,
|
||||||
saParity,
|
saParity,
|
||||||
0,
|
0,
|
||||||
|
String::default(),
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,6 +112,8 @@ impl DecoderRXingResult {
|
|||||||
saSequence: i32,
|
saSequence: i32,
|
||||||
saParity: i32,
|
saParity: i32,
|
||||||
symbologyModifier: u32,
|
symbologyModifier: u32,
|
||||||
|
contentType: String,
|
||||||
|
isMirrored: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let nb = rawBytes.len();
|
let nb = rawBytes.len();
|
||||||
Self {
|
Self {
|
||||||
@@ -110,6 +128,8 @@ impl DecoderRXingResult {
|
|||||||
structuredAppendParity: saParity,
|
structuredAppendParity: saParity,
|
||||||
structuredAppendSequenceNumber: saSequence,
|
structuredAppendSequenceNumber: saSequence,
|
||||||
symbologyModifier,
|
symbologyModifier,
|
||||||
|
contentType,
|
||||||
|
isMirrored,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,4 +225,20 @@ impl DecoderRXingResult {
|
|||||||
pub fn getSymbologyModifier(&self) -> u32 {
|
pub fn getSymbologyModifier(&self) -> u32 {
|
||||||
self.symbologyModifier
|
self.symbologyModifier
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn getContentType(&self) -> &str {
|
||||||
|
&self.contentType
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn setContentType(&mut self, content_type: String) {
|
||||||
|
self.contentType = content_type
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn getIsMirrored(&self) -> bool {
|
||||||
|
self.isMirrored
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn setIsMirrored(&mut self, is_mirrored: bool) {
|
||||||
|
self.isMirrored = is_mirrored
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,11 +107,11 @@ impl ECIStringBuilder {
|
|||||||
self.encodeCurrentBytesIfAny();
|
self.encodeCurrentBytesIfAny();
|
||||||
|
|
||||||
if let Ok(character_set_eci) = CharacterSetECI::getCharacterSetECIByValue(value) {
|
if let Ok(character_set_eci) = CharacterSetECI::getCharacterSetECIByValue(value) {
|
||||||
dbg!(
|
// dbg!(
|
||||||
character_set_eci,
|
// character_set_eci,
|
||||||
CharacterSetECI::getCharset(&character_set_eci).name(),
|
// CharacterSetECI::getCharset(&character_set_eci).name(),
|
||||||
CharacterSetECI::getCharset(&character_set_eci).whatwg_name()
|
// CharacterSetECI::getCharset(&character_set_eci).whatwg_name()
|
||||||
);
|
// );
|
||||||
self.current_charset = Some(CharacterSetECI::getCharset(&character_set_eci));
|
self.current_charset = Some(CharacterSetECI::getCharset(&character_set_eci));
|
||||||
} else {
|
} else {
|
||||||
self.current_charset = None
|
self.current_charset = None
|
||||||
|
|||||||
@@ -131,6 +131,31 @@ impl Reader for DataMatrixReader {
|
|||||||
RXingResultMetadataValue::ErrorCorrectionLevel(ecLevel.to_string()),
|
RXingResultMetadataValue::ErrorCorrectionLevel(ecLevel.to_string()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
let other_meta = decoderRXingResult.getOther();
|
||||||
|
if let Some(other) = other_meta {
|
||||||
|
if let Some(dcr) = other.downcast_ref::<String>() {
|
||||||
|
result.putMetadata(
|
||||||
|
RXingResultMetadataType::OTHER,
|
||||||
|
RXingResultMetadataValue::OTHER(dcr.to_owned()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let contentType = decoderRXingResult.getContentType();
|
||||||
|
if !contentType.is_empty() {
|
||||||
|
result.putMetadata(
|
||||||
|
RXingResultMetadataType::CONTENT_TYPE,
|
||||||
|
RXingResultMetadataValue::ContentType(contentType.to_owned()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mirrored = decoderRXingResult.getIsMirrored();
|
||||||
|
if mirrored {
|
||||||
|
result.putMetadata(
|
||||||
|
RXingResultMetadataType::IS_MIRRORED,
|
||||||
|
RXingResultMetadataValue::IsMirrored(mirrored),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
result.putMetadata(
|
result.putMetadata(
|
||||||
RXingResultMetadataType::SYMBOLOGY_IDENTIFIER,
|
RXingResultMetadataType::SYMBOLOGY_IDENTIFIER,
|
||||||
RXingResultMetadataValue::SymbologyIdentifier(format!(
|
RXingResultMetadataValue::SymbologyIdentifier(format!(
|
||||||
|
|||||||
@@ -50,12 +50,12 @@ impl Decoder {
|
|||||||
* @throws ChecksumException if error correction fails
|
* @throws ChecksumException if error correction fails
|
||||||
*/
|
*/
|
||||||
pub fn decode(&self, bits: &BitMatrix) -> Result<DecoderRXingResult, Exceptions> {
|
pub fn decode(&self, bits: &BitMatrix) -> Result<DecoderRXingResult, Exceptions> {
|
||||||
let decoded = self.perform_decode(bits, false);
|
let decoded = self.perform_decode(bits, false, false);
|
||||||
if decoded.is_ok() {
|
if decoded.is_ok() {
|
||||||
return decoded;
|
return decoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.perform_decode(&Self::flip_bitmatrix(bits)?, false)
|
self.perform_decode(&Self::flip_bitmatrix(bits)?, false, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flip_bitmatrix(bits: &BitMatrix) -> Result<BitMatrix, Exceptions> {
|
fn flip_bitmatrix(bits: &BitMatrix) -> Result<BitMatrix, Exceptions> {
|
||||||
@@ -85,7 +85,7 @@ impl Decoder {
|
|||||||
* @throws ChecksumException if error correction fails
|
* @throws ChecksumException if error correction fails
|
||||||
*/
|
*/
|
||||||
pub fn decode_bools(&self, image: &Vec<Vec<bool>>) -> Result<DecoderRXingResult, Exceptions> {
|
pub fn decode_bools(&self, image: &Vec<Vec<bool>>) -> Result<DecoderRXingResult, Exceptions> {
|
||||||
self.perform_decode(&BitMatrix::parse_bools(image), false)
|
self.perform_decode(&BitMatrix::parse_bools(image), false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -101,6 +101,7 @@ impl Decoder {
|
|||||||
&self,
|
&self,
|
||||||
bits: &BitMatrix,
|
bits: &BitMatrix,
|
||||||
fix259: bool,
|
fix259: bool,
|
||||||
|
is_flipped: bool,
|
||||||
) -> Result<DecoderRXingResult, Exceptions> {
|
) -> Result<DecoderRXingResult, Exceptions> {
|
||||||
// Construct a parser and read version, error-correction level
|
// Construct a parser and read version, error-correction level
|
||||||
let mut parser = BitMatrixParser::new(bits)?;
|
let mut parser = BitMatrixParser::new(bits)?;
|
||||||
@@ -129,7 +130,7 @@ impl Decoder {
|
|||||||
let numDataCodewords = dataBlock.getNumDataCodewords() as usize;
|
let numDataCodewords = dataBlock.getNumDataCodewords() as usize;
|
||||||
let errors_corrected = self.correctErrors(&mut codewordBytes, numDataCodewords as u32);
|
let errors_corrected = self.correctErrors(&mut codewordBytes, numDataCodewords as u32);
|
||||||
if errors_corrected.is_err() && !fix259 {
|
if errors_corrected.is_err() && !fix259 {
|
||||||
return self.perform_decode(bits, true);
|
return self.perform_decode(bits, true, is_flipped);
|
||||||
} else if errors_corrected.is_err() {
|
} else if errors_corrected.is_err() {
|
||||||
return Err(errors_corrected.err().unwrap());
|
return Err(errors_corrected.err().unwrap());
|
||||||
}
|
}
|
||||||
@@ -141,7 +142,7 @@ impl Decoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Decode the contents of that stream of bytes
|
// Decode the contents of that stream of bytes
|
||||||
decoded_bit_stream_parser::decode(&resultBytes)
|
decoded_bit_stream_parser::decode(&resultBytes, is_flipped)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ const INSERT_STRING_CONST: &str = "\u{001E}\u{0004}";
|
|||||||
const VALUE_236: &str = "[)>\u{001E}05\u{001D}";
|
const VALUE_236: &str = "[)>\u{001E}05\u{001D}";
|
||||||
const VALUE_237: &str = "[)>\u{001E}06\u{001D}";
|
const VALUE_237: &str = "[)>\u{001E}06\u{001D}";
|
||||||
|
|
||||||
pub fn decode(bytes: &[u8]) -> Result<DecoderRXingResult, Exceptions> {
|
pub fn decode(bytes: &[u8], is_flipped: bool) -> Result<DecoderRXingResult, Exceptions> {
|
||||||
let mut bits = BitSource::new(bytes.to_vec());
|
let mut bits = BitSource::new(bytes.to_vec());
|
||||||
let mut result = ECIStringBuilder::with_capacity(100);
|
let mut result = ECIStringBuilder::with_capacity(100);
|
||||||
let mut resultTrailer = String::new();
|
let mut resultTrailer = String::new();
|
||||||
@@ -120,6 +120,8 @@ pub fn decode(bytes: &[u8]) -> Result<DecoderRXingResult, Exceptions> {
|
|||||||
let mut fnc1Positions = Vec::new();
|
let mut fnc1Positions = Vec::new();
|
||||||
let symbologyModifier;
|
let symbologyModifier;
|
||||||
let mut isECIencoded = false;
|
let mut isECIencoded = false;
|
||||||
|
let mut known_eci = true;
|
||||||
|
let mut is_gs1 = false;
|
||||||
loop {
|
loop {
|
||||||
match mode {
|
match mode {
|
||||||
Mode::ASCII_ENCODE => {
|
Mode::ASCII_ENCODE => {
|
||||||
@@ -128,6 +130,7 @@ pub fn decode(bytes: &[u8]) -> Result<DecoderRXingResult, Exceptions> {
|
|||||||
&mut result,
|
&mut result,
|
||||||
&mut resultTrailer,
|
&mut resultTrailer,
|
||||||
&mut fnc1Positions,
|
&mut fnc1Positions,
|
||||||
|
&mut is_gs1,
|
||||||
)?
|
)?
|
||||||
}
|
}
|
||||||
Mode::C40_ENCODE => {
|
Mode::C40_ENCODE => {
|
||||||
@@ -151,7 +154,7 @@ pub fn decode(bytes: &[u8]) -> Result<DecoderRXingResult, Exceptions> {
|
|||||||
mode = Mode::ASCII_ENCODE;
|
mode = Mode::ASCII_ENCODE;
|
||||||
}
|
}
|
||||||
Mode::ECI_ENCODE => {
|
Mode::ECI_ENCODE => {
|
||||||
decodeECISegment(&mut bits, &mut result)?;
|
known_eci &= decodeECISegment(&mut bits, &mut result)?;
|
||||||
isECIencoded = true; // ECI detection only, atm continue decoding as ASCII
|
isECIencoded = true; // ECI detection only, atm continue decoding as ASCII
|
||||||
mode = Mode::ASCII_ENCODE;
|
mode = Mode::ASCII_ENCODE;
|
||||||
}
|
}
|
||||||
@@ -165,7 +168,7 @@ pub fn decode(bytes: &[u8]) -> Result<DecoderRXingResult, Exceptions> {
|
|||||||
if !resultTrailer.is_empty() {
|
if !resultTrailer.is_empty() {
|
||||||
result.appendCharacters(&resultTrailer);
|
result.appendCharacters(&resultTrailer);
|
||||||
}
|
}
|
||||||
if isECIencoded {
|
if isECIencoded && known_eci {
|
||||||
// Examples for this numbers can be found in this documentation of a hardware barcode scanner:
|
// Examples for this numbers can be found in this documentation of a hardware barcode scanner:
|
||||||
// https://honeywellaidc.force.com/supportppr/s/article/List-of-barcode-symbology-AIM-Identifiers
|
// https://honeywellaidc.force.com/supportppr/s/article/List-of-barcode-symbology-AIM-Identifiers
|
||||||
if fnc1Positions.contains(&0) || fnc1Positions.contains(&4) {
|
if fnc1Positions.contains(&0) || fnc1Positions.contains(&4) {
|
||||||
@@ -183,13 +186,26 @@ pub fn decode(bytes: &[u8]) -> Result<DecoderRXingResult, Exceptions> {
|
|||||||
symbologyModifier = 1;
|
symbologyModifier = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(DecoderRXingResult::with_symbology(
|
let mut result = DecoderRXingResult::with_symbology(
|
||||||
bytes.to_vec(),
|
bytes.to_vec(),
|
||||||
result.build_result().to_string(),
|
result.build_result().to_string(),
|
||||||
byteSegments,
|
byteSegments,
|
||||||
String::new(),
|
String::new(),
|
||||||
symbologyModifier,
|
symbologyModifier,
|
||||||
))
|
);
|
||||||
|
if is_gs1 {
|
||||||
|
result.setContentType(String::from("GS1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if !known_eci {
|
||||||
|
result.setContentType(String::from("UnknownECI"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if is_flipped {
|
||||||
|
result.setIsMirrored(is_flipped);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(result)
|
||||||
|
|
||||||
// return new DecoderRXingResult(bytes,
|
// return new DecoderRXingResult(bytes,
|
||||||
// result.toString(),
|
// result.toString(),
|
||||||
@@ -206,6 +222,7 @@ fn decodeAsciiSegment(
|
|||||||
result: &mut ECIStringBuilder,
|
result: &mut ECIStringBuilder,
|
||||||
resultTrailer: &mut String,
|
resultTrailer: &mut String,
|
||||||
fnc1positions: &mut Vec<usize>,
|
fnc1positions: &mut Vec<usize>,
|
||||||
|
is_gs1: &mut bool,
|
||||||
) -> Result<Mode, Exceptions> {
|
) -> Result<Mode, Exceptions> {
|
||||||
let mut upperShift = false;
|
let mut upperShift = false;
|
||||||
let mut firstFNC1Position = 1;
|
let mut firstFNC1Position = 1;
|
||||||
@@ -247,16 +264,20 @@ fn decodeAsciiSegment(
|
|||||||
}
|
}
|
||||||
232 => {
|
232 => {
|
||||||
// FNC1
|
// FNC1
|
||||||
if bits.getByteOffset() == firstFNC1Position { /*result.symbology.modifier = '2';*/
|
if bits.getByteOffset() == firstFNC1Position {
|
||||||
|
/*result.symbology.modifier = '2';*/
|
||||||
|
*is_gs1 = true;
|
||||||
}
|
}
|
||||||
// GS1
|
// GS1
|
||||||
else if bits.getByteOffset() == firstFNC1Position + 1 { /*result.symbology.modifier = '3';*/
|
else if bits.getByteOffset() == firstFNC1Position + 1 {
|
||||||
|
/*result.symbology.modifier = '3';*/
|
||||||
}
|
}
|
||||||
// AIM, note no AIM Application Indicator format defined, ISO 16022:2006 11.2
|
// AIM, note no AIM Application Indicator format defined, ISO 16022:2006 11.2
|
||||||
else {
|
else {
|
||||||
fnc1positions.push(result.len());
|
|
||||||
result.append_char(29 as char);
|
result.append_char(29 as char);
|
||||||
} // translate as ASCII 29
|
} // translate as ASCII 29
|
||||||
|
|
||||||
|
fnc1positions.push(result.len());
|
||||||
}
|
}
|
||||||
233 =>
|
233 =>
|
||||||
// Structured Append
|
// Structured Append
|
||||||
@@ -727,20 +748,26 @@ fn decodeBase256Segment(
|
|||||||
/**
|
/**
|
||||||
* See ISO 16022:2007, 5.4.1
|
* See ISO 16022:2007, 5.4.1
|
||||||
*/
|
*/
|
||||||
fn decodeECISegment(bits: &mut BitSource, result: &mut ECIStringBuilder) -> Result<(), Exceptions> {
|
fn decodeECISegment(
|
||||||
|
bits: &mut BitSource,
|
||||||
|
result: &mut ECIStringBuilder,
|
||||||
|
) -> Result<bool, Exceptions> {
|
||||||
let firstByte = bits.readBits(8)?;
|
let firstByte = bits.readBits(8)?;
|
||||||
if firstByte <= 127 {
|
if firstByte <= 127 {
|
||||||
return result.appendECI(firstByte - 1);
|
result.appendECI(firstByte - 1)?;
|
||||||
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
let secondByte = bits.readBits(8)?;
|
let secondByte = bits.readBits(8)?;
|
||||||
if firstByte <= 191 {
|
if firstByte <= 191 {
|
||||||
return result.appendECI((firstByte - 128) * 254 + 127 + secondByte - 1);
|
result.appendECI((firstByte - 128) * 254 + 127 + secondByte - 1)?;
|
||||||
|
return Ok((firstByte - 128) * 254 + 127 + secondByte - 1 > 900);
|
||||||
}
|
}
|
||||||
|
|
||||||
let thirdByte = bits.readBits(8)?;
|
let thirdByte = bits.readBits(8)?;
|
||||||
|
|
||||||
result.appendECI((firstByte - 192) * 64516 + 16383 + (secondByte - 1) * 254 + thirdByte - 1)
|
result.appendECI((firstByte - 192) * 64516 + 16383 + (secondByte - 1) * 254 + thirdByte - 1)?;
|
||||||
|
return Ok((firstByte - 192) * 64516 + 16383 + (secondByte - 1) * 254 + thirdByte - 1 > 900);
|
||||||
|
|
||||||
// if bits.available() < 8 {
|
// if bits.available() < 8 {
|
||||||
// return Err(Exceptions::FormatException(None));
|
// return Err(Exceptions::FormatException(None));
|
||||||
@@ -839,7 +866,7 @@ mod tests {
|
|||||||
(b'C' + 1),
|
(b'C' + 1),
|
||||||
];
|
];
|
||||||
let decodedString = String::from(
|
let decodedString = String::from(
|
||||||
decoded_bit_stream_parser::decode(&bytes)
|
decoded_bit_stream_parser::decode(&bytes, false)
|
||||||
.expect("decode")
|
.expect("decode")
|
||||||
.getText(),
|
.getText(),
|
||||||
);
|
);
|
||||||
@@ -851,7 +878,7 @@ mod tests {
|
|||||||
// ASCII double digit (00 - 99) Numeric Value + 130
|
// ASCII double digit (00 - 99) Numeric Value + 130
|
||||||
let bytes = [130, (1 + 130), (98 + 130), (99 + 130)];
|
let bytes = [130, (1 + 130), (98 + 130), (99 + 130)];
|
||||||
let decodedString = String::from(
|
let decodedString = String::from(
|
||||||
decoded_bit_stream_parser::decode(&bytes)
|
decoded_bit_stream_parser::decode(&bytes, false)
|
||||||
.expect("decode")
|
.expect("decode")
|
||||||
.getText(),
|
.getText(),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -432,7 +432,7 @@ fn find_concentric_circles(image: &BitMatrix) -> Option<Vec<Circle>> {
|
|||||||
// false alarm, go on with the row
|
// false alarm, go on with the row
|
||||||
let new_column = center - radius + (radius / 4);
|
let new_column = center - radius + (radius / 4);
|
||||||
if new_column == current_column {
|
if new_column == current_column {
|
||||||
// this is necessary because sometimes the loop can get
|
// this is necessary because sometimes the loop can get
|
||||||
// stuck when the result always comes out the same.
|
// stuck when the result always comes out the same.
|
||||||
row += ROW_SCAN_SKIP;
|
row += ROW_SCAN_SKIP;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -173,6 +173,8 @@ pub fn decode(
|
|||||||
symbolSequence,
|
symbolSequence,
|
||||||
parityData,
|
parityData,
|
||||||
symbologyModifier,
|
symbologyModifier,
|
||||||
|
String::default(),
|
||||||
|
false,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -108,23 +108,39 @@ pub enum RXingResultMetadataType {
|
|||||||
* when prepending to the barcode content.
|
* when prepending to the barcode content.
|
||||||
*/
|
*/
|
||||||
SYMBOLOGY_IDENTIFIER,
|
SYMBOLOGY_IDENTIFIER,
|
||||||
|
|
||||||
|
IS_MIRRORED,
|
||||||
|
|
||||||
|
CONTENT_TYPE,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<String> for RXingResultMetadataType {
|
impl From<String> for RXingResultMetadataType {
|
||||||
fn from(in_str: String) -> Self {
|
fn from(in_str: String) -> Self {
|
||||||
match in_str.as_str() {
|
match in_str.to_uppercase().as_str() {
|
||||||
"OTHER" => RXingResultMetadataType::OTHER,
|
"OTHER" => RXingResultMetadataType::OTHER,
|
||||||
"ORIENTATION" => RXingResultMetadataType::ORIENTATION,
|
"ORIENTATION" => RXingResultMetadataType::ORIENTATION,
|
||||||
"BYTE_SEGMENTS" => RXingResultMetadataType::BYTE_SEGMENTS,
|
"BYTE_SEGMENTS" | "BYTESEGMENTS" => RXingResultMetadataType::BYTE_SEGMENTS,
|
||||||
"ERROR_CORRECTION_LEVEL" => RXingResultMetadataType::ERROR_CORRECTION_LEVEL,
|
"ERROR_CORRECTION_LEVEL" | "ERRORCORRECTIONLEVEL" => {
|
||||||
"ISSUE_NUMBER" => RXingResultMetadataType::ISSUE_NUMBER,
|
RXingResultMetadataType::ERROR_CORRECTION_LEVEL
|
||||||
"SUGGESTED_PRICE" => RXingResultMetadataType::SUGGESTED_PRICE,
|
}
|
||||||
"POSSIBLE_COUNTRY" => RXingResultMetadataType::POSSIBLE_COUNTRY,
|
"ISSUE_NUMBER" | "ISSUENUMBER" => RXingResultMetadataType::ISSUE_NUMBER,
|
||||||
"UPC_EAN_EXTENSION" => RXingResultMetadataType::UPC_EAN_EXTENSION,
|
"SUGGESTED_PRICE" | "SUGGESTEDPRICE" => RXingResultMetadataType::SUGGESTED_PRICE,
|
||||||
"PDF417_EXTRA_METADATA" => RXingResultMetadataType::PDF417_EXTRA_METADATA,
|
"POSSIBLE_COUNTRY" | "POSSIBLECOUNTRY" => RXingResultMetadataType::POSSIBLE_COUNTRY,
|
||||||
"STRUCTURED_APPEND_SEQUENCE" => RXingResultMetadataType::STRUCTURED_APPEND_SEQUENCE,
|
"UPC_EAN_EXTENSION" | "UPCEANEXTENSION" => RXingResultMetadataType::UPC_EAN_EXTENSION,
|
||||||
"STRUCTURED_APPEND_PARITY" => RXingResultMetadataType::STRUCTURED_APPEND_PARITY,
|
"PDF417_EXTRA_METADATA" | "PDF417EXTRAMETADATA" => {
|
||||||
"SYMBOLOGY_IDENTIFIER" => RXingResultMetadataType::SYMBOLOGY_IDENTIFIER,
|
RXingResultMetadataType::PDF417_EXTRA_METADATA
|
||||||
|
}
|
||||||
|
"STRUCTURED_APPEND_SEQUENCE" | "STRUCTUREDAPPENDSEQUENCE" => {
|
||||||
|
RXingResultMetadataType::STRUCTURED_APPEND_SEQUENCE
|
||||||
|
}
|
||||||
|
"STRUCTURED_APPEND_PARITY" | "STRUCTUREDAPPENDPARITY" => {
|
||||||
|
RXingResultMetadataType::STRUCTURED_APPEND_PARITY
|
||||||
|
}
|
||||||
|
"SYMBOLOGY_IDENTIFIER" | "SYMBOLOGYIDENTIFIER" => {
|
||||||
|
RXingResultMetadataType::SYMBOLOGY_IDENTIFIER
|
||||||
|
}
|
||||||
|
"IS_MIRRORED" | "ISMIRRORED" => RXingResultMetadataType::IS_MIRRORED,
|
||||||
|
"CONTENT_TYPE" | "CONTENTTYPE" => RXingResultMetadataType::CONTENT_TYPE,
|
||||||
_ => RXingResultMetadataType::OTHER,
|
_ => RXingResultMetadataType::OTHER,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -209,4 +225,8 @@ pub enum RXingResultMetadataValue {
|
|||||||
* when prepending to the barcode content.
|
* when prepending to the barcode content.
|
||||||
*/
|
*/
|
||||||
SymbologyIdentifier(String),
|
SymbologyIdentifier(String),
|
||||||
|
|
||||||
|
IsMirrored(bool),
|
||||||
|
|
||||||
|
ContentType(String),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
symbologyIdentifier=]d1
|
|
||||||
isMirrored=false
|
|
||||||
@@ -175,8 +175,9 @@ impl<T: Reader> AbstractBlackBoxTestCase<T> {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut expected_metadata_file: PathBuf = self.test_base.clone().to_path_buf();
|
let mut expected_metadata_file: PathBuf = self.test_base.clone().to_path_buf();
|
||||||
expected_metadata_file.push(format!("{}.metadata", file_base_name.to_str().unwrap()));
|
expected_metadata_file
|
||||||
expected_metadata_file.set_extension("txt");
|
.push(format!("{}.metadata.txt", file_base_name.to_str().unwrap()));
|
||||||
|
// expected_metadata_file.set_extension("txt");
|
||||||
let expected_metadata_unfinished = if expected_metadata_file.exists() {
|
let expected_metadata_unfinished = if expected_metadata_file.exists() {
|
||||||
java_properties::read(
|
java_properties::read(
|
||||||
std::fs::File::open(expected_metadata_file)
|
std::fs::File::open(expected_metadata_file)
|
||||||
@@ -189,10 +190,10 @@ impl<T: Reader> AbstractBlackBoxTestCase<T> {
|
|||||||
} else {
|
} else {
|
||||||
HashMap::new()
|
HashMap::new()
|
||||||
};
|
};
|
||||||
let expected_metadata = HashMap::new();
|
let mut expected_metadata = HashMap::new();
|
||||||
for (k, v) in expected_metadata_unfinished {
|
for (k, v) in expected_metadata_unfinished {
|
||||||
let new_k = RXingResultMetadataType::from(k);
|
let new_k = RXingResultMetadataType::from(k);
|
||||||
let _new_v = match new_k {
|
let new_v = match new_k {
|
||||||
RXingResultMetadataType::OTHER => RXingResultMetadataValue::OTHER(v),
|
RXingResultMetadataType::OTHER => RXingResultMetadataValue::OTHER(v),
|
||||||
RXingResultMetadataType::ORIENTATION => {
|
RXingResultMetadataType::ORIENTATION => {
|
||||||
RXingResultMetadataValue::Orientation(v.parse().unwrap_or_default())
|
RXingResultMetadataValue::Orientation(v.parse().unwrap_or_default())
|
||||||
@@ -233,7 +234,14 @@ impl<T: Reader> AbstractBlackBoxTestCase<T> {
|
|||||||
RXingResultMetadataType::SYMBOLOGY_IDENTIFIER => {
|
RXingResultMetadataType::SYMBOLOGY_IDENTIFIER => {
|
||||||
RXingResultMetadataValue::SymbologyIdentifier(v)
|
RXingResultMetadataValue::SymbologyIdentifier(v)
|
||||||
}
|
}
|
||||||
|
RXingResultMetadataType::IS_MIRRORED => {
|
||||||
|
RXingResultMetadataValue::IsMirrored(v.parse().unwrap())
|
||||||
|
}
|
||||||
|
RXingResultMetadataType::CONTENT_TYPE => {
|
||||||
|
RXingResultMetadataValue::ContentType(v)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
expected_metadata.insert(new_k, new_v);
|
||||||
}
|
}
|
||||||
|
|
||||||
for x in 0..test_count {
|
for x in 0..test_count {
|
||||||
|
|||||||
@@ -334,10 +334,10 @@ impl<T: MultipleBarcodeReader + Reader> PDF417MultiImageSpanAbstractBlackBoxTest
|
|||||||
} else {
|
} else {
|
||||||
HashMap::new()
|
HashMap::new()
|
||||||
};
|
};
|
||||||
let expected_metadata = HashMap::new();
|
let mut expected_metadata = HashMap::new();
|
||||||
for (k, v) in expected_metadata_unfinished {
|
for (k, v) in expected_metadata_unfinished {
|
||||||
let new_k = RXingResultMetadataType::from(k);
|
let new_k = RXingResultMetadataType::from(k);
|
||||||
let _new_v = match new_k {
|
let new_v = match new_k {
|
||||||
RXingResultMetadataType::OTHER => RXingResultMetadataValue::OTHER(v),
|
RXingResultMetadataType::OTHER => RXingResultMetadataValue::OTHER(v),
|
||||||
RXingResultMetadataType::ORIENTATION => {
|
RXingResultMetadataType::ORIENTATION => {
|
||||||
RXingResultMetadataValue::Orientation(v.parse().unwrap_or_default())
|
RXingResultMetadataValue::Orientation(v.parse().unwrap_or_default())
|
||||||
@@ -378,7 +378,14 @@ impl<T: MultipleBarcodeReader + Reader> PDF417MultiImageSpanAbstractBlackBoxTest
|
|||||||
RXingResultMetadataType::SYMBOLOGY_IDENTIFIER => {
|
RXingResultMetadataType::SYMBOLOGY_IDENTIFIER => {
|
||||||
RXingResultMetadataValue::SymbologyIdentifier(v)
|
RXingResultMetadataValue::SymbologyIdentifier(v)
|
||||||
}
|
}
|
||||||
|
RXingResultMetadataType::IS_MIRRORED => {
|
||||||
|
RXingResultMetadataValue::IsMirrored(v.parse().unwrap())
|
||||||
|
}
|
||||||
|
RXingResultMetadataType::CONTENT_TYPE => {
|
||||||
|
RXingResultMetadataValue::ContentType(v)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
expected_metadata.insert(new_k, new_v);
|
||||||
}
|
}
|
||||||
|
|
||||||
for x in 0..test_count {
|
for x in 0..test_count {
|
||||||
|
|||||||
Reference in New Issue
Block a user