summaryrefslogtreecommitdiff
path: root/xfa/fxbarcode/oned/BC_OnedCode39Writer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxbarcode/oned/BC_OnedCode39Writer.cpp')
-rw-r--r--xfa/fxbarcode/oned/BC_OnedCode39Writer.cpp142
1 files changed, 29 insertions, 113 deletions
diff --git a/xfa/fxbarcode/oned/BC_OnedCode39Writer.cpp b/xfa/fxbarcode/oned/BC_OnedCode39Writer.cpp
index 58d9472e25..3edf87ba30 100644
--- a/xfa/fxbarcode/oned/BC_OnedCode39Writer.cpp
+++ b/xfa/fxbarcode/oned/BC_OnedCode39Writer.cpp
@@ -20,28 +20,33 @@
* limitations under the License.
*/
-#include "xfa/fxbarcode/BC_Reader.h"
#include "xfa/fxbarcode/BC_Writer.h"
#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h"
-#include "xfa/fxbarcode/oned/BC_OneDReader.h"
#include "xfa/fxbarcode/oned/BC_OneDimWriter.h"
-#include "xfa/fxbarcode/oned/BC_OnedCode39Reader.h"
#include "xfa/fxbarcode/oned/BC_OnedCode39Writer.h"
+namespace {
+
+const FX_CHAR ALPHABET_STRING[] =
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *$/+%";
+
+const FX_CHAR CHECKSUM_STRING[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%";
+
+const int32_t CHARACTER_ENCODINGS[44] = {
+ 0x034, 0x121, 0x061, 0x160, 0x031, 0x130, 0x070, 0x025, 0x124,
+ 0x064, 0x109, 0x049, 0x148, 0x019, 0x118, 0x058, 0x00D, 0x10C,
+ 0x04C, 0x01C, 0x103, 0x043, 0x142, 0x013, 0x112, 0x052, 0x007,
+ 0x106, 0x046, 0x016, 0x181, 0x0C1, 0x1C0, 0x091, 0x190, 0x0D0,
+ 0x085, 0x184, 0x0C4, 0x094, 0x0A8, 0x0A2, 0x08A, 0x02A};
+
+} // namespace
+
CBC_OnedCode39Writer::CBC_OnedCode39Writer() {
- m_extendedMode = FALSE;
- m_iWideNarrRatio = 3;
-}
-CBC_OnedCode39Writer::CBC_OnedCode39Writer(FX_BOOL extendedMode) {
m_iWideNarrRatio = 3;
- m_extendedMode = extendedMode;
}
CBC_OnedCode39Writer::~CBC_OnedCode39Writer() {}
FX_BOOL CBC_OnedCode39Writer::CheckContentValidity(
const CFX_WideStringC& contents) {
- if (m_extendedMode) {
- return CheckExtendedContentValidity(contents);
- }
for (int32_t i = 0; i < contents.GetLength(); i++) {
FX_WCHAR ch = contents.GetAt(i);
if ((ch >= (FX_WCHAR)'0' && ch <= (FX_WCHAR)'9') ||
@@ -55,21 +60,9 @@ FX_BOOL CBC_OnedCode39Writer::CheckContentValidity(
}
return TRUE;
}
-FX_BOOL CBC_OnedCode39Writer::CheckExtendedContentValidity(
- const CFX_WideStringC& contents) {
- for (int32_t i = 0; i < contents.GetLength(); i++) {
- FX_WCHAR ch = contents.GetAt(i);
- if (ch > 127) {
- return FALSE;
- }
- }
- return TRUE;
-}
+
CFX_WideString CBC_OnedCode39Writer::FilterContents(
const CFX_WideStringC& contents) {
- if (m_extendedMode) {
- return FilterExtendedContents(contents);
- }
CFX_WideString filtercontents;
for (int32_t i = 0; i < contents.GetLength(); i++) {
FX_WCHAR ch = contents.GetAt(i);
@@ -92,68 +85,9 @@ CFX_WideString CBC_OnedCode39Writer::FilterContents(
}
return filtercontents;
}
-CFX_WideString CBC_OnedCode39Writer::FilterExtendedContents(
- const CFX_WideStringC& contents) {
- CFX_WideString filtercontents;
- for (int32_t i = 0; i < contents.GetLength(); i++) {
- FX_WCHAR ch = contents.GetAt(i);
- if (ch == (FX_WCHAR)'*' && (i == 0 || i == contents.GetLength() - 1)) {
- continue;
- }
- if (ch > 175) {
- i++;
- continue;
- }
- if (ch > 127 && ch < 176) {
- continue;
- }
- if (ch == 0) {
- filtercontents += '%';
- filtercontents += 'U';
- } else if (ch >= 1 && ch <= 26) {
- filtercontents += '$';
- filtercontents += (ch + 64);
- } else if (ch >= 27 && ch <= 31) {
- filtercontents += '%';
- filtercontents += (ch + 38);
- } else if (ch >= 33 && ch <= 47 && ch != 45 && ch != 46) {
- filtercontents += '/';
- filtercontents += (ch + 32);
- } else if (ch == 58) {
- filtercontents += '/';
- filtercontents += 'Z';
- } else if (ch >= 59 && ch <= 63) {
- filtercontents += '%';
- filtercontents += ch + 11;
- } else if (ch == 64) {
- filtercontents += '%';
- filtercontents += 'V';
- } else if (ch >= 91 && ch <= 95) {
- filtercontents += '%';
- filtercontents += ch - 16;
- } else if (ch == 96) {
- filtercontents += '%';
- filtercontents += 'W';
- } else if (ch >= 97 && ch <= 122) {
- filtercontents += '+';
- filtercontents += ch - 32;
- } else if (ch >= 123 && ch <= 126) {
- filtercontents += '%';
- filtercontents += ch - 43;
- } else if (ch == 127) {
- filtercontents += '%';
- filtercontents += 'T';
- } else {
- filtercontents += ch;
- }
- }
- return filtercontents;
-}
+
CFX_WideString CBC_OnedCode39Writer::RenderTextContents(
const CFX_WideStringC& contents) {
- if (m_extendedMode) {
- return RenderExtendedTextContents(contents);
- }
CFX_WideString renderContents;
for (int32_t i = 0; i < contents.GetLength(); i++) {
FX_WCHAR ch = contents.GetAt(i);
@@ -175,25 +109,7 @@ CFX_WideString CBC_OnedCode39Writer::RenderTextContents(
}
return renderContents;
}
-CFX_WideString CBC_OnedCode39Writer::RenderExtendedTextContents(
- const CFX_WideStringC& contents) {
- CFX_WideString renderContents;
- for (int32_t i = 0; i < contents.GetLength(); i++) {
- FX_WCHAR ch = contents.GetAt(i);
- if (ch == (FX_WCHAR)'*' && (i == 0 || i == contents.GetLength() - 1)) {
- continue;
- }
- if (ch > 175) {
- i++;
- continue;
- }
- if (ch > 127 && ch < 176) {
- continue;
- }
- renderContents += ch;
- }
- return renderContents;
-}
+
FX_BOOL CBC_OnedCode39Writer::SetTextLocation(BC_TEXT_LOC location) {
if (location < BC_TEXT_LOC_NONE || location > BC_TEXT_LOC_BELOWEMBED) {
return FALSE;
@@ -245,11 +161,11 @@ FX_CHAR CBC_OnedCode39Writer::CalcCheckSum(const CFX_ByteString& contents,
return '*';
}
int32_t checksum = 0;
- int32_t len = (int32_t)strlen(CBC_OnedCode39Reader::ALPHABET_STRING);
+ int32_t len = (int32_t)strlen(ALPHABET_STRING);
for (int32_t i = 0; i < contents.GetLength(); i++) {
int32_t j = 0;
for (; j < len; j++) {
- if (CBC_OnedCode39Reader::ALPHABET_STRING[j] == contents[i]) {
+ if (ALPHABET_STRING[j] == contents[i]) {
if (contents[i] != '*') {
checksum += j;
break;
@@ -264,7 +180,7 @@ FX_CHAR CBC_OnedCode39Writer::CalcCheckSum(const CFX_ByteString& contents,
}
}
checksum = checksum % 43;
- return CBC_OnedCode39Reader::CHECKSUM_STRING[checksum];
+ return CHECKSUM_STRING[checksum];
}
uint8_t* CBC_OnedCode39Writer::Encode(const CFX_ByteString& contents,
int32_t& outlength,
@@ -283,11 +199,11 @@ uint8_t* CBC_OnedCode39Writer::Encode(const CFX_ByteString& contents,
m_iContentLen = encodedContents.GetLength();
int32_t codeWidth = (wideStrideNum * m_iWideNarrRatio + narrStrideNum) * 2 +
1 + m_iContentLen;
- int32_t len = (int32_t)strlen(CBC_OnedCode39Reader::ALPHABET_STRING);
+ int32_t len = (int32_t)strlen(ALPHABET_STRING);
for (int32_t j = 0; j < m_iContentLen; j++) {
for (int32_t i = 0; i < len; i++) {
- if (CBC_OnedCode39Reader::ALPHABET_STRING[i] == encodedContents[j]) {
- ToIntArray(CBC_OnedCode39Reader::CHARACTER_ENCODINGS[i], widths);
+ if (ALPHABET_STRING[i] == encodedContents[j]) {
+ ToIntArray(CHARACTER_ENCODINGS[i], widths);
for (int32_t k = 0; k < 9; k++) {
codeWidth += widths[k];
}
@@ -296,7 +212,7 @@ uint8_t* CBC_OnedCode39Writer::Encode(const CFX_ByteString& contents,
}
outlength = codeWidth;
uint8_t* result = FX_Alloc(uint8_t, codeWidth);
- ToIntArray(CBC_OnedCode39Reader::CHARACTER_ENCODINGS[39], widths);
+ ToIntArray(CHARACTER_ENCODINGS[39], widths);
int32_t pos = AppendPattern(result, 0, widths, 9, 1, e);
if (e != BCExceptionNO) {
FX_Free(result);
@@ -310,8 +226,8 @@ uint8_t* CBC_OnedCode39Writer::Encode(const CFX_ByteString& contents,
}
for (int32_t l = m_iContentLen - 1; l >= 0; l--) {
for (int32_t i = 0; i < len; i++) {
- if (CBC_OnedCode39Reader::ALPHABET_STRING[i] == encodedContents[l]) {
- ToIntArray(CBC_OnedCode39Reader::CHARACTER_ENCODINGS[i], widths);
+ if (ALPHABET_STRING[i] == encodedContents[l]) {
+ ToIntArray(CHARACTER_ENCODINGS[i], widths);
pos += AppendPattern(result, pos, widths, 9, 1, e);
if (e != BCExceptionNO) {
FX_Free(result);
@@ -325,7 +241,7 @@ uint8_t* CBC_OnedCode39Writer::Encode(const CFX_ByteString& contents,
return nullptr;
}
}
- ToIntArray(CBC_OnedCode39Reader::CHARACTER_ENCODINGS[39], widths);
+ ToIntArray(CHARACTER_ENCODINGS[39], widths);
pos += AppendPattern(result, pos, widths, 9, 1, e);
if (e != BCExceptionNO) {
FX_Free(result);