summaryrefslogtreecommitdiff
path: root/xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp')
-rw-r--r--xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp37
1 files changed, 23 insertions, 14 deletions
diff --git a/xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp
index e347cb2385..a7393a48f6 100644
--- a/xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp
+++ b/xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp
@@ -20,14 +20,27 @@
* limitations under the License.
*/
-#include "xfa/fxbarcode/BC_Reader.h"
#include "xfa/fxbarcode/BC_Writer.h"
-#include "xfa/fxbarcode/oned/BC_OneDReader.h"
-#include "xfa/fxbarcode/oned/BC_OneDimReader.h"
#include "xfa/fxbarcode/oned/BC_OneDimWriter.h"
-#include "xfa/fxbarcode/oned/BC_OnedEAN13Reader.h"
#include "xfa/fxbarcode/oned/BC_OnedEAN13Writer.h"
+namespace {
+
+const int32_t FIRST_DIGIT_ENCODINGS[10] = {0x00, 0x0B, 0x0D, 0xE, 0x13,
+ 0x19, 0x1C, 0x15, 0x16, 0x1A};
+const int32_t START_END_PATTERN[3] = {1, 1, 1};
+const int32_t MIDDLE_PATTERN[5] = {1, 1, 1, 1, 1};
+const int32_t L_PATTERNS[10][4] = {
+ {3, 2, 1, 1}, {2, 2, 2, 1}, {2, 1, 2, 2}, {1, 4, 1, 1}, {1, 1, 3, 2},
+ {1, 2, 3, 1}, {1, 1, 1, 4}, {1, 3, 1, 2}, {1, 2, 1, 3}, {3, 1, 1, 2}};
+const int32_t L_AND_G_PATTERNS[20][4] = {
+ {3, 2, 1, 1}, {2, 2, 2, 1}, {2, 1, 2, 2}, {1, 4, 1, 1}, {1, 1, 3, 2},
+ {1, 2, 3, 1}, {1, 1, 1, 4}, {1, 3, 1, 2}, {1, 2, 1, 3}, {3, 1, 1, 2},
+ {1, 1, 2, 3}, {1, 2, 2, 2}, {2, 2, 1, 2}, {1, 1, 4, 1}, {2, 3, 1, 1},
+ {1, 3, 2, 1}, {4, 1, 1, 1}, {2, 1, 3, 1}, {3, 1, 2, 1}, {2, 1, 1, 3}};
+
+} // namespace
+
CBC_OnedEAN13Writer::CBC_OnedEAN13Writer() {
m_bLeftPadding = TRUE;
m_codeWidth = 3 + (7 * 6) + 5 + (7 * 6) + 3;
@@ -108,12 +121,11 @@ uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents,
}
m_iDataLenth = 13;
int32_t firstDigit = FXSYS_atoi(contents.Mid(0, 1).c_str());
- int32_t parities = CBC_OnedEAN13Reader::FIRST_DIGIT_ENCODINGS[firstDigit];
+ int32_t parities = FIRST_DIGIT_ENCODINGS[firstDigit];
outLength = m_codeWidth;
uint8_t* result = FX_Alloc(uint8_t, m_codeWidth);
int32_t pos = 0;
- pos +=
- AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e);
+ pos += AppendPattern(result, pos, START_END_PATTERN, 3, 1, e);
if (e != BCExceptionNO) {
FX_Free(result);
return nullptr;
@@ -124,29 +136,26 @@ uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents,
if ((parities >> (6 - i) & 1) == 1) {
digit += 10;
}
- pos += AppendPattern(result, pos, CBC_OneDimReader::L_AND_G_PATTERNS[digit],
- 4, 0, e);
+ pos += AppendPattern(result, pos, L_AND_G_PATTERNS[digit], 4, 0, e);
if (e != BCExceptionNO) {
FX_Free(result);
return nullptr;
}
}
- pos += AppendPattern(result, pos, CBC_OneDimReader::MIDDLE_PATTERN, 5, 0, e);
+ pos += AppendPattern(result, pos, MIDDLE_PATTERN, 5, 0, e);
if (e != BCExceptionNO) {
FX_Free(result);
return nullptr;
}
for (i = 7; i <= 12; i++) {
int32_t digit = FXSYS_atoi(contents.Mid(i, 1).c_str());
- pos += AppendPattern(result, pos, CBC_OneDimReader::L_PATTERNS[digit], 4, 1,
- e);
+ pos += AppendPattern(result, pos, L_PATTERNS[digit], 4, 1, e);
if (e != BCExceptionNO) {
FX_Free(result);
return nullptr;
}
}
- pos +=
- AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e);
+ pos += AppendPattern(result, pos, START_END_PATTERN, 3, 1, e);
if (e != BCExceptionNO) {
FX_Free(result);
return nullptr;