summaryrefslogtreecommitdiff
path: root/xfa/fxbarcode/qrcode
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxbarcode/qrcode')
-rw-r--r--xfa/fxbarcode/qrcode/BC_QRCodeWriter.cpp11
-rw-r--r--xfa/fxbarcode/qrcode/BC_QRCoder.cpp83
-rw-r--r--xfa/fxbarcode/qrcode/BC_QRCoder.h56
-rw-r--r--xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.cpp31
-rw-r--r--xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.h19
-rw-r--r--xfa/fxbarcode/qrcode/BC_QRCoderEncoder.cpp51
-rw-r--r--xfa/fxbarcode/qrcode/BC_QRCoderMode.cpp67
-rw-r--r--xfa/fxbarcode/qrcode/BC_QRCoderMode.h42
8 files changed, 214 insertions, 146 deletions
diff --git a/xfa/fxbarcode/qrcode/BC_QRCodeWriter.cpp b/xfa/fxbarcode/qrcode/BC_QRCodeWriter.cpp
index c9f16cafd1..b2b87bc9a6 100644
--- a/xfa/fxbarcode/qrcode/BC_QRCodeWriter.cpp
+++ b/xfa/fxbarcode/qrcode/BC_QRCodeWriter.cpp
@@ -35,16 +35,19 @@ CBC_QRCodeWriter::CBC_QRCodeWriter() {
m_iCorrectLevel = 1;
m_iVersion = 0;
}
+
CBC_QRCodeWriter::~CBC_QRCodeWriter() {}
+
void CBC_QRCodeWriter::ReleaseAll() {
- delete CBC_ReedSolomonGF256::QRCodeFild;
- CBC_ReedSolomonGF256::QRCodeFild = nullptr;
+ delete CBC_ReedSolomonGF256::QRCodeField;
+ CBC_ReedSolomonGF256::QRCodeField = nullptr;
delete CBC_ReedSolomonGF256::DataMatrixField;
CBC_ReedSolomonGF256::DataMatrixField = nullptr;
CBC_QRCoderMode::Destroy();
CBC_QRCoderErrorCorrectionLevel::Destroy();
CBC_QRCoderVersion::Destroy();
}
+
FX_BOOL CBC_QRCodeWriter::SetVersion(int32_t version) {
if (version < 0 || version > 40) {
return FALSE;
@@ -52,6 +55,7 @@ FX_BOOL CBC_QRCodeWriter::SetVersion(int32_t version) {
m_iVersion = version;
return TRUE;
}
+
FX_BOOL CBC_QRCodeWriter::SetErrorCorrectionLevel(int32_t level) {
if (level < 0 || level > 3) {
return FALSE;
@@ -59,6 +63,7 @@ FX_BOOL CBC_QRCodeWriter::SetErrorCorrectionLevel(int32_t level) {
m_iCorrectLevel = level;
return TRUE;
}
+
uint8_t* CBC_QRCodeWriter::Encode(const CFX_WideString& contents,
int32_t ecLevel,
int32_t& outWidth,
@@ -97,6 +102,7 @@ uint8_t* CBC_QRCodeWriter::Encode(const CFX_WideString& contents,
FXSYS_memcpy(result, qr.GetMatrix()->GetArray(), outWidth * outHeight);
return result;
}
+
uint8_t* CBC_QRCodeWriter::Encode(const CFX_ByteString& contents,
BCFORMAT format,
int32_t& outWidth,
@@ -105,6 +111,7 @@ uint8_t* CBC_QRCodeWriter::Encode(const CFX_ByteString& contents,
int32_t& e) {
return nullptr;
}
+
uint8_t* CBC_QRCodeWriter::Encode(const CFX_ByteString& contents,
BCFORMAT format,
int32_t& outWidth,
diff --git a/xfa/fxbarcode/qrcode/BC_QRCoder.cpp b/xfa/fxbarcode/qrcode/BC_QRCoder.cpp
index 580ea7ded1..4c7956ed68 100644
--- a/xfa/fxbarcode/qrcode/BC_QRCoder.cpp
+++ b/xfa/fxbarcode/qrcode/BC_QRCoder.cpp
@@ -20,57 +20,67 @@
* limitations under the License.
*/
+#include <utility>
+
#include "xfa/fxbarcode/common/BC_CommonByteMatrix.h"
#include "xfa/fxbarcode/qrcode/BC_QRCoder.h"
#include "xfa/fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h"
#include "xfa/fxbarcode/qrcode/BC_QRCoderMode.h"
#include "xfa/fxbarcode/utils.h"
-CBC_QRCoder::CBC_QRCoder() {
- m_mode = nullptr;
- m_ecLevel = nullptr;
- m_version = -1;
- m_matrixWidth = -1;
- m_maskPattern = -1;
- m_numTotalBytes = -1;
- m_numDataBytes = -1;
- m_numECBytes = -1;
- m_numRSBlocks = -1;
- m_matrix = nullptr;
-}
-CBC_QRCoder::~CBC_QRCoder() {
- delete m_matrix;
-}
-CBC_QRCoderMode* CBC_QRCoder::GetMode() {
+CBC_QRCoder::CBC_QRCoder()
+ : m_mode(nullptr),
+ m_ecLevel(nullptr),
+ m_version(-1),
+ m_matrixWidth(-1),
+ m_maskPattern(-1),
+ m_numTotalBytes(-1),
+ m_numDataBytes(-1),
+ m_numECBytes(-1),
+ m_numRSBlocks(-1) {}
+
+CBC_QRCoder::~CBC_QRCoder() {}
+
+CBC_QRCoderMode* CBC_QRCoder::GetMode() const {
return m_mode;
}
-CBC_QRCoderErrorCorrectionLevel* CBC_QRCoder::GetECLevel() {
+
+CBC_QRCoderErrorCorrectionLevel* CBC_QRCoder::GetECLevel() const {
return m_ecLevel;
}
-int32_t CBC_QRCoder::GetVersion() {
+
+int32_t CBC_QRCoder::GetVersion() const {
return m_version;
}
-int32_t CBC_QRCoder::GetMatrixWidth() {
+
+int32_t CBC_QRCoder::GetMatrixWidth() const {
return m_matrixWidth;
}
-int32_t CBC_QRCoder::GetMaskPattern() {
+
+int32_t CBC_QRCoder::GetMaskPattern() const {
return m_maskPattern;
}
-int32_t CBC_QRCoder::GetNumTotalBytes() {
+
+int32_t CBC_QRCoder::GetNumTotalBytes() const {
return m_numTotalBytes;
}
-int32_t CBC_QRCoder::GetNumDataBytes() {
+
+int32_t CBC_QRCoder::GetNumDataBytes() const {
return m_numDataBytes;
}
-int32_t CBC_QRCoder::GetNumECBytes() {
+
+int32_t CBC_QRCoder::GetNumECBytes() const {
return m_numECBytes;
}
-int32_t CBC_QRCoder::GetNumRSBlocks() {
+
+int32_t CBC_QRCoder::GetNumRSBlocks() const {
return m_numRSBlocks;
}
-CBC_CommonByteMatrix* CBC_QRCoder::GetMatrix() {
- return m_matrix;
+
+CBC_CommonByteMatrix* CBC_QRCoder::GetMatrix() const {
+ return m_matrix.get();
}
+
int32_t CBC_QRCoder::At(int32_t x, int32_t y, int32_t& e) {
int32_t value = m_matrix->Get(x, y);
if (!(value == 0 || value == 1)) {
@@ -79,6 +89,7 @@ int32_t CBC_QRCoder::At(int32_t x, int32_t y, int32_t& e) {
}
return value;
}
+
FX_BOOL CBC_QRCoder::IsValid() {
return m_mode && m_ecLevel && m_version != -1 && m_matrixWidth != -1 &&
m_maskPattern != -1 && m_numTotalBytes != -1 && m_numDataBytes != -1 &&
@@ -88,37 +99,47 @@ FX_BOOL CBC_QRCoder::IsValid() {
m_matrixWidth == m_matrix->GetWidth() &&
m_matrix->GetWidth() == m_matrix->GetHeight();
}
+
void CBC_QRCoder::SetMode(CBC_QRCoderMode* value) {
m_mode = value;
}
+
void CBC_QRCoder::SetECLevel(CBC_QRCoderErrorCorrectionLevel* ecLevel) {
m_ecLevel = ecLevel;
}
+
void CBC_QRCoder::SetVersion(int32_t version) {
m_version = version;
}
+
void CBC_QRCoder::SetMatrixWidth(int32_t width) {
m_matrixWidth = width;
}
+
void CBC_QRCoder::SetMaskPattern(int32_t pattern) {
m_maskPattern = pattern;
}
+
void CBC_QRCoder::SetNumDataBytes(int32_t bytes) {
m_numDataBytes = bytes;
}
+
void CBC_QRCoder::SetNumTotalBytes(int32_t value) {
m_numTotalBytes = value;
}
+
void CBC_QRCoder::SetNumRSBlocks(int32_t block) {
m_numRSBlocks = block;
}
+
void CBC_QRCoder::SetNumECBytes(int32_t value) {
m_numECBytes = value;
}
-FX_BOOL CBC_QRCoder::IsValidMaskPattern(int32_t maskPattern) {
- return maskPattern >= 0 && maskPattern < NUM_MASK_PATTERNS;
+
+bool CBC_QRCoder::IsValidMaskPattern(int32_t maskPattern) {
+ return maskPattern >= 0 && maskPattern < kNumMaskPatterns;
}
-void CBC_QRCoder::SetMatrix(CBC_CommonByteMatrix* value) {
- m_matrix = value;
+
+void CBC_QRCoder::SetMatrix(std::unique_ptr<CBC_CommonByteMatrix> pMatrix) {
+ m_matrix = std::move(pMatrix);
}
-const int32_t CBC_QRCoder::NUM_MASK_PATTERNS = 8;
diff --git a/xfa/fxbarcode/qrcode/BC_QRCoder.h b/xfa/fxbarcode/qrcode/BC_QRCoder.h
index bbf7bd4429..bbb37355f2 100644
--- a/xfa/fxbarcode/qrcode/BC_QRCoder.h
+++ b/xfa/fxbarcode/qrcode/BC_QRCoder.h
@@ -7,37 +7,32 @@
#ifndef XFA_FXBARCODE_QRCODE_BC_QRCODER_H_
#define XFA_FXBARCODE_QRCODE_BC_QRCODER_H_
+#include <memory>
+
class CBC_QRCoderErrorCorrectionLevel;
class CBC_QRCoderMode;
class CBC_CommonByteMatrix;
class CBC_QRCoder {
- private:
- CBC_QRCoderMode* m_mode;
- CBC_QRCoderErrorCorrectionLevel* m_ecLevel;
- int32_t m_version;
- int32_t m_matrixWidth;
- int32_t m_maskPattern;
- int32_t m_numTotalBytes;
- int32_t m_numDataBytes;
- int32_t m_numECBytes;
- int32_t m_numRSBlocks;
- CBC_CommonByteMatrix* m_matrix;
-
public:
- static const int32_t NUM_MASK_PATTERNS;
+ static constexpr int32_t kNumMaskPatterns = 8;
+
CBC_QRCoder();
virtual ~CBC_QRCoder();
- CBC_QRCoderMode* GetMode();
- CBC_QRCoderErrorCorrectionLevel* GetECLevel();
- int32_t GetVersion();
- int32_t GetMatrixWidth();
- int32_t GetMaskPattern();
- int32_t GetNumTotalBytes();
- int32_t GetNumDataBytes();
- int32_t GetNumECBytes();
- int32_t GetNumRSBlocks();
- CBC_CommonByteMatrix* GetMatrix();
+
+ static bool IsValidMaskPattern(int32_t maskPattern);
+
+ CBC_QRCoderMode* GetMode() const;
+ CBC_QRCoderErrorCorrectionLevel* GetECLevel() const;
+ int32_t GetVersion() const;
+ int32_t GetMatrixWidth() const;
+ int32_t GetMaskPattern() const;
+ int32_t GetNumTotalBytes() const;
+ int32_t GetNumDataBytes() const;
+ int32_t GetNumECBytes() const;
+ int32_t GetNumRSBlocks() const;
+ CBC_CommonByteMatrix* GetMatrix() const;
+
int32_t At(int32_t x, int32_t y, int32_t& e);
FX_BOOL IsValid();
@@ -50,8 +45,19 @@ class CBC_QRCoder {
void SetNumTotalBytes(int32_t value);
void SetNumECBytes(int32_t value);
void SetNumRSBlocks(int32_t block);
- void SetMatrix(CBC_CommonByteMatrix* value);
- static FX_BOOL IsValidMaskPattern(int32_t maskPattern);
+ void SetMatrix(std::unique_ptr<CBC_CommonByteMatrix> pMatrix);
+
+ private:
+ CBC_QRCoderMode* m_mode;
+ CBC_QRCoderErrorCorrectionLevel* m_ecLevel;
+ int32_t m_version;
+ int32_t m_matrixWidth;
+ int32_t m_maskPattern;
+ int32_t m_numTotalBytes;
+ int32_t m_numDataBytes;
+ int32_t m_numECBytes;
+ int32_t m_numRSBlocks;
+ std::unique_ptr<CBC_CommonByteMatrix> m_matrix;
};
#endif // XFA_FXBARCODE_QRCODE_BC_QRCODER_H_
diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.cpp b/xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.cpp
index b8a032ae68..8dc73c4be4 100644
--- a/xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.cpp
+++ b/xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.cpp
@@ -20,22 +20,25 @@
* limitations under the License.
*/
-#include "xfa/fxbarcode/common/BC_CommonByteArray.h"
#include "xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.h"
+#include <utility>
+
+#include "xfa/fxbarcode/common/BC_CommonByteArray.h"
+
CBC_QRCoderBlockPair::CBC_QRCoderBlockPair(
- CBC_CommonByteArray* data,
- CBC_CommonByteArray* errorCorrection) {
- m_dataBytes = data;
- m_errorCorrectionBytes = errorCorrection;
-}
-CBC_QRCoderBlockPair::~CBC_QRCoderBlockPair() {
- delete m_dataBytes;
- delete m_errorCorrectionBytes;
-}
-CBC_CommonByteArray* CBC_QRCoderBlockPair::GetDataBytes() {
- return m_dataBytes;
+ std::unique_ptr<CBC_CommonByteArray> data,
+ std::unique_ptr<CBC_CommonByteArray> errorCorrection)
+ : m_dataBytes(std::move(data)),
+ m_errorCorrectionBytes(std::move(errorCorrection)) {}
+
+CBC_QRCoderBlockPair::~CBC_QRCoderBlockPair() {}
+
+const CBC_CommonByteArray* CBC_QRCoderBlockPair::GetDataBytes() const {
+ return m_dataBytes.get();
}
-CBC_CommonByteArray* CBC_QRCoderBlockPair::GetErrorCorrectionBytes() {
- return m_errorCorrectionBytes;
+
+const CBC_CommonByteArray* CBC_QRCoderBlockPair::GetErrorCorrectionBytes()
+ const {
+ return m_errorCorrectionBytes.get();
}
diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.h b/xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.h
index 5427436761..4259d6badd 100644
--- a/xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.h
+++ b/xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.h
@@ -7,19 +7,22 @@
#ifndef XFA_FXBARCODE_QRCODE_BC_QRCODERBLOCKPAIR_H_
#define XFA_FXBARCODE_QRCODE_BC_QRCODERBLOCKPAIR_H_
+#include <memory>
+
class CBC_CommonByteArray;
-class CBC_QRCoderBlockPair {
- private:
- CBC_CommonByteArray* m_dataBytes;
- CBC_CommonByteArray* m_errorCorrectionBytes;
+class CBC_QRCoderBlockPair {
public:
- CBC_QRCoderBlockPair(CBC_CommonByteArray* data,
- CBC_CommonByteArray* errorCorrection);
+ CBC_QRCoderBlockPair(std::unique_ptr<CBC_CommonByteArray> data,
+ std::unique_ptr<CBC_CommonByteArray> errorCorrection);
virtual ~CBC_QRCoderBlockPair();
- CBC_CommonByteArray* GetDataBytes();
- CBC_CommonByteArray* GetErrorCorrectionBytes();
+ const CBC_CommonByteArray* GetDataBytes() const;
+ const CBC_CommonByteArray* GetErrorCorrectionBytes() const;
+
+ private:
+ std::unique_ptr<CBC_CommonByteArray> m_dataBytes;
+ std::unique_ptr<CBC_CommonByteArray> m_errorCorrectionBytes;
};
#endif // XFA_FXBARCODE_QRCODE_BC_QRCODERBLOCKPAIR_H_
diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
index 9935326cc1..7f332b671e 100644
--- a/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
+++ b/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
@@ -24,6 +24,7 @@
#include <algorithm>
#include <memory>
+#include <utility>
#include "xfa/fxbarcode/BC_UtilCodingConvert.h"
#include "xfa/fxbarcode/common/BC_CommonByteArray.h"
@@ -48,7 +49,9 @@ const int32_t CBC_QRCoderEncoder::m_alphaNumbericTable[] = {
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1};
CBC_QRCoderEncoder::CBC_QRCoderEncoder() {}
+
CBC_QRCoderEncoder::~CBC_QRCoderEncoder() {}
+
class Make_Pair {
public:
CBC_QRCoderMode* m_mode;
@@ -86,7 +89,9 @@ void CBC_QRCoderEncoder::Encode(const CFX_ByteString& content,
BC_EXCEPTION_CHECK_ReturnVoid(e);
}
}
+
void CBC_QRCoderEncoder::AppendECI(CBC_QRCoderBitVector* bits) {}
+
void CBC_QRCoderEncoder::AppendDataModeLenghInfo(
const CFX_ArrayTemplate<Make_Pair*>& splitResult,
CBC_QRCoderBitVector& headerAndDataBits,
@@ -139,6 +144,7 @@ void CBC_QRCoderEncoder::AppendDataModeLenghInfo(
}
}
}
+
void CBC_QRCoderEncoder::SplitString(const CFX_ByteString& content,
CFX_ArrayTemplate<Make_Pair*>* result) {
int32_t index = 0, flag = 0;
@@ -316,6 +322,7 @@ void CBC_QRCoderEncoder::MergeString(CFX_ArrayTemplate<Make_Pair*>* result,
MergeString(result, versionNum, e);
BC_EXCEPTION_CHECK_ReturnVoid(e);
}
+
void CBC_QRCoderEncoder::InitQRCode(int32_t numInputBytes,
int32_t versionNumber,
CBC_QRCoderErrorCorrectionLevel* ecLevel,
@@ -344,6 +351,7 @@ void CBC_QRCoderEncoder::InitQRCode(int32_t numInputBytes,
e = BCExceptionCannotFindBlockInfo;
BC_EXCEPTION_CHECK_ReturnVoid(e);
}
+
void CBC_QRCoderEncoder::EncodeWithSpecifyVersion(
const CFX_ByteString& content,
CBC_QRCoderErrorCorrectionLevel* ecLevel,
@@ -408,12 +416,13 @@ void CBC_QRCoderEncoder::EncodeWithSpecifyVersion(
qrCode->GetVersion(),
qrCode->GetMaskPattern(), matrix.get(), e);
BC_EXCEPTION_CHECK_ReturnVoid(e);
- qrCode->SetMatrix(matrix.release());
+ qrCode->SetMatrix(std::move(matrix));
if (!qrCode->IsValid()) {
e = BCExceptionInvalidQRCode;
BC_EXCEPTION_CHECK_ReturnVoid(e);
}
}
+
void CBC_QRCoderEncoder::EncodeWithAutoVersion(
const CFX_ByteString& content,
CBC_QRCoderErrorCorrectionLevel* ecLevel,
@@ -492,12 +501,13 @@ catchException:
CBC_QRCoderMatrixUtil::BuildMatrix(&finalBits, qrCode->GetECLevel(),
qrCode->GetVersion(),
qrCode->GetMaskPattern(), matrix.get(), e);
- BC_EXCEPTION_CHECK_ReturnVoid(e) qrCode->SetMatrix(matrix.release());
+ BC_EXCEPTION_CHECK_ReturnVoid(e) qrCode->SetMatrix(std::move(matrix));
if (!qrCode->IsValid()) {
e = BCExceptionInvalidQRCode;
BC_EXCEPTION_CHECK_ReturnVoid(e);
}
}
+
void CBC_QRCoderEncoder::Encode(const CFX_WideString& content,
CBC_QRCoderErrorCorrectionLevel* ecLevel,
CBC_QRCoder* qrCode,
@@ -542,12 +552,13 @@ void CBC_QRCoderEncoder::Encode(const CFX_WideString& content,
CBC_QRCoderMatrixUtil::BuildMatrix(&finalBits, qrCode->GetECLevel(),
qrCode->GetVersion(),
qrCode->GetMaskPattern(), matrix.get(), e);
- BC_EXCEPTION_CHECK_ReturnVoid(e) qrCode->SetMatrix(matrix.release());
+ BC_EXCEPTION_CHECK_ReturnVoid(e) qrCode->SetMatrix(std::move(matrix));
if (!qrCode->IsValid()) {
e = BCExceptionInvalidQRCode;
BC_EXCEPTION_CHECK_ReturnVoid(e);
}
}
+
void CBC_QRCoderEncoder::TerminateBits(int32_t numDataBytes,
CBC_QRCoderBitVector* bits,
int32_t& e) {
@@ -587,6 +598,7 @@ void CBC_QRCoderEncoder::TerminateBits(int32_t numDataBytes,
BC_EXCEPTION_CHECK_ReturnVoid(e);
}
}
+
int32_t CBC_QRCoderEncoder::ChooseMaskPattern(
CBC_QRCoderBitVector* bits,
CBC_QRCoderErrorCorrectionLevel* ecLevel,
@@ -595,7 +607,7 @@ int32_t CBC_QRCoderEncoder::ChooseMaskPattern(
int32_t& e) {
int32_t minPenalty = 65535;
int32_t bestMaskPattern = -1;
- for (int32_t maskPattern = 0; maskPattern < CBC_QRCoder::NUM_MASK_PATTERNS;
+ for (int32_t maskPattern = 0; maskPattern < CBC_QRCoder::kNumMaskPatterns;
maskPattern++) {
CBC_QRCoderMatrixUtil::BuildMatrix(bits, ecLevel, version, maskPattern,
matrix, e);
@@ -608,6 +620,7 @@ int32_t CBC_QRCoderEncoder::ChooseMaskPattern(
}
return bestMaskPattern;
}
+
int32_t CBC_QRCoderEncoder::CalculateMaskPenalty(CBC_CommonByteMatrix* matrix) {
int32_t penalty = 0;
penalty += CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule1(matrix);
@@ -616,6 +629,7 @@ int32_t CBC_QRCoderEncoder::CalculateMaskPenalty(CBC_CommonByteMatrix* matrix) {
penalty += CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule4(matrix);
return penalty;
}
+
CBC_QRCoderMode* CBC_QRCoderEncoder::ChooseMode(const CFX_ByteString& content,
CFX_ByteString encoding) {
if (encoding.Compare("SHIFT_JIS") == 0) {
@@ -639,12 +653,14 @@ CBC_QRCoderMode* CBC_QRCoderEncoder::ChooseMode(const CFX_ByteString& content,
}
return CBC_QRCoderMode::sBYTE;
}
+
int32_t CBC_QRCoderEncoder::GetAlphaNumericCode(int32_t code) {
if (code < 96 && code >= 0) {
return m_alphaNumbericTable[code];
}
return -1;
}
+
void CBC_QRCoderEncoder::AppendBytes(const CFX_ByteString& content,
CBC_QRCoderMode* mode,
CBC_QRCoderBitVector* bits,
@@ -670,6 +686,7 @@ void CBC_QRCoderEncoder::AppendBytes(const CFX_ByteString& content,
BC_EXCEPTION_CHECK_ReturnVoid(e);
}
}
+
void CBC_QRCoderEncoder::AppendNumericBytes(const CFX_ByteString& content,
CBC_QRCoderBitVector* bits,
int32_t& e) {
@@ -693,6 +710,7 @@ void CBC_QRCoderEncoder::AppendNumericBytes(const CFX_ByteString& content,
}
}
}
+
void CBC_QRCoderEncoder::AppendAlphaNumericBytes(const CFX_ByteString& content,
CBC_QRCoderBitVector* bits,
int32_t& e) {
@@ -719,6 +737,7 @@ void CBC_QRCoderEncoder::AppendAlphaNumericBytes(const CFX_ByteString& content,
}
}
}
+
void CBC_QRCoderEncoder::AppendGBKBytes(const CFX_ByteString& content,
CBC_QRCoderBitVector* bits,
int32_t& e) {
@@ -739,6 +758,7 @@ void CBC_QRCoderEncoder::AppendGBKBytes(const CFX_ByteString& content,
BC_EXCEPTION_CHECK_ReturnVoid(e);
}
}
+
void CBC_QRCoderEncoder::Append8BitBytes(const CFX_ByteString& content,
CBC_QRCoderBitVector* bits,
CFX_ByteString encoding,
@@ -748,6 +768,7 @@ void CBC_QRCoderEncoder::Append8BitBytes(const CFX_ByteString& content,
BC_EXCEPTION_CHECK_ReturnVoid(e);
}
}
+
void CBC_QRCoderEncoder::Append8BitBytes(CFX_ByteArray& bytes,
CBC_QRCoderBitVector* bits,
int32_t& e) {
@@ -756,6 +777,7 @@ void CBC_QRCoderEncoder::Append8BitBytes(CFX_ByteArray& bytes,
BC_EXCEPTION_CHECK_ReturnVoid(e);
}
}
+
void CBC_QRCoderEncoder::AppendKanjiBytes(const CFX_ByteString& content,
CBC_QRCoderBitVector* bits,
int32_t& e) {
@@ -776,6 +798,7 @@ void CBC_QRCoderEncoder::AppendKanjiBytes(const CFX_ByteString& content,
BC_EXCEPTION_CHECK_ReturnVoid(e);
}
}
+
void CBC_QRCoderEncoder::InitQRCode(int32_t numInputBytes,
CBC_QRCoderErrorCorrectionLevel* ecLevel,
CBC_QRCoderMode* mode,
@@ -805,6 +828,7 @@ void CBC_QRCoderEncoder::InitQRCode(int32_t numInputBytes,
e = BCExceptionCannotFindBlockInfo;
BC_EXCEPTION_CHECK_ReturnVoid(e);
}
+
void CBC_QRCoderEncoder::AppendModeInfo(CBC_QRCoderMode* mode,
CBC_QRCoderBitVector* bits,
int32_t& e) {
@@ -814,6 +838,7 @@ void CBC_QRCoderEncoder::AppendModeInfo(CBC_QRCoderMode* mode,
BC_EXCEPTION_CHECK_ReturnVoid(e);
}
}
+
void CBC_QRCoderEncoder::AppendLengthInfo(int32_t numLetters,
int32_t version,
CBC_QRCoderMode* mode,
@@ -833,6 +858,7 @@ void CBC_QRCoderEncoder::AppendLengthInfo(int32_t numLetters,
bits->AppendBits(numLetters, numBits, e);
BC_EXCEPTION_CHECK_ReturnVoid(e);
}
+
void CBC_QRCoderEncoder::InterleaveWithECBytes(CBC_QRCoderBitVector* bits,
int32_t numTotalBytes,
int32_t numDataBytes,
@@ -854,12 +880,13 @@ void CBC_QRCoderEncoder::InterleaveWithECBytes(CBC_QRCoderBitVector* bits,
GetNumDataBytesAndNumECBytesForBlockID(numTotalBytes, numDataBytes,
numRSBlocks, i, numDataBytesInBlock,
numEcBytesInBlosk);
- CBC_CommonByteArray* dataBytes = new CBC_CommonByteArray;
+ std::unique_ptr<CBC_CommonByteArray> dataBytes(new CBC_CommonByteArray);
dataBytes->Set(bits->GetArray(), dataBytesOffset, numDataBytesInBlock);
- CBC_CommonByteArray* ecBytes =
- GenerateECBytes(dataBytes, numEcBytesInBlosk, e);
+ std::unique_ptr<CBC_CommonByteArray> ecBytes(
+ GenerateECBytes(dataBytes.get(), numEcBytesInBlosk, e));
BC_EXCEPTION_CHECK_ReturnVoid(e);
- blocks.Add(new CBC_QRCoderBlockPair(dataBytes, ecBytes));
+ blocks.Add(
+ new CBC_QRCoderBlockPair(std::move(dataBytes), std::move(ecBytes)));
maxNumDataBytes = std::max(maxNumDataBytes, dataBytes->Size());
maxNumEcBytes = std::max(maxNumEcBytes, ecBytes->Size());
dataBytesOffset += numDataBytesInBlock;
@@ -870,7 +897,7 @@ void CBC_QRCoderEncoder::InterleaveWithECBytes(CBC_QRCoderBitVector* bits,
}
for (int32_t x = 0; x < maxNumDataBytes; x++) {
for (int32_t j = 0; j < blocks.GetSize(); j++) {
- CBC_CommonByteArray* dataBytes = blocks[j]->GetDataBytes();
+ const CBC_CommonByteArray* dataBytes = blocks[j]->GetDataBytes();
if (x < dataBytes->Size()) {
result->AppendBits(dataBytes->At(x), 8, e);
BC_EXCEPTION_CHECK_ReturnVoid(e);
@@ -879,7 +906,7 @@ void CBC_QRCoderEncoder::InterleaveWithECBytes(CBC_QRCoderBitVector* bits,
}
for (int32_t y = 0; y < maxNumEcBytes; y++) {
for (int32_t l = 0; l < blocks.GetSize(); l++) {
- CBC_CommonByteArray* ecBytes = blocks[l]->GetErrorCorrectionBytes();
+ const CBC_CommonByteArray* ecBytes = blocks[l]->GetErrorCorrectionBytes();
if (y < ecBytes->Size()) {
result->AppendBits(ecBytes->At(y), 8, e);
BC_EXCEPTION_CHECK_ReturnVoid(e);
@@ -894,6 +921,7 @@ void CBC_QRCoderEncoder::InterleaveWithECBytes(CBC_QRCoderBitVector* bits,
BC_EXCEPTION_CHECK_ReturnVoid(e);
}
}
+
void CBC_QRCoderEncoder::GetNumDataBytesAndNumECBytesForBlockID(
int32_t numTotalBytes,
int32_t numDataBytes,
@@ -920,6 +948,7 @@ void CBC_QRCoderEncoder::GetNumDataBytesAndNumECBytesForBlockID(
numECBytesInBlock = numEcBytesInGroup2;
}
}
+
CBC_CommonByteArray* CBC_QRCoderEncoder::GenerateECBytes(
CBC_CommonByteArray* dataBytes,
int32_t numEcBytesInBlock,
@@ -930,7 +959,7 @@ CBC_CommonByteArray* CBC_QRCoderEncoder::GenerateECBytes(
for (int32_t i = 0; i < numDataBytes; i++) {
toEncode[i] = (dataBytes->At(i));
}
- CBC_ReedSolomonEncoder encode(CBC_ReedSolomonGF256::QRCodeFild);
+ CBC_ReedSolomonEncoder encode(CBC_ReedSolomonGF256::QRCodeField);
encode.Init();
encode.Encode(&toEncode, numEcBytesInBlock, e);
BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderMode.cpp b/xfa/fxbarcode/qrcode/BC_QRCoderMode.cpp
index 5a05d9f633..74c5563927 100644
--- a/xfa/fxbarcode/qrcode/BC_QRCoderMode.cpp
+++ b/xfa/fxbarcode/qrcode/BC_QRCoderMode.cpp
@@ -21,6 +21,9 @@
*/
#include "xfa/fxbarcode/qrcode/BC_QRCoderMode.h"
+
+#include <utility>
+
#include "xfa/fxbarcode/qrcode/BC_QRCoderVersion.h"
#include "xfa/fxbarcode/utils.h"
@@ -35,42 +38,31 @@ CBC_QRCoderMode* CBC_QRCoderMode::sFNC1_FIRST_POSITION = nullptr;
CBC_QRCoderMode* CBC_QRCoderMode::sFNC1_SECOND_POSITION = nullptr;
CBC_QRCoderMode* CBC_QRCoderMode::sSTRUCTURED_APPEND = nullptr;
-CBC_QRCoderMode::CBC_QRCoderMode(int32_t* characterCountBitsForVersions,
- int32_t x1,
- int32_t x2,
- int32_t x3,
+CBC_QRCoderMode::CBC_QRCoderMode(std::vector<int32_t> charCountBits,
int32_t bits,
- CFX_ByteString name) {
- m_characterCountBitsForVersions = characterCountBitsForVersions;
- if (m_characterCountBitsForVersions) {
- m_characterCountBitsForVersions[0] = x1;
- m_characterCountBitsForVersions[1] = x2;
- m_characterCountBitsForVersions[2] = x3;
- }
- m_name += name;
- m_bits = bits;
-}
-CBC_QRCoderMode::~CBC_QRCoderMode() {
- FX_Free(m_characterCountBitsForVersions);
-}
+ CFX_ByteString name)
+ : m_characterCountBitsForVersions(std::move(charCountBits)),
+ m_bits(bits),
+ m_name(name) {}
+
+CBC_QRCoderMode::~CBC_QRCoderMode() {}
+
void CBC_QRCoderMode::Initialize() {
- sBYTE = new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 8, 16, 16, 0x4, "BYTE");
- sALPHANUMERIC =
- new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 9, 11, 13, 0x2, "ALPHANUMERIC");
- sECI = new CBC_QRCoderMode(nullptr, 0, 0, 0, 0x7, "ECI");
- sKANJI = new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 8, 10, 12, 0x8, "KANJI");
- sNUMERIC =
- new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 10, 12, 14, 0x1, "NUMERIC");
- sGBK = new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 8, 10, 12, 0x0D, "GBK");
- sTERMINATOR =
- new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 0, 0, 0, 0x00, "TERMINATOR");
+ sBYTE = new CBC_QRCoderMode({8, 16, 16}, 0x4, "BYTE");
+ sALPHANUMERIC = new CBC_QRCoderMode({9, 11, 13}, 0x2, "ALPHANUMERIC");
+ sECI = new CBC_QRCoderMode(std::vector<int32_t>(), 0x7, "ECI");
+ sKANJI = new CBC_QRCoderMode({8, 10, 12}, 0x8, "KANJI");
+ sNUMERIC = new CBC_QRCoderMode({10, 12, 14}, 0x1, "NUMERIC");
+ sGBK = new CBC_QRCoderMode({8, 10, 12}, 0x0D, "GBK");
+ sTERMINATOR = new CBC_QRCoderMode(std::vector<int32_t>(), 0x00, "TERMINATOR");
sFNC1_FIRST_POSITION =
- new CBC_QRCoderMode(nullptr, 0, 0, 0, 0x05, "FNC1_FIRST_POSITION");
+ new CBC_QRCoderMode(std::vector<int32_t>(), 0x05, "FNC1_FIRST_POSITION");
sFNC1_SECOND_POSITION =
- new CBC_QRCoderMode(nullptr, 0, 0, 0, 0x09, "FNC1_SECOND_POSITION");
- sSTRUCTURED_APPEND = new CBC_QRCoderMode(FX_Alloc(int32_t, 3), 0, 0, 0, 0x03,
- "STRUCTURED_APPEND");
+ new CBC_QRCoderMode(std::vector<int32_t>(), 0x09, "FNC1_SECOND_POSITION");
+ sSTRUCTURED_APPEND =
+ new CBC_QRCoderMode(std::vector<int32_t>(), 0x03, "STRUCTURED_APPEND");
}
+
void CBC_QRCoderMode::Finalize() {
delete sBYTE;
delete sALPHANUMERIC;
@@ -83,6 +75,7 @@ void CBC_QRCoderMode::Finalize() {
delete sFNC1_SECOND_POSITION;
delete sSTRUCTURED_APPEND;
}
+
CBC_QRCoderMode* CBC_QRCoderMode::ForBits(int32_t bits, int32_t& e) {
switch (bits) {
case 0x0:
@@ -112,15 +105,18 @@ CBC_QRCoderMode* CBC_QRCoderMode::ForBits(int32_t bits, int32_t& e) {
}
return nullptr;
}
-int32_t CBC_QRCoderMode::GetBits() {
+
+int32_t CBC_QRCoderMode::GetBits() const {
return m_bits;
}
-CFX_ByteString CBC_QRCoderMode::GetName() {
+
+CFX_ByteString CBC_QRCoderMode::GetName() const {
return m_name;
}
+
int32_t CBC_QRCoderMode::GetCharacterCountBits(CBC_QRCoderVersion* version,
- int32_t& e) {
- if (!m_characterCountBitsForVersions) {
+ int32_t& e) const {
+ if (m_characterCountBitsForVersions.empty()) {
e = BCExceptionCharacterNotThisMode;
BC_EXCEPTION_CHECK_ReturnValue(e, 0);
}
@@ -135,6 +131,7 @@ int32_t CBC_QRCoderMode::GetCharacterCountBits(CBC_QRCoderVersion* version,
}
return m_characterCountBitsForVersions[offset];
}
+
void CBC_QRCoderMode::Destroy() {
if (sBYTE) {
delete CBC_QRCoderMode::sBYTE;
diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderMode.h b/xfa/fxbarcode/qrcode/BC_QRCoderMode.h
index 91a991f898..63048dca43 100644
--- a/xfa/fxbarcode/qrcode/BC_QRCoderMode.h
+++ b/xfa/fxbarcode/qrcode/BC_QRCoderMode.h
@@ -9,24 +9,25 @@
#include <stdint.h>
+#include <vector>
+
#include "core/fxcrt/include/fx_string.h"
class CBC_QRCoderVersion;
class CBC_QRCoderMode {
- private:
- int32_t* m_characterCountBitsForVersions;
- int32_t m_bits;
- CFX_ByteString m_name;
- CBC_QRCoderMode(int32_t* characterCountBitsForVersions,
- int32_t x1,
- int32_t x2,
- int32_t x3,
- int32_t bits,
- CFX_ByteString name);
- CBC_QRCoderMode();
-
public:
+ virtual ~CBC_QRCoderMode();
+
+ static void Initialize();
+ static void Finalize();
+ static CBC_QRCoderMode* ForBits(int32_t bits, int32_t& e);
+ static void Destroy();
+
+ int32_t GetCharacterCountBits(CBC_QRCoderVersion* version, int32_t& e) const;
+ int32_t GetBits() const;
+ CFX_ByteString GetName() const;
+
static CBC_QRCoderMode* sBYTE;
static CBC_QRCoderMode* sNUMERIC;
static CBC_QRCoderMode* sALPHANUMERIC;
@@ -37,15 +38,16 @@ class CBC_QRCoderMode {
static CBC_QRCoderMode* sFNC1_FIRST_POSITION;
static CBC_QRCoderMode* sFNC1_SECOND_POSITION;
static CBC_QRCoderMode* sSTRUCTURED_APPEND;
- virtual ~CBC_QRCoderMode();
- static void Initialize();
- static void Finalize();
- static CBC_QRCoderMode* ForBits(int32_t bits, int32_t& e);
- int32_t GetCharacterCountBits(CBC_QRCoderVersion* version, int32_t& e);
- int32_t GetBits();
- CFX_ByteString GetName();
- static void Destroy();
+ private:
+ CBC_QRCoderMode();
+ CBC_QRCoderMode(std::vector<int32_t> charCountBits,
+ int32_t bits,
+ CFX_ByteString name);
+
+ std::vector<int32_t> m_characterCountBitsForVersions;
+ const int32_t m_bits;
+ const CFX_ByteString m_name;
};
#endif // XFA_FXBARCODE_QRCODE_BC_QRCODERMODE_H_