diff options
author | Lei Zhang <thestig@chromium.org> | 2017-05-22 18:47:12 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-05-23 21:17:23 +0000 |
commit | abc83aa862050642a90ed109074a9cf1018fee9b (patch) | |
tree | b842d471c3cc49a0268a0647ca4c574248610ae9 /fxbarcode/datamatrix | |
parent | e0f1310795f1cf886b9b2a134b28ace9e8fc25ba (diff) | |
download | pdfium-abc83aa862050642a90ed109074a9cf1018fee9b.tar.xz |
Clean up CBC_SymbolInfo.chromium/3109
- Remove rectangular ctor param. It can be derived from dimensions.
- Make members private and add accessors.
- Remove exceptions that cannot occur.
Change-Id: Iec113205241562a0559e594fe257f5b9064ed97e
Reviewed-on: https://pdfium-review.googlesource.com/5737
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fxbarcode/datamatrix')
-rw-r--r-- | fxbarcode/datamatrix/BC_Base256Encoder.cpp | 2 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_C40Encoder.cpp | 4 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.cpp | 10 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_DataMatrixWriter.cpp | 50 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_EdifactEncoder.cpp | 4 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_EncoderContext.cpp | 2 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_ErrorCorrection.cpp | 8 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_HighLevelEncoder.cpp | 2 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_SymbolInfo.cpp | 149 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_SymbolInfo.h | 51 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_X12Encoder.cpp | 2 |
11 files changed, 146 insertions, 138 deletions
diff --git a/fxbarcode/datamatrix/BC_Base256Encoder.cpp b/fxbarcode/datamatrix/BC_Base256Encoder.cpp index a360f6372e..c34ff02939 100644 --- a/fxbarcode/datamatrix/BC_Base256Encoder.cpp +++ b/fxbarcode/datamatrix/BC_Base256Encoder.cpp @@ -59,7 +59,7 @@ void CBC_Base256Encoder::Encode(CBC_EncoderContext& context, int32_t& e) { if (e != BCExceptionNO) { return; } - bool mustPad = (context.m_symbolInfo->m_dataCapacity - currentSize) > 0; + bool mustPad = (context.m_symbolInfo->dataCapacity() - currentSize) > 0; if (context.hasMoreCharacters() || mustPad) { if (dataCount <= 249) { buffer.SetAt(0, (wchar_t)dataCount); diff --git a/fxbarcode/datamatrix/BC_C40Encoder.cpp b/fxbarcode/datamatrix/BC_C40Encoder.cpp index a264482305..11d477c07d 100644 --- a/fxbarcode/datamatrix/BC_C40Encoder.cpp +++ b/fxbarcode/datamatrix/BC_C40Encoder.cpp @@ -65,7 +65,7 @@ void CBC_C40Encoder::Encode(CBC_EncoderContext& context, int32_t& e) { if (e != BCExceptionNO) { return; } - int32_t available = context.m_symbolInfo->m_dataCapacity - curCodewordCount; + int32_t available = context.m_symbolInfo->dataCapacity() - curCodewordCount; if (!context.hasMoreCharacters()) { if ((buffer.GetLength() % 3) == 2) { if (available < 2 || available > 2) { @@ -113,7 +113,7 @@ void CBC_C40Encoder::handleEOD(CBC_EncoderContext& context, if (e != BCExceptionNO) { return; } - int32_t available = context.m_symbolInfo->m_dataCapacity - curCodewordCount; + int32_t available = context.m_symbolInfo->dataCapacity() - curCodewordCount; if (rest == 2) { buffer += (wchar_t)'\0'; while (buffer.GetLength() >= 3) { diff --git a/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.cpp b/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.cpp index d0ccfc2f1e..c0994af6e0 100644 --- a/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.cpp +++ b/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.cpp @@ -26,15 +26,15 @@ #include "fxbarcode/datamatrix/BC_SymbolShapeHint.h" CBC_DataMatrixSymbolInfo144::CBC_DataMatrixSymbolInfo144() - : CBC_SymbolInfo(false, 1558, 620, 22, 22, 36) { - m_rsBlockData = -1; - m_rsBlockError = 62; -} + : CBC_SymbolInfo(1558, 620, 22, 22, 36, -1, 62) {} + CBC_DataMatrixSymbolInfo144::~CBC_DataMatrixSymbolInfo144() {} + int32_t CBC_DataMatrixSymbolInfo144::getInterleavedBlockCount() { return 10; } + int32_t CBC_DataMatrixSymbolInfo144getDataLengthForInterleavedBlock( int32_t index) { - return (index <= 8) ? 156 : 155; + return index <= 8 ? 156 : 155; } diff --git a/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp b/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp index f45c338a7c..075449377f 100644 --- a/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp +++ b/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp @@ -50,50 +50,45 @@ namespace { std::unique_ptr<CBC_CommonByteMatrix> encodeLowLevel( CBC_DefaultPlacement* placement, CBC_SymbolInfo* symbolInfo) { - int32_t e = BCExceptionNO; - int32_t symbolWidth = symbolInfo->getSymbolDataWidth(e); - if (e != BCExceptionNO) - return nullptr; - int32_t symbolHeight = symbolInfo->getSymbolDataHeight(e); - if (e != BCExceptionNO) - return nullptr; - int32_t width = symbolInfo->getSymbolWidth(e); - if (e != BCExceptionNO) - return nullptr; - int32_t height = symbolInfo->getSymbolHeight(e); - if (e != BCExceptionNO) - return nullptr; + int32_t symbolWidth = symbolInfo->getSymbolDataWidth(); + ASSERT(symbolWidth); + int32_t symbolHeight = symbolInfo->getSymbolDataHeight(); + ASSERT(symbolHeight); + int32_t width = symbolInfo->getSymbolWidth(); + ASSERT(width); + int32_t height = symbolInfo->getSymbolHeight(); + ASSERT(height); auto matrix = pdfium::MakeUnique<CBC_CommonByteMatrix>(width, height); matrix->Init(); int32_t matrixY = 0; for (int32_t y = 0; y < symbolHeight; y++) { int32_t matrixX; - if ((y % symbolInfo->m_matrixHeight) == 0) { + if ((y % symbolInfo->matrixHeight()) == 0) { matrixX = 0; - for (int32_t x = 0; x < symbolInfo->getSymbolWidth(e); x++) { - matrix->Set(matrixX, matrixY, (x % 2) == 0); + for (int32_t x = 0; x < width; x++) { + matrix->Set(matrixX, matrixY, x % 2 == 0); matrixX++; } matrixY++; } matrixX = 0; for (int32_t x = 0; x < symbolWidth; x++) { - if ((x % symbolInfo->m_matrixWidth) == 0) { + if (x % symbolInfo->matrixWidth() == 0) { matrix->Set(matrixX, matrixY, true); matrixX++; } matrix->Set(matrixX, matrixY, placement->getBit(x, y)); matrixX++; - if ((x % symbolInfo->m_matrixWidth) == symbolInfo->m_matrixWidth - 1) { - matrix->Set(matrixX, matrixY, (y % 2) == 0); + if (x % symbolInfo->matrixWidth() == symbolInfo->matrixWidth() - 1) { + matrix->Set(matrixX, matrixY, y % 2 == 0); matrixX++; } } matrixY++; - if ((y % symbolInfo->m_matrixHeight) == symbolInfo->m_matrixHeight - 1) { + if (y % symbolInfo->matrixHeight() == symbolInfo->matrixHeight() - 1) { matrixX = 0; - for (int32_t x = 0; x < symbolInfo->getSymbolWidth(e); x++) { + for (int32_t x = 0; x < width; x++) { matrix->Set(matrixX, matrixY, true); matrixX++; } @@ -106,7 +101,9 @@ std::unique_ptr<CBC_CommonByteMatrix> encodeLowLevel( } // namespace CBC_DataMatrixWriter::CBC_DataMatrixWriter() {} + CBC_DataMatrixWriter::~CBC_DataMatrixWriter() {} + bool CBC_DataMatrixWriter::SetErrorCorrectionLevel(int32_t level) { m_iCorrectLevel = level; return true; @@ -135,13 +132,10 @@ uint8_t* CBC_DataMatrixWriter::Encode(const CFX_WideString& contents, if (e != BCExceptionNO) return nullptr; - int32_t width = symbolInfo->getSymbolDataWidth(e); - if (e != BCExceptionNO) - return nullptr; - - int32_t height = symbolInfo->getSymbolDataHeight(e); - if (e != BCExceptionNO) - return nullptr; + int32_t width = symbolInfo->getSymbolDataWidth(); + ASSERT(width); + int32_t height = symbolInfo->getSymbolDataHeight(); + ASSERT(height); auto placement = pdfium::MakeUnique<CBC_DefaultPlacement>(codewords, width, height); diff --git a/fxbarcode/datamatrix/BC_EdifactEncoder.cpp b/fxbarcode/datamatrix/BC_EdifactEncoder.cpp index 9231b1e293..cc72a311c9 100644 --- a/fxbarcode/datamatrix/BC_EdifactEncoder.cpp +++ b/fxbarcode/datamatrix/BC_EdifactEncoder.cpp @@ -66,7 +66,7 @@ bool HandleEOD(CBC_EncoderContext* context, const CFX_WideString& buffer) { return false; int32_t available = - context->m_symbolInfo->m_dataCapacity - context->getCodewordCount(); + context->m_symbolInfo->dataCapacity() - context->getCodewordCount(); int32_t remaining = context->getRemainingCharacters(); if (remaining == 0 && available <= 2) return true; @@ -86,7 +86,7 @@ bool HandleEOD(CBC_EncoderContext* context, const CFX_WideString& buffer) { return false; int32_t available = - context->m_symbolInfo->m_dataCapacity - context->getCodewordCount(); + context->m_symbolInfo->dataCapacity() - context->getCodewordCount(); if (available >= 3) { restInAscii = false; context->updateSymbolInfo( diff --git a/fxbarcode/datamatrix/BC_EncoderContext.cpp b/fxbarcode/datamatrix/BC_EncoderContext.cpp index 0411d03b5d..b4719656b2 100644 --- a/fxbarcode/datamatrix/BC_EncoderContext.cpp +++ b/fxbarcode/datamatrix/BC_EncoderContext.cpp @@ -90,7 +90,7 @@ void CBC_EncoderContext::updateSymbolInfo(int32_t& e) { updateSymbolInfo(getCodewordCount(), e); } void CBC_EncoderContext::updateSymbolInfo(int32_t len, int32_t& e) { - if (!m_symbolInfo || len > m_symbolInfo->m_dataCapacity) { + if (!m_symbolInfo || len > m_symbolInfo->dataCapacity()) { m_symbolInfo = CBC_SymbolInfo::lookup(len, m_shape, true, e); if (e != BCExceptionNO) return; diff --git a/fxbarcode/datamatrix/BC_ErrorCorrection.cpp b/fxbarcode/datamatrix/BC_ErrorCorrection.cpp index cd2355b8fe..cc6d1b320b 100644 --- a/fxbarcode/datamatrix/BC_ErrorCorrection.cpp +++ b/fxbarcode/datamatrix/BC_ErrorCorrection.cpp @@ -123,7 +123,7 @@ CBC_ErrorCorrection::~CBC_ErrorCorrection() {} CFX_WideString CBC_ErrorCorrection::encodeECC200(CFX_WideString codewords, CBC_SymbolInfo* symbolInfo, int32_t& e) { - if (codewords.GetLength() != symbolInfo->m_dataCapacity) { + if (codewords.GetLength() != symbolInfo->dataCapacity()) { e = BCExceptionIllegalArgument; return CFX_WideString(); } @@ -132,7 +132,7 @@ CFX_WideString CBC_ErrorCorrection::encodeECC200(CFX_WideString codewords, int32_t blockCount = symbolInfo->getInterleavedBlockCount(); if (blockCount == 1) { CFX_WideString ecc = - createECCBlock(codewords, symbolInfo->m_errorCodewords, e); + createECCBlock(codewords, symbolInfo->errorCodewords(), e); if (e != BCExceptionNO) return CFX_WideString(); sb += ecc; @@ -150,7 +150,7 @@ CFX_WideString CBC_ErrorCorrection::encodeECC200(CFX_WideString codewords, } for (int32_t block = 0; block < blockCount; block++) { CFX_WideString temp; - for (int32_t d = block; d < symbolInfo->m_dataCapacity; d += blockCount) { + for (int32_t d = block; d < symbolInfo->dataCapacity(); d += blockCount) { temp += (wchar_t)codewords.GetAt(d); } CFX_WideString ecc = createECCBlock(temp, errorSizes[block], e); @@ -159,7 +159,7 @@ CFX_WideString CBC_ErrorCorrection::encodeECC200(CFX_WideString codewords, int32_t pos = 0; for (int32_t l = block; l < errorSizes[block] * blockCount; l += blockCount) { - sb.SetAt(symbolInfo->m_dataCapacity + l, ecc.GetAt(pos++)); + sb.SetAt(symbolInfo->dataCapacity() + l, ecc.GetAt(pos++)); } } } diff --git a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp index 93f20305be..dd92f5e2d5 100644 --- a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp +++ b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp @@ -114,7 +114,7 @@ CFX_WideString CBC_HighLevelEncoder::encodeHighLevel(CFX_WideString msg, if (e != BCExceptionNO) return L""; - int32_t capacity = context.m_symbolInfo->m_dataCapacity; + int32_t capacity = context.m_symbolInfo->dataCapacity(); if (len < capacity) { if (encodingMode != ASCII_ENCODATION && encodingMode != BASE256_ENCODATION) { diff --git a/fxbarcode/datamatrix/BC_SymbolInfo.cpp b/fxbarcode/datamatrix/BC_SymbolInfo.cpp index 5d12f1c090..1d5a84f5c4 100644 --- a/fxbarcode/datamatrix/BC_SymbolInfo.cpp +++ b/fxbarcode/datamatrix/BC_SymbolInfo.cpp @@ -41,35 +41,35 @@ CBC_SymbolInfo* g_symbols[kSymbolsCount] = { } // namespace void CBC_SymbolInfo::Initialize() { - g_symbols[0] = new CBC_SymbolInfo(false, 3, 5, 8, 8, 1); - g_symbols[1] = new CBC_SymbolInfo(false, 5, 7, 10, 10, 1); - g_symbols[2] = new CBC_SymbolInfo(true, 5, 7, 16, 6, 1); - g_symbols[3] = new CBC_SymbolInfo(false, 8, 10, 12, 12, 1); - g_symbols[4] = new CBC_SymbolInfo(true, 10, 11, 14, 6, 2); - g_symbols[5] = new CBC_SymbolInfo(false, 12, 12, 14, 14, 1); - g_symbols[6] = new CBC_SymbolInfo(true, 16, 14, 24, 10, 1); - g_symbols[7] = new CBC_SymbolInfo(false, 18, 14, 16, 16, 1); - g_symbols[8] = new CBC_SymbolInfo(false, 22, 18, 18, 18, 1); - g_symbols[9] = new CBC_SymbolInfo(true, 22, 18, 16, 10, 2); - g_symbols[10] = new CBC_SymbolInfo(false, 30, 20, 20, 20, 1); - g_symbols[11] = new CBC_SymbolInfo(true, 32, 24, 16, 14, 2); - g_symbols[12] = new CBC_SymbolInfo(false, 36, 24, 22, 22, 1); - g_symbols[13] = new CBC_SymbolInfo(false, 44, 28, 24, 24, 1); - g_symbols[14] = new CBC_SymbolInfo(true, 49, 28, 22, 14, 2); - g_symbols[15] = new CBC_SymbolInfo(false, 62, 36, 14, 14, 4); - g_symbols[16] = new CBC_SymbolInfo(false, 86, 42, 16, 16, 4); - g_symbols[17] = new CBC_SymbolInfo(false, 114, 48, 18, 18, 4); - g_symbols[18] = new CBC_SymbolInfo(false, 144, 56, 20, 20, 4); - g_symbols[19] = new CBC_SymbolInfo(false, 174, 68, 22, 22, 4); - g_symbols[20] = new CBC_SymbolInfo(false, 204, 84, 24, 24, 4, 102, 42); - g_symbols[21] = new CBC_SymbolInfo(false, 280, 112, 14, 14, 16, 140, 56); - g_symbols[22] = new CBC_SymbolInfo(false, 368, 144, 16, 16, 16, 92, 36); - g_symbols[23] = new CBC_SymbolInfo(false, 456, 192, 18, 18, 16, 114, 48); - g_symbols[24] = new CBC_SymbolInfo(false, 576, 224, 20, 20, 16, 144, 56); - g_symbols[25] = new CBC_SymbolInfo(false, 696, 272, 22, 22, 16, 174, 68); - g_symbols[26] = new CBC_SymbolInfo(false, 816, 336, 24, 24, 16, 136, 56); - g_symbols[27] = new CBC_SymbolInfo(false, 1050, 408, 18, 18, 36, 175, 68); - g_symbols[28] = new CBC_SymbolInfo(false, 1304, 496, 20, 20, 36, 163, 62); + g_symbols[0] = new CBC_SymbolInfo(3, 5, 8, 8, 1); + g_symbols[1] = new CBC_SymbolInfo(5, 7, 10, 10, 1); + g_symbols[2] = new CBC_SymbolInfo(5, 7, 16, 6, 1); + g_symbols[3] = new CBC_SymbolInfo(8, 10, 12, 12, 1); + g_symbols[4] = new CBC_SymbolInfo(10, 11, 14, 6, 2); + g_symbols[5] = new CBC_SymbolInfo(12, 12, 14, 14, 1); + g_symbols[6] = new CBC_SymbolInfo(16, 14, 24, 10, 1); + g_symbols[7] = new CBC_SymbolInfo(18, 14, 16, 16, 1); + g_symbols[8] = new CBC_SymbolInfo(22, 18, 18, 18, 1); + g_symbols[9] = new CBC_SymbolInfo(22, 18, 16, 10, 2); + g_symbols[10] = new CBC_SymbolInfo(30, 20, 20, 20, 1); + g_symbols[11] = new CBC_SymbolInfo(32, 24, 16, 14, 2); + g_symbols[12] = new CBC_SymbolInfo(36, 24, 22, 22, 1); + g_symbols[13] = new CBC_SymbolInfo(44, 28, 24, 24, 1); + g_symbols[14] = new CBC_SymbolInfo(49, 28, 22, 14, 2); + g_symbols[15] = new CBC_SymbolInfo(62, 36, 14, 14, 4); + g_symbols[16] = new CBC_SymbolInfo(86, 42, 16, 16, 4); + g_symbols[17] = new CBC_SymbolInfo(114, 48, 18, 18, 4); + g_symbols[18] = new CBC_SymbolInfo(144, 56, 20, 20, 4); + g_symbols[19] = new CBC_SymbolInfo(174, 68, 22, 22, 4); + g_symbols[20] = new CBC_SymbolInfo(204, 84, 24, 24, 4, 102, 42); + g_symbols[21] = new CBC_SymbolInfo(280, 112, 14, 14, 16, 140, 56); + g_symbols[22] = new CBC_SymbolInfo(368, 144, 16, 16, 16, 92, 36); + g_symbols[23] = new CBC_SymbolInfo(456, 192, 18, 18, 16, 114, 48); + g_symbols[24] = new CBC_SymbolInfo(576, 224, 20, 20, 16, 144, 56); + g_symbols[25] = new CBC_SymbolInfo(696, 272, 22, 22, 16, 174, 68); + g_symbols[26] = new CBC_SymbolInfo(816, 336, 24, 24, 16, 136, 56); + g_symbols[27] = new CBC_SymbolInfo(1050, 408, 18, 18, 36, 175, 68); + g_symbols[28] = new CBC_SymbolInfo(1304, 496, 20, 20, 36, 163, 62); g_symbols[29] = new CBC_DataMatrixSymbolInfo144(); } @@ -80,48 +80,47 @@ void CBC_SymbolInfo::Finalize() { } } -CBC_SymbolInfo::CBC_SymbolInfo(bool rectangular, - int32_t dataCapacity, +CBC_SymbolInfo::CBC_SymbolInfo(int32_t dataCapacity, int32_t errorCodewords, int32_t matrixWidth, int32_t matrixHeight, - int32_t dataRegions) { - m_rectangular = rectangular; - m_dataCapacity = dataCapacity; - m_errorCodewords = errorCodewords; - m_matrixWidth = matrixWidth; - m_matrixHeight = matrixHeight; - m_dataRegions = dataRegions; - m_rsBlockData = dataCapacity; - m_rsBlockError = errorCodewords; -} -CBC_SymbolInfo::CBC_SymbolInfo(bool rectangular, - int32_t dataCapacity, + int32_t dataRegions) + : CBC_SymbolInfo(dataCapacity, + errorCodewords, + matrixWidth, + matrixHeight, + dataRegions, + dataCapacity, + errorCodewords) {} + +CBC_SymbolInfo::CBC_SymbolInfo(int32_t dataCapacity, int32_t errorCodewords, int32_t matrixWidth, int32_t matrixHeight, int32_t dataRegions, int32_t rsBlockData, - int32_t rsBlockError) { - m_rectangular = rectangular; - m_dataCapacity = dataCapacity; - m_errorCodewords = errorCodewords; - m_matrixWidth = matrixWidth; - m_matrixHeight = matrixHeight; - m_dataRegions = dataRegions; - m_rsBlockData = rsBlockData; - m_rsBlockError = rsBlockError; -} + int32_t rsBlockError) + : m_rectangular(matrixWidth != matrixHeight), + m_dataCapacity(dataCapacity), + m_errorCodewords(errorCodewords), + m_matrixWidth(matrixWidth), + m_matrixHeight(matrixHeight), + m_dataRegions(dataRegions), + m_rsBlockData(rsBlockData), + m_rsBlockError(rsBlockError) {} + CBC_SymbolInfo::~CBC_SymbolInfo() {} CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, int32_t& e) { return lookup(dataCodewords, FORCE_NONE, true, e); } + CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, SymbolShapeHint shape, int32_t& e) { return lookup(dataCodewords, shape, true, e); } + CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, bool allowRectangular, bool fail, @@ -129,6 +128,7 @@ CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, SymbolShapeHint shape = allowRectangular ? FORCE_NONE : FORCE_SQUARE; return lookup(dataCodewords, shape, fail, e); } + CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, SymbolShapeHint shape, bool fail, @@ -139,7 +139,7 @@ CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, (shape == FORCE_RECTANGLE && !symbol->m_rectangular)) { continue; } - if (dataCodewords <= symbol->m_dataCapacity) + if (dataCodewords <= symbol->dataCapacity()) return symbol; } if (fail) @@ -147,7 +147,7 @@ CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, return nullptr; } -int32_t CBC_SymbolInfo::getHorizontalDataRegions(int32_t& e) { +int32_t CBC_SymbolInfo::getHorizontalDataRegions() const { switch (m_dataRegions) { case 1: return 1; @@ -160,11 +160,12 @@ int32_t CBC_SymbolInfo::getHorizontalDataRegions(int32_t& e) { case 36: return 6; default: - e = BCExceptionCannotHandleThisNumberOfDataRegions; + NOTREACHED(); return 0; } } -int32_t CBC_SymbolInfo::getVerticalDataRegions(int32_t& e) { + +int32_t CBC_SymbolInfo::getVerticalDataRegions() const { switch (m_dataRegions) { case 1: return 1; @@ -177,31 +178,39 @@ int32_t CBC_SymbolInfo::getVerticalDataRegions(int32_t& e) { case 36: return 6; default: - e = BCExceptionCannotHandleThisNumberOfDataRegions; + NOTREACHED(); return 0; } } -int32_t CBC_SymbolInfo::getSymbolDataWidth(int32_t& e) { - return getHorizontalDataRegions(e) * m_matrixWidth; + +int32_t CBC_SymbolInfo::getSymbolDataWidth() const { + return getHorizontalDataRegions() * m_matrixWidth; } -int32_t CBC_SymbolInfo::getSymbolDataHeight(int32_t& e) { - return getVerticalDataRegions(e) * m_matrixHeight; + +int32_t CBC_SymbolInfo::getSymbolDataHeight() const { + return getVerticalDataRegions() * m_matrixHeight; } -int32_t CBC_SymbolInfo::getSymbolWidth(int32_t& e) { - return getSymbolDataWidth(e) + (getHorizontalDataRegions(e) * 2); + +int32_t CBC_SymbolInfo::getSymbolWidth() const { + return getSymbolDataWidth() + (getHorizontalDataRegions() * 2); } -int32_t CBC_SymbolInfo::getSymbolHeight(int32_t& e) { - return getSymbolDataHeight(e) + (getVerticalDataRegions(e) * 2); + +int32_t CBC_SymbolInfo::getSymbolHeight() const { + return getSymbolDataHeight() + (getVerticalDataRegions() * 2); } -int32_t CBC_SymbolInfo::getCodewordCount() { + +int32_t CBC_SymbolInfo::getCodewordCount() const { return m_dataCapacity + m_errorCodewords; } -int32_t CBC_SymbolInfo::getInterleavedBlockCount() { + +int32_t CBC_SymbolInfo::getInterleavedBlockCount() const { return m_dataCapacity / m_rsBlockData; } -int32_t CBC_SymbolInfo::getDataLengthForInterleavedBlock(int32_t index) { + +int32_t CBC_SymbolInfo::getDataLengthForInterleavedBlock(int32_t index) const { return m_rsBlockData; } -int32_t CBC_SymbolInfo::getErrorLengthForInterleavedBlock(int32_t index) { + +int32_t CBC_SymbolInfo::getErrorLengthForInterleavedBlock(int32_t index) const { return m_rsBlockError; } diff --git a/fxbarcode/datamatrix/BC_SymbolInfo.h b/fxbarcode/datamatrix/BC_SymbolInfo.h index 0a5cd20247..18d7b68f09 100644 --- a/fxbarcode/datamatrix/BC_SymbolInfo.h +++ b/fxbarcode/datamatrix/BC_SymbolInfo.h @@ -13,8 +13,7 @@ class CBC_SymbolInfo : public CBC_SymbolShapeHint { public: - CBC_SymbolInfo(bool rectangular, - int32_t dataCapacity, + CBC_SymbolInfo(int32_t dataCapacity, int32_t errorCodewords, int32_t matrixWidth, int32_t matrixHeight, @@ -36,27 +35,23 @@ class CBC_SymbolInfo : public CBC_SymbolShapeHint { SymbolShapeHint shape, bool fail, int32_t& e); - int32_t getHorizontalDataRegions(int32_t& e); - int32_t getVerticalDataRegions(int32_t& e); - int32_t getSymbolDataWidth(int32_t& e); - int32_t getSymbolDataHeight(int32_t& e); - int32_t getSymbolWidth(int32_t& e); - int32_t getSymbolHeight(int32_t& e); - int32_t getCodewordCount(); - int32_t getInterleavedBlockCount(); - int32_t getDataLengthForInterleavedBlock(int32_t index); - int32_t getErrorLengthForInterleavedBlock(int32_t index); - int32_t m_dataCapacity; - int32_t m_errorCodewords; - int32_t m_matrixWidth; - int32_t m_matrixHeight; - int32_t m_rsBlockData; - int32_t m_rsBlockError; + int32_t getSymbolDataWidth() const; + int32_t getSymbolDataHeight() const; + int32_t getSymbolWidth() const; + int32_t getSymbolHeight() const; + int32_t getCodewordCount() const; + int32_t getInterleavedBlockCount() const; + int32_t getDataLengthForInterleavedBlock(int32_t index) const; + int32_t getErrorLengthForInterleavedBlock(int32_t index) const; - private: - CBC_SymbolInfo(bool rectangular, - int32_t dataCapacity, + int32_t dataCapacity() const { return m_dataCapacity; } + int32_t errorCodewords() const { return m_errorCodewords; } + int32_t matrixWidth() const { return m_matrixWidth; } + int32_t matrixHeight() const { return m_matrixHeight; } + + protected: + CBC_SymbolInfo(int32_t dataCapacity, int32_t errorCodewords, int32_t matrixWidth, int32_t matrixHeight, @@ -64,8 +59,18 @@ class CBC_SymbolInfo : public CBC_SymbolShapeHint { int32_t rsBlockData, int32_t rsBlockError); - bool m_rectangular; - int32_t m_dataRegions; + private: + int32_t getHorizontalDataRegions() const; + int32_t getVerticalDataRegions() const; + + const bool m_rectangular; + const int32_t m_dataCapacity; + const int32_t m_errorCodewords; + const int32_t m_matrixWidth; + const int32_t m_matrixHeight; + const int32_t m_dataRegions; + const int32_t m_rsBlockData; + const int32_t m_rsBlockError; }; #endif // FXBARCODE_DATAMATRIX_BC_SYMBOLINFO_H_ diff --git a/fxbarcode/datamatrix/BC_X12Encoder.cpp b/fxbarcode/datamatrix/BC_X12Encoder.cpp index 04bf958bf4..0d874b0de0 100644 --- a/fxbarcode/datamatrix/BC_X12Encoder.cpp +++ b/fxbarcode/datamatrix/BC_X12Encoder.cpp @@ -66,7 +66,7 @@ void CBC_X12Encoder::handleEOD(CBC_EncoderContext& context, return; } int32_t available = - context.m_symbolInfo->m_dataCapacity - context.getCodewordCount(); + context.m_symbolInfo->dataCapacity() - context.getCodewordCount(); int32_t count = buffer.GetLength(); if (count == 2) { context.writeCodeword(CBC_HighLevelEncoder::X12_UNLATCH); |