diff --git a/src/common/cpp_essentials/decoder_result.rs b/src/common/cpp_essentials/decoder_result.rs index a2e85fb..bccd94a 100644 --- a/src/common/cpp_essentials/decoder_result.rs +++ b/src/common/cpp_essentials/decoder_result.rs @@ -1,6 +1,6 @@ use std::{any::Any, rc::Rc}; -use crate::{common::ECIStringBuilder, Exceptions}; +use crate::{common::ECIStringBuilder, Exceptions, RXingResult}; use super::StructuredAppendInfo; @@ -64,59 +64,6 @@ where } } -// DecoderResult(const DecoderResult &) = delete; -// DecoderResult& operator=(const DecoderResult &) = delete; -// } - -// public: -// DecoderResult() = default; -// DecoderResult(Error error) : _error(std::move(error)) {} -// DecoderResult(Content&& bytes) : _content(std::move(bytes)) {} - -// DecoderResult(DecoderResult&&) noexcept = default; -// DecoderResult& operator=(DecoderResult&&) noexcept = default; - -// bool isValid(bool includeErrors = false) const -// { -// return includeErrors || (_content.symbology.code != 0 && !_error); -// } - -// const Content& content() const & { return _content; } -// Content&& content() && { return std::move(_content); } - -// to keep the unit tests happy for now: -// std::wstring text() const { return _content.utfW(); } -// std::string symbologyIdentifier() const { return _content.symbology.toString(false); } - -// Simple macro to set up getter/setter methods that save lots of boilerplate. -// It sets up a standard 'const & () const', 2 setters for setting lvalues via -// copy and 2 for setting rvalues via move. They are provided each to work -// either on lvalues (normal 'void (...)') or on rvalues (returning '*this' as -// rvalue). The latter can be used to optionally initialize a temporary in a -// return statement, e.g. -// return DecoderResult(bytes, text).setEcLevel(level); -// #define ZX_PROPERTY(TYPE, GETTER, SETTER) \ -// const TYPE& GETTER() const & { return _##GETTER; } \ -// TYPE&& GETTER() && { return std::move(_##GETTER); } \ -// void SETTER(const TYPE& v) & { _##GETTER = v; } \ -// void SETTER(TYPE&& v) & { _##GETTER = std::move(v); } \ -// DecoderResult&& SETTER(const TYPE& v) && { _##GETTER = v; return std::move(*this); } \ -// DecoderResult&& SETTER(TYPE&& v) && { _##GETTER = std::move(v); return std::move(*this); } - -// ZX_PROPERTY(std::string, ecLevel, setEcLevel) -// ZX_PROPERTY(int, lineCount, setLineCount) -// ZX_PROPERTY(int, versionNumber, setVersionNumber) -// ZX_PROPERTY(StructuredAppendInfo, structuredAppend, setStructuredAppend) - -// ZX_PROPERTY(Error, error, setError) - -// ZX_PROPERTY(bool, isMirrored, setIsMirrored) -// ZX_PROPERTY(bool, readerInit, setReaderInit) -// ZX_PROPERTY(std::shared_ptr, extra, setExtra) - -// #undef ZX_PROPERTY -// }; - impl DecoderResult where T: Copy + Clone + Default + Eq + PartialEq, diff --git a/src/common/eci_string_builder.rs b/src/common/eci_string_builder.rs index 2aee154..78f0941 100644 --- a/src/common/eci_string_builder.rs +++ b/src/common/eci_string_builder.rs @@ -21,7 +21,9 @@ // import java.nio.charset.Charset; // import java.nio.charset.StandardCharsets; -use std::{collections::HashMap, fmt}; +use std::{collections::HashMap, fmt::{self, Display}}; + +use crate::BarcodeFormat; use super::{CharacterSet, Eci, StringUtils}; @@ -126,10 +128,10 @@ impl ECIStringBuilder { /// Change the current encoding characterset, finding an eci to do so pub fn switch_encoding(&mut self, charset: CharacterSet) { //self.append_eci(Eci::from(charset)) - if (false && !self.has_eci) { + if false && !self.has_eci { self.eci_positions.clear(); } - if (false || !self.has_eci) + if false || !self.has_eci //{self.eci_positions.push_back({eci, Size(bytes)});} { self.append_eci(Eci::from(charset)) @@ -322,4 +324,4 @@ impl Default for SymbologyIdentifier { aiFlag: AIFlag::None, } } -} +} \ No newline at end of file diff --git a/src/qrcode/cpp_port/qr_cpp_reader.rs b/src/qrcode/cpp_port/qr_cpp_reader.rs index 09eb44e..1123feb 100644 --- a/src/qrcode/cpp_port/qr_cpp_reader.rs +++ b/src/qrcode/cpp_port/qr_cpp_reader.rs @@ -306,10 +306,15 @@ impl QrReader { } if (decoderResult.isValid()) { - results.push(RXingResult::new( - &decoderResult.content().to_string(), - decoderResult.content().bytes().to_vec(), - position.to_vec(), + // results.push(RXingResult::new( + // &decoderResult.content().to_string(), + // decoderResult.content().bytes().to_vec(), + // position.to_vec(), + // BarcodeFormat::QR_CODE, + // )); + results.push(RXingResult::with_decoder_result( + decoderResult, + position, BarcodeFormat::QR_CODE, )); // results.emplace_back(std::move(decoderResult), std::move(position), BarcodeFormat::QR_CODE); diff --git a/src/rxing_result.rs b/src/rxing_result.rs index ea49223..f888935 100644 --- a/src/rxing_result.rs +++ b/src/rxing_result.rs @@ -16,7 +16,10 @@ use std::{collections::HashMap, fmt}; -use crate::{BarcodeFormat, Point, RXingResultMetadataType, RXingResultMetadataValue}; +use crate::{ + common::cpp_essentials::DecoderResult, BarcodeFormat, MetadataDictionary, Point, + RXingResultMetadataType, RXingResultMetadataValue, +}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -95,6 +98,44 @@ impl RXingResult { } } + pub fn with_decoder_result( + res: DecoderResult, + resultPoints: &[Point], + format: BarcodeFormat, + ) -> Self + where + T: Copy + Clone + Default + Eq + PartialEq, + { + let mut new_res = Self::new( + &res.text(), + res.content().bytes().to_vec(), + resultPoints.to_vec(), + format, + ); + + let mut meta_data = MetadataDictionary::new(); + meta_data.insert( + RXingResultMetadataType::ERROR_CORRECTION_LEVEL, + RXingResultMetadataValue::ErrorCorrectionLevel(res.ecLevel().to_owned()), + ); + meta_data.insert( + RXingResultMetadataType::STRUCTURED_APPEND_PARITY, + RXingResultMetadataValue::StructuredAppendParity(res.structuredAppend().count), + ); + meta_data.insert( + RXingResultMetadataType::STRUCTURED_APPEND_SEQUENCE, + RXingResultMetadataValue::StructuredAppendSequence(res.structuredAppend().index), + ); + meta_data.insert( + RXingResultMetadataType::SYMBOLOGY_IDENTIFIER, + RXingResultMetadataValue::SymbologyIdentifier(res.symbologyIdentifier()), + ); + + new_res.putAllMetadata(meta_data); + + new_res + } + /** * @return raw text encoded by the barcode */