From e76203dbefd1df075a063ee019c3908513f6bee5 Mon Sep 17 00:00:00 2001 From: weili Date: Tue, 9 Aug 2016 13:45:03 -0700 Subject: Use smart pointers for class owned pointers in xfa/fxbarcode For classes under xfa/fxbarcode, use smart pointers instead of raw pointer to make memory management easier. Also fix some styling issues along the changes. BUG=pdfium:518 Review-Url: https://codereview.chromium.org/2221023003 --- xfa/fxbarcode/BC_TwoDimWriter.cpp | 16 ++--- xfa/fxbarcode/BC_TwoDimWriter.h | 7 +- xfa/fxbarcode/common/BC_CommonByteArray.cpp | 6 +- xfa/fxbarcode/common/BC_CommonByteArray.h | 8 ++- .../common/reedsolomon/BC_ReedSolomonGF256.cpp | 38 ++++++---- .../common/reedsolomon/BC_ReedSolomonGF256.h | 22 +++--- xfa/fxbarcode/oned/BC_OneDimWriter.cpp | 19 +++-- xfa/fxbarcode/oned/BC_OneDimWriter.h | 4 +- xfa/fxbarcode/oned/BC_OnedUPCAWriter.cpp | 12 ++-- xfa/fxbarcode/oned/BC_OnedUPCAWriter.h | 8 ++- xfa/fxbarcode/pdf417/BC_PDF417.cpp | 50 ++++++------- xfa/fxbarcode/pdf417/BC_PDF417.h | 26 +++---- xfa/fxbarcode/qrcode/BC_QRCodeWriter.cpp | 11 ++- xfa/fxbarcode/qrcode/BC_QRCoder.cpp | 83 ++++++++++++++-------- xfa/fxbarcode/qrcode/BC_QRCoder.h | 56 ++++++++------- xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.cpp | 31 ++++---- xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.h | 19 ++--- xfa/fxbarcode/qrcode/BC_QRCoderEncoder.cpp | 51 ++++++++++--- xfa/fxbarcode/qrcode/BC_QRCoderMode.cpp | 67 +++++++++-------- xfa/fxbarcode/qrcode/BC_QRCoderMode.h | 42 +++++------ 20 files changed, 336 insertions(+), 240 deletions(-) (limited to 'xfa') diff --git a/xfa/fxbarcode/BC_TwoDimWriter.cpp b/xfa/fxbarcode/BC_TwoDimWriter.cpp index 91ea57097a..e4cc6e890a 100644 --- a/xfa/fxbarcode/BC_TwoDimWriter.cpp +++ b/xfa/fxbarcode/BC_TwoDimWriter.cpp @@ -13,14 +13,10 @@ #include "xfa/fxbarcode/BC_Writer.h" #include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" -CBC_TwoDimWriter::CBC_TwoDimWriter() { - m_iCorrectLevel = 1; - m_bFixedSize = TRUE; - m_output = nullptr; -} -CBC_TwoDimWriter::~CBC_TwoDimWriter() { - delete m_output; -} +CBC_TwoDimWriter::CBC_TwoDimWriter() : m_iCorrectLevel(1), m_bFixedSize(TRUE) {} + +CBC_TwoDimWriter::~CBC_TwoDimWriter() {} + void CBC_TwoDimWriter::RenderDeviceResult(CFX_RenderDevice* device, const CFX_Matrix* matrix) { CFX_GraphStateData stateData; @@ -55,7 +51,7 @@ void CBC_TwoDimWriter::RenderDeviceResult(CFX_RenderDevice* device, } } -int32_t CBC_TwoDimWriter::GetErrorCorrectionLevel() { +int32_t CBC_TwoDimWriter::GetErrorCorrectionLevel() const { return m_iCorrectLevel; } @@ -136,7 +132,7 @@ void CBC_TwoDimWriter::RenderResult(uint8_t* code, if (topPadding < 0) { topPadding = 0; } - m_output = new CBC_CommonBitMatrix; + m_output.reset(new CBC_CommonBitMatrix); m_output->Init(outputWidth, outputHeight); for (int32_t inputY = 0, outputY = topPadding; (inputY < inputHeight) && (outputY < outputHeight - multiY); diff --git a/xfa/fxbarcode/BC_TwoDimWriter.h b/xfa/fxbarcode/BC_TwoDimWriter.h index da2e6d9c4d..76f176bfaf 100644 --- a/xfa/fxbarcode/BC_TwoDimWriter.h +++ b/xfa/fxbarcode/BC_TwoDimWriter.h @@ -7,6 +7,8 @@ #ifndef XFA_FXBARCODE_BC_TWODIMWRITER_H_ #define XFA_FXBARCODE_BC_TWODIMWRITER_H_ +#include + #include "xfa/fxbarcode/BC_Writer.h" class CBC_CommonBitMatrix; @@ -25,12 +27,13 @@ class CBC_TwoDimWriter : public CBC_Writer { virtual void RenderDeviceResult(CFX_RenderDevice* device, const CFX_Matrix* matrix); virtual FX_BOOL SetErrorCorrectionLevel(int32_t level) = 0; - virtual int32_t GetErrorCorrectionLevel(); + + int32_t GetErrorCorrectionLevel() const; protected: int32_t m_iCorrectLevel; FX_BOOL m_bFixedSize; - CBC_CommonBitMatrix* m_output; + std::unique_ptr m_output; }; #endif // XFA_FXBARCODE_BC_TWODIMWRITER_H_ diff --git a/xfa/fxbarcode/common/BC_CommonByteArray.cpp b/xfa/fxbarcode/common/BC_CommonByteArray.cpp index be48d51b5b..afa8ac6836 100644 --- a/xfa/fxbarcode/common/BC_CommonByteArray.cpp +++ b/xfa/fxbarcode/common/BC_CommonByteArray.cpp @@ -44,16 +44,16 @@ CBC_CommonByteArray::CBC_CommonByteArray(uint8_t* byteArray, int32_t size) { CBC_CommonByteArray::~CBC_CommonByteArray() { FX_Free(m_bytes); } -int32_t CBC_CommonByteArray::At(int32_t index) { +int32_t CBC_CommonByteArray::At(int32_t index) const { return m_bytes[index] & 0xff; } void CBC_CommonByteArray::Set(int32_t index, int32_t value) { m_bytes[index] = (uint8_t)value; } -int32_t CBC_CommonByteArray::Size() { +int32_t CBC_CommonByteArray::Size() const { return m_size; } -FX_BOOL CBC_CommonByteArray::IsEmpty() { +FX_BOOL CBC_CommonByteArray::IsEmpty() const { return m_size == 0; } void CBC_CommonByteArray::AppendByte(int32_t value) { diff --git a/xfa/fxbarcode/common/BC_CommonByteArray.h b/xfa/fxbarcode/common/BC_CommonByteArray.h index 2570f81c0f..cdda41b4fd 100644 --- a/xfa/fxbarcode/common/BC_CommonByteArray.h +++ b/xfa/fxbarcode/common/BC_CommonByteArray.h @@ -9,6 +9,8 @@ #include "core/fxcrt/include/fx_basic.h" +// TODO(weili): The usage of this class should be replaced by +// std::vector. class CBC_CommonByteArray { public: CBC_CommonByteArray(); @@ -16,10 +18,10 @@ class CBC_CommonByteArray { CBC_CommonByteArray(uint8_t* byteArray, int32_t size); virtual ~CBC_CommonByteArray(); - int32_t At(int32_t index); + int32_t At(int32_t index) const; + int32_t Size() const; + FX_BOOL IsEmpty() const; void Set(int32_t index, int32_t value); - int32_t Size(); - FX_BOOL IsEmpty(); void AppendByte(int32_t value); void Reserve(int32_t capacity); void Set(uint8_t* source, int32_t offset, int32_t count); diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp index da0ad3ff05..c9425dfa19 100644 --- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp +++ b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp @@ -23,18 +23,19 @@ #include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" #include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h" -CBC_ReedSolomonGF256* CBC_ReedSolomonGF256::QRCodeFild = nullptr; +CBC_ReedSolomonGF256* CBC_ReedSolomonGF256::QRCodeField = nullptr; CBC_ReedSolomonGF256* CBC_ReedSolomonGF256::DataMatrixField = nullptr; + void CBC_ReedSolomonGF256::Initialize() { - QRCodeFild = new CBC_ReedSolomonGF256(0x011D); - QRCodeFild->Init(); + QRCodeField = new CBC_ReedSolomonGF256(0x011D); + QRCodeField->Init(); DataMatrixField = new CBC_ReedSolomonGF256(0x012D); DataMatrixField->Init(); } void CBC_ReedSolomonGF256::Finalize() { - delete QRCodeFild; - QRCodeFild = nullptr; + delete QRCodeField; + QRCodeField = nullptr; delete DataMatrixField; DataMatrixField = nullptr; } @@ -53,20 +54,22 @@ CBC_ReedSolomonGF256::CBC_ReedSolomonGF256(int32_t primitive) { } m_logTable[0] = 0; } + void CBC_ReedSolomonGF256::Init() { - m_zero = new CBC_ReedSolomonGF256Poly(this, 0); - m_one = new CBC_ReedSolomonGF256Poly(this, 1); -} -CBC_ReedSolomonGF256::~CBC_ReedSolomonGF256() { - delete m_zero; - delete m_one; + m_zero.reset(new CBC_ReedSolomonGF256Poly(this, 0)); + m_one.reset(new CBC_ReedSolomonGF256Poly(this, 1)); } -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::GetZero() { - return m_zero; + +CBC_ReedSolomonGF256::~CBC_ReedSolomonGF256() {} + +CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::GetZero() const { + return m_zero.get(); } -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::GetOne() { - return m_one; + +CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::GetOne() const { + return m_one.get(); } + CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::BuildMonomial( int32_t degree, int32_t coefficient, @@ -88,12 +91,15 @@ CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::BuildMonomial( BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); return temp; } + int32_t CBC_ReedSolomonGF256::AddOrSubtract(int32_t a, int32_t b) { return a ^ b; } + int32_t CBC_ReedSolomonGF256::Exp(int32_t a) { return m_expTable[a]; } + int32_t CBC_ReedSolomonGF256::Log(int32_t a, int32_t& e) { if (a == 0) { e = BCExceptionAIsZero; @@ -101,6 +107,7 @@ int32_t CBC_ReedSolomonGF256::Log(int32_t a, int32_t& e) { } return m_logTable[a]; } + int32_t CBC_ReedSolomonGF256::Inverse(int32_t a, int32_t& e) { if (a == 0) { e = BCExceptionAIsZero; @@ -108,6 +115,7 @@ int32_t CBC_ReedSolomonGF256::Inverse(int32_t a, int32_t& e) { } return m_expTable[255 - m_logTable[a]]; } + int32_t CBC_ReedSolomonGF256::Multiply(int32_t a, int32_t b) { if (a == 0 || b == 0) { return 0; diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h index cd788111ed..ec0f1ff549 100644 --- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h +++ b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h @@ -7,20 +7,23 @@ #ifndef XFA_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMONGF256_H_ #define XFA_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMONGF256_H_ +#include + #include "core/fxcrt/include/fx_basic.h" #include "xfa/fxbarcode/utils.h" class CBC_ReedSolomonGF256Poly; + class CBC_ReedSolomonGF256 { public: + explicit CBC_ReedSolomonGF256(int32_t primitive); + virtual ~CBC_ReedSolomonGF256(); + static void Initialize(); static void Finalize(); - static CBC_ReedSolomonGF256* QRCodeFild; - static CBC_ReedSolomonGF256* DataMatrixField; - CBC_ReedSolomonGF256(int32_t primitive); - virtual ~CBC_ReedSolomonGF256(); - CBC_ReedSolomonGF256Poly* GetZero(); - CBC_ReedSolomonGF256Poly* GetOne(); + + CBC_ReedSolomonGF256Poly* GetZero() const; + CBC_ReedSolomonGF256Poly* GetOne() const; CBC_ReedSolomonGF256Poly* BuildMonomial(int32_t degree, int32_t coefficient, int32_t& e); @@ -31,11 +34,14 @@ class CBC_ReedSolomonGF256 { int32_t Multiply(int32_t a, int32_t b); virtual void Init(); + static CBC_ReedSolomonGF256* QRCodeField; + static CBC_ReedSolomonGF256* DataMatrixField; + private: int32_t m_expTable[256]; int32_t m_logTable[256]; - CBC_ReedSolomonGF256Poly* m_zero; - CBC_ReedSolomonGF256Poly* m_one; + std::unique_ptr m_zero; + std::unique_ptr m_one; }; #endif // XFA_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMONGF256_H_ diff --git a/xfa/fxbarcode/oned/BC_OneDimWriter.cpp b/xfa/fxbarcode/oned/BC_OneDimWriter.cpp index ea2f3f9f89..9ab1aeb53e 100644 --- a/xfa/fxbarcode/oned/BC_OneDimWriter.cpp +++ b/xfa/fxbarcode/oned/BC_OneDimWriter.cpp @@ -42,20 +42,22 @@ CBC_OneDimWriter::CBC_OneDimWriter() { m_iContentLen = 0; m_bLeftPadding = FALSE; m_bRightPadding = FALSE; - m_output = nullptr; -} -CBC_OneDimWriter::~CBC_OneDimWriter() { - delete m_output; } + +CBC_OneDimWriter::~CBC_OneDimWriter() {} + void CBC_OneDimWriter::SetPrintChecksum(FX_BOOL checksum) { m_bPrintChecksum = checksum; } + void CBC_OneDimWriter::SetDataLength(int32_t length) { m_iDataLenth = length; } + void CBC_OneDimWriter::SetCalcChecksum(int32_t state) { m_bCalcChecksum = state; } + FX_BOOL CBC_OneDimWriter::SetFont(CFX_Font* cFont) { if (!cFont) return FALSE; @@ -63,21 +65,26 @@ FX_BOOL CBC_OneDimWriter::SetFont(CFX_Font* cFont) { m_pFont = cFont; return TRUE; } + void CBC_OneDimWriter::SetFontSize(FX_FLOAT size) { m_fFontSize = size; } + void CBC_OneDimWriter::SetFontStyle(int32_t style) { m_iFontStyle = style; } + void CBC_OneDimWriter::SetFontColor(FX_ARGB color) { m_fontColor = color; } + FX_WCHAR CBC_OneDimWriter::Upper(FX_WCHAR ch) { if (ch >= 'a' && ch <= 'z') { ch = ch - ('a' - 'A'); } return ch; } + uint8_t* CBC_OneDimWriter::Encode(const CFX_ByteString& contents, BCFORMAT format, int32_t& outWidth, @@ -94,6 +101,7 @@ uint8_t* CBC_OneDimWriter::Encode(const CFX_ByteString& contents, BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); return ret; } + uint8_t* CBC_OneDimWriter::Encode(const CFX_ByteString& contents, BCFORMAT format, int32_t& outWidth, @@ -183,6 +191,7 @@ void CBC_OneDimWriter::CalcTextInfo(const CFX_ByteString& text, } FX_Free(pCharCode); } + void CBC_OneDimWriter::ShowDeviceChars(CFX_RenderDevice* device, const CFX_Matrix* matrix, const CFX_ByteString str, @@ -429,7 +438,7 @@ void CBC_OneDimWriter::RenderResult(const CFX_WideStringC& contents, if (!isDevice) { m_barWidth = codeLength * m_multiple; } - m_output = new CBC_CommonBitMatrix; + m_output.reset(new CBC_CommonBitMatrix); m_output->Init(outputWidth, outputHeight); int32_t outputX = leftPadding * m_multiple; for (int32_t inputX = 0; inputX < codeOldLength; inputX++) { diff --git a/xfa/fxbarcode/oned/BC_OneDimWriter.h b/xfa/fxbarcode/oned/BC_OneDimWriter.h index 10eccf9eea..1480b82df1 100644 --- a/xfa/fxbarcode/oned/BC_OneDimWriter.h +++ b/xfa/fxbarcode/oned/BC_OneDimWriter.h @@ -7,6 +7,8 @@ #ifndef XFA_FXBARCODE_ONED_BC_ONEDIMWRITER_H_ #define XFA_FXBARCODE_ONED_BC_ONEDIMWRITER_H_ +#include + #include "core/fxge/include/fx_ge.h" #include "xfa/fxbarcode/BC_Writer.h" #include "xfa/fxbarcode/include/BC_Library.h" @@ -107,7 +109,7 @@ class CBC_OneDimWriter : public CBC_Writer { int32_t m_iContentLen; FX_BOOL m_bLeftPadding; FX_BOOL m_bRightPadding; - CBC_CommonBitMatrix* m_output; + std::unique_ptr m_output; int32_t m_barWidth; int32_t m_multiple; FX_FLOAT m_outputHScale; diff --git a/xfa/fxbarcode/oned/BC_OnedUPCAWriter.cpp b/xfa/fxbarcode/oned/BC_OnedUPCAWriter.cpp index 8ed5971e0e..8fd85fc6a1 100644 --- a/xfa/fxbarcode/oned/BC_OnedUPCAWriter.cpp +++ b/xfa/fxbarcode/oned/BC_OnedUPCAWriter.cpp @@ -27,17 +27,16 @@ #include "xfa/fxbarcode/oned/BC_OnedUPCAWriter.h" CBC_OnedUPCAWriter::CBC_OnedUPCAWriter() { - m_subWriter = nullptr; m_bLeftPadding = TRUE; m_bRightPadding = TRUE; } + void CBC_OnedUPCAWriter::Init() { - m_subWriter = new CBC_OnedEAN13Writer; -} -CBC_OnedUPCAWriter::~CBC_OnedUPCAWriter() { - delete m_subWriter; + m_subWriter.reset(new CBC_OnedEAN13Writer); } +CBC_OnedUPCAWriter::~CBC_OnedUPCAWriter() {} + FX_BOOL CBC_OnedUPCAWriter::CheckContentValidity( const CFX_WideStringC& contents) { for (FX_STRSIZE i = 0; i < contents.GetLength(); ++i) { @@ -63,6 +62,7 @@ CFX_WideString CBC_OnedUPCAWriter::FilterContents( } return filtercontents; } + int32_t CBC_OnedUPCAWriter::CalcChecksum(const CFX_ByteString& contents) { int32_t odd = 0; int32_t even = 0; @@ -79,6 +79,7 @@ int32_t CBC_OnedUPCAWriter::CalcChecksum(const CFX_ByteString& contents) { checksum = (10 - checksum) % 10; return (checksum); } + uint8_t* CBC_OnedUPCAWriter::Encode(const CFX_ByteString& contents, BCFORMAT format, int32_t& outWidth, @@ -88,6 +89,7 @@ uint8_t* CBC_OnedUPCAWriter::Encode(const CFX_ByteString& contents, BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); return ret; } + uint8_t* CBC_OnedUPCAWriter::Encode(const CFX_ByteString& contents, BCFORMAT format, int32_t& outWidth, diff --git a/xfa/fxbarcode/oned/BC_OnedUPCAWriter.h b/xfa/fxbarcode/oned/BC_OnedUPCAWriter.h index 8257dfa4b6..b38a235076 100644 --- a/xfa/fxbarcode/oned/BC_OnedUPCAWriter.h +++ b/xfa/fxbarcode/oned/BC_OnedUPCAWriter.h @@ -7,6 +7,8 @@ #ifndef XFA_FXBARCODE_ONED_BC_ONEDUPCAWRITER_H_ #define XFA_FXBARCODE_ONED_BC_ONEDUPCAWRITER_H_ +#include + #include "core/fxcrt/include/fx_string.h" #include "core/fxcrt/include/fx_system.h" #include "xfa/fxbarcode/oned/BC_OneDimWriter.h" @@ -21,8 +23,6 @@ class CBC_OnedUPCAWriter : public CBC_OneDimWriter { CBC_OnedUPCAWriter(); ~CBC_OnedUPCAWriter() override; - virtual void Init(); - // CBC_OneDimWriter uint8_t* Encode(const CFX_ByteString& contents, BCFORMAT format, @@ -46,6 +46,8 @@ class CBC_OnedUPCAWriter : public CBC_OneDimWriter { int32_t& e) override; FX_BOOL CheckContentValidity(const CFX_WideStringC& contents) override; CFX_WideString FilterContents(const CFX_WideStringC& contents) override; + + void Init(); int32_t CalcChecksum(const CFX_ByteString& contents); protected: @@ -58,7 +60,7 @@ class CBC_OnedUPCAWriter : public CBC_OneDimWriter { int32_t& e) override; private: - CBC_OnedEAN13Writer* m_subWriter; + std::unique_ptr m_subWriter; }; #endif // XFA_FXBARCODE_ONED_BC_ONEDUPCAWRITER_H_ diff --git a/xfa/fxbarcode/pdf417/BC_PDF417.cpp b/xfa/fxbarcode/pdf417/BC_PDF417.cpp index 317a1cb92b..843ee23364 100644 --- a/xfa/fxbarcode/pdf417/BC_PDF417.cpp +++ b/xfa/fxbarcode/pdf417/BC_PDF417.cpp @@ -380,35 +380,23 @@ const int32_t CBC_PDF417::CODEWORD_TABLE[][929] = { 0x11f1a, 0x13f3a, 0x103ac, 0x103a6, 0x107a8, 0x183d6, 0x107a4, 0x107a2, 0x10396, 0x107b6, 0x187d4, 0x187d2, 0x10794, 0x10fb4, 0x10792, 0x10fb2, 0x1c7ea}}; -FX_FLOAT CBC_PDF417::PREFERRED_RATIO = 3.0f; -FX_FLOAT CBC_PDF417::DEFAULT_MODULE_WIDTH = 0.357f; -FX_FLOAT CBC_PDF417::HEIGHT = 2.0f; -CBC_PDF417::CBC_PDF417() { - m_compact = FALSE; - m_compaction = AUTO; - m_minCols = 1; - m_maxCols = 30; - m_maxRows = 90; - m_minRows = 3; - m_barcodeMatrix = nullptr; -} -CBC_PDF417::CBC_PDF417(FX_BOOL compact) { - m_compact = compact; - m_compaction = AUTO; - m_minCols = 1; - m_maxCols = 30; - m_maxRows = 90; - m_minRows = 3; - m_barcodeMatrix = nullptr; -} -CBC_PDF417::~CBC_PDF417() { - delete m_barcodeMatrix; -} +CBC_PDF417::CBC_PDF417() : CBC_PDF417(FALSE) {} + +CBC_PDF417::CBC_PDF417(FX_BOOL compact) + : m_compact(compact), + m_compaction(AUTO), + m_minCols(1), + m_maxCols(30), + m_maxRows(90), + m_minRows(3) {} + +CBC_PDF417::~CBC_PDF417() {} CBC_BarcodeMatrix* CBC_PDF417::getBarcodeMatrix() { - return m_barcodeMatrix; + return m_barcodeMatrix.get(); } + void CBC_PDF417::generateBarcodeLogic(CFX_WideString msg, int32_t errorCorrectionLevel, int32_t& e) { @@ -444,10 +432,11 @@ void CBC_PDF417::generateBarcodeLogic(CFX_WideString msg, dataCodewords, errorCorrectionLevel, e); BC_EXCEPTION_CHECK_ReturnVoid(e); CFX_WideString fullCodewords = dataCodewords + ec; - m_barcodeMatrix = new CBC_BarcodeMatrix(rows, cols); + m_barcodeMatrix.reset(new CBC_BarcodeMatrix(rows, cols)); encodeLowLevel(fullCodewords, cols, rows, errorCorrectionLevel, - m_barcodeMatrix); + m_barcodeMatrix.get()); } + void CBC_PDF417::setDimensions(int32_t maxCols, int32_t minCols, int32_t maxRows, @@ -457,12 +446,15 @@ void CBC_PDF417::setDimensions(int32_t maxCols, m_maxRows = maxRows; m_minRows = minRows; } + void CBC_PDF417::setCompaction(Compaction compaction) { m_compaction = compaction; } + void CBC_PDF417::setCompact(FX_BOOL compact) { m_compact = compact; } + int32_t CBC_PDF417::calculateNumberOfRows(int32_t m, int32_t k, int32_t c) { int32_t r = ((m + 1 + k) / c) + 1; if (c * r >= (m + 1 + k + c)) { @@ -470,6 +462,7 @@ int32_t CBC_PDF417::calculateNumberOfRows(int32_t m, int32_t k, int32_t c) { } return r; } + int32_t CBC_PDF417::getNumberOfPadCodewords(int32_t m, int32_t k, int32_t c, @@ -477,6 +470,7 @@ int32_t CBC_PDF417::getNumberOfPadCodewords(int32_t m, int32_t n = c * r - k; return n > m + 1 ? n - m - 1 : 0; } + void CBC_PDF417::encodeChar(int32_t pattern, int32_t len, CBC_BarcodeRow* logic) { @@ -496,6 +490,7 @@ void CBC_PDF417::encodeChar(int32_t pattern, } logic->addBar(last, width); } + void CBC_PDF417::encodeLowLevel(CFX_WideString fullCodewords, int32_t c, int32_t r, @@ -534,6 +529,7 @@ void CBC_PDF417::encodeLowLevel(CFX_WideString fullCodewords, } } } + CFX_Int32Array* CBC_PDF417::determineDimensions( int32_t sourceCodeWords, int32_t errorCorrectionCodeWords, diff --git a/xfa/fxbarcode/pdf417/BC_PDF417.h b/xfa/fxbarcode/pdf417/BC_PDF417.h index f2fb5cb89e..eeffc1e6ee 100644 --- a/xfa/fxbarcode/pdf417/BC_PDF417.h +++ b/xfa/fxbarcode/pdf417/BC_PDF417.h @@ -7,6 +7,8 @@ #ifndef XFA_FXBARCODE_PDF417_BC_PDF417_H_ #define XFA_FXBARCODE_PDF417_BC_PDF417_H_ +#include + #include "core/fxcrt/include/fx_basic.h" #include "xfa/fxbarcode/pdf417/BC_PDF417Compaction.h" @@ -16,7 +18,7 @@ class CBC_BarcodeMatrix; class CBC_PDF417 { public: CBC_PDF417(); - CBC_PDF417(FX_BOOL compact); + explicit CBC_PDF417(FX_BOOL compact); virtual ~CBC_PDF417(); CBC_BarcodeMatrix* getBarcodeMatrix(); @@ -34,18 +36,10 @@ class CBC_PDF417 { static const int32_t START_PATTERN = 0x1fea8; static const int32_t STOP_PATTERN = 0x3fa29; static const int32_t CODEWORD_TABLE[][929]; - static FX_FLOAT PREFERRED_RATIO; - static FX_FLOAT DEFAULT_MODULE_WIDTH; - static FX_FLOAT HEIGHT; - CBC_BarcodeMatrix* m_barcodeMatrix; - FX_BOOL m_compact; - Compaction m_compaction; - int32_t m_minCols; - int32_t m_maxCols; - int32_t m_maxRows; - int32_t m_minRows; + static constexpr FX_FLOAT PREFERRED_RATIO = 3.0f; + static constexpr FX_FLOAT DEFAULT_MODULE_WIDTH = 0.357f; + static constexpr FX_FLOAT HEIGHT = 2.0f; - private: static int32_t calculateNumberOfRows(int32_t m, int32_t k, int32_t c); static int32_t getNumberOfPadCodewords(int32_t m, int32_t k, @@ -60,6 +54,14 @@ class CBC_PDF417 { CFX_Int32Array* determineDimensions(int32_t sourceCodeWords, int32_t errorCorrectionCodeWords, int32_t& e); + + std::unique_ptr m_barcodeMatrix; + FX_BOOL m_compact; + Compaction m_compaction; + int32_t m_minCols; + int32_t m_maxCols; + int32_t m_maxRows; + int32_t m_minRows; }; #endif // XFA_FXBARCODE_PDF417_BC_PDF417_H_ 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 + #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 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 + 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 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 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 + +#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 data, + std::unique_ptr 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 + 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 data, + std::unique_ptr errorCorrection); virtual ~CBC_QRCoderBlockPair(); - CBC_CommonByteArray* GetDataBytes(); - CBC_CommonByteArray* GetErrorCorrectionBytes(); + const CBC_CommonByteArray* GetDataBytes() const; + const CBC_CommonByteArray* GetErrorCorrectionBytes() const; + + private: + std::unique_ptr m_dataBytes; + std::unique_ptr 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 #include +#include #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& splitResult, CBC_QRCoderBitVector& headerAndDataBits, @@ -139,6 +144,7 @@ void CBC_QRCoderEncoder::AppendDataModeLenghInfo( } } } + void CBC_QRCoderEncoder::SplitString(const CFX_ByteString& content, CFX_ArrayTemplate* result) { int32_t index = 0, flag = 0; @@ -316,6 +322,7 @@ void CBC_QRCoderEncoder::MergeString(CFX_ArrayTemplate* 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 dataBytes(new CBC_CommonByteArray); dataBytes->Set(bits->GetArray(), dataBytesOffset, numDataBytesInBlock); - CBC_CommonByteArray* ecBytes = - GenerateECBytes(dataBytes, numEcBytesInBlosk, e); + std::unique_ptr 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 + #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 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(), 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(), 0x00, "TERMINATOR"); sFNC1_FIRST_POSITION = - new CBC_QRCoderMode(nullptr, 0, 0, 0, 0x05, "FNC1_FIRST_POSITION"); + new CBC_QRCoderMode(std::vector(), 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(), 0x09, "FNC1_SECOND_POSITION"); + sSTRUCTURED_APPEND = + new CBC_QRCoderMode(std::vector(), 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 +#include + #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 charCountBits, + int32_t bits, + CFX_ByteString name); + + std::vector m_characterCountBitsForVersions; + const int32_t m_bits; + const CFX_ByteString m_name; }; #endif // XFA_FXBARCODE_QRCODE_BC_QRCODERMODE_H_ -- cgit v1.2.3