diff options
author | Nico Weber <thakis@chromium.org> | 2015-08-04 13:00:21 -0700 |
---|---|---|
committer | Nico Weber <thakis@chromium.org> | 2015-08-04 13:00:21 -0700 |
commit | 9d8ec5a6e37e8d1d4d4edca9040de234e2d4728f (patch) | |
tree | c97037f398d714665aefccb6eb54d0969ad7030c /xfa/src/fxbarcode/datamatrix | |
parent | 780cee82236d1b3b0f9b01a22424e4b8ec9a6f12 (diff) | |
download | pdfium-9d8ec5a6e37e8d1d4d4edca9040de234e2d4728f.tar.xz |
XFA: clang-format all pdfium code.
No behavior change.
Generated by:
find . -name '*.cpp' -o -name '*.h' | \
grep -E -v 'third_party|thirdparties|lpng_v163|tiff_v403' | \
xargs ../../buildtools/mac/clang-format -i
Then manually merged https://codereview.chromium.org/1269223002/
See thread "tabs vs spaces" on pdfium@googlegroups.com for discussion.
BUG=none
Diffstat (limited to 'xfa/src/fxbarcode/datamatrix')
44 files changed, 3430 insertions, 3264 deletions
diff --git a/xfa/src/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp b/xfa/src/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp index df58f15212..3931206140 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp @@ -3,7 +3,7 @@ // found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-// Original code is licensed as follows: +// Original code is licensed as follows:
/*
* Copyright 2006-2007 Jeremias Maerki.
*
@@ -28,72 +28,72 @@ #include "BC_EncoderContext.h"
#include "BC_HighLevelEncoder.h"
#include "BC_ASCIIEncoder.h"
-CBC_ASCIIEncoder::CBC_ASCIIEncoder()
-{
+CBC_ASCIIEncoder::CBC_ASCIIEncoder() {}
+CBC_ASCIIEncoder::~CBC_ASCIIEncoder() {}
+int32_t CBC_ASCIIEncoder::getEncodingMode() {
+ return ASCII_ENCODATION;
}
-CBC_ASCIIEncoder::~CBC_ASCIIEncoder()
-{
-}
-int32_t CBC_ASCIIEncoder::getEncodingMode()
-{
- return ASCII_ENCODATION;
-}
-void CBC_ASCIIEncoder::Encode(CBC_EncoderContext &context, int32_t &e)
-{
- int32_t n = CBC_HighLevelEncoder::determineConsecutiveDigitCount(context.m_msg, context.m_pos);
- if (n >= 2) {
- FX_WCHAR code = encodeASCIIDigits(context.m_msg.GetAt(context.m_pos), context.m_msg.GetAt(context.m_pos + 1), e);
- if (e != BCExceptionNO) {
- return;
- }
- context.writeCodeword(code);
- context.m_pos += 2;
+void CBC_ASCIIEncoder::Encode(CBC_EncoderContext& context, int32_t& e) {
+ int32_t n = CBC_HighLevelEncoder::determineConsecutiveDigitCount(
+ context.m_msg, context.m_pos);
+ if (n >= 2) {
+ FX_WCHAR code =
+ encodeASCIIDigits(context.m_msg.GetAt(context.m_pos),
+ context.m_msg.GetAt(context.m_pos + 1), e);
+ if (e != BCExceptionNO) {
+ return;
+ }
+ context.writeCodeword(code);
+ context.m_pos += 2;
+ } else {
+ FX_WCHAR c = context.getCurrentChar();
+ int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(
+ context.m_msg, context.m_pos, getEncodingMode());
+ if (newMode != getEncodingMode()) {
+ switch (newMode) {
+ case BASE256_ENCODATION:
+ context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_BASE256);
+ context.signalEncoderChange(BASE256_ENCODATION);
+ return;
+ case C40_ENCODATION:
+ context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_C40);
+ context.signalEncoderChange(C40_ENCODATION);
+ return;
+ case X12_ENCODATION:
+ context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_ANSIX12);
+ context.signalEncoderChange(X12_ENCODATION);
+ break;
+ case TEXT_ENCODATION:
+ context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_TEXT);
+ context.signalEncoderChange(TEXT_ENCODATION);
+ break;
+ case EDIFACT_ENCODATION:
+ context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_EDIFACT);
+ context.signalEncoderChange(EDIFACT_ENCODATION);
+ break;
+ default:
+ e = BCExceptionIllegalStateIllegalMode;
+ return;
+ }
+ } else if (CBC_HighLevelEncoder::isExtendedASCII(c)) {
+ context.writeCodeword(CBC_HighLevelEncoder::UPPER_SHIFT);
+ context.writeCodeword((FX_WCHAR)(c - 128 + 1));
+ context.m_pos++;
} else {
- FX_WCHAR c = context.getCurrentChar();
- int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(context.m_msg, context.m_pos, getEncodingMode());
- if (newMode != getEncodingMode()) {
- switch (newMode) {
- case BASE256_ENCODATION:
- context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_BASE256);
- context.signalEncoderChange(BASE256_ENCODATION);
- return;
- case C40_ENCODATION:
- context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_C40);
- context.signalEncoderChange(C40_ENCODATION);
- return;
- case X12_ENCODATION:
- context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_ANSIX12);
- context.signalEncoderChange(X12_ENCODATION);
- break;
- case TEXT_ENCODATION:
- context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_TEXT);
- context.signalEncoderChange(TEXT_ENCODATION);
- break;
- case EDIFACT_ENCODATION:
- context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_EDIFACT);
- context.signalEncoderChange(EDIFACT_ENCODATION);
- break;
- default:
- e = BCExceptionIllegalStateIllegalMode;
- return;
- }
- } else if (CBC_HighLevelEncoder::isExtendedASCII(c)) {
- context.writeCodeword(CBC_HighLevelEncoder::UPPER_SHIFT);
- context.writeCodeword((FX_WCHAR) (c - 128 + 1));
- context.m_pos++;
- } else {
- context.writeCodeword((FX_WCHAR) (c + 1));
- context.m_pos++;
- }
+ context.writeCodeword((FX_WCHAR)(c + 1));
+ context.m_pos++;
}
+ }
}
-FX_WCHAR CBC_ASCIIEncoder::encodeASCIIDigits(FX_WCHAR digit1, FX_WCHAR digit2, int32_t &e)
-{
- if (CBC_HighLevelEncoder::isDigit(digit1) && CBC_HighLevelEncoder::isDigit(digit2)) {
- int32_t num = (digit1 - 48) * 10 + (digit2 - 48);
- FX_WCHAR a = (FX_WCHAR) (num + 130);
- return (FX_WCHAR) (num + 130);
- }
- e = BCExceptionIllegalArgumentNotGigits;
- return 0;
+FX_WCHAR CBC_ASCIIEncoder::encodeASCIIDigits(FX_WCHAR digit1,
+ FX_WCHAR digit2,
+ int32_t& e) {
+ if (CBC_HighLevelEncoder::isDigit(digit1) &&
+ CBC_HighLevelEncoder::isDigit(digit2)) {
+ int32_t num = (digit1 - 48) * 10 + (digit2 - 48);
+ FX_WCHAR a = (FX_WCHAR)(num + 130);
+ return (FX_WCHAR)(num + 130);
+ }
+ e = BCExceptionIllegalArgumentNotGigits;
+ return 0;
}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_ASCIIEncoder.h b/xfa/src/fxbarcode/datamatrix/BC_ASCIIEncoder.h index 3c05a41d7b..4afd3237ad 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_ASCIIEncoder.h +++ b/xfa/src/fxbarcode/datamatrix/BC_ASCIIEncoder.h @@ -9,14 +9,16 @@ class CBC_Encoder;
class CBC_EncoderContext;
class CBC_ASCIIEncoder;
-class CBC_ASCIIEncoder : public CBC_Encoder
-{
-public:
- CBC_ASCIIEncoder();
- virtual ~CBC_ASCIIEncoder();
- int32_t getEncodingMode();
- void Encode(CBC_EncoderContext &context, int32_t &e);
-private:
- static FX_WCHAR encodeASCIIDigits(FX_WCHAR digit1, FX_WCHAR digit2, int32_t &e);
+class CBC_ASCIIEncoder : public CBC_Encoder {
+ public:
+ CBC_ASCIIEncoder();
+ virtual ~CBC_ASCIIEncoder();
+ int32_t getEncodingMode();
+ void Encode(CBC_EncoderContext& context, int32_t& e);
+
+ private:
+ static FX_WCHAR encodeASCIIDigits(FX_WCHAR digit1,
+ FX_WCHAR digit2,
+ int32_t& e);
};
#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_Base256Encoder.cpp b/xfa/src/fxbarcode/datamatrix/BC_Base256Encoder.cpp index 7a68fcaef6..9df28e1b5b 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_Base256Encoder.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_Base256Encoder.cpp @@ -3,7 +3,7 @@ // found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-// Original code is licensed as follows: +// Original code is licensed as follows:
/*
* Copyright 2006-2007 Jeremias Maerki.
*
@@ -28,68 +28,65 @@ #include "BC_EncoderContext.h"
#include "BC_HighLevelEncoder.h"
#include "BC_Base256Encoder.h"
-CBC_Base256Encoder::CBC_Base256Encoder()
-{
+CBC_Base256Encoder::CBC_Base256Encoder() {}
+CBC_Base256Encoder::~CBC_Base256Encoder() {}
+int32_t CBC_Base256Encoder::getEncodingMode() {
+ return BASE256_ENCODATION;
}
-CBC_Base256Encoder::~CBC_Base256Encoder()
-{
-}
-int32_t CBC_Base256Encoder::getEncodingMode()
-{
- return BASE256_ENCODATION;
-}
-void CBC_Base256Encoder::Encode(CBC_EncoderContext &context, int32_t &e)
-{
- CFX_WideString buffer;
- buffer += (FX_WCHAR)'\0';
- while (context.hasMoreCharacters()) {
- FX_WCHAR c = context.getCurrentChar();
- buffer += c;
- context.m_pos++;
- int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(context.m_msg, context.m_pos, getEncodingMode());
- if (newMode != getEncodingMode()) {
- context.signalEncoderChange(newMode);
- break;
- }
+void CBC_Base256Encoder::Encode(CBC_EncoderContext& context, int32_t& e) {
+ CFX_WideString buffer;
+ buffer += (FX_WCHAR)'\0';
+ while (context.hasMoreCharacters()) {
+ FX_WCHAR c = context.getCurrentChar();
+ buffer += c;
+ context.m_pos++;
+ int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(
+ context.m_msg, context.m_pos, getEncodingMode());
+ if (newMode != getEncodingMode()) {
+ context.signalEncoderChange(newMode);
+ break;
}
- int32_t dataCount = buffer.GetLength() - 1;
- FX_CHAR buf[128];
+ }
+ int32_t dataCount = buffer.GetLength() - 1;
+ FX_CHAR buf[128];
#if defined(_FX_WINAPI_PARTITION_APP_)
- memset(buf, 0, sizeof(FX_CHAR) * 128);
- _itoa_s(dataCount, buf, 128, 10);
+ memset(buf, 0, sizeof(FX_CHAR) * 128);
+ _itoa_s(dataCount, buf, 128, 10);
#else
- FXSYS_itoa(dataCount, buf, 10);
+ FXSYS_itoa(dataCount, buf, 10);
#endif
- buffer.SetAt(0, FX_WCHAR(*buf) - '0');
- int32_t lengthFieldSize = 1;
- int32_t currentSize = context.getCodewordCount() + dataCount + lengthFieldSize;
- context.updateSymbolInfo(currentSize, e);
- if (e != BCExceptionNO) {
- return;
- }
- FX_BOOL mustPad = (context.m_symbolInfo->m_dataCapacity - currentSize) > 0;
- if (context.hasMoreCharacters() || mustPad) {
- if (dataCount <= 249) {
- buffer.SetAt(0, (FX_WCHAR) dataCount);
- } else if (dataCount > 249 && dataCount <= 1555) {
- buffer.SetAt(0, (FX_WCHAR) ((dataCount / 250) + 249));
- buffer.Insert(1, (FX_WCHAR) (dataCount % 250));
- } else {
- e = BCExceptionIllegalStateMessageLengthInvalid;
- return;
- }
- }
- for (int32_t i = 0, c = buffer.GetLength(); i < c; i++) {
- context.writeCodeword(randomize255State(buffer.GetAt(i), context.getCodewordCount() + 1));
- }
-}
-FX_WCHAR CBC_Base256Encoder::randomize255State(FX_WCHAR ch, int32_t codewordPosition)
-{
- int32_t pseudoRandom = ((149 * codewordPosition) % 255) + 1;
- int32_t tempVariable = ch + pseudoRandom;
- if (tempVariable <= 255) {
- return (FX_WCHAR) tempVariable;
+ buffer.SetAt(0, FX_WCHAR(*buf) - '0');
+ int32_t lengthFieldSize = 1;
+ int32_t currentSize =
+ context.getCodewordCount() + dataCount + lengthFieldSize;
+ context.updateSymbolInfo(currentSize, e);
+ if (e != BCExceptionNO) {
+ return;
+ }
+ FX_BOOL mustPad = (context.m_symbolInfo->m_dataCapacity - currentSize) > 0;
+ if (context.hasMoreCharacters() || mustPad) {
+ if (dataCount <= 249) {
+ buffer.SetAt(0, (FX_WCHAR)dataCount);
+ } else if (dataCount > 249 && dataCount <= 1555) {
+ buffer.SetAt(0, (FX_WCHAR)((dataCount / 250) + 249));
+ buffer.Insert(1, (FX_WCHAR)(dataCount % 250));
} else {
- return (FX_WCHAR) (tempVariable - 256);
+ e = BCExceptionIllegalStateMessageLengthInvalid;
+ return;
}
+ }
+ for (int32_t i = 0, c = buffer.GetLength(); i < c; i++) {
+ context.writeCodeword(
+ randomize255State(buffer.GetAt(i), context.getCodewordCount() + 1));
+ }
+}
+FX_WCHAR CBC_Base256Encoder::randomize255State(FX_WCHAR ch,
+ int32_t codewordPosition) {
+ int32_t pseudoRandom = ((149 * codewordPosition) % 255) + 1;
+ int32_t tempVariable = ch + pseudoRandom;
+ if (tempVariable <= 255) {
+ return (FX_WCHAR)tempVariable;
+ } else {
+ return (FX_WCHAR)(tempVariable - 256);
+ }
}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_Base256Encoder.h b/xfa/src/fxbarcode/datamatrix/BC_Base256Encoder.h index 61e6c8085f..734242af45 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_Base256Encoder.h +++ b/xfa/src/fxbarcode/datamatrix/BC_Base256Encoder.h @@ -8,14 +8,14 @@ #define _BC_BASE256ENCODER_H_
class CBC_Encoder;
class CBC_Base256Encoder;
-class CBC_Base256Encoder : public CBC_Encoder
-{
-public:
- CBC_Base256Encoder();
- virtual ~CBC_Base256Encoder();
- int32_t getEncodingMode();
- void Encode(CBC_EncoderContext &context, int32_t &e);
-private:
- static FX_WCHAR randomize255State(FX_WCHAR ch, int32_t codewordPosition);
+class CBC_Base256Encoder : public CBC_Encoder {
+ public:
+ CBC_Base256Encoder();
+ virtual ~CBC_Base256Encoder();
+ int32_t getEncodingMode();
+ void Encode(CBC_EncoderContext& context, int32_t& e);
+
+ private:
+ static FX_WCHAR randomize255State(FX_WCHAR ch, int32_t codewordPosition);
};
#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_C40Encoder.cpp b/xfa/src/fxbarcode/datamatrix/BC_C40Encoder.cpp index 0afd018558..7e58d8ef06 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_C40Encoder.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_C40Encoder.cpp @@ -29,170 +29,170 @@ #include "BC_EncoderContext.h"
#include "BC_HighLevelEncoder.h"
#include "BC_C40Encoder.h"
-CBC_C40Encoder::CBC_C40Encoder()
-{
+CBC_C40Encoder::CBC_C40Encoder() {}
+CBC_C40Encoder::~CBC_C40Encoder() {}
+int32_t CBC_C40Encoder::getEncodingMode() {
+ return C40_ENCODATION;
}
-CBC_C40Encoder::~CBC_C40Encoder()
-{
-}
-int32_t CBC_C40Encoder::getEncodingMode()
-{
- return C40_ENCODATION;
-}
-void CBC_C40Encoder::Encode(CBC_EncoderContext &context, int32_t &e)
-{
- CFX_WideString buffer;
- while (context.hasMoreCharacters()) {
- FX_WCHAR c = context.getCurrentChar();
- context.m_pos++;
- int32_t lastCharSize = encodeChar(c, buffer, e);
- if (e != BCExceptionNO) {
- return;
- }
- int32_t unwritten = (buffer.GetLength() / 3) * 2;
- int32_t curCodewordCount = context.getCodewordCount() + unwritten;
- context.updateSymbolInfo(curCodewordCount, e);
- if (e != BCExceptionNO) {
- return;
- }
- int32_t available = context.m_symbolInfo->m_dataCapacity - curCodewordCount;
- if (!context.hasMoreCharacters()) {
- CFX_WideString removed;
- if ((buffer.GetLength() % 3) == 2) {
- if (available < 2 || available > 2) {
- lastCharSize = backtrackOneCharacter(context, buffer, removed, lastCharSize, e);
- if (e != BCExceptionNO) {
- return;
- }
- }
- }
- while ((buffer.GetLength() % 3) == 1
- && ((lastCharSize <= 3 && available != 1) || lastCharSize > 3)) {
- lastCharSize = backtrackOneCharacter(context, buffer, removed, lastCharSize, e);
- if (e != BCExceptionNO) {
- return;
- }
- }
- break;
- }
- int32_t count = buffer.GetLength();
- if ((count % 3) == 0) {
- int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(context.m_msg, context.m_pos, getEncodingMode());
- if (newMode != getEncodingMode()) {
- context.signalEncoderChange(newMode);
- break;
- }
- }
+void CBC_C40Encoder::Encode(CBC_EncoderContext& context, int32_t& e) {
+ CFX_WideString buffer;
+ while (context.hasMoreCharacters()) {
+ FX_WCHAR c = context.getCurrentChar();
+ context.m_pos++;
+ int32_t lastCharSize = encodeChar(c, buffer, e);
+ if (e != BCExceptionNO) {
+ return;
}
- handleEOD(context, buffer, e);
-}
-void CBC_C40Encoder::writeNextTriplet(CBC_EncoderContext &context, CFX_WideString &buffer)
-{
- context.writeCodewords(encodeToCodewords(buffer, 0));
- buffer.Delete(0, 3);
-}
-void CBC_C40Encoder::handleEOD(CBC_EncoderContext &context, CFX_WideString &buffer, int32_t &e)
-{
int32_t unwritten = (buffer.GetLength() / 3) * 2;
- int32_t rest = buffer.GetLength() % 3;
int32_t curCodewordCount = context.getCodewordCount() + unwritten;
context.updateSymbolInfo(curCodewordCount, e);
if (e != BCExceptionNO) {
- return;
+ return;
}
int32_t available = context.m_symbolInfo->m_dataCapacity - curCodewordCount;
- if (rest == 2) {
- buffer += (FX_WCHAR)'\0';
- while (buffer.GetLength() >= 3) {
- writeNextTriplet(context, buffer);
- }
- if (context.hasMoreCharacters()) {
- context.writeCodeword(CBC_HighLevelEncoder::C40_UNLATCH);
- }
- } else if (available == 1 && rest == 1) {
- while (buffer.GetLength() >= 3) {
- writeNextTriplet(context, buffer);
- }
- if (context.hasMoreCharacters()) {
- context.writeCodeword(CBC_HighLevelEncoder::C40_UNLATCH);
- }
- context.m_pos--;
- } else if (rest == 0) {
- while (buffer.GetLength() >= 3) {
- writeNextTriplet(context, buffer);
+ if (!context.hasMoreCharacters()) {
+ CFX_WideString removed;
+ if ((buffer.GetLength() % 3) == 2) {
+ if (available < 2 || available > 2) {
+ lastCharSize =
+ backtrackOneCharacter(context, buffer, removed, lastCharSize, e);
+ if (e != BCExceptionNO) {
+ return;
+ }
}
- if (available > 0 || context.hasMoreCharacters()) {
- context.writeCodeword(CBC_HighLevelEncoder::C40_UNLATCH);
+ }
+ while ((buffer.GetLength() % 3) == 1 &&
+ ((lastCharSize <= 3 && available != 1) || lastCharSize > 3)) {
+ lastCharSize =
+ backtrackOneCharacter(context, buffer, removed, lastCharSize, e);
+ if (e != BCExceptionNO) {
+ return;
}
- } else {
- e = BCExceptionIllegalStateUnexpectedCase;
- return;
+ }
+ break;
}
- context.signalEncoderChange(ASCII_ENCODATION);
-}
-int32_t CBC_C40Encoder::encodeChar(FX_WCHAR c, CFX_WideString &sb, int32_t &e)
-{
- if (c == ' ') {
- sb += (FX_WCHAR)'\3';
- return 1;
- } else if ((c >= '0') && (c <= '9')) {
- sb += (FX_WCHAR)(c - 48 + 4);
- return 1;
- } else if ((c >= 'A') && (c <= 'Z')) {
- sb += (FX_WCHAR)(c - 65 + 14);
- return 1;
- } else if ((c >= '\0') && (c <= 0x1f)) {
- sb += (FX_WCHAR)'\0';
- sb += c;
- return 2;
- } else if ((c >= '!') && (c <= '/')) {
- sb += (FX_WCHAR)'\1';
- sb += (FX_WCHAR)(c - 33);
- return 2;
- } else if ((c >= ':') && (c <= '@')) {
- sb += (FX_WCHAR)'\1';
- sb += (FX_WCHAR)(c - 58 + 15);
- return 2;
- } else if ((c >= '[') && (c <= '_')) {
- sb += (FX_WCHAR)'\1';
- sb += (FX_WCHAR)(c - 91 + 22);
- return 2;
- } else if ((c >= 60) && (c <= 0x7f)) {
- sb += (FX_WCHAR)'\2';
- sb += (FX_WCHAR)(c - 96);
- return 2;
- } else if (c >= 80) {
- sb += (FX_WCHAR)'\1';
- sb += (FX_WCHAR)0x001e;
- int32_t len = 2;
- len += encodeChar((c - 128), sb, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, 0);
- return len;
- } else {
- e = BCExceptionIllegalArgument;
- return 0;
+ int32_t count = buffer.GetLength();
+ if ((count % 3) == 0) {
+ int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(
+ context.m_msg, context.m_pos, getEncodingMode());
+ if (newMode != getEncodingMode()) {
+ context.signalEncoderChange(newMode);
+ break;
+ }
}
+ }
+ handleEOD(context, buffer, e);
}
-int32_t CBC_C40Encoder::backtrackOneCharacter(CBC_EncoderContext &context, CFX_WideString &buffer, CFX_WideString &removed, int32_t lastCharSize, int32_t &e)
-{
- int32_t count = buffer.GetLength();
- buffer.Delete(count - lastCharSize, count);
+void CBC_C40Encoder::writeNextTriplet(CBC_EncoderContext& context,
+ CFX_WideString& buffer) {
+ context.writeCodewords(encodeToCodewords(buffer, 0));
+ buffer.Delete(0, 3);
+}
+void CBC_C40Encoder::handleEOD(CBC_EncoderContext& context,
+ CFX_WideString& buffer,
+ int32_t& e) {
+ int32_t unwritten = (buffer.GetLength() / 3) * 2;
+ int32_t rest = buffer.GetLength() % 3;
+ int32_t curCodewordCount = context.getCodewordCount() + unwritten;
+ context.updateSymbolInfo(curCodewordCount, e);
+ if (e != BCExceptionNO) {
+ return;
+ }
+ int32_t available = context.m_symbolInfo->m_dataCapacity - curCodewordCount;
+ if (rest == 2) {
+ buffer += (FX_WCHAR)'\0';
+ while (buffer.GetLength() >= 3) {
+ writeNextTriplet(context, buffer);
+ }
+ if (context.hasMoreCharacters()) {
+ context.writeCodeword(CBC_HighLevelEncoder::C40_UNLATCH);
+ }
+ } else if (available == 1 && rest == 1) {
+ while (buffer.GetLength() >= 3) {
+ writeNextTriplet(context, buffer);
+ }
+ if (context.hasMoreCharacters()) {
+ context.writeCodeword(CBC_HighLevelEncoder::C40_UNLATCH);
+ }
context.m_pos--;
- FX_WCHAR c = context.getCurrentChar();
- lastCharSize = encodeChar(c, removed, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, -1);
- context.resetSymbolInfo();
- return lastCharSize;
+ } else if (rest == 0) {
+ while (buffer.GetLength() >= 3) {
+ writeNextTriplet(context, buffer);
+ }
+ if (available > 0 || context.hasMoreCharacters()) {
+ context.writeCodeword(CBC_HighLevelEncoder::C40_UNLATCH);
+ }
+ } else {
+ e = BCExceptionIllegalStateUnexpectedCase;
+ return;
+ }
+ context.signalEncoderChange(ASCII_ENCODATION);
+}
+int32_t CBC_C40Encoder::encodeChar(FX_WCHAR c, CFX_WideString& sb, int32_t& e) {
+ if (c == ' ') {
+ sb += (FX_WCHAR)'\3';
+ return 1;
+ } else if ((c >= '0') && (c <= '9')) {
+ sb += (FX_WCHAR)(c - 48 + 4);
+ return 1;
+ } else if ((c >= 'A') && (c <= 'Z')) {
+ sb += (FX_WCHAR)(c - 65 + 14);
+ return 1;
+ } else if ((c >= '\0') && (c <= 0x1f)) {
+ sb += (FX_WCHAR)'\0';
+ sb += c;
+ return 2;
+ } else if ((c >= '!') && (c <= '/')) {
+ sb += (FX_WCHAR)'\1';
+ sb += (FX_WCHAR)(c - 33);
+ return 2;
+ } else if ((c >= ':') && (c <= '@')) {
+ sb += (FX_WCHAR)'\1';
+ sb += (FX_WCHAR)(c - 58 + 15);
+ return 2;
+ } else if ((c >= '[') && (c <= '_')) {
+ sb += (FX_WCHAR)'\1';
+ sb += (FX_WCHAR)(c - 91 + 22);
+ return 2;
+ } else if ((c >= 60) && (c <= 0x7f)) {
+ sb += (FX_WCHAR)'\2';
+ sb += (FX_WCHAR)(c - 96);
+ return 2;
+ } else if (c >= 80) {
+ sb += (FX_WCHAR)'\1';
+ sb += (FX_WCHAR)0x001e;
+ int32_t len = 2;
+ len += encodeChar((c - 128), sb, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, 0);
+ return len;
+ } else {
+ e = BCExceptionIllegalArgument;
+ return 0;
+ }
+}
+int32_t CBC_C40Encoder::backtrackOneCharacter(CBC_EncoderContext& context,
+ CFX_WideString& buffer,
+ CFX_WideString& removed,
+ int32_t lastCharSize,
+ int32_t& e) {
+ int32_t count = buffer.GetLength();
+ buffer.Delete(count - lastCharSize, count);
+ context.m_pos--;
+ FX_WCHAR c = context.getCurrentChar();
+ lastCharSize = encodeChar(c, removed, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, -1);
+ context.resetSymbolInfo();
+ return lastCharSize;
}
-CFX_WideString CBC_C40Encoder::encodeToCodewords(CFX_WideString sb, int32_t startPos)
-{
- FX_WCHAR c1 = sb.GetAt(startPos);
- FX_WCHAR c2 = sb.GetAt(startPos + 1);
- FX_WCHAR c3 = sb.GetAt(startPos + 2);
- int32_t v = (1600 * c1) + (40 * c2) + c3 + 1;
- FX_WCHAR cw1 = (FX_WCHAR) (v / 256);
- FX_WCHAR cw2 = (FX_WCHAR) (v % 256);
- CFX_WideString b1(cw1);
- CFX_WideString b2(cw2);
- return b1 + b2;
+CFX_WideString CBC_C40Encoder::encodeToCodewords(CFX_WideString sb,
+ int32_t startPos) {
+ FX_WCHAR c1 = sb.GetAt(startPos);
+ FX_WCHAR c2 = sb.GetAt(startPos + 1);
+ FX_WCHAR c3 = sb.GetAt(startPos + 2);
+ int32_t v = (1600 * c1) + (40 * c2) + c3 + 1;
+ FX_WCHAR cw1 = (FX_WCHAR)(v / 256);
+ FX_WCHAR cw2 = (FX_WCHAR)(v % 256);
+ CFX_WideString b1(cw1);
+ CFX_WideString b2(cw2);
+ return b1 + b2;
}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_C40Encoder.h b/xfa/src/fxbarcode/datamatrix/BC_C40Encoder.h index 2ab7f4e29b..da980961f3 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_C40Encoder.h +++ b/xfa/src/fxbarcode/datamatrix/BC_C40Encoder.h @@ -7,18 +7,25 @@ #ifndef _BC_C40ENCODER_H_
#define _BC_C40ENCODER_H_
class CBC_C40Encoder;
-class CBC_C40Encoder : public CBC_Encoder
-{
-public:
- CBC_C40Encoder();
- virtual ~CBC_C40Encoder();
- virtual int32_t getEncodingMode();
- virtual void Encode(CBC_EncoderContext &context, int32_t &e);
- static void writeNextTriplet(CBC_EncoderContext &context, CFX_WideString &buffer);
- virtual void handleEOD(CBC_EncoderContext &context, CFX_WideString &buffer, int32_t &e);
- virtual int32_t encodeChar(FX_WCHAR c, CFX_WideString &sb, int32_t &e);
-private:
- int32_t backtrackOneCharacter(CBC_EncoderContext &context, CFX_WideString &buffer, CFX_WideString &removed, int32_t lastCharSize, int32_t &e);
- static CFX_WideString encodeToCodewords(CFX_WideString sb, int32_t startPos);
+class CBC_C40Encoder : public CBC_Encoder {
+ public:
+ CBC_C40Encoder();
+ virtual ~CBC_C40Encoder();
+ virtual int32_t getEncodingMode();
+ virtual void Encode(CBC_EncoderContext& context, int32_t& e);
+ static void writeNextTriplet(CBC_EncoderContext& context,
+ CFX_WideString& buffer);
+ virtual void handleEOD(CBC_EncoderContext& context,
+ CFX_WideString& buffer,
+ int32_t& e);
+ virtual int32_t encodeChar(FX_WCHAR c, CFX_WideString& sb, int32_t& e);
+
+ private:
+ int32_t backtrackOneCharacter(CBC_EncoderContext& context,
+ CFX_WideString& buffer,
+ CFX_WideString& removed,
+ int32_t lastCharSize,
+ int32_t& e);
+ static CFX_WideString encodeToCodewords(CFX_WideString sb, int32_t startPos);
};
#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.cpp b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.cpp index 4fb82f1034..16275a0c55 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.cpp @@ -24,343 +24,357 @@ #include "../common/BC_CommonBitMatrix.h"
#include "BC_DataMatrixVersion.h"
#include "BC_DataMatrixBitMatrixParser.h"
-CBC_DataMatrixBitMatrixParser::CBC_DataMatrixBitMatrixParser()
-{
- m_mappingBitMatrix = NULL;
- m_version = NULL;
- m_readMappingMatrix = NULL;
+CBC_DataMatrixBitMatrixParser::CBC_DataMatrixBitMatrixParser() {
+ m_mappingBitMatrix = NULL;
+ m_version = NULL;
+ m_readMappingMatrix = NULL;
}
-void CBC_DataMatrixBitMatrixParser::Init(CBC_CommonBitMatrix *bitMatrix, int32_t &e)
-{
- int32_t dimension = bitMatrix->GetHeight();
- if (dimension < 8 || dimension > 144 || (dimension & 0x01) != 0) {
- e = BCExceptionFormatException;
- return;
- }
- m_version = ReadVersion(bitMatrix, e);
- BC_EXCEPTION_CHECK_ReturnVoid(e);
- m_mappingBitMatrix = ExtractDataRegion(bitMatrix, e);
- BC_EXCEPTION_CHECK_ReturnVoid(e);
- m_readMappingMatrix = FX_NEW CBC_CommonBitMatrix();
- m_readMappingMatrix->Init(m_mappingBitMatrix->GetWidth(), m_mappingBitMatrix->GetHeight());
+void CBC_DataMatrixBitMatrixParser::Init(CBC_CommonBitMatrix* bitMatrix,
+ int32_t& e) {
+ int32_t dimension = bitMatrix->GetHeight();
+ if (dimension < 8 || dimension > 144 || (dimension & 0x01) != 0) {
+ e = BCExceptionFormatException;
+ return;
+ }
+ m_version = ReadVersion(bitMatrix, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ m_mappingBitMatrix = ExtractDataRegion(bitMatrix, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ m_readMappingMatrix = FX_NEW CBC_CommonBitMatrix();
+ m_readMappingMatrix->Init(m_mappingBitMatrix->GetWidth(),
+ m_mappingBitMatrix->GetHeight());
}
-CBC_DataMatrixBitMatrixParser::~CBC_DataMatrixBitMatrixParser()
-{
- if(m_mappingBitMatrix != NULL) {
- delete m_mappingBitMatrix;
- }
- m_mappingBitMatrix = NULL;
- if(m_readMappingMatrix != NULL) {
- delete m_readMappingMatrix;
- }
- m_readMappingMatrix = NULL;
+CBC_DataMatrixBitMatrixParser::~CBC_DataMatrixBitMatrixParser() {
+ if (m_mappingBitMatrix != NULL) {
+ delete m_mappingBitMatrix;
+ }
+ m_mappingBitMatrix = NULL;
+ if (m_readMappingMatrix != NULL) {
+ delete m_readMappingMatrix;
+ }
+ m_readMappingMatrix = NULL;
}
-CBC_DataMatrixVersion *CBC_DataMatrixBitMatrixParser::GetVersion()
-{
- return m_version;
+CBC_DataMatrixVersion* CBC_DataMatrixBitMatrixParser::GetVersion() {
+ return m_version;
}
-CBC_DataMatrixVersion *CBC_DataMatrixBitMatrixParser::ReadVersion(CBC_CommonBitMatrix *bitMatrix, int32_t &e)
-{
- int32_t rows = bitMatrix->GetHeight();
- int32_t columns = bitMatrix->GetWidth();
- CBC_DataMatrixVersion *temp = CBC_DataMatrixVersion::GetVersionForDimensions(rows, columns, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- return temp;
+CBC_DataMatrixVersion* CBC_DataMatrixBitMatrixParser::ReadVersion(
+ CBC_CommonBitMatrix* bitMatrix,
+ int32_t& e) {
+ int32_t rows = bitMatrix->GetHeight();
+ int32_t columns = bitMatrix->GetWidth();
+ CBC_DataMatrixVersion* temp =
+ CBC_DataMatrixVersion::GetVersionForDimensions(rows, columns, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return temp;
}
-CFX_ByteArray *CBC_DataMatrixBitMatrixParser::ReadCodewords(int32_t &e)
-{
- CBC_AutoPtr<CFX_ByteArray> result(FX_NEW CFX_ByteArray());
- result->SetSize(m_version->GetTotalCodewords());
- int32_t resultOffset = 0;
- int32_t row = 4;
- int32_t column = 0;
- int32_t numRows = m_mappingBitMatrix->GetHeight();
- int32_t numColumns = m_mappingBitMatrix->GetWidth();
- FX_BOOL corner1Read = FALSE;
- FX_BOOL corner2Read = FALSE;
- FX_BOOL corner3Read = FALSE;
- FX_BOOL corner4Read = FALSE;
- do {
- if ((row == numRows) && (column == 0) && !corner1Read) {
- (*result)[resultOffset++] = (uint8_t) ReadCorner1(numRows, numColumns);
- row -= 2;
- column += 2;
- corner1Read = TRUE;
- } else if ((row == numRows - 2) && (column == 0) && ((numColumns & 0x03) != 0) && !corner2Read) {
- (*result)[resultOffset++] = (uint8_t) ReadCorner2(numRows, numColumns);
- row -= 2;
- column += 2;
- corner2Read = TRUE;
- } else if ((row == numRows + 4) && (column == 2) && ((numColumns & 0x07) == 0) && !corner3Read) {
- (*result)[resultOffset++] = (uint8_t) ReadCorner3(numRows, numColumns);
- row -= 2;
- column += 2;
- corner3Read = TRUE;
- } else if ((row == numRows - 2) && (column == 0) && ((numColumns & 0x07) == 4) && !corner4Read) {
- (*result)[resultOffset++] = (uint8_t) ReadCorner4(numRows, numColumns);
- row -= 2;
- column += 2;
- corner4Read = TRUE;
- } else {
- do {
- if ((row < numRows) && (column >= 0) && !m_readMappingMatrix->Get(column, row)) {
- if (resultOffset < (*result).GetSize() ) {
- (*result)[resultOffset++] = (uint8_t) ReadUtah(row, column, numRows, numColumns);
- }
- }
- row -= 2;
- column += 2;
- } while ((row >= 0) && (column < numColumns));
- row += 1;
- column += 3;
- do {
- if ((row >= 0) && (column < numColumns) && !m_readMappingMatrix->Get(column, row)) {
- if (resultOffset < (*result).GetSize() ) {
- (*result)[resultOffset++] = (uint8_t) ReadUtah(row, column, numRows, numColumns);
- }
- }
- row += 2;
- column -= 2;
- } while ((row < numRows) && (column >= 0));
- row += 3;
- column += 1;
+CFX_ByteArray* CBC_DataMatrixBitMatrixParser::ReadCodewords(int32_t& e) {
+ CBC_AutoPtr<CFX_ByteArray> result(FX_NEW CFX_ByteArray());
+ result->SetSize(m_version->GetTotalCodewords());
+ int32_t resultOffset = 0;
+ int32_t row = 4;
+ int32_t column = 0;
+ int32_t numRows = m_mappingBitMatrix->GetHeight();
+ int32_t numColumns = m_mappingBitMatrix->GetWidth();
+ FX_BOOL corner1Read = FALSE;
+ FX_BOOL corner2Read = FALSE;
+ FX_BOOL corner3Read = FALSE;
+ FX_BOOL corner4Read = FALSE;
+ do {
+ if ((row == numRows) && (column == 0) && !corner1Read) {
+ (*result)[resultOffset++] = (uint8_t)ReadCorner1(numRows, numColumns);
+ row -= 2;
+ column += 2;
+ corner1Read = TRUE;
+ } else if ((row == numRows - 2) && (column == 0) &&
+ ((numColumns & 0x03) != 0) && !corner2Read) {
+ (*result)[resultOffset++] = (uint8_t)ReadCorner2(numRows, numColumns);
+ row -= 2;
+ column += 2;
+ corner2Read = TRUE;
+ } else if ((row == numRows + 4) && (column == 2) &&
+ ((numColumns & 0x07) == 0) && !corner3Read) {
+ (*result)[resultOffset++] = (uint8_t)ReadCorner3(numRows, numColumns);
+ row -= 2;
+ column += 2;
+ corner3Read = TRUE;
+ } else if ((row == numRows - 2) && (column == 0) &&
+ ((numColumns & 0x07) == 4) && !corner4Read) {
+ (*result)[resultOffset++] = (uint8_t)ReadCorner4(numRows, numColumns);
+ row -= 2;
+ column += 2;
+ corner4Read = TRUE;
+ } else {
+ do {
+ if ((row < numRows) && (column >= 0) &&
+ !m_readMappingMatrix->Get(column, row)) {
+ if (resultOffset < (*result).GetSize()) {
+ (*result)[resultOffset++] =
+ (uint8_t)ReadUtah(row, column, numRows, numColumns);
+ }
}
- } while ((row < numRows) || (column < numColumns));
- if (resultOffset != m_version->GetTotalCodewords()) {
- e = BCExceptionFormatException;
- return NULL;
- }
- return result.release();
+ row -= 2;
+ column += 2;
+ } while ((row >= 0) && (column < numColumns));
+ row += 1;
+ column += 3;
+ do {
+ if ((row >= 0) && (column < numColumns) &&
+ !m_readMappingMatrix->Get(column, row)) {
+ if (resultOffset < (*result).GetSize()) {
+ (*result)[resultOffset++] =
+ (uint8_t)ReadUtah(row, column, numRows, numColumns);
+ }
+ }
+ row += 2;
+ column -= 2;
+ } while ((row < numRows) && (column >= 0));
+ row += 3;
+ column += 1;
+ }
+ } while ((row < numRows) || (column < numColumns));
+ if (resultOffset != m_version->GetTotalCodewords()) {
+ e = BCExceptionFormatException;
+ return NULL;
+ }
+ return result.release();
}
-FX_BOOL CBC_DataMatrixBitMatrixParser::ReadModule(int32_t row, int32_t column, int32_t numRows, int32_t numColumns)
-{
- if (row < 0) {
- row += numRows;
- column += 4 - ((numRows + 4) & 0x07);
- }
- if (column < 0) {
- column += numColumns;
- row += 4 - ((numColumns + 4) & 0x07);
- }
- m_readMappingMatrix->Set(column, row);
- return m_mappingBitMatrix->Get(column, row);
+FX_BOOL CBC_DataMatrixBitMatrixParser::ReadModule(int32_t row,
+ int32_t column,
+ int32_t numRows,
+ int32_t numColumns) {
+ if (row < 0) {
+ row += numRows;
+ column += 4 - ((numRows + 4) & 0x07);
+ }
+ if (column < 0) {
+ column += numColumns;
+ row += 4 - ((numColumns + 4) & 0x07);
+ }
+ m_readMappingMatrix->Set(column, row);
+ return m_mappingBitMatrix->Get(column, row);
}
-int32_t CBC_DataMatrixBitMatrixParser::ReadUtah(int32_t row, int32_t column, int32_t numRows, int32_t numColumns)
-{
- int32_t currentByte = 0;
- if (ReadModule(row - 2, column - 2, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(row - 2, column - 1, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(row - 1, column - 2, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(row - 1, column - 1, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(row - 1, column, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(row, column - 2, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(row, column - 1, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(row, column, numRows, numColumns)) {
- currentByte |= 1;
- }
- return currentByte;
+int32_t CBC_DataMatrixBitMatrixParser::ReadUtah(int32_t row,
+ int32_t column,
+ int32_t numRows,
+ int32_t numColumns) {
+ int32_t currentByte = 0;
+ if (ReadModule(row - 2, column - 2, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(row - 2, column - 1, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(row - 1, column - 2, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(row - 1, column - 1, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(row - 1, column, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(row, column - 2, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(row, column - 1, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(row, column, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ return currentByte;
}
-int32_t CBC_DataMatrixBitMatrixParser::ReadCorner1(int32_t numRows, int32_t numColumns)
-{
- int32_t currentByte = 0;
- if (ReadModule(numRows - 1, 0, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(numRows - 1, 1, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(numRows - 1, 2, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(0, numColumns - 2, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(0, numColumns - 1, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(1, numColumns - 1, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(2, numColumns - 1, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(3, numColumns - 1, numRows, numColumns)) {
- currentByte |= 1;
- }
- return currentByte;
+int32_t CBC_DataMatrixBitMatrixParser::ReadCorner1(int32_t numRows,
+ int32_t numColumns) {
+ int32_t currentByte = 0;
+ if (ReadModule(numRows - 1, 0, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(numRows - 1, 1, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(numRows - 1, 2, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(0, numColumns - 2, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(0, numColumns - 1, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(1, numColumns - 1, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(2, numColumns - 1, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(3, numColumns - 1, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ return currentByte;
}
-int32_t CBC_DataMatrixBitMatrixParser::ReadCorner2(int32_t numRows, int32_t numColumns)
-{
- int32_t currentByte = 0;
- if (ReadModule(numRows - 3, 0, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(numRows - 2, 0, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(numRows - 1, 0, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(0, numColumns - 4, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(0, numColumns - 3, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(0, numColumns - 2, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(0, numColumns - 1, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(1, numColumns - 1, numRows, numColumns)) {
- currentByte |= 1;
- }
- return currentByte;
+int32_t CBC_DataMatrixBitMatrixParser::ReadCorner2(int32_t numRows,
+ int32_t numColumns) {
+ int32_t currentByte = 0;
+ if (ReadModule(numRows - 3, 0, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(numRows - 2, 0, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(numRows - 1, 0, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(0, numColumns - 4, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(0, numColumns - 3, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(0, numColumns - 2, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(0, numColumns - 1, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(1, numColumns - 1, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ return currentByte;
}
-int32_t CBC_DataMatrixBitMatrixParser::ReadCorner3(int32_t numRows, int32_t numColumns)
-{
- int32_t currentByte = 0;
- if (ReadModule(numRows - 1, 0, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(numRows - 1, numColumns - 1, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(0, numColumns - 3, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(0, numColumns - 2, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(0, numColumns - 1, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(1, numColumns - 3, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(1, numColumns - 2, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(1, numColumns - 1, numRows, numColumns)) {
- currentByte |= 1;
- }
- return currentByte;
+int32_t CBC_DataMatrixBitMatrixParser::ReadCorner3(int32_t numRows,
+ int32_t numColumns) {
+ int32_t currentByte = 0;
+ if (ReadModule(numRows - 1, 0, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(numRows - 1, numColumns - 1, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(0, numColumns - 3, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(0, numColumns - 2, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(0, numColumns - 1, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(1, numColumns - 3, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(1, numColumns - 2, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(1, numColumns - 1, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ return currentByte;
}
-int32_t CBC_DataMatrixBitMatrixParser::ReadCorner4(int32_t numRows, int32_t numColumns)
-{
- int32_t currentByte = 0;
- if (ReadModule(numRows - 3, 0, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(numRows - 2, 0, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(numRows - 1, 0, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(0, numColumns - 2, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(0, numColumns - 1, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(1, numColumns - 1, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(2, numColumns - 1, numRows, numColumns)) {
- currentByte |= 1;
- }
- currentByte <<= 1;
- if (ReadModule(3, numColumns - 1, numRows, numColumns)) {
- currentByte |= 1;
- }
- return currentByte;
+int32_t CBC_DataMatrixBitMatrixParser::ReadCorner4(int32_t numRows,
+ int32_t numColumns) {
+ int32_t currentByte = 0;
+ if (ReadModule(numRows - 3, 0, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(numRows - 2, 0, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(numRows - 1, 0, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(0, numColumns - 2, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(0, numColumns - 1, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(1, numColumns - 1, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(2, numColumns - 1, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ currentByte <<= 1;
+ if (ReadModule(3, numColumns - 1, numRows, numColumns)) {
+ currentByte |= 1;
+ }
+ return currentByte;
}
-CBC_CommonBitMatrix *CBC_DataMatrixBitMatrixParser::ExtractDataRegion(CBC_CommonBitMatrix *bitMatrix , int32_t &e)
-{
- int32_t symbolSizeRows = m_version->GetSymbolSizeRows();
- int32_t symbolSizeColumns = m_version->GetSymbolSizeColumns();
- if (bitMatrix->GetHeight() != symbolSizeRows) {
- e = BCExceptionCanNotCallGetDimensionOnNonSquareMatrix;
- return NULL;
- }
- int32_t dataRegionSizeRows = m_version->GetDataRegionSizeRows();
- int32_t dataRegionSizeColumns = m_version->GetDataRegionSizeColumns();
- int32_t numDataRegionsRow = symbolSizeRows / dataRegionSizeRows;
- int32_t numDataRegionsColumn = symbolSizeColumns / dataRegionSizeColumns;
- int32_t sizeDataRegionRow = numDataRegionsRow * dataRegionSizeRows;
- int32_t sizeDataRegionColumn = numDataRegionsColumn * dataRegionSizeColumns;
- CBC_CommonBitMatrix *bitMatrixWithoutAlignment = FX_NEW CBC_CommonBitMatrix();
- bitMatrixWithoutAlignment->Init(sizeDataRegionColumn, sizeDataRegionRow);
- int32_t dataRegionRow;
- for (dataRegionRow = 0; dataRegionRow < numDataRegionsRow; ++dataRegionRow) {
- int32_t dataRegionRowOffset = dataRegionRow * dataRegionSizeRows;
- int32_t dataRegionColumn;
- for (dataRegionColumn = 0; dataRegionColumn < numDataRegionsColumn; ++dataRegionColumn) {
- int32_t dataRegionColumnOffset = dataRegionColumn * dataRegionSizeColumns;
- int32_t i;
- for (i = 0; i < dataRegionSizeRows; ++i) {
- int32_t readRowOffset = dataRegionRow * (dataRegionSizeRows + 2) + 1 + i;
- int32_t writeRowOffset = dataRegionRowOffset + i;
- int32_t j;
- for (j = 0; j < dataRegionSizeColumns; ++j) {
- int32_t readColumnOffset = dataRegionColumn * (dataRegionSizeColumns + 2) + 1 + j;
- if (bitMatrix->Get(readColumnOffset, readRowOffset)) {
- int32_t writeColumnOffset = dataRegionColumnOffset + j;
- bitMatrixWithoutAlignment->Set(writeColumnOffset, writeRowOffset);
- }
- }
- }
+CBC_CommonBitMatrix* CBC_DataMatrixBitMatrixParser::ExtractDataRegion(
+ CBC_CommonBitMatrix* bitMatrix,
+ int32_t& e) {
+ int32_t symbolSizeRows = m_version->GetSymbolSizeRows();
+ int32_t symbolSizeColumns = m_version->GetSymbolSizeColumns();
+ if (bitMatrix->GetHeight() != symbolSizeRows) {
+ e = BCExceptionCanNotCallGetDimensionOnNonSquareMatrix;
+ return NULL;
+ }
+ int32_t dataRegionSizeRows = m_version->GetDataRegionSizeRows();
+ int32_t dataRegionSizeColumns = m_version->GetDataRegionSizeColumns();
+ int32_t numDataRegionsRow = symbolSizeRows / dataRegionSizeRows;
+ int32_t numDataRegionsColumn = symbolSizeColumns / dataRegionSizeColumns;
+ int32_t sizeDataRegionRow = numDataRegionsRow * dataRegionSizeRows;
+ int32_t sizeDataRegionColumn = numDataRegionsColumn * dataRegionSizeColumns;
+ CBC_CommonBitMatrix* bitMatrixWithoutAlignment = FX_NEW CBC_CommonBitMatrix();
+ bitMatrixWithoutAlignment->Init(sizeDataRegionColumn, sizeDataRegionRow);
+ int32_t dataRegionRow;
+ for (dataRegionRow = 0; dataRegionRow < numDataRegionsRow; ++dataRegionRow) {
+ int32_t dataRegionRowOffset = dataRegionRow * dataRegionSizeRows;
+ int32_t dataRegionColumn;
+ for (dataRegionColumn = 0; dataRegionColumn < numDataRegionsColumn;
+ ++dataRegionColumn) {
+ int32_t dataRegionColumnOffset = dataRegionColumn * dataRegionSizeColumns;
+ int32_t i;
+ for (i = 0; i < dataRegionSizeRows; ++i) {
+ int32_t readRowOffset =
+ dataRegionRow * (dataRegionSizeRows + 2) + 1 + i;
+ int32_t writeRowOffset = dataRegionRowOffset + i;
+ int32_t j;
+ for (j = 0; j < dataRegionSizeColumns; ++j) {
+ int32_t readColumnOffset =
+ dataRegionColumn * (dataRegionSizeColumns + 2) + 1 + j;
+ if (bitMatrix->Get(readColumnOffset, readRowOffset)) {
+ int32_t writeColumnOffset = dataRegionColumnOffset + j;
+ bitMatrixWithoutAlignment->Set(writeColumnOffset, writeRowOffset);
+ }
}
+ }
}
- return bitMatrixWithoutAlignment;
+ }
+ return bitMatrixWithoutAlignment;
}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.h b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.h index da9fdc7db5..492bc05478 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.h +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.h @@ -8,25 +8,33 @@ #define _BC_DATAMATRIXBITMATRIXPARSER_H_
class CBC_CommonBitMatrix;
class CBC_DataMatrixVersion;
-class CBC_DataMatrixBitMatrixParser
-{
-public:
- CBC_DataMatrixBitMatrixParser();
- virtual ~CBC_DataMatrixBitMatrixParser();
- CBC_DataMatrixVersion *GetVersion();
- CFX_ByteArray *ReadCodewords(int32_t &e);
- FX_BOOL ReadModule(int32_t row, int32_t column, int32_t numRows, int32_t numColumns);
- int32_t ReadUtah(int32_t row, int32_t column, int32_t numRows, int32_t numColumns);
- int32_t ReadCorner1(int32_t numRows, int32_t numColumns);
- int32_t ReadCorner2(int32_t numRows, int32_t numColumns);
- int32_t ReadCorner3(int32_t numRows, int32_t numColumns);
- int32_t ReadCorner4(int32_t numRows, int32_t numColumns);
- CBC_CommonBitMatrix *ExtractDataRegion(CBC_CommonBitMatrix *bitMatrix, int32_t &e);
- virtual void Init(CBC_CommonBitMatrix *bitMatrix, int32_t &e);
-private:
- static CBC_DataMatrixVersion* ReadVersion(CBC_CommonBitMatrix *bitMatrix, int32_t &e);
- CBC_CommonBitMatrix *m_mappingBitMatrix;
- CBC_CommonBitMatrix *m_readMappingMatrix;
- CBC_DataMatrixVersion *m_version;
+class CBC_DataMatrixBitMatrixParser {
+ public:
+ CBC_DataMatrixBitMatrixParser();
+ virtual ~CBC_DataMatrixBitMatrixParser();
+ CBC_DataMatrixVersion* GetVersion();
+ CFX_ByteArray* ReadCodewords(int32_t& e);
+ FX_BOOL ReadModule(int32_t row,
+ int32_t column,
+ int32_t numRows,
+ int32_t numColumns);
+ int32_t ReadUtah(int32_t row,
+ int32_t column,
+ int32_t numRows,
+ int32_t numColumns);
+ int32_t ReadCorner1(int32_t numRows, int32_t numColumns);
+ int32_t ReadCorner2(int32_t numRows, int32_t numColumns);
+ int32_t ReadCorner3(int32_t numRows, int32_t numColumns);
+ int32_t ReadCorner4(int32_t numRows, int32_t numColumns);
+ CBC_CommonBitMatrix* ExtractDataRegion(CBC_CommonBitMatrix* bitMatrix,
+ int32_t& e);
+ virtual void Init(CBC_CommonBitMatrix* bitMatrix, int32_t& e);
+
+ private:
+ static CBC_DataMatrixVersion* ReadVersion(CBC_CommonBitMatrix* bitMatrix,
+ int32_t& e);
+ CBC_CommonBitMatrix* m_mappingBitMatrix;
+ CBC_CommonBitMatrix* m_readMappingMatrix;
+ CBC_DataMatrixVersion* m_version;
};
#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDataBlock.cpp b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDataBlock.cpp index fcf2804ef2..f9d991b32f 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDataBlock.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDataBlock.cpp @@ -23,77 +23,89 @@ #include "../barcode.h"
#include "BC_DataMatrixVersion.h"
#include "BC_DataMatrixDataBlock.h"
-CBC_DataMatrixDataBlock::~CBC_DataMatrixDataBlock()
-{
+CBC_DataMatrixDataBlock::~CBC_DataMatrixDataBlock() {}
+CBC_DataMatrixDataBlock::CBC_DataMatrixDataBlock(int32_t numDataCodewords,
+ CFX_ByteArray* codewords) {
+ m_codewords.Copy(*codewords);
+ m_numDataCodewords = numDataCodewords;
}
-CBC_DataMatrixDataBlock::CBC_DataMatrixDataBlock(int32_t numDataCodewords, CFX_ByteArray *codewords)
-{
- m_codewords.Copy(*codewords);
- m_numDataCodewords = numDataCodewords;
-}
-CFX_PtrArray *CBC_DataMatrixDataBlock::GetDataBlocks(CFX_ByteArray* rawCodewords, CBC_DataMatrixVersion *version, int32_t &e)
-{
- ECBlocks *ecBlocks = version->GetECBlocks();
- int32_t totalBlocks = 0;
- const CFX_PtrArray &ecBlockArray = ecBlocks->GetECBlocks();
- int32_t i;
- for (i = 0; i < ecBlockArray.GetSize(); i++) {
- totalBlocks += ((ECB*)ecBlockArray[i])->GetCount();
+CFX_PtrArray* CBC_DataMatrixDataBlock::GetDataBlocks(
+ CFX_ByteArray* rawCodewords,
+ CBC_DataMatrixVersion* version,
+ int32_t& e) {
+ ECBlocks* ecBlocks = version->GetECBlocks();
+ int32_t totalBlocks = 0;
+ const CFX_PtrArray& ecBlockArray = ecBlocks->GetECBlocks();
+ int32_t i;
+ for (i = 0; i < ecBlockArray.GetSize(); i++) {
+ totalBlocks += ((ECB*)ecBlockArray[i])->GetCount();
+ }
+ CBC_AutoPtr<CFX_PtrArray> result(FX_NEW CFX_PtrArray());
+ result->SetSize(totalBlocks);
+ int32_t numResultBlocks = 0;
+ int32_t j;
+ for (j = 0; j < ecBlockArray.GetSize(); j++) {
+ for (i = 0; i < ((ECB*)ecBlockArray[j])->GetCount(); i++) {
+ int32_t numDataCodewords = ((ECB*)ecBlockArray[j])->GetDataCodewords();
+ int32_t numBlockCodewords = ecBlocks->GetECCodewords() + numDataCodewords;
+ CFX_ByteArray codewords;
+ codewords.SetSize(numBlockCodewords);
+ (*result)[numResultBlocks++] =
+ FX_NEW CBC_DataMatrixDataBlock(numDataCodewords, &codewords);
+ codewords.SetSize(0);
}
- CBC_AutoPtr<CFX_PtrArray>result(FX_NEW CFX_PtrArray());
- result->SetSize(totalBlocks);
- int32_t numResultBlocks = 0;
+ }
+ int32_t longerBlocksTotalCodewords =
+ ((CBC_DataMatrixDataBlock*)(*result)[0])->GetCodewords()->GetSize();
+ int32_t longerBlocksNumDataCodewords =
+ longerBlocksTotalCodewords - ecBlocks->GetECCodewords();
+ int32_t shorterBlocksNumDataCodewords = longerBlocksNumDataCodewords - 1;
+ int32_t rawCodewordsOffset = 0;
+ for (i = 0; i < shorterBlocksNumDataCodewords; i++) {
int32_t j;
- for (j = 0; j < ecBlockArray.GetSize(); j++) {
- for (i = 0; i < ((ECB*)ecBlockArray[j])->GetCount(); i++) {
- int32_t numDataCodewords = ((ECB*)ecBlockArray[j])->GetDataCodewords();
- int32_t numBlockCodewords = ecBlocks->GetECCodewords() + numDataCodewords;
- CFX_ByteArray codewords;
- codewords.SetSize(numBlockCodewords);
- (*result)[numResultBlocks++] = FX_NEW CBC_DataMatrixDataBlock(numDataCodewords, &codewords);
- codewords.SetSize(0);
- }
- }
- int32_t longerBlocksTotalCodewords = ((CBC_DataMatrixDataBlock*)(*result)[0])->GetCodewords()->GetSize();
- int32_t longerBlocksNumDataCodewords = longerBlocksTotalCodewords - ecBlocks->GetECCodewords();
- int32_t shorterBlocksNumDataCodewords = longerBlocksNumDataCodewords - 1;
- int32_t rawCodewordsOffset = 0;
- for (i = 0; i < shorterBlocksNumDataCodewords; i++) {
- int32_t j;
- for (j = 0; j < numResultBlocks; j++) {
- if (rawCodewordsOffset < rawCodewords->GetSize()) {
- ((CBC_DataMatrixDataBlock*)(*result)[j])->GetCodewords()->operator [](i) = (*rawCodewords)[rawCodewordsOffset++];
- }
- }
+ for (j = 0; j < numResultBlocks; j++) {
+ if (rawCodewordsOffset < rawCodewords->GetSize()) {
+ ((CBC_DataMatrixDataBlock*)(*result)[j])
+ ->GetCodewords()
+ ->
+ operator[](i) = (*rawCodewords)[rawCodewordsOffset++];
+ }
}
- FX_BOOL specialVersion = version->GetVersionNumber() == 24;
- int32_t numLongerBlocks = specialVersion ? 8 : numResultBlocks;
- for (j = 0; j < numLongerBlocks; j++) {
- if (rawCodewordsOffset < rawCodewords->GetSize()) {
- ((CBC_DataMatrixDataBlock*)(*result)[j])->GetCodewords()->operator [](longerBlocksNumDataCodewords - 1) = (*rawCodewords)[rawCodewordsOffset++];
- }
+ }
+ FX_BOOL specialVersion = version->GetVersionNumber() == 24;
+ int32_t numLongerBlocks = specialVersion ? 8 : numResultBlocks;
+ for (j = 0; j < numLongerBlocks; j++) {
+ if (rawCodewordsOffset < rawCodewords->GetSize()) {
+ ((CBC_DataMatrixDataBlock*)(*result)[j])
+ ->GetCodewords()
+ ->
+ operator[](longerBlocksNumDataCodewords - 1) =
+ (*rawCodewords)[rawCodewordsOffset++];
}
- int32_t max = ((CBC_DataMatrixDataBlock*)(*result)[0])->GetCodewords()->GetSize();
- for (i = longerBlocksNumDataCodewords; i < max; i++) {
- int32_t j;
- for (j = 0; j < numResultBlocks; j++) {
- int32_t iOffset = specialVersion && j > 7 ? i - 1 : i;
- if (rawCodewordsOffset < rawCodewords->GetSize()) {
- ((CBC_DataMatrixDataBlock*)(*result)[j])->GetCodewords()->operator [](iOffset) = (*rawCodewords)[rawCodewordsOffset++];
- }
- }
- }
- if (rawCodewordsOffset != rawCodewords->GetSize()) {
- e = BCExceptionIllegalArgument;
- return NULL;
+ }
+ int32_t max =
+ ((CBC_DataMatrixDataBlock*)(*result)[0])->GetCodewords()->GetSize();
+ for (i = longerBlocksNumDataCodewords; i < max; i++) {
+ int32_t j;
+ for (j = 0; j < numResultBlocks; j++) {
+ int32_t iOffset = specialVersion && j > 7 ? i - 1 : i;
+ if (rawCodewordsOffset < rawCodewords->GetSize()) {
+ ((CBC_DataMatrixDataBlock*)(*result)[j])
+ ->GetCodewords()
+ ->
+ operator[](iOffset) = (*rawCodewords)[rawCodewordsOffset++];
+ }
}
- return result.release();
+ }
+ if (rawCodewordsOffset != rawCodewords->GetSize()) {
+ e = BCExceptionIllegalArgument;
+ return NULL;
+ }
+ return result.release();
}
-int32_t CBC_DataMatrixDataBlock::GetNumDataCodewords()
-{
- return m_numDataCodewords;
+int32_t CBC_DataMatrixDataBlock::GetNumDataCodewords() {
+ return m_numDataCodewords;
}
-CFX_ByteArray *CBC_DataMatrixDataBlock::GetCodewords()
-{
- return &m_codewords;
+CFX_ByteArray* CBC_DataMatrixDataBlock::GetCodewords() {
+ return &m_codewords;
}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDataBlock.h b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDataBlock.h index 21be66549c..6f34e6850a 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDataBlock.h +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDataBlock.h @@ -7,19 +7,21 @@ #ifndef _BC_DATAMATRIXDATABLOCK_H_
#define _BC_DATAMATRIXDATABLOCK_H_
class CBC_DataMatrixVersion;
-class CBC_DataMatrixDataBlock
-{
-public:
- virtual ~CBC_DataMatrixDataBlock();
+class CBC_DataMatrixDataBlock {
+ public:
+ virtual ~CBC_DataMatrixDataBlock();
- int32_t GetNumDataCodewords();
- CFX_ByteArray* GetCodewords();
+ int32_t GetNumDataCodewords();
+ CFX_ByteArray* GetCodewords();
- static CFX_PtrArray *GetDataBlocks(CFX_ByteArray* rawCodewords, CBC_DataMatrixVersion *version, int32_t &e);
-private:
- int32_t m_numDataCodewords;
- CFX_ByteArray m_codewords;
+ static CFX_PtrArray* GetDataBlocks(CFX_ByteArray* rawCodewords,
+ CBC_DataMatrixVersion* version,
+ int32_t& e);
- CBC_DataMatrixDataBlock(int32_t numDataCodewords, CFX_ByteArray *codewords);
+ private:
+ int32_t m_numDataCodewords;
+ CFX_ByteArray m_codewords;
+
+ CBC_DataMatrixDataBlock(int32_t numDataCodewords, CFX_ByteArray* codewords);
};
#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.cpp b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.cpp index 07393c0fec..86a93d13ee 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.cpp @@ -27,21 +27,18 @@ const FX_CHAR CBC_DataMatrixDecodedBitStreamParser::C40_BASIC_SET_CHARS[] = {
'*', '*', '*', ' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
- 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
-};
+ 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
const FX_CHAR CBC_DataMatrixDecodedBitStreamParser::C40_SHIFT2_SET_CHARS[] = {
'!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.',
- '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_'
-};
+ '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_'};
const FX_CHAR CBC_DataMatrixDecodedBitStreamParser::TEXT_BASIC_SET_CHARS[] = {
'*', '*', '*', ' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
- 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
-};
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const FX_CHAR CBC_DataMatrixDecodedBitStreamParser::TEXT_SHIFT3_SET_CHARS[] = {
- '\'', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
- 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '{', '|', '}', '~', (FX_CHAR) 127
-};
+ '\'', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
+ 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
+ 'V', 'W', 'X', 'Y', 'Z', '{', '|', '}', '~', (FX_CHAR)127};
const int32_t CBC_DataMatrixDecodedBitStreamParser::PAD_ENCODE = 0;
const int32_t CBC_DataMatrixDecodedBitStreamParser::ASCII_ENCODE = 1;
const int32_t CBC_DataMatrixDecodedBitStreamParser::C40_ENCODE = 2;
@@ -49,424 +46,440 @@ const int32_t CBC_DataMatrixDecodedBitStreamParser::TEXT_ENCODE = 3; const int32_t CBC_DataMatrixDecodedBitStreamParser::ANSIX12_ENCODE = 4;
const int32_t CBC_DataMatrixDecodedBitStreamParser::EDIFACT_ENCODE = 5;
const int32_t CBC_DataMatrixDecodedBitStreamParser::BASE256_ENCODE = 6;
-CBC_DataMatrixDecodedBitStreamParser::CBC_DataMatrixDecodedBitStreamParser()
-{
-}
-CBC_DataMatrixDecodedBitStreamParser::~CBC_DataMatrixDecodedBitStreamParser()
-{
-}
-CBC_CommonDecoderResult *CBC_DataMatrixDecodedBitStreamParser::Decode(CFX_ByteArray &bytes, int32_t &e)
-{
- CBC_CommonBitSource bits(&bytes);
- CFX_ByteString result;
- CFX_ByteString resultTrailer;
- CFX_Int32Array byteSegments;
- int32_t mode = ASCII_ENCODE;
- do {
- if (mode == 1) {
- mode = DecodeAsciiSegment(&bits, result, resultTrailer, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- } else {
- switch (mode) {
- case 2:
- DecodeC40Segment(&bits, result, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- break;
- case 3:
- DecodeTextSegment(&bits, result, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- break;
- case 4:
- DecodeAnsiX12Segment(&bits, result, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- break;
- case 5:
- DecodeEdifactSegment(&bits, result, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- break;
- case 6:
- DecodeBase256Segment(&bits, result, byteSegments, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- break;
- default:
- NULL;
- e = BCExceptionFormatException;
- return NULL;
- }
- mode = ASCII_ENCODE;
- }
- } while (mode != PAD_ENCODE && bits.Available() > 0);
- if (resultTrailer.GetLength() > 0) {
- result += resultTrailer;
+CBC_DataMatrixDecodedBitStreamParser::CBC_DataMatrixDecodedBitStreamParser() {}
+CBC_DataMatrixDecodedBitStreamParser::~CBC_DataMatrixDecodedBitStreamParser() {}
+CBC_CommonDecoderResult* CBC_DataMatrixDecodedBitStreamParser::Decode(
+ CFX_ByteArray& bytes,
+ int32_t& e) {
+ CBC_CommonBitSource bits(&bytes);
+ CFX_ByteString result;
+ CFX_ByteString resultTrailer;
+ CFX_Int32Array byteSegments;
+ int32_t mode = ASCII_ENCODE;
+ do {
+ if (mode == 1) {
+ mode = DecodeAsciiSegment(&bits, result, resultTrailer, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ } else {
+ switch (mode) {
+ case 2:
+ DecodeC40Segment(&bits, result, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ break;
+ case 3:
+ DecodeTextSegment(&bits, result, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ break;
+ case 4:
+ DecodeAnsiX12Segment(&bits, result, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ break;
+ case 5:
+ DecodeEdifactSegment(&bits, result, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ break;
+ case 6:
+ DecodeBase256Segment(&bits, result, byteSegments, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ break;
+ default:
+ NULL;
+ e = BCExceptionFormatException;
+ return NULL;
+ }
+ mode = ASCII_ENCODE;
}
- CBC_CommonDecoderResult *tempCp = FX_NEW CBC_CommonDecoderResult();
- tempCp->Init(bytes, result, (byteSegments.GetSize() <= 0) ? CFX_Int32Array() : byteSegments, NULL, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- return tempCp;
+ } while (mode != PAD_ENCODE && bits.Available() > 0);
+ if (resultTrailer.GetLength() > 0) {
+ result += resultTrailer;
+ }
+ CBC_CommonDecoderResult* tempCp = FX_NEW CBC_CommonDecoderResult();
+ tempCp->Init(bytes, result,
+ (byteSegments.GetSize() <= 0) ? CFX_Int32Array() : byteSegments,
+ NULL, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return tempCp;
}
-int32_t CBC_DataMatrixDecodedBitStreamParser::DecodeAsciiSegment(CBC_CommonBitSource *bits, CFX_ByteString &result, CFX_ByteString &resultTrailer, int32_t &e)
-{
- FX_CHAR buffer[128];
- FX_BOOL upperShift = FALSE;
- do {
- int32_t oneByte = bits->ReadBits(8, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, 0);
- if (oneByte == 0) {
- e = BCExceptionFormatException;
- return 0;
- } else if (oneByte <= 128) {
- oneByte = upperShift ? oneByte + 128 : oneByte;
- upperShift = FALSE;
- result += ((FX_CHAR) (oneByte - 1));
- return ASCII_ENCODE;
- } else if (oneByte == 129) {
- return PAD_ENCODE;
- } else if (oneByte <= 229) {
- int32_t value = oneByte - 130;
+int32_t CBC_DataMatrixDecodedBitStreamParser::DecodeAsciiSegment(
+ CBC_CommonBitSource* bits,
+ CFX_ByteString& result,
+ CFX_ByteString& resultTrailer,
+ int32_t& e) {
+ FX_CHAR buffer[128];
+ FX_BOOL upperShift = FALSE;
+ do {
+ int32_t oneByte = bits->ReadBits(8, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, 0);
+ if (oneByte == 0) {
+ e = BCExceptionFormatException;
+ return 0;
+ } else if (oneByte <= 128) {
+ oneByte = upperShift ? oneByte + 128 : oneByte;
+ upperShift = FALSE;
+ result += ((FX_CHAR)(oneByte - 1));
+ return ASCII_ENCODE;
+ } else if (oneByte == 129) {
+ return PAD_ENCODE;
+ } else if (oneByte <= 229) {
+ int32_t value = oneByte - 130;
#if defined(_FX_WINAPI_PARTITION_APP_)
- memset(buffer, 0, sizeof(FX_CHAR) * 128);
- _itoa_s(value, buffer, 128, 10);
+ memset(buffer, 0, sizeof(FX_CHAR) * 128);
+ _itoa_s(value, buffer, 128, 10);
#else
- FXSYS_itoa(value, buffer, 10);
+ FXSYS_itoa(value, buffer, 10);
#endif
- if (value < 10) {
- result += '0';
- buffer[1] = '\0';
+ if (value < 10) {
+ result += '0';
+ buffer[1] = '\0';
+ } else {
+ buffer[2] = '\0';
+ }
+ result += buffer;
+ } else if (oneByte == 230) {
+ return C40_ENCODE;
+ } else if (oneByte == 231) {
+ return BASE256_ENCODE;
+ } else if (oneByte == 232 || oneByte == 233 || oneByte == 234) {
+ } else if (oneByte == 235) {
+ upperShift = TRUE;
+ } else if (oneByte == 236) {
+ result += "[)>";
+ result += 0x1E;
+ result += "05";
+ result += 0x1D;
+ resultTrailer.Insert(0, 0x1E);
+ resultTrailer.Insert(0 + 1, 0x04);
+ } else if (oneByte == 237) {
+ result += "[)>";
+ result += 0x1E;
+ result += "06";
+ result += 0x1D;
+ resultTrailer.Insert(0, 0x1E);
+ resultTrailer.Insert(0 + 1, 0x04);
+ } else if (oneByte == 238) {
+ return ANSIX12_ENCODE;
+ } else if (oneByte == 239) {
+ return TEXT_ENCODE;
+ } else if (oneByte == 240) {
+ return EDIFACT_ENCODE;
+ } else if (oneByte == 241) {
+ } else if (oneByte >= 242) {
+ if (oneByte == 254 && bits->Available() == 0) {
+ } else {
+ e = BCExceptionFormatException;
+ return 0;
+ }
+ }
+ } while (bits->Available() > 0);
+ return ASCII_ENCODE;
+}
+void CBC_DataMatrixDecodedBitStreamParser::DecodeC40Segment(
+ CBC_CommonBitSource* bits,
+ CFX_ByteString& result,
+ int32_t& e) {
+ FX_BOOL upperShift = FALSE;
+ CFX_Int32Array cValues;
+ cValues.SetSize(3);
+ do {
+ if (bits->Available() == 8) {
+ return;
+ }
+ int32_t firstByte = bits->ReadBits(8, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ if (firstByte == 254) {
+ return;
+ }
+ int32_t tempp = bits->ReadBits(8, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ ParseTwoBytes(firstByte, tempp, cValues);
+ int32_t shift = 0;
+ int32_t i;
+ for (i = 0; i < 3; i++) {
+ int32_t cValue = cValues[i];
+ switch (shift) {
+ case 0:
+ if (cValue < 3) {
+ shift = cValue + 1;
+ } else if (cValue < 27) {
+ FX_CHAR c40char = C40_BASIC_SET_CHARS[cValue];
+ if (upperShift) {
+ result += (FX_CHAR)(c40char + 128);
+ upperShift = FALSE;
} else {
- buffer[2] = '\0';
+ result += c40char;
}
- result += buffer;
- } else if (oneByte == 230) {
- return C40_ENCODE;
- } else if (oneByte == 231) {
- return BASE256_ENCODE;
- } else if (oneByte == 232 || oneByte == 233 || oneByte == 234) {
- } else if (oneByte == 235) {
- upperShift = TRUE;
- } else if (oneByte == 236) {
- result += "[)>";
- result += 0x1E;
- result += "05";
- result += 0x1D;
- resultTrailer.Insert(0, 0x1E);
- resultTrailer.Insert(0 + 1, 0x04);
- } else if (oneByte == 237) {
- result += "[)>";
- result += 0x1E;
- result += "06";
- result += 0x1D;
- resultTrailer.Insert(0, 0x1E);
- resultTrailer.Insert(0 + 1, 0x04);
- } else if (oneByte == 238) {
- return ANSIX12_ENCODE;
- } else if (oneByte == 239) {
- return TEXT_ENCODE;
- } else if (oneByte == 240) {
- return EDIFACT_ENCODE;
- } else if (oneByte == 241) {
- } else if (oneByte >= 242) {
- if (oneByte == 254 && bits->Available() == 0) {
+ } else {
+ e = BCExceptionFormatException;
+ return;
+ }
+ break;
+ case 1:
+ if (upperShift) {
+ result += (FX_CHAR)(cValue + 128);
+ upperShift = FALSE;
+ } else {
+ result += cValue;
+ }
+ shift = 0;
+ break;
+ case 2:
+ if (cValue < 27) {
+ FX_CHAR c40char = C40_SHIFT2_SET_CHARS[cValue];
+ if (upperShift) {
+ result += (FX_CHAR)(c40char + 128);
+ upperShift = FALSE;
} else {
- e = BCExceptionFormatException;
- return 0;
+ result += c40char;
}
- }
- } while (bits->Available() > 0);
- return ASCII_ENCODE;
-}
-void CBC_DataMatrixDecodedBitStreamParser::DecodeC40Segment(CBC_CommonBitSource *bits, CFX_ByteString &result, int32_t &e)
-{
- FX_BOOL upperShift = FALSE;
- CFX_Int32Array cValues;
- cValues.SetSize(3);
- do {
- if (bits->Available() == 8) {
+ } else if (cValue == 27) {
+ e = BCExceptionFormatException;
return;
- }
- int32_t firstByte = bits->ReadBits(8, e);
- BC_EXCEPTION_CHECK_ReturnVoid(e);
- if (firstByte == 254) {
+ } else if (cValue == 30) {
+ upperShift = TRUE;
+ } else {
+ e = BCExceptionFormatException;
return;
- }
- int32_t tempp = bits->ReadBits(8, e);
- BC_EXCEPTION_CHECK_ReturnVoid(e);
- ParseTwoBytes(firstByte, tempp, cValues);
- int32_t shift = 0;
- int32_t i;
- for (i = 0; i < 3; i++) {
- int32_t cValue = cValues[i];
- switch (shift) {
- case 0:
- if (cValue < 3) {
- shift = cValue + 1;
- } else if (cValue < 27) {
- FX_CHAR c40char = C40_BASIC_SET_CHARS[cValue];
- if (upperShift) {
- result += (FX_CHAR) (c40char + 128);
- upperShift = FALSE;
- } else {
- result += c40char;
- }
- } else {
- e = BCExceptionFormatException;
- return ;
- }
- break;
- case 1:
- if (upperShift) {
- result += (FX_CHAR) (cValue + 128);
- upperShift = FALSE;
- } else {
- result += cValue;
- }
- shift = 0;
- break;
- case 2:
- if (cValue < 27) {
- FX_CHAR c40char = C40_SHIFT2_SET_CHARS[cValue];
- if (upperShift) {
- result += (FX_CHAR) (c40char + 128);
- upperShift = FALSE;
- } else {
- result += c40char;
- }
- } else if (cValue == 27) {
- e = BCExceptionFormatException;
- return;
- } else if (cValue == 30) {
- upperShift = TRUE;
- } else {
- e = BCExceptionFormatException;
- return;
- }
- shift = 0;
- break;
- case 3:
- if (upperShift) {
- result += (FX_CHAR) (cValue + 224);
- upperShift = FALSE;
- } else {
- result += (FX_CHAR) (cValue + 96);
- }
- shift = 0;
- break;
- default:
- break;
- e = BCExceptionFormatException;
- return;
- }
- }
- } while (bits->Available() > 0);
+ }
+ shift = 0;
+ break;
+ case 3:
+ if (upperShift) {
+ result += (FX_CHAR)(cValue + 224);
+ upperShift = FALSE;
+ } else {
+ result += (FX_CHAR)(cValue + 96);
+ }
+ shift = 0;
+ break;
+ default:
+ break;
+ e = BCExceptionFormatException;
+ return;
+ }
+ }
+ } while (bits->Available() > 0);
}
-void CBC_DataMatrixDecodedBitStreamParser::DecodeTextSegment(CBC_CommonBitSource *bits, CFX_ByteString &result, int32_t &e)
-{
- FX_BOOL upperShift = FALSE;
- CFX_Int32Array cValues;
- cValues.SetSize(3);
- int32_t shift = 0;
- do {
- if (bits->Available() == 8) {
- return;
- }
- int32_t firstByte = bits->ReadBits(8, e);
- BC_EXCEPTION_CHECK_ReturnVoid(e);
- if (firstByte == 254) {
+void CBC_DataMatrixDecodedBitStreamParser::DecodeTextSegment(
+ CBC_CommonBitSource* bits,
+ CFX_ByteString& result,
+ int32_t& e) {
+ FX_BOOL upperShift = FALSE;
+ CFX_Int32Array cValues;
+ cValues.SetSize(3);
+ int32_t shift = 0;
+ do {
+ if (bits->Available() == 8) {
+ return;
+ }
+ int32_t firstByte = bits->ReadBits(8, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ if (firstByte == 254) {
+ return;
+ }
+ int32_t inTp = bits->ReadBits(8, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ ParseTwoBytes(firstByte, inTp, cValues);
+ for (int32_t i = 0; i < 3; i++) {
+ int32_t cValue = cValues[i];
+ switch (shift) {
+ case 0:
+ if (cValue < 3) {
+ shift = cValue + 1;
+ } else if (cValue < 40) {
+ FX_CHAR textChar = TEXT_BASIC_SET_CHARS[cValue];
+ if (upperShift) {
+ result += (FX_CHAR)(textChar + 128);
+ upperShift = FALSE;
+ } else {
+ result += textChar;
+ }
+ } else {
+ e = BCExceptionFormatException;
return;
- }
- int32_t inTp = bits->ReadBits(8, e);
- BC_EXCEPTION_CHECK_ReturnVoid(e);
- ParseTwoBytes(firstByte, inTp, cValues);
- for (int32_t i = 0; i < 3; i++) {
- int32_t cValue = cValues[i];
- switch (shift) {
- case 0:
- if (cValue < 3) {
- shift = cValue + 1;
- } else if (cValue < 40) {
- FX_CHAR textChar = TEXT_BASIC_SET_CHARS[cValue];
- if (upperShift) {
- result += (FX_CHAR) (textChar + 128);
- upperShift = FALSE;
- } else {
- result += textChar;
- }
- } else {
- e = BCExceptionFormatException;
- return;
- }
- break;
- case 1:
- if (upperShift) {
- result += (FX_CHAR) (cValue + 128);
- upperShift = FALSE;
- } else {
- result += cValue;
- }
- shift = 0;
- break;
- case 2:
- if (cValue < 27) {
- FX_CHAR c40char = C40_SHIFT2_SET_CHARS[cValue];
- if (upperShift) {
- result += (FX_CHAR) (c40char + 128);
- upperShift = FALSE;
- } else {
- result += c40char;
- }
- } else if (cValue == 27) {
- e = BCExceptionFormatException;
- return;
- } else if (cValue == 30) {
- upperShift = TRUE;
- } else {
- e = BCExceptionFormatException;
- return;
- }
- shift = 0;
- break;
- case 3:
- if (cValue < 19) {
- FX_CHAR textChar = TEXT_SHIFT3_SET_CHARS[cValue];
- if (upperShift) {
- result += (FX_CHAR) (textChar + 128);
- upperShift = FALSE;
- } else {
- result += textChar;
- }
- shift = 0;
- } else {
- e = BCExceptionFormatException;
- return;
- }
- break;
- default:
- break;
- e = BCExceptionFormatException;
- return;
+ }
+ break;
+ case 1:
+ if (upperShift) {
+ result += (FX_CHAR)(cValue + 128);
+ upperShift = FALSE;
+ } else {
+ result += cValue;
+ }
+ shift = 0;
+ break;
+ case 2:
+ if (cValue < 27) {
+ FX_CHAR c40char = C40_SHIFT2_SET_CHARS[cValue];
+ if (upperShift) {
+ result += (FX_CHAR)(c40char + 128);
+ upperShift = FALSE;
+ } else {
+ result += c40char;
}
- }
- } while (bits->Available() > 0);
-}
-void CBC_DataMatrixDecodedBitStreamParser::DecodeAnsiX12Segment(CBC_CommonBitSource *bits, CFX_ByteString &result, int32_t &e)
-{
- CFX_Int32Array cValues;
- cValues.SetSize(3);
- do {
- if (bits->Available() == 8) {
+ } else if (cValue == 27) {
+ e = BCExceptionFormatException;
return;
- }
- int32_t firstByte = bits->ReadBits(8, e);
- BC_EXCEPTION_CHECK_ReturnVoid(e);
- if (firstByte == 254) {
+ } else if (cValue == 30) {
+ upperShift = TRUE;
+ } else {
+ e = BCExceptionFormatException;
return;
- }
- int32_t iTemp1 = bits->ReadBits(8, e);
- BC_EXCEPTION_CHECK_ReturnVoid(e);
- ParseTwoBytes(firstByte, iTemp1, cValues);
- int32_t i;
- for (i = 0; i < 3; i++) {
- int32_t cValue = cValues[i];
- if (cValue == 0) {
- BC_FX_ByteString_Append(result, 1, '\r');
- } else if (cValue == 1) {
- BC_FX_ByteString_Append(result, 1, '*');
- } else if (cValue == 2) {
- BC_FX_ByteString_Append(result, 1, '>');
- } else if (cValue == 3) {
- BC_FX_ByteString_Append(result, 1, ' ');
- } else if (cValue < 14) {
- BC_FX_ByteString_Append(result, 1, (FX_CHAR) (cValue + 44));
- } else if (cValue < 40) {
- BC_FX_ByteString_Append(result, 1, (FX_CHAR) (cValue + 51));
+ }
+ shift = 0;
+ break;
+ case 3:
+ if (cValue < 19) {
+ FX_CHAR textChar = TEXT_SHIFT3_SET_CHARS[cValue];
+ if (upperShift) {
+ result += (FX_CHAR)(textChar + 128);
+ upperShift = FALSE;
} else {
- e = BCExceptionFormatException;
- return;
+ result += textChar;
}
- }
- } while (bits->Available() > 0);
-}
-void CBC_DataMatrixDecodedBitStreamParser::ParseTwoBytes(int32_t firstByte, int32_t secondByte, CFX_Int32Array &result)
-{
- int32_t fullBitValue = (firstByte << 8) + secondByte - 1;
- int32_t temp = fullBitValue / 1600;
- result[0] = temp;
- fullBitValue -= temp * 1600;
- temp = fullBitValue / 40;
- result[1] = temp;
- result[2] = fullBitValue - temp * 40;
-}
-void CBC_DataMatrixDecodedBitStreamParser::DecodeEdifactSegment(CBC_CommonBitSource *bits, CFX_ByteString &result, int32_t &e)
-{
- FX_CHAR buffer[128];
- FX_BOOL unlatch = FALSE;
- do {
- if (bits->Available() <= 16) {
+ shift = 0;
+ } else {
+ e = BCExceptionFormatException;
return;
- }
- int32_t i;
- for (i = 0; i < 4; i++) {
- int32_t edifactValue = bits->ReadBits(6, e);
- BC_EXCEPTION_CHECK_ReturnVoid(e);
- if (edifactValue == 0x1F) {
- unlatch = TRUE;
- }
- if (!unlatch) {
- if ((edifactValue & 32) == 0) {
- edifactValue |= 64;
- }
-#if defined(_FX_WINAPI_PARTITION_APP_)
- memset(buffer, 0, sizeof(FX_CHAR) * 128);
- _itoa_s(edifactValue, buffer, 128, 10);
- result += buffer;
-#else
- result += FXSYS_itoa(edifactValue, buffer, 10);
-#endif
- }
- }
- } while (!unlatch && bits->Available() > 0);
+ }
+ break;
+ default:
+ break;
+ e = BCExceptionFormatException;
+ return;
+ }
+ }
+ } while (bits->Available() > 0);
}
-void CBC_DataMatrixDecodedBitStreamParser::DecodeBase256Segment(CBC_CommonBitSource *bits, CFX_ByteString &result, CFX_Int32Array &byteSegments, int32_t &e)
-{
- int32_t codewordPosition = 1 + bits->getByteOffset();
- int32_t iTmp = bits->ReadBits(8, e);
+void CBC_DataMatrixDecodedBitStreamParser::DecodeAnsiX12Segment(
+ CBC_CommonBitSource* bits,
+ CFX_ByteString& result,
+ int32_t& e) {
+ CFX_Int32Array cValues;
+ cValues.SetSize(3);
+ do {
+ if (bits->Available() == 8) {
+ return;
+ }
+ int32_t firstByte = bits->ReadBits(8, e);
BC_EXCEPTION_CHECK_ReturnVoid(e);
- int32_t d1 = Unrandomize255State(iTmp, codewordPosition++);
- int32_t count;
- if (d1 == 0) {
- count = bits->Available() / 8;
- } else if (d1 < 250) {
- count = d1;
- } else {
- int32_t iTmp3 = bits->ReadBits(8, e);
- BC_EXCEPTION_CHECK_ReturnVoid(e);
- count = 250 * (d1 - 249) + Unrandomize255State(iTmp3, codewordPosition++);
+ if (firstByte == 254) {
+ return;
}
- if (count < 0) {
+ int32_t iTemp1 = bits->ReadBits(8, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ ParseTwoBytes(firstByte, iTemp1, cValues);
+ int32_t i;
+ for (i = 0; i < 3; i++) {
+ int32_t cValue = cValues[i];
+ if (cValue == 0) {
+ BC_FX_ByteString_Append(result, 1, '\r');
+ } else if (cValue == 1) {
+ BC_FX_ByteString_Append(result, 1, '*');
+ } else if (cValue == 2) {
+ BC_FX_ByteString_Append(result, 1, '>');
+ } else if (cValue == 3) {
+ BC_FX_ByteString_Append(result, 1, ' ');
+ } else if (cValue < 14) {
+ BC_FX_ByteString_Append(result, 1, (FX_CHAR)(cValue + 44));
+ } else if (cValue < 40) {
+ BC_FX_ByteString_Append(result, 1, (FX_CHAR)(cValue + 51));
+ } else {
e = BCExceptionFormatException;
return;
+ }
+ }
+ } while (bits->Available() > 0);
+}
+void CBC_DataMatrixDecodedBitStreamParser::ParseTwoBytes(
+ int32_t firstByte,
+ int32_t secondByte,
+ CFX_Int32Array& result) {
+ int32_t fullBitValue = (firstByte << 8) + secondByte - 1;
+ int32_t temp = fullBitValue / 1600;
+ result[0] = temp;
+ fullBitValue -= temp * 1600;
+ temp = fullBitValue / 40;
+ result[1] = temp;
+ result[2] = fullBitValue - temp * 40;
+}
+void CBC_DataMatrixDecodedBitStreamParser::DecodeEdifactSegment(
+ CBC_CommonBitSource* bits,
+ CFX_ByteString& result,
+ int32_t& e) {
+ FX_CHAR buffer[128];
+ FX_BOOL unlatch = FALSE;
+ do {
+ if (bits->Available() <= 16) {
+ return;
}
- CFX_ByteArray *bytes = FX_NEW CFX_ByteArray();
- bytes->SetSize(count);
int32_t i;
- for (i = 0; i < count; i++) {
- if (bits->Available() < 8) {
- e = BCExceptionFormatException;
- delete bytes;
- return;
- }
- int32_t iTemp5 = bits->ReadBits(8, e);
- if (e != BCExceptionNO) {
- delete bytes;
- return;
+ for (i = 0; i < 4; i++) {
+ int32_t edifactValue = bits->ReadBits(6, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ if (edifactValue == 0x1F) {
+ unlatch = TRUE;
+ }
+ if (!unlatch) {
+ if ((edifactValue & 32) == 0) {
+ edifactValue |= 64;
}
- bytes->SetAt(i, Unrandomize255State(iTemp5, codewordPosition++));
+#if defined(_FX_WINAPI_PARTITION_APP_)
+ memset(buffer, 0, sizeof(FX_CHAR) * 128);
+ _itoa_s(edifactValue, buffer, 128, 10);
+ result += buffer;
+#else
+ result += FXSYS_itoa(edifactValue, buffer, 10);
+#endif
+ }
+ }
+ } while (!unlatch && bits->Available() > 0);
+}
+void CBC_DataMatrixDecodedBitStreamParser::DecodeBase256Segment(
+ CBC_CommonBitSource* bits,
+ CFX_ByteString& result,
+ CFX_Int32Array& byteSegments,
+ int32_t& e) {
+ int32_t codewordPosition = 1 + bits->getByteOffset();
+ int32_t iTmp = bits->ReadBits(8, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ int32_t d1 = Unrandomize255State(iTmp, codewordPosition++);
+ int32_t count;
+ if (d1 == 0) {
+ count = bits->Available() / 8;
+ } else if (d1 < 250) {
+ count = d1;
+ } else {
+ int32_t iTmp3 = bits->ReadBits(8, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ count = 250 * (d1 - 249) + Unrandomize255State(iTmp3, codewordPosition++);
+ }
+ if (count < 0) {
+ e = BCExceptionFormatException;
+ return;
+ }
+ CFX_ByteArray* bytes = FX_NEW CFX_ByteArray();
+ bytes->SetSize(count);
+ int32_t i;
+ for (i = 0; i < count; i++) {
+ if (bits->Available() < 8) {
+ e = BCExceptionFormatException;
+ delete bytes;
+ return;
+ }
+ int32_t iTemp5 = bits->ReadBits(8, e);
+ if (e != BCExceptionNO) {
+ delete bytes;
+ return;
}
- BC_FX_ByteString_Append(result, *bytes);
- delete bytes;
+ bytes->SetAt(i, Unrandomize255State(iTemp5, codewordPosition++));
+ }
+ BC_FX_ByteString_Append(result, *bytes);
+ delete bytes;
}
-uint8_t CBC_DataMatrixDecodedBitStreamParser::Unrandomize255State(int32_t randomizedBase256Codeword, int32_t base256CodewordPosition)
-{
- int32_t pseudoRandomNumber = ((149 * base256CodewordPosition) % 255) + 1;
- int32_t tempVariable = randomizedBase256Codeword - pseudoRandomNumber;
- return (uint8_t) (tempVariable >= 0 ? tempVariable : tempVariable + 256);
+uint8_t CBC_DataMatrixDecodedBitStreamParser::Unrandomize255State(
+ int32_t randomizedBase256Codeword,
+ int32_t base256CodewordPosition) {
+ int32_t pseudoRandomNumber = ((149 * base256CodewordPosition) % 255) + 1;
+ int32_t tempVariable = randomizedBase256Codeword - pseudoRandomNumber;
+ return (uint8_t)(tempVariable >= 0 ? tempVariable : tempVariable + 256);
}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.h b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.h index 4fa5407fb5..04ad396e0d 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.h +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.h @@ -8,35 +8,50 @@ #define _BC_DATAMATRIXDECODEDBITSTREAMPARSER_H_
class CBC_CommonDecoderResult;
class CBC_CommonBitSource;
-class CBC_DataMatrixDecodedBitStreamParser
-{
-public:
- CBC_DataMatrixDecodedBitStreamParser();
- virtual ~CBC_DataMatrixDecodedBitStreamParser();
- static CBC_CommonDecoderResult *Decode(CFX_ByteArray &bytes, int32_t &e);
+class CBC_DataMatrixDecodedBitStreamParser {
+ public:
+ CBC_DataMatrixDecodedBitStreamParser();
+ virtual ~CBC_DataMatrixDecodedBitStreamParser();
+ static CBC_CommonDecoderResult* Decode(CFX_ByteArray& bytes, int32_t& e);
-private:
- static int32_t DecodeAsciiSegment(CBC_CommonBitSource *bits, CFX_ByteString &result, CFX_ByteString &resultTrailer, int32_t &e);
- static void DecodeC40Segment(CBC_CommonBitSource *bits, CFX_ByteString &result, int32_t &e);
- static void DecodeTextSegment(CBC_CommonBitSource *bits, CFX_ByteString &result, int32_t &e);
- static void DecodeAnsiX12Segment(CBC_CommonBitSource *bits, CFX_ByteString &result, int32_t &e);
- static void ParseTwoBytes(int32_t firstByte, int32_t secondByte, CFX_Int32Array &result);
- static void DecodeEdifactSegment(CBC_CommonBitSource *bits, CFX_ByteString &result, int32_t &e);
- static void DecodeBase256Segment(CBC_CommonBitSource *bits, CFX_ByteString &result, CFX_Int32Array &byteSegments, int32_t &e);
- static uint8_t Unrandomize255State(int32_t randomizedBase256Codeword, int32_t base256CodewordPosition);
+ private:
+ static int32_t DecodeAsciiSegment(CBC_CommonBitSource* bits,
+ CFX_ByteString& result,
+ CFX_ByteString& resultTrailer,
+ int32_t& e);
+ static void DecodeC40Segment(CBC_CommonBitSource* bits,
+ CFX_ByteString& result,
+ int32_t& e);
+ static void DecodeTextSegment(CBC_CommonBitSource* bits,
+ CFX_ByteString& result,
+ int32_t& e);
+ static void DecodeAnsiX12Segment(CBC_CommonBitSource* bits,
+ CFX_ByteString& result,
+ int32_t& e);
+ static void ParseTwoBytes(int32_t firstByte,
+ int32_t secondByte,
+ CFX_Int32Array& result);
+ static void DecodeEdifactSegment(CBC_CommonBitSource* bits,
+ CFX_ByteString& result,
+ int32_t& e);
+ static void DecodeBase256Segment(CBC_CommonBitSource* bits,
+ CFX_ByteString& result,
+ CFX_Int32Array& byteSegments,
+ int32_t& e);
+ static uint8_t Unrandomize255State(int32_t randomizedBase256Codeword,
+ int32_t base256CodewordPosition);
- const static FX_CHAR C40_BASIC_SET_CHARS[];
- const static FX_CHAR C40_SHIFT2_SET_CHARS[];
+ const static FX_CHAR C40_BASIC_SET_CHARS[];
+ const static FX_CHAR C40_SHIFT2_SET_CHARS[];
-
- const static FX_CHAR TEXT_BASIC_SET_CHARS[];
- const static FX_CHAR TEXT_SHIFT3_SET_CHARS[];
- const static int32_t PAD_ENCODE;
- const static int32_t ASCII_ENCODE;
- const static int32_t C40_ENCODE;
- const static int32_t TEXT_ENCODE;
- const static int32_t ANSIX12_ENCODE;
- const static int32_t EDIFACT_ENCODE;
- const static int32_t BASE256_ENCODE;
+ const static FX_CHAR TEXT_BASIC_SET_CHARS[];
+ const static FX_CHAR TEXT_SHIFT3_SET_CHARS[];
+ const static int32_t PAD_ENCODE;
+ const static int32_t ASCII_ENCODE;
+ const static int32_t C40_ENCODE;
+ const static int32_t TEXT_ENCODE;
+ const static int32_t ANSIX12_ENCODE;
+ const static int32_t EDIFACT_ENCODE;
+ const static int32_t BASE256_ENCODE;
};
#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp index 8dfdea81c1..d0fe37f167 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp @@ -29,82 +29,87 @@ #include "BC_DataMatrixVersion.h"
#include "BC_DataMatrixDataBlock.h"
#include "BC_DataMatrixDecodedBitStreamParser.h"
-CBC_DataMatrixDecoder::CBC_DataMatrixDecoder()
-{
- m_rsDecoder = NULL;
+CBC_DataMatrixDecoder::CBC_DataMatrixDecoder() {
+ m_rsDecoder = NULL;
}
-void CBC_DataMatrixDecoder::Init()
-{
- m_rsDecoder = FX_NEW CBC_ReedSolomonDecoder(CBC_ReedSolomonGF256::DataMatrixField);
+void CBC_DataMatrixDecoder::Init() {
+ m_rsDecoder =
+ FX_NEW CBC_ReedSolomonDecoder(CBC_ReedSolomonGF256::DataMatrixField);
}
-CBC_DataMatrixDecoder::~CBC_DataMatrixDecoder()
-{
- if(m_rsDecoder != NULL) {
- delete m_rsDecoder;
- }
- m_rsDecoder = NULL;
+CBC_DataMatrixDecoder::~CBC_DataMatrixDecoder() {
+ if (m_rsDecoder != NULL) {
+ delete m_rsDecoder;
+ }
+ m_rsDecoder = NULL;
}
-CBC_CommonDecoderResult *CBC_DataMatrixDecoder::Decode(CBC_CommonBitMatrix *bits, int32_t &e)
-{
- CBC_DataMatrixBitMatrixParser parser;
- parser.Init(bits, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- CBC_DataMatrixVersion *version = parser.GetVersion();
- CFX_ByteArray* byteTemp = parser.ReadCodewords(e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- CBC_AutoPtr<CFX_ByteArray> codewords(byteTemp);
- CFX_PtrArray *dataBlocks = CBC_DataMatrixDataBlock::GetDataBlocks(codewords.get(), version, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- int32_t dataBlocksCount = dataBlocks->GetSize();
- int32_t totalBytes = 0;
- int32_t i, j;
- for (i = 0; i < dataBlocksCount; i++) {
- totalBytes += ((CBC_DataMatrixDataBlock*)(*dataBlocks)[i])->GetNumDataCodewords();
- }
- CFX_ByteArray resultBytes;
- resultBytes.SetSize(totalBytes);
- for (j = 0; j < dataBlocksCount; j++) {
- CFX_ByteArray *codewordBytes = ((CBC_DataMatrixDataBlock*)(*dataBlocks)[j])->GetCodewords();
- int32_t numDataCodewords = ((CBC_DataMatrixDataBlock*)(*dataBlocks)[j])->GetNumDataCodewords();
- CorrectErrors(*codewordBytes, numDataCodewords, e);
- if (e != BCExceptionNO) {
- for(int32_t i = 0; i < dataBlocks->GetSize(); i++) {
- delete (CBC_DataMatrixDataBlock*)(*dataBlocks)[i];
- }
- delete dataBlocks;
- dataBlocks = NULL;
- return NULL;
- }
- int32_t i;
- for (i = 0; i < numDataCodewords; i++) {
- resultBytes[i * dataBlocksCount + j] = (*codewordBytes)[i];
- }
- }
- for(i = 0; i < (dataBlocks->GetSize()); i++) {
+CBC_CommonDecoderResult* CBC_DataMatrixDecoder::Decode(
+ CBC_CommonBitMatrix* bits,
+ int32_t& e) {
+ CBC_DataMatrixBitMatrixParser parser;
+ parser.Init(bits, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_DataMatrixVersion* version = parser.GetVersion();
+ CFX_ByteArray* byteTemp = parser.ReadCodewords(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CFX_ByteArray> codewords(byteTemp);
+ CFX_PtrArray* dataBlocks =
+ CBC_DataMatrixDataBlock::GetDataBlocks(codewords.get(), version, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ int32_t dataBlocksCount = dataBlocks->GetSize();
+ int32_t totalBytes = 0;
+ int32_t i, j;
+ for (i = 0; i < dataBlocksCount; i++) {
+ totalBytes +=
+ ((CBC_DataMatrixDataBlock*)(*dataBlocks)[i])->GetNumDataCodewords();
+ }
+ CFX_ByteArray resultBytes;
+ resultBytes.SetSize(totalBytes);
+ for (j = 0; j < dataBlocksCount; j++) {
+ CFX_ByteArray* codewordBytes =
+ ((CBC_DataMatrixDataBlock*)(*dataBlocks)[j])->GetCodewords();
+ int32_t numDataCodewords =
+ ((CBC_DataMatrixDataBlock*)(*dataBlocks)[j])->GetNumDataCodewords();
+ CorrectErrors(*codewordBytes, numDataCodewords, e);
+ if (e != BCExceptionNO) {
+ for (int32_t i = 0; i < dataBlocks->GetSize(); i++) {
delete (CBC_DataMatrixDataBlock*)(*dataBlocks)[i];
+ }
+ delete dataBlocks;
+ dataBlocks = NULL;
+ return NULL;
}
- delete dataBlocks;
- dataBlocks = NULL;
- CBC_CommonDecoderResult *resultR = CBC_DataMatrixDecodedBitStreamParser::Decode(resultBytes, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- return resultR;
-}
-void CBC_DataMatrixDecoder::CorrectErrors(CFX_ByteArray &codewordBytes, int32_t numDataCodewords, int32_t &e)
-{
- int32_t numCodewords = codewordBytes.GetSize();
- CFX_Int32Array codewordsInts;
- codewordsInts.SetSize(numCodewords);
int32_t i;
- for (i = 0; i < numCodewords; i++) {
- codewordsInts[i] = codewordBytes[i] & 0xFF;
- }
- int32_t numECCodewords = codewordBytes.GetSize() - numDataCodewords;
- m_rsDecoder->Decode(&codewordsInts, numECCodewords, e);
- if (e != BCExceptionNO) {
- e = BCExceptionChecksumException;
- return ;
- }
for (i = 0; i < numDataCodewords; i++) {
- codewordBytes[i] = (uint8_t) codewordsInts[i];
+ resultBytes[i * dataBlocksCount + j] = (*codewordBytes)[i];
}
+ }
+ for (i = 0; i < (dataBlocks->GetSize()); i++) {
+ delete (CBC_DataMatrixDataBlock*)(*dataBlocks)[i];
+ }
+ delete dataBlocks;
+ dataBlocks = NULL;
+ CBC_CommonDecoderResult* resultR =
+ CBC_DataMatrixDecodedBitStreamParser::Decode(resultBytes, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return resultR;
+}
+void CBC_DataMatrixDecoder::CorrectErrors(CFX_ByteArray& codewordBytes,
+ int32_t numDataCodewords,
+ int32_t& e) {
+ int32_t numCodewords = codewordBytes.GetSize();
+ CFX_Int32Array codewordsInts;
+ codewordsInts.SetSize(numCodewords);
+ int32_t i;
+ for (i = 0; i < numCodewords; i++) {
+ codewordsInts[i] = codewordBytes[i] & 0xFF;
+ }
+ int32_t numECCodewords = codewordBytes.GetSize() - numDataCodewords;
+ m_rsDecoder->Decode(&codewordsInts, numECCodewords, e);
+ if (e != BCExceptionNO) {
+ e = BCExceptionChecksumException;
+ return;
+ }
+ for (i = 0; i < numDataCodewords; i++) {
+ codewordBytes[i] = (uint8_t)codewordsInts[i];
+ }
}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecoder.h b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecoder.h index d4d2cc7bb9..31311b597b 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecoder.h +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecoder.h @@ -9,15 +9,17 @@ class CBC_ReedSolomonDecoder;
class CBC_CommonDecoderResult;
class CBC_CommonBitMatrix;
-class CBC_DataMatrixDecoder
-{
-public:
- CBC_DataMatrixDecoder();
- virtual ~CBC_DataMatrixDecoder();
- CBC_CommonDecoderResult *Decode(CBC_CommonBitMatrix *bits, int32_t &e);
- virtual void Init();
-private:
- void CorrectErrors(CFX_ByteArray &codewordBytes, int32_t numDataCodewords, int32_t &e);
- CBC_ReedSolomonDecoder *m_rsDecoder;
+class CBC_DataMatrixDecoder {
+ public:
+ CBC_DataMatrixDecoder();
+ virtual ~CBC_DataMatrixDecoder();
+ CBC_CommonDecoderResult* Decode(CBC_CommonBitMatrix* bits, int32_t& e);
+ virtual void Init();
+
+ private:
+ void CorrectErrors(CFX_ByteArray& codewordBytes,
+ int32_t numDataCodewords,
+ int32_t& e);
+ CBC_ReedSolomonDecoder* m_rsDecoder;
};
#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp index 5a4a2066fc..2dce972f9e 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp @@ -29,340 +29,376 @@ #include "../qrcode/BC_QRGridSampler.h"
#include "BC_DataMatrixDetector.h"
const int32_t CBC_DataMatrixDetector::INTEGERS[5] = {0, 1, 2, 3, 4};
-CBC_DataMatrixDetector::CBC_DataMatrixDetector(CBC_CommonBitMatrix *image):
- m_image(image), m_rectangleDetector(NULL)
-{
+CBC_DataMatrixDetector::CBC_DataMatrixDetector(CBC_CommonBitMatrix* image)
+ : m_image(image), m_rectangleDetector(NULL) {}
+void CBC_DataMatrixDetector::Init(int32_t& e) {
+ m_rectangleDetector = FX_NEW CBC_WhiteRectangleDetector(m_image);
+ m_rectangleDetector->Init(e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
}
-void CBC_DataMatrixDetector::Init(int32_t &e)
-{
- m_rectangleDetector = FX_NEW CBC_WhiteRectangleDetector(m_image);
- m_rectangleDetector->Init(e);
- BC_EXCEPTION_CHECK_ReturnVoid(e);
+CBC_DataMatrixDetector::~CBC_DataMatrixDetector() {
+ if (m_rectangleDetector != NULL) {
+ delete m_rectangleDetector;
+ }
+ m_rectangleDetector = NULL;
}
-CBC_DataMatrixDetector::~CBC_DataMatrixDetector()
-{
- if(m_rectangleDetector != NULL) {
- delete m_rectangleDetector;
- }
- m_rectangleDetector = NULL;
-}
-inline FX_BOOL ResultPointsAndTransitionsComparator(void* a, void* b)
-{
- return ((CBC_ResultPointsAndTransitions *)b)->GetTransitions() > ((CBC_ResultPointsAndTransitions *)a)->GetTransitions();
+inline FX_BOOL ResultPointsAndTransitionsComparator(void* a, void* b) {
+ return ((CBC_ResultPointsAndTransitions*)b)->GetTransitions() >
+ ((CBC_ResultPointsAndTransitions*)a)->GetTransitions();
}
-CBC_QRDetectorResult *CBC_DataMatrixDetector::Detect(int32_t &e)
-{
- CFX_PtrArray* cornerPoints = m_rectangleDetector->Detect(e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- CBC_ResultPoint *pointA = (CBC_ResultPoint*)(*cornerPoints)[0];
- CBC_ResultPoint *pointB = (CBC_ResultPoint*)(*cornerPoints)[1];
- CBC_ResultPoint *pointC = (CBC_ResultPoint*)(*cornerPoints)[2];
- CBC_ResultPoint *pointD = (CBC_ResultPoint*)(*cornerPoints)[3];
- delete cornerPoints;
- cornerPoints = NULL;
- CFX_PtrArray transitions;
- transitions.Add(TransitionsBetween(pointA, pointB));
- transitions.Add(TransitionsBetween(pointA, pointC));
- transitions.Add(TransitionsBetween(pointB, pointD));
- transitions.Add(TransitionsBetween(pointC, pointD));
- BC_FX_PtrArray_Sort(transitions, &ResultPointsAndTransitionsComparator);
- delete ( (CBC_ResultPointsAndTransitions *)transitions[2] );
- delete ( (CBC_ResultPointsAndTransitions *)transitions[3] );
- CBC_ResultPointsAndTransitions *lSideOne = (CBC_ResultPointsAndTransitions*)transitions[0];
- CBC_ResultPointsAndTransitions *lSideTwo = (CBC_ResultPointsAndTransitions*)transitions[1];
- CFX_MapPtrTemplate<CBC_ResultPoint*, int32_t> pointCount;
- Increment(pointCount, lSideOne->GetFrom());
- Increment(pointCount, lSideOne->GetTo());
- Increment(pointCount, lSideTwo->GetFrom());
- Increment(pointCount, lSideTwo->GetTo());
- delete ( (CBC_ResultPointsAndTransitions *)transitions[1] );
- delete ( (CBC_ResultPointsAndTransitions *)transitions[0] );
- transitions.RemoveAll();
- CBC_ResultPoint *maybeTopLeft = NULL;
- CBC_ResultPoint *bottomLeft = NULL;
- CBC_ResultPoint *maybeBottomRight = NULL;
- FX_POSITION itBegin = pointCount.GetStartPosition();
- while(itBegin != NULL) {
- CBC_ResultPoint *key = 0;
- int32_t value = 0;
- pointCount.GetNextAssoc(itBegin, key, value);
- if(value == 2) {
- bottomLeft = key;
- } else {
- if (maybeBottomRight == NULL) {
- maybeBottomRight = key;
- } else {
- maybeTopLeft = key;
- }
- }
- }
- if (maybeTopLeft == NULL || bottomLeft == NULL || maybeBottomRight == NULL) {
- delete pointA;
- delete pointB;
- delete pointC;
- delete pointD;
- e = BCExceptionNotFound;
- return NULL;
+CBC_QRDetectorResult* CBC_DataMatrixDetector::Detect(int32_t& e) {
+ CFX_PtrArray* cornerPoints = m_rectangleDetector->Detect(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_ResultPoint* pointA = (CBC_ResultPoint*)(*cornerPoints)[0];
+ CBC_ResultPoint* pointB = (CBC_ResultPoint*)(*cornerPoints)[1];
+ CBC_ResultPoint* pointC = (CBC_ResultPoint*)(*cornerPoints)[2];
+ CBC_ResultPoint* pointD = (CBC_ResultPoint*)(*cornerPoints)[3];
+ delete cornerPoints;
+ cornerPoints = NULL;
+ CFX_PtrArray transitions;
+ transitions.Add(TransitionsBetween(pointA, pointB));
+ transitions.Add(TransitionsBetween(pointA, pointC));
+ transitions.Add(TransitionsBetween(pointB, pointD));
+ transitions.Add(TransitionsBetween(pointC, pointD));
+ BC_FX_PtrArray_Sort(transitions, &ResultPointsAndTransitionsComparator);
+ delete ((CBC_ResultPointsAndTransitions*)transitions[2]);
+ delete ((CBC_ResultPointsAndTransitions*)transitions[3]);
+ CBC_ResultPointsAndTransitions* lSideOne =
+ (CBC_ResultPointsAndTransitions*)transitions[0];
+ CBC_ResultPointsAndTransitions* lSideTwo =
+ (CBC_ResultPointsAndTransitions*)transitions[1];
+ CFX_MapPtrTemplate<CBC_ResultPoint*, int32_t> pointCount;
+ Increment(pointCount, lSideOne->GetFrom());
+ Increment(pointCount, lSideOne->GetTo());
+ Increment(pointCount, lSideTwo->GetFrom());
+ Increment(pointCount, lSideTwo->GetTo());
+ delete ((CBC_ResultPointsAndTransitions*)transitions[1]);
+ delete ((CBC_ResultPointsAndTransitions*)transitions[0]);
+ transitions.RemoveAll();
+ CBC_ResultPoint* maybeTopLeft = NULL;
+ CBC_ResultPoint* bottomLeft = NULL;
+ CBC_ResultPoint* maybeBottomRight = NULL;
+ FX_POSITION itBegin = pointCount.GetStartPosition();
+ while (itBegin != NULL) {
+ CBC_ResultPoint* key = 0;
+ int32_t value = 0;
+ pointCount.GetNextAssoc(itBegin, key, value);
+ if (value == 2) {
+ bottomLeft = key;
+ } else {
+ if (maybeBottomRight == NULL) {
+ maybeBottomRight = key;
+ } else {
+ maybeTopLeft = key;
+ }
}
- CFX_PtrArray corners;
- corners.SetSize(3);
- corners[0] = maybeTopLeft;
- corners[1] = bottomLeft;
- corners[2] = maybeBottomRight;
- OrderBestPatterns(&corners);
- CBC_ResultPoint *bottomRight = (CBC_ResultPoint*)corners[0];
- bottomLeft = (CBC_ResultPoint*)corners[1];
- CBC_ResultPoint *topLeft = (CBC_ResultPoint*)corners[2];
- CBC_ResultPoint *topRight = NULL;
- int32_t value;
- if (!pointCount.Lookup(pointA, value)) {
- topRight = pointA;
- } else if (!pointCount.Lookup(pointB, value)) {
- topRight = pointB;
- } else if (!pointCount.Lookup(pointC, value)) {
- topRight = pointC;
+ }
+ if (maybeTopLeft == NULL || bottomLeft == NULL || maybeBottomRight == NULL) {
+ delete pointA;
+ delete pointB;
+ delete pointC;
+ delete pointD;
+ e = BCExceptionNotFound;
+ return NULL;
+ }
+ CFX_PtrArray corners;
+ corners.SetSize(3);
+ corners[0] = maybeTopLeft;
+ corners[1] = bottomLeft;
+ corners[2] = maybeBottomRight;
+ OrderBestPatterns(&corners);
+ CBC_ResultPoint* bottomRight = (CBC_ResultPoint*)corners[0];
+ bottomLeft = (CBC_ResultPoint*)corners[1];
+ CBC_ResultPoint* topLeft = (CBC_ResultPoint*)corners[2];
+ CBC_ResultPoint* topRight = NULL;
+ int32_t value;
+ if (!pointCount.Lookup(pointA, value)) {
+ topRight = pointA;
+ } else if (!pointCount.Lookup(pointB, value)) {
+ topRight = pointB;
+ } else if (!pointCount.Lookup(pointC, value)) {
+ topRight = pointC;
+ } else {
+ topRight = pointD;
+ }
+ int32_t dimensionTop = CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
+ TransitionsBetween(topLeft, topRight))
+ ->GetTransitions();
+ int32_t dimensionRight = CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
+ TransitionsBetween(bottomRight, topRight))
+ ->GetTransitions();
+ if ((dimensionTop & 0x01) == 1) {
+ dimensionTop++;
+ }
+ dimensionTop += 2;
+ if ((dimensionRight & 0x01) == 1) {
+ dimensionRight++;
+ }
+ dimensionRight += 2;
+ CBC_AutoPtr<CBC_CommonBitMatrix> bits(NULL);
+ CBC_AutoPtr<CBC_ResultPoint> correctedTopRight(NULL);
+ if (4 * dimensionTop >= 7 * dimensionRight ||
+ 4 * dimensionRight >= 7 * dimensionTop) {
+ correctedTopRight = CBC_AutoPtr<CBC_ResultPoint>(
+ CorrectTopRightRectangular(bottomLeft, bottomRight, topLeft, topRight,
+ dimensionTop, dimensionRight));
+ if (correctedTopRight.get() == NULL) {
+ correctedTopRight = CBC_AutoPtr<CBC_ResultPoint>(topRight);
} else {
- topRight = pointD;
+ delete topRight;
+ topRight = NULL;
}
- int32_t dimensionTop = CBC_AutoPtr<CBC_ResultPointsAndTransitions>(TransitionsBetween(topLeft, topRight))->GetTransitions();
- int32_t dimensionRight = CBC_AutoPtr<CBC_ResultPointsAndTransitions>(TransitionsBetween(bottomRight, topRight))->GetTransitions();
+ dimensionTop = CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
+ TransitionsBetween(topLeft, correctedTopRight.get()))
+ ->GetTransitions();
+ dimensionRight =
+ CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
+ TransitionsBetween(bottomRight, correctedTopRight.get()))
+ ->GetTransitions();
if ((dimensionTop & 0x01) == 1) {
- dimensionTop++;
+ dimensionTop++;
}
- dimensionTop += 2;
if ((dimensionRight & 0x01) == 1) {
- dimensionRight++;
+ dimensionRight++;
}
- dimensionRight += 2;
- CBC_AutoPtr<CBC_CommonBitMatrix> bits(NULL);
- CBC_AutoPtr<CBC_ResultPoint> correctedTopRight(NULL);
- if (4 * dimensionTop >= 7 * dimensionRight || 4 * dimensionRight >= 7 * dimensionTop) {
- correctedTopRight =
- CBC_AutoPtr<CBC_ResultPoint>(CorrectTopRightRectangular(bottomLeft, bottomRight, topLeft, topRight,
- dimensionTop, dimensionRight));
- if (correctedTopRight.get() == NULL) {
- correctedTopRight = CBC_AutoPtr<CBC_ResultPoint>(topRight);
- } else {
- delete topRight;
- topRight = NULL;
- }
- dimensionTop = CBC_AutoPtr<CBC_ResultPointsAndTransitions>(TransitionsBetween(topLeft, correctedTopRight.get()))->GetTransitions();
- dimensionRight = CBC_AutoPtr<CBC_ResultPointsAndTransitions>(TransitionsBetween(bottomRight, correctedTopRight.get()))->GetTransitions();
- if ((dimensionTop & 0x01) == 1) {
- dimensionTop++;
- }
- if ((dimensionRight & 0x01) == 1) {
- dimensionRight++;
- }
- bits = CBC_AutoPtr<CBC_CommonBitMatrix>(SampleGrid(m_image, topLeft, bottomLeft, bottomRight,
- correctedTopRight.get(), dimensionTop, dimensionRight, e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ bits = CBC_AutoPtr<CBC_CommonBitMatrix>(
+ SampleGrid(m_image, topLeft, bottomLeft, bottomRight,
+ correctedTopRight.get(), dimensionTop, dimensionRight, e));
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ } else {
+ int32_t dimension = FX_MIN(dimensionRight, dimensionTop);
+ correctedTopRight = CBC_AutoPtr<CBC_ResultPoint>(
+ CorrectTopRight(bottomLeft, bottomRight, topLeft, topRight, dimension));
+ if (correctedTopRight.get() == NULL) {
+ correctedTopRight = CBC_AutoPtr<CBC_ResultPoint>(topRight);
} else {
- int32_t dimension = FX_MIN(dimensionRight, dimensionTop);
- correctedTopRight = CBC_AutoPtr<CBC_ResultPoint>(CorrectTopRight(bottomLeft, bottomRight,
- topLeft, topRight, dimension));
- if (correctedTopRight.get() == NULL) {
- correctedTopRight = CBC_AutoPtr<CBC_ResultPoint>(topRight);
- } else {
- delete topRight;
- topRight = NULL;
- }
- int32_t dimensionCorrected = FX_MAX(CBC_AutoPtr<CBC_ResultPointsAndTransitions>(TransitionsBetween(topLeft, correctedTopRight.get()))->GetTransitions(),
- CBC_AutoPtr<CBC_ResultPointsAndTransitions>(TransitionsBetween(bottomRight, correctedTopRight.get()))->GetTransitions());
- dimensionCorrected++;
- if ((dimensionCorrected & 0x01) == 1) {
- dimensionCorrected++;
- }
- bits = CBC_AutoPtr<CBC_CommonBitMatrix>(SampleGrid(m_image,
- topLeft,
- bottomLeft,
- bottomRight,
- correctedTopRight.get(),
- dimensionCorrected,
- dimensionCorrected, e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ delete topRight;
+ topRight = NULL;
}
- CFX_PtrArray *result = FX_NEW CFX_PtrArray;
- result->SetSize(4);
- result->Add(topLeft);
- result->Add(bottomLeft);
- result->Add(bottomRight);
- result->Add(correctedTopRight.release());
- return FX_NEW CBC_QRDetectorResult(bits.release(), result);
-}
-CBC_ResultPoint *CBC_DataMatrixDetector::CorrectTopRightRectangular(CBC_ResultPoint *bottomLeft, CBC_ResultPoint *bottomRight, CBC_ResultPoint *topLeft, CBC_ResultPoint *topRight, int32_t dimensionTop, int32_t dimensionRight)
-{
- FX_FLOAT corr = Distance(bottomLeft, bottomRight) / (FX_FLOAT)dimensionTop;
- int32_t norm = Distance(topLeft, topRight);
- FX_FLOAT cos = (topRight->GetX() - topLeft->GetX()) / norm;
- FX_FLOAT sin = (topRight->GetY() - topLeft->GetY()) / norm;
- CBC_AutoPtr<CBC_ResultPoint> c1(FX_NEW CBC_ResultPoint(topRight->GetX() + corr * cos, topRight->GetY() + corr * sin));
- corr = Distance(bottomLeft, topLeft) / (FX_FLOAT)dimensionRight;
- norm = Distance(bottomRight, topRight);
- cos = (topRight->GetX() - bottomRight->GetX()) / norm;
- sin = (topRight->GetY() - bottomRight->GetY()) / norm;
- CBC_AutoPtr<CBC_ResultPoint> c2(FX_NEW CBC_ResultPoint(topRight->GetX() + corr * cos, topRight->GetY() + corr * sin));
- if (!IsValid(c1.get())) {
- if (IsValid(c2.get())) {
- return c2.release();
- }
- return NULL;
- } else if (!IsValid(c2.get())) {
- return c1.release();
+ int32_t dimensionCorrected =
+ FX_MAX(CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
+ TransitionsBetween(topLeft, correctedTopRight.get()))
+ ->GetTransitions(),
+ CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
+ TransitionsBetween(bottomRight, correctedTopRight.get()))
+ ->GetTransitions());
+ dimensionCorrected++;
+ if ((dimensionCorrected & 0x01) == 1) {
+ dimensionCorrected++;
}
- int32_t l1 = FXSYS_abs(dimensionTop - CBC_AutoPtr<CBC_ResultPointsAndTransitions>(TransitionsBetween(topLeft, c1.get()))->GetTransitions()) +
- FXSYS_abs(dimensionRight - CBC_AutoPtr<CBC_ResultPointsAndTransitions>(TransitionsBetween(bottomRight, c1.get()))->GetTransitions());
- int32_t l2 = FXSYS_abs(dimensionTop - CBC_AutoPtr<CBC_ResultPointsAndTransitions>(TransitionsBetween(topLeft, c2.get()))->GetTransitions()) +
- FXSYS_abs(dimensionRight - CBC_AutoPtr<CBC_ResultPointsAndTransitions>(TransitionsBetween(bottomRight, c2.get()))->GetTransitions());
- if (l1 <= l2) {
- return c1.release();
+ bits = CBC_AutoPtr<CBC_CommonBitMatrix>(SampleGrid(
+ m_image, topLeft, bottomLeft, bottomRight, correctedTopRight.get(),
+ dimensionCorrected, dimensionCorrected, e));
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ }
+ CFX_PtrArray* result = FX_NEW CFX_PtrArray;
+ result->SetSize(4);
+ result->Add(topLeft);
+ result->Add(bottomLeft);
+ result->Add(bottomRight);
+ result->Add(correctedTopRight.release());
+ return FX_NEW CBC_QRDetectorResult(bits.release(), result);
+}
+CBC_ResultPoint* CBC_DataMatrixDetector::CorrectTopRightRectangular(
+ CBC_ResultPoint* bottomLeft,
+ CBC_ResultPoint* bottomRight,
+ CBC_ResultPoint* topLeft,
+ CBC_ResultPoint* topRight,
+ int32_t dimensionTop,
+ int32_t dimensionRight) {
+ FX_FLOAT corr = Distance(bottomLeft, bottomRight) / (FX_FLOAT)dimensionTop;
+ int32_t norm = Distance(topLeft, topRight);
+ FX_FLOAT cos = (topRight->GetX() - topLeft->GetX()) / norm;
+ FX_FLOAT sin = (topRight->GetY() - topLeft->GetY()) / norm;
+ CBC_AutoPtr<CBC_ResultPoint> c1(FX_NEW CBC_ResultPoint(
+ topRight->GetX() + corr * cos, topRight->GetY() + corr * sin));
+ corr = Distance(bottomLeft, topLeft) / (FX_FLOAT)dimensionRight;
+ norm = Distance(bottomRight, topRight);
+ cos = (topRight->GetX() - bottomRight->GetX()) / norm;
+ sin = (topRight->GetY() - bottomRight->GetY()) / norm;
+ CBC_AutoPtr<CBC_ResultPoint> c2(FX_NEW CBC_ResultPoint(
+ topRight->GetX() + corr * cos, topRight->GetY() + corr * sin));
+ if (!IsValid(c1.get())) {
+ if (IsValid(c2.get())) {
+ return c2.release();
}
- return c2.release();
+ return NULL;
+ } else if (!IsValid(c2.get())) {
+ return c1.release();
+ }
+ int32_t l1 = FXSYS_abs(dimensionTop -
+ CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
+ TransitionsBetween(topLeft, c1.get()))
+ ->GetTransitions()) +
+ FXSYS_abs(dimensionRight -
+ CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
+ TransitionsBetween(bottomRight, c1.get()))
+ ->GetTransitions());
+ int32_t l2 = FXSYS_abs(dimensionTop -
+ CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
+ TransitionsBetween(topLeft, c2.get()))
+ ->GetTransitions()) +
+ FXSYS_abs(dimensionRight -
+ CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
+ TransitionsBetween(bottomRight, c2.get()))
+ ->GetTransitions());
+ if (l1 <= l2) {
+ return c1.release();
+ }
+ return c2.release();
}
-CBC_ResultPoint *CBC_DataMatrixDetector::CorrectTopRight(CBC_ResultPoint *bottomLeft, CBC_ResultPoint *bottomRight, CBC_ResultPoint *topLeft, CBC_ResultPoint *topRight, int32_t dimension)
-{
- FX_FLOAT corr = Distance(bottomLeft, bottomRight) / (FX_FLOAT) dimension;
- int32_t norm = Distance(topLeft, topRight);
- FX_FLOAT cos = (topRight->GetX() - topLeft->GetX()) / norm;
- FX_FLOAT sin = (topRight->GetY() - topLeft->GetY()) / norm;
- CBC_AutoPtr<CBC_ResultPoint> c1(FX_NEW CBC_ResultPoint(topRight->GetX() + corr * cos, topRight->GetY() + corr * sin));
- corr = Distance(bottomLeft, bottomRight) / (FX_FLOAT) dimension;
- norm = Distance(bottomRight, topRight);
- cos = (topRight->GetX() - bottomRight->GetX()) / norm;
- sin = (topRight->GetY() - bottomRight->GetY()) / norm;
- CBC_AutoPtr<CBC_ResultPoint> c2(FX_NEW CBC_ResultPoint(topRight->GetX() + corr * cos, topRight->GetY() + corr * sin));
- if (!IsValid(c1.get())) {
- if (IsValid(c2.get())) {
- return c2.release();
- }
- return NULL;
- } else if (!IsValid(c2.get())) {
- return c1.release();
+CBC_ResultPoint* CBC_DataMatrixDetector::CorrectTopRight(
+ CBC_ResultPoint* bottomLeft,
+ CBC_ResultPoint* bottomRight,
+ CBC_ResultPoint* topLeft,
+ CBC_ResultPoint* topRight,
+ int32_t dimension) {
+ FX_FLOAT corr = Distance(bottomLeft, bottomRight) / (FX_FLOAT)dimension;
+ int32_t norm = Distance(topLeft, topRight);
+ FX_FLOAT cos = (topRight->GetX() - topLeft->GetX()) / norm;
+ FX_FLOAT sin = (topRight->GetY() - topLeft->GetY()) / norm;
+ CBC_AutoPtr<CBC_ResultPoint> c1(FX_NEW CBC_ResultPoint(
+ topRight->GetX() + corr * cos, topRight->GetY() + corr * sin));
+ corr = Distance(bottomLeft, bottomRight) / (FX_FLOAT)dimension;
+ norm = Distance(bottomRight, topRight);
+ cos = (topRight->GetX() - bottomRight->GetX()) / norm;
+ sin = (topRight->GetY() - bottomRight->GetY()) / norm;
+ CBC_AutoPtr<CBC_ResultPoint> c2(FX_NEW CBC_ResultPoint(
+ topRight->GetX() + corr * cos, topRight->GetY() + corr * sin));
+ if (!IsValid(c1.get())) {
+ if (IsValid(c2.get())) {
+ return c2.release();
}
- int32_t l1 = FXSYS_abs(CBC_AutoPtr<CBC_ResultPointsAndTransitions>(TransitionsBetween(topLeft, c1.get()))->GetTransitions() -
- CBC_AutoPtr<CBC_ResultPointsAndTransitions>(TransitionsBetween(bottomRight, c1.get()))->GetTransitions());
- int32_t l2 = FXSYS_abs(CBC_AutoPtr<CBC_ResultPointsAndTransitions>(TransitionsBetween(topLeft, c2.get()))->GetTransitions() -
- CBC_AutoPtr<CBC_ResultPointsAndTransitions>(TransitionsBetween(bottomRight, c2.get()))->GetTransitions());
- return l1 <= l2 ? c1.release() : c2.release();
+ return NULL;
+ } else if (!IsValid(c2.get())) {
+ return c1.release();
+ }
+ int32_t l1 = FXSYS_abs(CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
+ TransitionsBetween(topLeft, c1.get()))
+ ->GetTransitions() -
+ CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
+ TransitionsBetween(bottomRight, c1.get()))
+ ->GetTransitions());
+ int32_t l2 = FXSYS_abs(CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
+ TransitionsBetween(topLeft, c2.get()))
+ ->GetTransitions() -
+ CBC_AutoPtr<CBC_ResultPointsAndTransitions>(
+ TransitionsBetween(bottomRight, c2.get()))
+ ->GetTransitions());
+ return l1 <= l2 ? c1.release() : c2.release();
}
-FX_BOOL CBC_DataMatrixDetector::IsValid(CBC_ResultPoint *p)
-{
- return p->GetX() >= 0 && p->GetX() < m_image->GetWidth() && p->GetY() > 0 && p->GetY() < m_image->GetHeight();
+FX_BOOL CBC_DataMatrixDetector::IsValid(CBC_ResultPoint* p) {
+ return p->GetX() >= 0 && p->GetX() < m_image->GetWidth() && p->GetY() > 0 &&
+ p->GetY() < m_image->GetHeight();
}
-int32_t CBC_DataMatrixDetector::Round(FX_FLOAT d)
-{
- return (int32_t) (d + 0.5f);
+int32_t CBC_DataMatrixDetector::Round(FX_FLOAT d) {
+ return (int32_t)(d + 0.5f);
}
-int32_t CBC_DataMatrixDetector::Distance(CBC_ResultPoint *a, CBC_ResultPoint *b)
-{
- return Round((FX_FLOAT) sqrt((a->GetX() - b->GetX())
- * (a->GetX() - b->GetX()) + (a->GetY() - b->GetY())
- * (a->GetY() - b->GetY())));
+int32_t CBC_DataMatrixDetector::Distance(CBC_ResultPoint* a,
+ CBC_ResultPoint* b) {
+ return Round(
+ (FX_FLOAT)sqrt((a->GetX() - b->GetX()) * (a->GetX() - b->GetX()) +
+ (a->GetY() - b->GetY()) * (a->GetY() - b->GetY())));
}
-void CBC_DataMatrixDetector::Increment(CFX_MapPtrTemplate<CBC_ResultPoint*, int32_t> &table, CBC_ResultPoint *key)
-{
- int32_t value;
- if(table.Lookup(key, value)) {
- table.SetAt(key, INTEGERS[value + 1]);
- } else {
- table.SetAt(key, INTEGERS[1]);
- }
+void CBC_DataMatrixDetector::Increment(
+ CFX_MapPtrTemplate<CBC_ResultPoint*, int32_t>& table,
+ CBC_ResultPoint* key) {
+ int32_t value;
+ if (table.Lookup(key, value)) {
+ table.SetAt(key, INTEGERS[value + 1]);
+ } else {
+ table.SetAt(key, INTEGERS[1]);
+ }
}
-CBC_CommonBitMatrix *CBC_DataMatrixDetector::SampleGrid(CBC_CommonBitMatrix *image,
- CBC_ResultPoint *topLeft,
- CBC_ResultPoint *bottomLeft,
- CBC_ResultPoint *bottomRight,
- CBC_ResultPoint *topRight,
- int32_t dimensionX, int32_t dimensionY, int32_t &e)
-{
- CBC_QRGridSampler &sampler = CBC_QRGridSampler::GetInstance();
- CBC_CommonBitMatrix* cbm = sampler.SampleGrid(image,
- dimensionX,
- dimensionY,
- 0.5f,
- 0.5f,
- dimensionX - 0.5f,
- 0.5f,
- dimensionX - 0.5f,
- dimensionY - 0.5f,
- 0.5f,
- dimensionY - 0.5f,
- topLeft->GetX(),
- topLeft->GetY(),
- topRight->GetX(),
- topRight->GetY(),
- bottomRight->GetX(),
- bottomRight->GetY(),
- bottomLeft->GetX(),
- bottomLeft->GetY(), e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- return cbm;
+CBC_CommonBitMatrix* CBC_DataMatrixDetector::SampleGrid(
+ CBC_CommonBitMatrix* image,
+ CBC_ResultPoint* topLeft,
+ CBC_ResultPoint* bottomLeft,
+ CBC_ResultPoint* bottomRight,
+ CBC_ResultPoint* topRight,
+ int32_t dimensionX,
+ int32_t dimensionY,
+ int32_t& e) {
+ CBC_QRGridSampler& sampler = CBC_QRGridSampler::GetInstance();
+ CBC_CommonBitMatrix* cbm = sampler.SampleGrid(
+ image, dimensionX, dimensionY, 0.5f, 0.5f, dimensionX - 0.5f, 0.5f,
+ dimensionX - 0.5f, dimensionY - 0.5f, 0.5f, dimensionY - 0.5f,
+ topLeft->GetX(), topLeft->GetY(), topRight->GetX(), topRight->GetY(),
+ bottomRight->GetX(), bottomRight->GetY(), bottomLeft->GetX(),
+ bottomLeft->GetY(), e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return cbm;
}
-CBC_ResultPointsAndTransitions *CBC_DataMatrixDetector::TransitionsBetween(CBC_ResultPoint *from, CBC_ResultPoint *to)
-{
- int32_t fromX = (int32_t) from->GetX();
- int32_t fromY = (int32_t) from->GetY();
- int32_t toX = (int32_t) to->GetX();
- int32_t toY = (int32_t) to->GetY();
- FX_BOOL steep = FXSYS_abs(toY - fromY) > FXSYS_abs(toX - fromX);
- if (steep) {
- int32_t temp = fromX;
- fromX = fromY;
- fromY = temp;
- temp = toX;
- toX = toY;
- toY = temp;
+CBC_ResultPointsAndTransitions* CBC_DataMatrixDetector::TransitionsBetween(
+ CBC_ResultPoint* from,
+ CBC_ResultPoint* to) {
+ int32_t fromX = (int32_t)from->GetX();
+ int32_t fromY = (int32_t)from->GetY();
+ int32_t toX = (int32_t)to->GetX();
+ int32_t toY = (int32_t)to->GetY();
+ FX_BOOL steep = FXSYS_abs(toY - fromY) > FXSYS_abs(toX - fromX);
+ if (steep) {
+ int32_t temp = fromX;
+ fromX = fromY;
+ fromY = temp;
+ temp = toX;
+ toX = toY;
+ toY = temp;
+ }
+ int32_t dx = FXSYS_abs(toX - fromX);
+ int32_t dy = FXSYS_abs(toY - fromY);
+ int32_t error = -dx >> 1;
+ int32_t ystep = fromY < toY ? 1 : -1;
+ int32_t xstep = fromX < toX ? 1 : -1;
+ int32_t transitions = 0;
+ FX_BOOL inBlack = m_image->Get(steep ? fromY : fromX, steep ? fromX : fromY);
+ for (int32_t x = fromX, y = fromY; x != toX; x += xstep) {
+ FX_BOOL isBlack = m_image->Get(steep ? y : x, steep ? x : y);
+ if (isBlack != inBlack) {
+ transitions++;
+ inBlack = isBlack;
}
- int32_t dx = FXSYS_abs(toX - fromX);
- int32_t dy = FXSYS_abs(toY - fromY);
- int32_t error = -dx >> 1;
- int32_t ystep = fromY < toY ? 1 : -1;
- int32_t xstep = fromX < toX ? 1 : -1;
- int32_t transitions = 0;
- FX_BOOL inBlack = m_image->Get(steep ? fromY : fromX, steep ? fromX : fromY);
- for (int32_t x = fromX, y = fromY; x != toX; x += xstep) {
- FX_BOOL isBlack = m_image->Get(steep ? y : x, steep ? x : y);
- if (isBlack != inBlack) {
- transitions++;
- inBlack = isBlack;
- }
- error += dy;
- if (error > 0) {
- if (y == toY) {
- break;
- }
- y += ystep;
- error -= dx;
- }
+ error += dy;
+ if (error > 0) {
+ if (y == toY) {
+ break;
+ }
+ y += ystep;
+ error -= dx;
}
- return FX_NEW CBC_ResultPointsAndTransitions(from, to, transitions);
+ }
+ return FX_NEW CBC_ResultPointsAndTransitions(from, to, transitions);
}
-void CBC_DataMatrixDetector::OrderBestPatterns(CFX_PtrArray *patterns)
-{
- FX_FLOAT abDistance = (FX_FLOAT)Distance((CBC_ResultPoint*)(*patterns)[0], (CBC_ResultPoint*)(*patterns)[1]);
- FX_FLOAT bcDistance = (FX_FLOAT)Distance((CBC_ResultPoint*)(*patterns)[1], (CBC_ResultPoint*)(*patterns)[2]);
- FX_FLOAT acDistance = (FX_FLOAT)Distance((CBC_ResultPoint*)(*patterns)[0], (CBC_ResultPoint*)(*patterns)[2]);
- CBC_ResultPoint *topLeft, *topRight, *bottomLeft;
- if (bcDistance >= abDistance && bcDistance >= acDistance) {
- topLeft = (CBC_ResultPoint*)(*patterns)[0];
- topRight = (CBC_ResultPoint*)(*patterns)[1];
- bottomLeft = (CBC_ResultPoint*)(*patterns)[2];
- } else if (acDistance >= bcDistance && acDistance >= abDistance) {
- topLeft = (CBC_ResultPoint*)(*patterns)[1];
- topRight = (CBC_ResultPoint*)(*patterns)[0];
- bottomLeft = (CBC_ResultPoint*)(*patterns)[2];
- } else {
- topLeft = (CBC_ResultPoint*)(*patterns)[2];
- topRight = (CBC_ResultPoint*)(*patterns)[0];
- bottomLeft = (CBC_ResultPoint*)(*patterns)[1];
- }
- if ((bottomLeft->GetY() - topLeft->GetY()) * (topRight->GetX() - topLeft->GetX()) < (bottomLeft->GetX()
- - topLeft->GetX()) * (topRight->GetY() - topLeft->GetY())) {
- CBC_ResultPoint *temp = topRight;
- topRight = bottomLeft;
- bottomLeft = temp;
- }
- (*patterns)[0] = bottomLeft;
- (*patterns)[1] = topLeft;
- (*patterns)[2] = topRight;
+void CBC_DataMatrixDetector::OrderBestPatterns(CFX_PtrArray* patterns) {
+ FX_FLOAT abDistance = (FX_FLOAT)Distance((CBC_ResultPoint*)(*patterns)[0],
+ (CBC_ResultPoint*)(*patterns)[1]);
+ FX_FLOAT bcDistance = (FX_FLOAT)Distance((CBC_ResultPoint*)(*patterns)[1],
+ (CBC_ResultPoint*)(*patterns)[2]);
+ FX_FLOAT acDistance = (FX_FLOAT)Distance((CBC_ResultPoint*)(*patterns)[0],
+ (CBC_ResultPoint*)(*patterns)[2]);
+ CBC_ResultPoint *topLeft, *topRight, *bottomLeft;
+ if (bcDistance >= abDistance && bcDistance >= acDistance) {
+ topLeft = (CBC_ResultPoint*)(*patterns)[0];
+ topRight = (CBC_ResultPoint*)(*patterns)[1];
+ bottomLeft = (CBC_ResultPoint*)(*patterns)[2];
+ } else if (acDistance >= bcDistance && acDistance >= abDistance) {
+ topLeft = (CBC_ResultPoint*)(*patterns)[1];
+ topRight = (CBC_ResultPoint*)(*patterns)[0];
+ bottomLeft = (CBC_ResultPoint*)(*patterns)[2];
+ } else {
+ topLeft = (CBC_ResultPoint*)(*patterns)[2];
+ topRight = (CBC_ResultPoint*)(*patterns)[0];
+ bottomLeft = (CBC_ResultPoint*)(*patterns)[1];
+ }
+ if ((bottomLeft->GetY() - topLeft->GetY()) *
+ (topRight->GetX() - topLeft->GetX()) <
+ (bottomLeft->GetX() - topLeft->GetX()) *
+ (topRight->GetY() - topLeft->GetY())) {
+ CBC_ResultPoint* temp = topRight;
+ topRight = bottomLeft;
+ bottomLeft = temp;
+ }
+ (*patterns)[0] = bottomLeft;
+ (*patterns)[1] = topLeft;
+ (*patterns)[2] = topRight;
}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.h b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.h index e36ef678cd..7cf32da700 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.h +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.h @@ -12,67 +12,62 @@ class CBC_ResultPoint; class CBC_QRDetectorResult;
class CBC_DataMatrixDetector;
class ResultPointsAndTransitions;
-class CBC_ResultPointsAndTransitions
-{
-public:
- CBC_ResultPointsAndTransitions(CBC_ResultPoint *from, CBC_ResultPoint *to, int32_t transitions)
- {
- m_from = from;
- m_to = to;
- m_transitions = transitions;
- }
- ~CBC_ResultPointsAndTransitions()
- {
- }
- CBC_ResultPoint *GetFrom()
- {
- return m_from;
- }
- CBC_ResultPoint *GetTo()
- {
- return m_to;
- }
- int32_t GetTransitions()
- {
- return m_transitions;
- }
-private:
- CBC_ResultPoint *m_from;
- CBC_ResultPoint *m_to;
- int32_t m_transitions;
+class CBC_ResultPointsAndTransitions {
+ public:
+ CBC_ResultPointsAndTransitions(CBC_ResultPoint* from,
+ CBC_ResultPoint* to,
+ int32_t transitions) {
+ m_from = from;
+ m_to = to;
+ m_transitions = transitions;
+ }
+ ~CBC_ResultPointsAndTransitions() {}
+ CBC_ResultPoint* GetFrom() { return m_from; }
+ CBC_ResultPoint* GetTo() { return m_to; }
+ int32_t GetTransitions() { return m_transitions; }
+
+ private:
+ CBC_ResultPoint* m_from;
+ CBC_ResultPoint* m_to;
+ int32_t m_transitions;
};
-class CBC_DataMatrixDetector
-{
-public:
- CBC_DataMatrixDetector(CBC_CommonBitMatrix *image);
- virtual ~CBC_DataMatrixDetector();
- CBC_QRDetectorResult *Detect(int32_t &e);
- CBC_ResultPoint *CorrectTopRightRectangular(CBC_ResultPoint *bottomLeft,
- CBC_ResultPoint *bottomRight,
- CBC_ResultPoint *topLeft,
- CBC_ResultPoint *topRight,
- int32_t dimensionTop, int32_t dimensionRight);
- CBC_ResultPoint *CorrectTopRight(CBC_ResultPoint *bottomLeft,
- CBC_ResultPoint *bottomRight,
- CBC_ResultPoint *topLeft,
- CBC_ResultPoint *topRight,
- int32_t dimension);
- CBC_CommonBitMatrix *SampleGrid(CBC_CommonBitMatrix *image,
- CBC_ResultPoint *topLeft,
- CBC_ResultPoint *bottomLeft,
- CBC_ResultPoint *bottomRight,
- CBC_ResultPoint *topRight,
- int32_t dimensionX, int32_t dimensionY, int32_t &e);
- CBC_ResultPointsAndTransitions *TransitionsBetween(CBC_ResultPoint *from, CBC_ResultPoint *to);
- FX_BOOL IsValid(CBC_ResultPoint *p);
- int32_t Distance(CBC_ResultPoint *a, CBC_ResultPoint *b);
- void Increment(CFX_MapPtrTemplate<CBC_ResultPoint*, int32_t> &table, CBC_ResultPoint *key);
- int32_t Round(FX_FLOAT d);
- void OrderBestPatterns(CFX_PtrArray *patterns);
- virtual void Init(int32_t &e);
-private:
- CBC_CommonBitMatrix *m_image;
- CBC_WhiteRectangleDetector *m_rectangleDetector;
- const static int32_t INTEGERS[5];
+class CBC_DataMatrixDetector {
+ public:
+ CBC_DataMatrixDetector(CBC_CommonBitMatrix* image);
+ virtual ~CBC_DataMatrixDetector();
+ CBC_QRDetectorResult* Detect(int32_t& e);
+ CBC_ResultPoint* CorrectTopRightRectangular(CBC_ResultPoint* bottomLeft,
+ CBC_ResultPoint* bottomRight,
+ CBC_ResultPoint* topLeft,
+ CBC_ResultPoint* topRight,
+ int32_t dimensionTop,
+ int32_t dimensionRight);
+ CBC_ResultPoint* CorrectTopRight(CBC_ResultPoint* bottomLeft,
+ CBC_ResultPoint* bottomRight,
+ CBC_ResultPoint* topLeft,
+ CBC_ResultPoint* topRight,
+ int32_t dimension);
+ CBC_CommonBitMatrix* SampleGrid(CBC_CommonBitMatrix* image,
+ CBC_ResultPoint* topLeft,
+ CBC_ResultPoint* bottomLeft,
+ CBC_ResultPoint* bottomRight,
+ CBC_ResultPoint* topRight,
+ int32_t dimensionX,
+ int32_t dimensionY,
+ int32_t& e);
+ CBC_ResultPointsAndTransitions* TransitionsBetween(CBC_ResultPoint* from,
+ CBC_ResultPoint* to);
+ FX_BOOL IsValid(CBC_ResultPoint* p);
+ int32_t Distance(CBC_ResultPoint* a, CBC_ResultPoint* b);
+ void Increment(CFX_MapPtrTemplate<CBC_ResultPoint*, int32_t>& table,
+ CBC_ResultPoint* key);
+ int32_t Round(FX_FLOAT d);
+ void OrderBestPatterns(CFX_PtrArray* patterns);
+ virtual void Init(int32_t& e);
+
+ private:
+ CBC_CommonBitMatrix* m_image;
+ CBC_WhiteRectangleDetector* m_rectangleDetector;
+ const static int32_t INTEGERS[5];
};
#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixReader.cpp b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixReader.cpp index 1b9f55dc9f..7e1777fa7b 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixReader.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixReader.cpp @@ -28,40 +28,39 @@ #include "BC_DataMatrixDecoder.h"
#include "BC_DataMatrixDetector.h"
#include "BC_DataMatrixReader.h"
-CBC_DataMatrixReader::CBC_DataMatrixReader()
-{
- m_decoder = NULL;
+CBC_DataMatrixReader::CBC_DataMatrixReader() {
+ m_decoder = NULL;
}
-void CBC_DataMatrixReader::Init()
-{
- m_decoder = FX_NEW CBC_DataMatrixDecoder;
- m_decoder->Init();
+void CBC_DataMatrixReader::Init() {
+ m_decoder = FX_NEW CBC_DataMatrixDecoder;
+ m_decoder->Init();
}
-CBC_DataMatrixReader::~CBC_DataMatrixReader()
-{
- if(m_decoder != NULL) {
- delete m_decoder;
- }
- m_decoder = NULL;
+CBC_DataMatrixReader::~CBC_DataMatrixReader() {
+ if (m_decoder != NULL) {
+ delete m_decoder;
+ }
+ m_decoder = NULL;
}
-CFX_ByteString CBC_DataMatrixReader::Decode(CBC_BinaryBitmap *image, int32_t hints, int32_t &e)
-{
- CBC_CommonBitMatrix *cdr = image->GetBlackMatrix(e);
- BC_EXCEPTION_CHECK_ReturnValue(e, "");
- CBC_DataMatrixDetector detector(cdr);
- detector.Init(e);
- BC_EXCEPTION_CHECK_ReturnValue(e, "");
- CBC_QRDetectorResult* ddr = detector.Detect(e);
- BC_EXCEPTION_CHECK_ReturnValue(e, "");
- CBC_AutoPtr<CBC_QRDetectorResult> detectorResult(ddr);
- CBC_CommonDecoderResult* ResultTemp = m_decoder->Decode(detectorResult->GetBits(), e);
- BC_EXCEPTION_CHECK_ReturnValue(e, "");
- CBC_AutoPtr<CBC_CommonDecoderResult> decodeResult(ResultTemp);
- return decodeResult->GetText();
+CFX_ByteString CBC_DataMatrixReader::Decode(CBC_BinaryBitmap* image,
+ int32_t hints,
+ int32_t& e) {
+ CBC_CommonBitMatrix* cdr = image->GetBlackMatrix(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ CBC_DataMatrixDetector detector(cdr);
+ detector.Init(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ CBC_QRDetectorResult* ddr = detector.Detect(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ CBC_AutoPtr<CBC_QRDetectorResult> detectorResult(ddr);
+ CBC_CommonDecoderResult* ResultTemp =
+ m_decoder->Decode(detectorResult->GetBits(), e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ CBC_AutoPtr<CBC_CommonDecoderResult> decodeResult(ResultTemp);
+ return decodeResult->GetText();
}
-CFX_ByteString CBC_DataMatrixReader::Decode(CBC_BinaryBitmap *image, int32_t &e)
-{
- CFX_ByteString bs = Decode(image, 0, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, "");
- return bs;
+CFX_ByteString CBC_DataMatrixReader::Decode(CBC_BinaryBitmap* image,
+ int32_t& e) {
+ CFX_ByteString bs = Decode(image, 0, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ return bs;
}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixReader.h b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixReader.h index 6ba17a89e3..29582235e0 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixReader.h +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixReader.h @@ -10,16 +10,16 @@ class CBC_BinaryBitmap; class CBC_DataMatrixDecoder;
class CBC_Reader;
class CBC_DataMatrixReader;
-class CBC_DataMatrixReader : public CBC_Reader
-{
-public:
- CBC_DataMatrixReader();
- virtual ~CBC_DataMatrixReader();
- CFX_ByteString Decode(CBC_BinaryBitmap *image, int32_t &e);
- CFX_ByteString Decode(CBC_BinaryBitmap *image, int hints, int32_t &e);
+class CBC_DataMatrixReader : public CBC_Reader {
+ public:
+ CBC_DataMatrixReader();
+ virtual ~CBC_DataMatrixReader();
+ CFX_ByteString Decode(CBC_BinaryBitmap* image, int32_t& e);
+ CFX_ByteString Decode(CBC_BinaryBitmap* image, int hints, int32_t& e);
- virtual void Init();
-private:
- CBC_DataMatrixDecoder *m_decoder;
+ virtual void Init();
+
+ private:
+ CBC_DataMatrixDecoder* m_decoder;
};
#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.cpp b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.cpp index dfe0e11f1c..d6176be909 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.cpp @@ -25,19 +25,16 @@ #include "BC_SymbolShapeHint.h"
#include "BC_SymbolInfo.h"
#include "BC_DataMatrixSymbolInfo144.h"
-CBC_DataMatrixSymbolInfo144::CBC_DataMatrixSymbolInfo144() : CBC_SymbolInfo(FALSE, 1558, 620, 22, 22, 36)
-{
- m_rsBlockData = -1;
- m_rsBlockError = 62;
+CBC_DataMatrixSymbolInfo144::CBC_DataMatrixSymbolInfo144()
+ : CBC_SymbolInfo(FALSE, 1558, 620, 22, 22, 36) {
+ m_rsBlockData = -1;
+ m_rsBlockError = 62;
}
-CBC_DataMatrixSymbolInfo144::~CBC_DataMatrixSymbolInfo144()
-{
+CBC_DataMatrixSymbolInfo144::~CBC_DataMatrixSymbolInfo144() {}
+int32_t CBC_DataMatrixSymbolInfo144::getInterleavedBlockCount() {
+ return 10;
}
-int32_t CBC_DataMatrixSymbolInfo144::getInterleavedBlockCount()
-{
- return 10;
-}
-int32_t CBC_DataMatrixSymbolInfo144getDataLengthForInterleavedBlock(int32_t index)
-{
- return (index <= 8) ? 156 : 155;
+int32_t CBC_DataMatrixSymbolInfo144getDataLengthForInterleavedBlock(
+ int32_t index) {
+ return (index <= 8) ? 156 : 155;
}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.h b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.h index 2c13551145..6c325a450e 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.h +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.h @@ -8,12 +8,11 @@ #define _BC_DATAMATRIXSYMBOLINFO144_H_
class CBC_SymbolInfo;
class CBC_DataMatrixSymbolInfo144;
-class CBC_DataMatrixSymbolInfo144 : public CBC_SymbolInfo
-{
-public:
- CBC_DataMatrixSymbolInfo144();
- virtual ~CBC_DataMatrixSymbolInfo144();
- int32_t getInterleavedBlockCount();
- int32_t getDataLengthForInterleavedBlock(int32_t index);
+class CBC_DataMatrixSymbolInfo144 : public CBC_SymbolInfo {
+ public:
+ CBC_DataMatrixSymbolInfo144();
+ virtual ~CBC_DataMatrixSymbolInfo144();
+ int32_t getInterleavedBlockCount();
+ int32_t getDataLengthForInterleavedBlock(int32_t index);
};
#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixVersion.cpp b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixVersion.cpp index bbbf4bdee5..55b3c8d557 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixVersion.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixVersion.cpp @@ -23,125 +23,150 @@ #include "../barcode.h"
#include "BC_DataMatrixVersion.h"
CFX_PtrArray* CBC_DataMatrixVersion::VERSIONS = NULL;
-void CBC_DataMatrixVersion::Initialize()
-{
- VERSIONS = FX_NEW CFX_PtrArray();
+void CBC_DataMatrixVersion::Initialize() {
+ VERSIONS = FX_NEW CFX_PtrArray();
}
-void CBC_DataMatrixVersion::Finalize()
-{
- for (int32_t i = 0; i < VERSIONS->GetSize(); i++) {
- delete ( (CBC_DataMatrixVersion*)(VERSIONS->GetAt(i)) );
- }
- VERSIONS->RemoveAll();
- delete VERSIONS;
+void CBC_DataMatrixVersion::Finalize() {
+ for (int32_t i = 0; i < VERSIONS->GetSize(); i++) {
+ delete ((CBC_DataMatrixVersion*)(VERSIONS->GetAt(i)));
+ }
+ VERSIONS->RemoveAll();
+ delete VERSIONS;
}
CBC_DataMatrixVersion::CBC_DataMatrixVersion(int32_t versionNumber,
- int32_t symbolSizeRows,
- int32_t symbolSizeColumns,
- int32_t dataRegionSizeRows,
- int32_t dataRegionSizeColumns,
- ECBlocks *ecBlocks)
-{
- m_versionNumber = versionNumber;
- m_symbolSizeRows = symbolSizeRows;
- m_symbolSizeColumns = symbolSizeColumns;
- m_dataRegionSizeRows = dataRegionSizeRows;
- m_dataRegionSizeColumns = dataRegionSizeColumns;
- m_ecBlocks = ecBlocks;
- int32_t total = 0;
- int32_t ecCodewords = ecBlocks->GetECCodewords();
- const CFX_PtrArray &ecbArray = ecBlocks->GetECBlocks();
- for (int32_t i = 0; i < ecbArray.GetSize(); i++) {
- total += ((ECB*)ecbArray[i])->GetCount() * (((ECB*)ecbArray[i])->GetDataCodewords() + ecCodewords);
- }
- m_totalCodewords = total;
+ int32_t symbolSizeRows,
+ int32_t symbolSizeColumns,
+ int32_t dataRegionSizeRows,
+ int32_t dataRegionSizeColumns,
+ ECBlocks* ecBlocks) {
+ m_versionNumber = versionNumber;
+ m_symbolSizeRows = symbolSizeRows;
+ m_symbolSizeColumns = symbolSizeColumns;
+ m_dataRegionSizeRows = dataRegionSizeRows;
+ m_dataRegionSizeColumns = dataRegionSizeColumns;
+ m_ecBlocks = ecBlocks;
+ int32_t total = 0;
+ int32_t ecCodewords = ecBlocks->GetECCodewords();
+ const CFX_PtrArray& ecbArray = ecBlocks->GetECBlocks();
+ for (int32_t i = 0; i < ecbArray.GetSize(); i++) {
+ total += ((ECB*)ecbArray[i])->GetCount() *
+ (((ECB*)ecbArray[i])->GetDataCodewords() + ecCodewords);
+ }
+ m_totalCodewords = total;
}
-CBC_DataMatrixVersion::~CBC_DataMatrixVersion()
-{
- if(m_ecBlocks != NULL) {
- delete m_ecBlocks;
- }
- m_ecBlocks = NULL;
+CBC_DataMatrixVersion::~CBC_DataMatrixVersion() {
+ if (m_ecBlocks != NULL) {
+ delete m_ecBlocks;
+ }
+ m_ecBlocks = NULL;
}
-int32_t CBC_DataMatrixVersion::GetVersionNumber()
-{
- return m_versionNumber;
+int32_t CBC_DataMatrixVersion::GetVersionNumber() {
+ return m_versionNumber;
}
-int32_t CBC_DataMatrixVersion::GetSymbolSizeRows()
-{
- return m_symbolSizeRows;
+int32_t CBC_DataMatrixVersion::GetSymbolSizeRows() {
+ return m_symbolSizeRows;
}
-int32_t CBC_DataMatrixVersion::GetSymbolSizeColumns()
-{
- return m_symbolSizeColumns;
+int32_t CBC_DataMatrixVersion::GetSymbolSizeColumns() {
+ return m_symbolSizeColumns;
}
-int32_t CBC_DataMatrixVersion::GetDataRegionSizeRows()
-{
- return m_dataRegionSizeRows;
+int32_t CBC_DataMatrixVersion::GetDataRegionSizeRows() {
+ return m_dataRegionSizeRows;
}
-int32_t CBC_DataMatrixVersion::GetDataRegionSizeColumns()
-{
- return m_dataRegionSizeColumns;
+int32_t CBC_DataMatrixVersion::GetDataRegionSizeColumns() {
+ return m_dataRegionSizeColumns;
}
-int32_t CBC_DataMatrixVersion::GetTotalCodewords()
-{
- return m_totalCodewords;
+int32_t CBC_DataMatrixVersion::GetTotalCodewords() {
+ return m_totalCodewords;
}
-ECBlocks *CBC_DataMatrixVersion::GetECBlocks()
-{
- return m_ecBlocks;
+ECBlocks* CBC_DataMatrixVersion::GetECBlocks() {
+ return m_ecBlocks;
}
-void CBC_DataMatrixVersion::ReleaseAll()
-{
- for (int32_t i = 0; i < VERSIONS->GetSize(); i++) {
- delete (CBC_DataMatrixVersion*)VERSIONS->GetAt(i);
- }
- VERSIONS->RemoveAll();
+void CBC_DataMatrixVersion::ReleaseAll() {
+ for (int32_t i = 0; i < VERSIONS->GetSize(); i++) {
+ delete (CBC_DataMatrixVersion*)VERSIONS->GetAt(i);
+ }
+ VERSIONS->RemoveAll();
}
-CBC_DataMatrixVersion *CBC_DataMatrixVersion::GetVersionForDimensions(int32_t numRows, int32_t numColumns, int32_t &e)
-{
- if ((numRows & 0x01) != 0 || (numColumns & 0x01) != 0) {
- e = BCExceptionNotFound;
- return NULL;
- }
- if(VERSIONS->GetSize() == 0) {
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(1, 10, 10, 8, 8, FX_NEW ECBlocks(5, FX_NEW ECB(1, 3))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(2, 12, 12, 10, 10, FX_NEW ECBlocks(7, FX_NEW ECB(1, 5))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(3, 14, 14, 12, 12, FX_NEW ECBlocks(10, FX_NEW ECB(1, 8))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(4, 16, 16, 14, 14, FX_NEW ECBlocks(12, FX_NEW ECB(1, 12))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(5, 18, 18, 16, 16, FX_NEW ECBlocks(14, FX_NEW ECB(1, 18))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(6, 20, 20, 18, 18, FX_NEW ECBlocks(18, FX_NEW ECB(1, 22))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(7, 22, 22, 20, 20, FX_NEW ECBlocks(20, FX_NEW ECB(1, 30))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(8, 24, 24, 22, 22, FX_NEW ECBlocks(24, FX_NEW ECB(1, 36))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(9, 26, 26, 24, 24, FX_NEW ECBlocks(28, FX_NEW ECB(1, 44))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(10, 32, 32, 14, 14, FX_NEW ECBlocks(36, FX_NEW ECB(1, 62))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(11, 36, 36, 16, 16, FX_NEW ECBlocks(42, FX_NEW ECB(1, 86))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(12, 40, 40, 18, 18, FX_NEW ECBlocks(48, FX_NEW ECB(1, 114))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(13, 44, 44, 20, 20, FX_NEW ECBlocks(56, FX_NEW ECB(1, 144))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(14, 48, 48, 22, 22, FX_NEW ECBlocks(68, FX_NEW ECB(1, 174))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(15, 52, 52, 24, 24, FX_NEW ECBlocks(42, FX_NEW ECB(2, 102))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(16, 64, 64, 14, 14, FX_NEW ECBlocks(56, FX_NEW ECB(2, 140))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(17, 72, 72, 16, 16, FX_NEW ECBlocks(36, FX_NEW ECB(4, 92))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(18, 80, 80, 18, 18, FX_NEW ECBlocks(48, FX_NEW ECB(4, 114))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(19, 88, 88, 20, 20, FX_NEW ECBlocks(56, FX_NEW ECB(4, 144))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(20, 96, 96, 22, 22, FX_NEW ECBlocks(68, FX_NEW ECB(4, 174))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(21, 104, 104, 24, 24, FX_NEW ECBlocks(56, FX_NEW ECB(6, 136))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(22, 120, 120, 18, 18, FX_NEW ECBlocks(68, FX_NEW ECB(6, 175))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(23, 132, 132, 20, 20, FX_NEW ECBlocks(62, FX_NEW ECB(8, 163))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(24, 144, 144, 22, 22, FX_NEW ECBlocks(62, FX_NEW ECB(8, 156), FX_NEW ECB(2, 155))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(25, 8, 18, 6, 16, FX_NEW ECBlocks(7, FX_NEW ECB(1, 5))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(26, 8, 32, 6, 14, FX_NEW ECBlocks(11, FX_NEW ECB(1, 10))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(27, 12, 26, 10, 24, FX_NEW ECBlocks(14, FX_NEW ECB(1, 16))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(28, 12, 36, 10, 16, FX_NEW ECBlocks(18, FX_NEW ECB(1, 22))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(29, 16, 36, 14, 16, FX_NEW ECBlocks(24, FX_NEW ECB(1, 32))));
- VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(30, 16, 48, 14, 22, FX_NEW ECBlocks(28, FX_NEW ECB(1, 49))));
- }
- int32_t numVersions = VERSIONS->GetSize();
- for (int32_t i = 0; i < numVersions; ++i) {
- if (((CBC_DataMatrixVersion*)((*VERSIONS)[i]))->m_symbolSizeRows == numRows && ((CBC_DataMatrixVersion*)((*VERSIONS)[i]))->m_symbolSizeColumns == numColumns) {
- return (CBC_DataMatrixVersion*)(*VERSIONS)[i];
- }
- }
+CBC_DataMatrixVersion* CBC_DataMatrixVersion::GetVersionForDimensions(
+ int32_t numRows,
+ int32_t numColumns,
+ int32_t& e) {
+ if ((numRows & 0x01) != 0 || (numColumns & 0x01) != 0) {
e = BCExceptionNotFound;
return NULL;
+ }
+ if (VERSIONS->GetSize() == 0) {
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 1, 10, 10, 8, 8, FX_NEW ECBlocks(5, FX_NEW ECB(1, 3))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 2, 12, 12, 10, 10, FX_NEW ECBlocks(7, FX_NEW ECB(1, 5))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 3, 14, 14, 12, 12, FX_NEW ECBlocks(10, FX_NEW ECB(1, 8))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 4, 16, 16, 14, 14, FX_NEW ECBlocks(12, FX_NEW ECB(1, 12))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 5, 18, 18, 16, 16, FX_NEW ECBlocks(14, FX_NEW ECB(1, 18))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 6, 20, 20, 18, 18, FX_NEW ECBlocks(18, FX_NEW ECB(1, 22))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 7, 22, 22, 20, 20, FX_NEW ECBlocks(20, FX_NEW ECB(1, 30))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 8, 24, 24, 22, 22, FX_NEW ECBlocks(24, FX_NEW ECB(1, 36))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 9, 26, 26, 24, 24, FX_NEW ECBlocks(28, FX_NEW ECB(1, 44))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 10, 32, 32, 14, 14, FX_NEW ECBlocks(36, FX_NEW ECB(1, 62))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 11, 36, 36, 16, 16, FX_NEW ECBlocks(42, FX_NEW ECB(1, 86))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 12, 40, 40, 18, 18, FX_NEW ECBlocks(48, FX_NEW ECB(1, 114))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 13, 44, 44, 20, 20, FX_NEW ECBlocks(56, FX_NEW ECB(1, 144))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 14, 48, 48, 22, 22, FX_NEW ECBlocks(68, FX_NEW ECB(1, 174))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 15, 52, 52, 24, 24, FX_NEW ECBlocks(42, FX_NEW ECB(2, 102))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 16, 64, 64, 14, 14, FX_NEW ECBlocks(56, FX_NEW ECB(2, 140))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 17, 72, 72, 16, 16, FX_NEW ECBlocks(36, FX_NEW ECB(4, 92))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 18, 80, 80, 18, 18, FX_NEW ECBlocks(48, FX_NEW ECB(4, 114))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 19, 88, 88, 20, 20, FX_NEW ECBlocks(56, FX_NEW ECB(4, 144))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 20, 96, 96, 22, 22, FX_NEW ECBlocks(68, FX_NEW ECB(4, 174))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 21, 104, 104, 24, 24, FX_NEW ECBlocks(56, FX_NEW ECB(6, 136))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 22, 120, 120, 18, 18, FX_NEW ECBlocks(68, FX_NEW ECB(6, 175))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 23, 132, 132, 20, 20, FX_NEW ECBlocks(62, FX_NEW ECB(8, 163))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 24, 144, 144, 22, 22,
+ FX_NEW ECBlocks(62, FX_NEW ECB(8, 156), FX_NEW ECB(2, 155))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 25, 8, 18, 6, 16, FX_NEW ECBlocks(7, FX_NEW ECB(1, 5))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 26, 8, 32, 6, 14, FX_NEW ECBlocks(11, FX_NEW ECB(1, 10))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 27, 12, 26, 10, 24, FX_NEW ECBlocks(14, FX_NEW ECB(1, 16))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 28, 12, 36, 10, 16, FX_NEW ECBlocks(18, FX_NEW ECB(1, 22))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 29, 16, 36, 14, 16, FX_NEW ECBlocks(24, FX_NEW ECB(1, 32))));
+ VERSIONS->Add(FX_NEW CBC_DataMatrixVersion(
+ 30, 16, 48, 14, 22, FX_NEW ECBlocks(28, FX_NEW ECB(1, 49))));
+ }
+ int32_t numVersions = VERSIONS->GetSize();
+ for (int32_t i = 0; i < numVersions; ++i) {
+ if (((CBC_DataMatrixVersion*)((*VERSIONS)[i]))->m_symbolSizeRows ==
+ numRows &&
+ ((CBC_DataMatrixVersion*)((*VERSIONS)[i]))->m_symbolSizeColumns ==
+ numColumns) {
+ return (CBC_DataMatrixVersion*)(*VERSIONS)[i];
+ }
+ }
+ e = BCExceptionNotFound;
+ return NULL;
}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixVersion.h b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixVersion.h index 90f6509f0f..8e197b1f92 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixVersion.h +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixVersion.h @@ -8,93 +8,79 @@ #define _BC_DATAMATRIXVERSION_H_
class ECBlocks;
class CBC_DataMatrixVersion;
-class ECB
-{
-public:
- ECB(int32_t count, int32_t dataCodewords)
- {
- m_count = count;
- m_dataCodewords = dataCodewords;
- }
+class ECB {
+ public:
+ ECB(int32_t count, int32_t dataCodewords) {
+ m_count = count;
+ m_dataCodewords = dataCodewords;
+ }
- int32_t GetCount()
- {
- return m_count;
- }
+ int32_t GetCount() { return m_count; }
- int32_t GetDataCodewords()
- {
- return m_dataCodewords;
- }
-private:
- int32_t m_count;
- int32_t m_dataCodewords;
+ int32_t GetDataCodewords() { return m_dataCodewords; }
+
+ private:
+ int32_t m_count;
+ int32_t m_dataCodewords;
};
-class ECBlocks
-{
-public:
- ECBlocks(int32_t ecCodewords, ECB *ecBlocks)
- {
- m_ecCodewords = ecCodewords;
- m_ecBlocks.Add(ecBlocks);
- }
+class ECBlocks {
+ public:
+ ECBlocks(int32_t ecCodewords, ECB* ecBlocks) {
+ m_ecCodewords = ecCodewords;
+ m_ecBlocks.Add(ecBlocks);
+ }
- ECBlocks(int32_t ecCodewords, ECB *ecBlocks1, ECB *ecBlocks2)
- {
- m_ecCodewords = ecCodewords;
- m_ecBlocks.Add(ecBlocks1);
- m_ecBlocks.Add(ecBlocks2);
- }
- ~ECBlocks()
- {
- for(int32_t i = 0; i < m_ecBlocks.GetSize(); i++) {
- delete (ECB*)m_ecBlocks[i];
- }
- m_ecBlocks.RemoveAll();
+ ECBlocks(int32_t ecCodewords, ECB* ecBlocks1, ECB* ecBlocks2) {
+ m_ecCodewords = ecCodewords;
+ m_ecBlocks.Add(ecBlocks1);
+ m_ecBlocks.Add(ecBlocks2);
+ }
+ ~ECBlocks() {
+ for (int32_t i = 0; i < m_ecBlocks.GetSize(); i++) {
+ delete (ECB*)m_ecBlocks[i];
}
+ m_ecBlocks.RemoveAll();
+ }
- int32_t GetECCodewords()
- {
- return m_ecCodewords;
- }
+ int32_t GetECCodewords() { return m_ecCodewords; }
- const CFX_PtrArray &GetECBlocks()
- {
- return m_ecBlocks;
- }
-private:
- int32_t m_ecCodewords;
- CFX_PtrArray m_ecBlocks;
+ const CFX_PtrArray& GetECBlocks() { return m_ecBlocks; }
+
+ private:
+ int32_t m_ecCodewords;
+ CFX_PtrArray m_ecBlocks;
};
-class CBC_DataMatrixVersion
-{
-public:
- CBC_DataMatrixVersion(int32_t versionNumber,
- int32_t symbolSizeRows,
- int32_t symbolSizeColumns,
- int32_t dataRegionSizeRows,
- int32_t dataRegionSizeColumns,
- ECBlocks *ecBlocks);
- virtual ~CBC_DataMatrixVersion();
- static void Initialize();
- static void Finalize();
- int32_t GetVersionNumber();
- int32_t GetSymbolSizeRows();
- int32_t GetSymbolSizeColumns();
- int32_t GetDataRegionSizeRows();
- int32_t GetDataRegionSizeColumns();
- int32_t GetTotalCodewords();
- ECBlocks *GetECBlocks();
- static CBC_DataMatrixVersion *GetVersionForDimensions(int32_t numRows, int32_t numColumns, int32_t &e);
- static void ReleaseAll();
-private:
- int32_t m_versionNumber;
- int32_t m_symbolSizeRows;
- int32_t m_symbolSizeColumns;
- int32_t m_dataRegionSizeRows;
- int32_t m_dataRegionSizeColumns;
- ECBlocks *m_ecBlocks;
- int32_t m_totalCodewords;
- static CFX_PtrArray* VERSIONS;
+class CBC_DataMatrixVersion {
+ public:
+ CBC_DataMatrixVersion(int32_t versionNumber,
+ int32_t symbolSizeRows,
+ int32_t symbolSizeColumns,
+ int32_t dataRegionSizeRows,
+ int32_t dataRegionSizeColumns,
+ ECBlocks* ecBlocks);
+ virtual ~CBC_DataMatrixVersion();
+ static void Initialize();
+ static void Finalize();
+ int32_t GetVersionNumber();
+ int32_t GetSymbolSizeRows();
+ int32_t GetSymbolSizeColumns();
+ int32_t GetDataRegionSizeRows();
+ int32_t GetDataRegionSizeColumns();
+ int32_t GetTotalCodewords();
+ ECBlocks* GetECBlocks();
+ static CBC_DataMatrixVersion* GetVersionForDimensions(int32_t numRows,
+ int32_t numColumns,
+ int32_t& e);
+ static void ReleaseAll();
+
+ private:
+ int32_t m_versionNumber;
+ int32_t m_symbolSizeRows;
+ int32_t m_symbolSizeColumns;
+ int32_t m_dataRegionSizeRows;
+ int32_t m_dataRegionSizeColumns;
+ ECBlocks* m_ecBlocks;
+ int32_t m_totalCodewords;
+ static CFX_PtrArray* VERSIONS;
};
#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp index 7b1339ea19..539572f5da 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp @@ -43,96 +43,109 @@ #include "BC_ASCIIEncoder.h"
#include "BC_HighLevelEncoder.h"
#include "BC_DataMatrixWriter.h"
-CBC_DataMatrixWriter::CBC_DataMatrixWriter()
-{
+CBC_DataMatrixWriter::CBC_DataMatrixWriter() {}
+CBC_DataMatrixWriter::~CBC_DataMatrixWriter() {}
+FX_BOOL CBC_DataMatrixWriter::SetErrorCorrectionLevel(int32_t level) {
+ m_iCorrectLevel = level;
+ return TRUE;
}
-CBC_DataMatrixWriter::~CBC_DataMatrixWriter()
-{
+uint8_t* CBC_DataMatrixWriter::Encode(const CFX_WideString& contents,
+ int32_t& outWidth,
+ int32_t& outHeight,
+ int32_t& e) {
+ if (outWidth < 0 || outHeight < 0) {
+ e = BCExceptionHeightAndWidthMustBeAtLeast1;
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ }
+ CBC_SymbolShapeHint::SymbolShapeHint shape =
+ CBC_SymbolShapeHint::FORCE_SQUARE;
+ CBC_Dimension* minSize = NULL;
+ CBC_Dimension* maxSize = NULL;
+ CFX_WideString ecLevel;
+ CFX_WideString encoded = CBC_HighLevelEncoder::encodeHighLevel(
+ contents, ecLevel, shape, minSize, maxSize, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_SymbolInfo* symbolInfo = CBC_SymbolInfo::lookup(
+ encoded.GetLength(), shape, minSize, maxSize, TRUE, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CFX_WideString codewords =
+ CBC_ErrorCorrection::encodeECC200(encoded, symbolInfo, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_DefaultPlacement* placement =
+ FX_NEW CBC_DefaultPlacement(codewords, symbolInfo->getSymbolDataWidth(e),
+ symbolInfo->getSymbolDataHeight(e));
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ placement->place();
+ CBC_CommonByteMatrix* bytematrix = encodeLowLevel(placement, symbolInfo, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ outWidth = bytematrix->GetWidth();
+ outHeight = bytematrix->GetHeight();
+ uint8_t* result = FX_Alloc(uint8_t, outWidth * outHeight);
+ FXSYS_memcpy(result, bytematrix->GetArray(), outWidth * outHeight);
+ delete bytematrix;
+ delete placement;
+ return result;
}
-FX_BOOL CBC_DataMatrixWriter::SetErrorCorrectionLevel (int32_t level)
-{
- m_iCorrectLevel = level;
- return TRUE;
+uint8_t* CBC_DataMatrixWriter::Encode(const CFX_ByteString& contents,
+ BCFORMAT format,
+ int32_t& outWidth,
+ int32_t& outHeight,
+ int32_t& e) {
+ return NULL;
}
-uint8_t* CBC_DataMatrixWriter::Encode(const CFX_WideString &contents, int32_t &outWidth, int32_t &outHeight, int32_t &e)
-{
- if (outWidth < 0 || outHeight < 0) {
- e = BCExceptionHeightAndWidthMustBeAtLeast1;
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- }
- CBC_SymbolShapeHint::SymbolShapeHint shape = CBC_SymbolShapeHint::FORCE_SQUARE;
- CBC_Dimension* minSize = NULL;
- CBC_Dimension* maxSize = NULL;
- CFX_WideString ecLevel;
- CFX_WideString encoded = CBC_HighLevelEncoder::encodeHighLevel(contents, ecLevel, shape, minSize, maxSize, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- CBC_SymbolInfo* symbolInfo = CBC_SymbolInfo::lookup(encoded.GetLength(), shape, minSize, maxSize, TRUE, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- CFX_WideString codewords = CBC_ErrorCorrection::encodeECC200(encoded, symbolInfo, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- CBC_DefaultPlacement* placement = FX_NEW CBC_DefaultPlacement(codewords, symbolInfo->getSymbolDataWidth(e), symbolInfo->getSymbolDataHeight(e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- placement->place();
- CBC_CommonByteMatrix* bytematrix = encodeLowLevel(placement, symbolInfo, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- outWidth = bytematrix->GetWidth();
- outHeight = bytematrix->GetHeight();
- uint8_t* result = FX_Alloc(uint8_t, outWidth * outHeight);
- FXSYS_memcpy(result, bytematrix->GetArray(), outWidth * outHeight);
- delete bytematrix;
- delete placement;
- return result;
-}
-uint8_t *CBC_DataMatrixWriter::Encode(const CFX_ByteString &contents, BCFORMAT format, int32_t &outWidth, int32_t &outHeight, int32_t &e)
-{
- return NULL;
-}
-uint8_t *CBC_DataMatrixWriter::Encode(const CFX_ByteString &contents, BCFORMAT format, int32_t &outWidth, int32_t &outHeight, int32_t hints, int32_t &e)
-{
- return NULL;
+uint8_t* CBC_DataMatrixWriter::Encode(const CFX_ByteString& contents,
+ BCFORMAT format,
+ int32_t& outWidth,
+ int32_t& outHeight,
+ int32_t hints,
+ int32_t& e) {
+ return NULL;
}
-CBC_CommonByteMatrix* CBC_DataMatrixWriter::encodeLowLevel(CBC_DefaultPlacement* placement, CBC_SymbolInfo* symbolInfo, int32_t &e)
-{
- int32_t symbolWidth = symbolInfo->getSymbolDataWidth(e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- int32_t symbolHeight = symbolInfo->getSymbolDataHeight(e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- CBC_CommonByteMatrix* matrix = FX_NEW CBC_CommonByteMatrix(symbolInfo->getSymbolWidth(e), symbolInfo->getSymbolHeight(e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- matrix->Init();
- int32_t matrixY = 0;
- for (int32_t y = 0; y < symbolHeight; y++) {
- int32_t matrixX;
- if ((y % symbolInfo->m_matrixHeight) == 0) {
- matrixX = 0;
- for (int32_t x = 0; x < symbolInfo->getSymbolWidth(e); 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) {
- 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);
- matrixX++;
- }
- }
- matrixY++;
- if ((y % symbolInfo->m_matrixHeight) == symbolInfo->m_matrixHeight - 1) {
- matrixX = 0;
- for (int32_t x = 0; x < symbolInfo->getSymbolWidth(e); x++) {
- matrix->Set(matrixX, matrixY, TRUE);
- matrixX++;
- }
- matrixY++;
- }
+CBC_CommonByteMatrix* CBC_DataMatrixWriter::encodeLowLevel(
+ CBC_DefaultPlacement* placement,
+ CBC_SymbolInfo* symbolInfo,
+ int32_t& e) {
+ int32_t symbolWidth = symbolInfo->getSymbolDataWidth(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ int32_t symbolHeight = symbolInfo->getSymbolDataHeight(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_CommonByteMatrix* matrix = FX_NEW CBC_CommonByteMatrix(
+ symbolInfo->getSymbolWidth(e), symbolInfo->getSymbolHeight(e));
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ matrix->Init();
+ int32_t matrixY = 0;
+ for (int32_t y = 0; y < symbolHeight; y++) {
+ int32_t matrixX;
+ if ((y % symbolInfo->m_matrixHeight) == 0) {
+ matrixX = 0;
+ for (int32_t x = 0; x < symbolInfo->getSymbolWidth(e); 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) {
+ 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);
+ matrixX++;
+ }
+ }
+ matrixY++;
+ if ((y % symbolInfo->m_matrixHeight) == symbolInfo->m_matrixHeight - 1) {
+ matrixX = 0;
+ for (int32_t x = 0; x < symbolInfo->getSymbolWidth(e); x++) {
+ matrix->Set(matrixX, matrixY, TRUE);
+ matrixX++;
+ }
+ matrixY++;
}
- return matrix;
+ }
+ return matrix;
}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixWriter.h b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixWriter.h index 241229b467..5ef124fc8f 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixWriter.h +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixWriter.h @@ -13,18 +13,31 @@ class CBC_SymbolShapeHint; class CBC_SymbolInfo;
class CBC_TwoDimWriter;
class CBC_DataMatrixWriter;
-class CBC_DataMatrixWriter : public CBC_TwoDimWriter
-{
-public:
- CBC_DataMatrixWriter();
- virtual ~CBC_DataMatrixWriter();
- uint8_t* Encode(const CFX_WideString &contents, int32_t &outWidth, int32_t &outHeight, int32_t &e);
- uint8_t * Encode(const CFX_ByteString &contents, BCFORMAT format, int32_t &outWidth, int32_t &outHeight, int32_t &e);
- uint8_t * Encode(const CFX_ByteString &contents, BCFORMAT format, int32_t &outWidth, int32_t &outHeight, int32_t hints, int32_t &e);
- FX_BOOL SetErrorCorrectionLevel (int32_t level);
+class CBC_DataMatrixWriter : public CBC_TwoDimWriter {
+ public:
+ CBC_DataMatrixWriter();
+ virtual ~CBC_DataMatrixWriter();
+ uint8_t* Encode(const CFX_WideString& contents,
+ int32_t& outWidth,
+ int32_t& outHeight,
+ int32_t& e);
+ uint8_t* Encode(const CFX_ByteString& contents,
+ BCFORMAT format,
+ int32_t& outWidth,
+ int32_t& outHeight,
+ int32_t& e);
+ uint8_t* Encode(const CFX_ByteString& contents,
+ BCFORMAT format,
+ int32_t& outWidth,
+ int32_t& outHeight,
+ int32_t hints,
+ int32_t& e);
+ FX_BOOL SetErrorCorrectionLevel(int32_t level);
-private:
- static CBC_CommonByteMatrix* encodeLowLevel(CBC_DefaultPlacement* placement, CBC_SymbolInfo* symbolInfo, int32_t &e);
- int32_t m_iCorrectLevel;
+ private:
+ static CBC_CommonByteMatrix* encodeLowLevel(CBC_DefaultPlacement* placement,
+ CBC_SymbolInfo* symbolInfo,
+ int32_t& e);
+ int32_t m_iCorrectLevel;
};
#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DefaultPlacement.cpp b/xfa/src/fxbarcode/datamatrix/BC_DefaultPlacement.cpp index 57c6cc92d2..86c2a80210 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DefaultPlacement.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_DefaultPlacement.cpp @@ -23,152 +23,142 @@ #include "../barcode.h"
#include "BC_Encoder.h"
#include "BC_DefaultPlacement.h"
-CBC_DefaultPlacement::CBC_DefaultPlacement(CFX_WideString codewords, int32_t numcols, int32_t numrows)
-{
- m_codewords = codewords;
- m_numcols = numcols;
- m_numrows = numrows;
- m_bits.SetSize(numcols * numrows);
- for (int32_t i = 0; i < numcols * numrows; i++) {
- m_bits[i] = (uint8_t) 2;
- }
+CBC_DefaultPlacement::CBC_DefaultPlacement(CFX_WideString codewords,
+ int32_t numcols,
+ int32_t numrows) {
+ m_codewords = codewords;
+ m_numcols = numcols;
+ m_numrows = numrows;
+ m_bits.SetSize(numcols * numrows);
+ for (int32_t i = 0; i < numcols * numrows; i++) {
+ m_bits[i] = (uint8_t)2;
+ }
}
-CBC_DefaultPlacement::~CBC_DefaultPlacement()
-{
- m_bits.RemoveAll();
+CBC_DefaultPlacement::~CBC_DefaultPlacement() {
+ m_bits.RemoveAll();
}
-int32_t CBC_DefaultPlacement::getNumrows()
-{
- return m_numrows;
+int32_t CBC_DefaultPlacement::getNumrows() {
+ return m_numrows;
}
-int32_t CBC_DefaultPlacement::getNumcols()
-{
- return m_numcols;
+int32_t CBC_DefaultPlacement::getNumcols() {
+ return m_numcols;
}
-CFX_ByteArray& CBC_DefaultPlacement::getBits()
-{
- return m_bits;
+CFX_ByteArray& CBC_DefaultPlacement::getBits() {
+ return m_bits;
}
-FX_BOOL CBC_DefaultPlacement::getBit(int32_t col, int32_t row)
-{
- return m_bits[row * m_numcols + col] == 1;
+FX_BOOL CBC_DefaultPlacement::getBit(int32_t col, int32_t row) {
+ return m_bits[row * m_numcols + col] == 1;
}
-void CBC_DefaultPlacement::setBit(int32_t col, int32_t row, FX_BOOL bit)
-{
- m_bits[row * m_numcols + col] = bit ? (uint8_t) 1 : (uint8_t) 0;
+void CBC_DefaultPlacement::setBit(int32_t col, int32_t row, FX_BOOL bit) {
+ m_bits[row * m_numcols + col] = bit ? (uint8_t)1 : (uint8_t)0;
}
-FX_BOOL CBC_DefaultPlacement::hasBit(int32_t col, int32_t row)
-{
- return m_bits[row * m_numcols + col] != 2;
+FX_BOOL CBC_DefaultPlacement::hasBit(int32_t col, int32_t row) {
+ return m_bits[row * m_numcols + col] != 2;
}
-void CBC_DefaultPlacement::place()
-{
- int32_t pos = 0;
- int32_t row = 4;
- int32_t col = 0;
- do {
- if ((row == m_numrows) && (col == 0)) {
- corner1(pos++);
- }
- if ((row == m_numrows - 2) && (col == 0) && ((m_numcols % 4) != 0)) {
- corner2(pos++);
- }
- if ((row == m_numrows - 2) && (col == 0) && (m_numcols % 8 == 4)) {
- corner3(pos++);
- }
- if ((row == m_numrows + 4) && (col == 2) && ((m_numcols % 8) == 0)) {
- corner4(pos++);
- }
- do {
- if ((row < m_numrows) && (col >= 0) && !hasBit(col, row)) {
- utah(row, col, pos++);
- }
- row -= 2;
- col += 2;
- } while (row >= 0 && (col < m_numcols));
- row++;
- col += 3;
- do {
- if ((row >= 0) && (col < m_numcols) && !hasBit(col, row)) {
- utah(row, col, pos++);
- }
- row += 2;
- col -= 2;
- } while ((row < m_numrows) && (col >= 0));
- row += 3;
- col++;
- } while ((row < m_numrows) || (col < m_numcols));
- if (!hasBit(m_numcols - 1, m_numrows - 1)) {
- setBit(m_numcols - 1, m_numrows - 1, TRUE);
- setBit(m_numcols - 2, m_numrows - 2, TRUE);
+void CBC_DefaultPlacement::place() {
+ int32_t pos = 0;
+ int32_t row = 4;
+ int32_t col = 0;
+ do {
+ if ((row == m_numrows) && (col == 0)) {
+ corner1(pos++);
}
-}
-void CBC_DefaultPlacement::module(int32_t row, int32_t col, int32_t pos, int32_t bit)
-{
- if (row < 0) {
- row += m_numrows;
- col += 4 - ((m_numrows + 4) % 8);
+ if ((row == m_numrows - 2) && (col == 0) && ((m_numcols % 4) != 0)) {
+ corner2(pos++);
+ }
+ if ((row == m_numrows - 2) && (col == 0) && (m_numcols % 8 == 4)) {
+ corner3(pos++);
}
- if (col < 0) {
- col += m_numcols;
- row += 4 - ((m_numcols + 4) % 8);
+ if ((row == m_numrows + 4) && (col == 2) && ((m_numcols % 8) == 0)) {
+ corner4(pos++);
}
- int32_t v = m_codewords.GetAt(pos);
- v &= 1 << (8 - bit);
- setBit(col, row, v != 0);
+ do {
+ if ((row < m_numrows) && (col >= 0) && !hasBit(col, row)) {
+ utah(row, col, pos++);
+ }
+ row -= 2;
+ col += 2;
+ } while (row >= 0 && (col < m_numcols));
+ row++;
+ col += 3;
+ do {
+ if ((row >= 0) && (col < m_numcols) && !hasBit(col, row)) {
+ utah(row, col, pos++);
+ }
+ row += 2;
+ col -= 2;
+ } while ((row < m_numrows) && (col >= 0));
+ row += 3;
+ col++;
+ } while ((row < m_numrows) || (col < m_numcols));
+ if (!hasBit(m_numcols - 1, m_numrows - 1)) {
+ setBit(m_numcols - 1, m_numrows - 1, TRUE);
+ setBit(m_numcols - 2, m_numrows - 2, TRUE);
+ }
+}
+void CBC_DefaultPlacement::module(int32_t row,
+ int32_t col,
+ int32_t pos,
+ int32_t bit) {
+ if (row < 0) {
+ row += m_numrows;
+ col += 4 - ((m_numrows + 4) % 8);
+ }
+ if (col < 0) {
+ col += m_numcols;
+ row += 4 - ((m_numcols + 4) % 8);
+ }
+ int32_t v = m_codewords.GetAt(pos);
+ v &= 1 << (8 - bit);
+ setBit(col, row, v != 0);
}
-void CBC_DefaultPlacement::utah(int32_t row, int32_t col, int32_t pos)
-{
- module(row - 2, col - 2, pos, 1);
- module(row - 2, col - 1, pos, 2);
- module(row - 1, col - 2, pos, 3);
- module(row - 1, col - 1, pos, 4);
- module(row - 1, col, pos, 5);
- module(row, col - 2, pos, 6);
- module(row, col - 1, pos, 7);
- module(row, col, pos, 8);
+void CBC_DefaultPlacement::utah(int32_t row, int32_t col, int32_t pos) {
+ module(row - 2, col - 2, pos, 1);
+ module(row - 2, col - 1, pos, 2);
+ module(row - 1, col - 2, pos, 3);
+ module(row - 1, col - 1, pos, 4);
+ module(row - 1, col, pos, 5);
+ module(row, col - 2, pos, 6);
+ module(row, col - 1, pos, 7);
+ module(row, col, pos, 8);
}
-void CBC_DefaultPlacement::corner1(int32_t pos)
-{
- module(m_numrows - 1, 0, pos, 1);
- module(m_numrows - 1, 1, pos, 2);
- module(m_numrows - 1, 2, pos, 3);
- module(0, m_numcols - 2, pos, 4);
- module(0, m_numcols - 1, pos, 5);
- module(1, m_numcols - 1, pos, 6);
- module(2, m_numcols - 1, pos, 7);
- module(3, m_numcols - 1, pos, 8);
+void CBC_DefaultPlacement::corner1(int32_t pos) {
+ module(m_numrows - 1, 0, pos, 1);
+ module(m_numrows - 1, 1, pos, 2);
+ module(m_numrows - 1, 2, pos, 3);
+ module(0, m_numcols - 2, pos, 4);
+ module(0, m_numcols - 1, pos, 5);
+ module(1, m_numcols - 1, pos, 6);
+ module(2, m_numcols - 1, pos, 7);
+ module(3, m_numcols - 1, pos, 8);
}
-void CBC_DefaultPlacement::corner2(int32_t pos)
-{
- module(m_numrows - 3, 0, pos, 1);
- module(m_numrows - 2, 0, pos, 2);
- module(m_numrows - 1, 0, pos, 3);
- module(0, m_numcols - 4, pos, 4);
- module(0, m_numcols - 3, pos, 5);
- module(0, m_numcols - 2, pos, 6);
- module(0, m_numcols - 1, pos, 7);
- module(1, m_numcols - 1, pos, 8);
+void CBC_DefaultPlacement::corner2(int32_t pos) {
+ module(m_numrows - 3, 0, pos, 1);
+ module(m_numrows - 2, 0, pos, 2);
+ module(m_numrows - 1, 0, pos, 3);
+ module(0, m_numcols - 4, pos, 4);
+ module(0, m_numcols - 3, pos, 5);
+ module(0, m_numcols - 2, pos, 6);
+ module(0, m_numcols - 1, pos, 7);
+ module(1, m_numcols - 1, pos, 8);
}
-void CBC_DefaultPlacement::corner3(int32_t pos)
-{
- module(m_numrows - 3, 0, pos, 1);
- module(m_numrows - 2, 0, pos, 2);
- module(m_numrows - 1, 0, pos, 3);
- module(0, m_numcols - 2, pos, 4);
- module(0, m_numcols - 1, pos, 5);
- module(1, m_numcols - 1, pos, 6);
- module(2, m_numcols - 1, pos, 7);
- module(3, m_numcols - 1, pos, 8);
+void CBC_DefaultPlacement::corner3(int32_t pos) {
+ module(m_numrows - 3, 0, pos, 1);
+ module(m_numrows - 2, 0, pos, 2);
+ module(m_numrows - 1, 0, pos, 3);
+ module(0, m_numcols - 2, pos, 4);
+ module(0, m_numcols - 1, pos, 5);
+ module(1, m_numcols - 1, pos, 6);
+ module(2, m_numcols - 1, pos, 7);
+ module(3, m_numcols - 1, pos, 8);
}
-void CBC_DefaultPlacement::corner4(int32_t pos)
-{
- module(m_numrows - 1, 0, pos, 1);
- module(m_numrows - 1, m_numcols - 1, pos, 2);
- module(0, m_numcols - 3, pos, 3);
- module(0, m_numcols - 2, pos, 4);
- module(0, m_numcols - 1, pos, 5);
- module(1, m_numcols - 3, pos, 6);
- module(1, m_numcols - 2, pos, 7);
- module(1, m_numcols - 1, pos, 8);
+void CBC_DefaultPlacement::corner4(int32_t pos) {
+ module(m_numrows - 1, 0, pos, 1);
+ module(m_numrows - 1, m_numcols - 1, pos, 2);
+ module(0, m_numcols - 3, pos, 3);
+ module(0, m_numcols - 2, pos, 4);
+ module(0, m_numcols - 1, pos, 5);
+ module(1, m_numcols - 3, pos, 6);
+ module(1, m_numcols - 2, pos, 7);
+ module(1, m_numcols - 1, pos, 8);
}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DefaultPlacement.h b/xfa/src/fxbarcode/datamatrix/BC_DefaultPlacement.h index dec26a6c70..67bf7d95dd 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_DefaultPlacement.h +++ b/xfa/src/fxbarcode/datamatrix/BC_DefaultPlacement.h @@ -6,29 +6,31 @@ #ifndef _BC_DEFAULTPLACEMENT_H_
#define _BC_DEFAULTPLACEMENT_H_
-class CBC_DefaultPlacement
-{
-public:
- CBC_DefaultPlacement(CFX_WideString codewords, int32_t numcols, int32_t numrows);
- virtual ~CBC_DefaultPlacement();
+class CBC_DefaultPlacement {
+ public:
+ CBC_DefaultPlacement(CFX_WideString codewords,
+ int32_t numcols,
+ int32_t numrows);
+ virtual ~CBC_DefaultPlacement();
- int32_t getNumrows();
- int32_t getNumcols();
- CFX_ByteArray& getBits();
- FX_BOOL getBit(int32_t col, int32_t row);
- void setBit(int32_t col, int32_t row, FX_BOOL bit);
- FX_BOOL hasBit(int32_t col, int32_t row);
- void place();
-private:
- CFX_WideString m_codewords;
- int32_t m_numrows;
- int32_t m_numcols;
- CFX_ByteArray m_bits;
- void module(int32_t row, int32_t col, int32_t pos, int32_t bit);
- void utah(int32_t row, int32_t col, int32_t pos);
- void corner1(int32_t pos);
- void corner2(int32_t pos);
- void corner3(int32_t pos);
- void corner4(int32_t pos);
+ int32_t getNumrows();
+ int32_t getNumcols();
+ CFX_ByteArray& getBits();
+ FX_BOOL getBit(int32_t col, int32_t row);
+ void setBit(int32_t col, int32_t row, FX_BOOL bit);
+ FX_BOOL hasBit(int32_t col, int32_t row);
+ void place();
+
+ private:
+ CFX_WideString m_codewords;
+ int32_t m_numrows;
+ int32_t m_numcols;
+ CFX_ByteArray m_bits;
+ void module(int32_t row, int32_t col, int32_t pos, int32_t bit);
+ void utah(int32_t row, int32_t col, int32_t pos);
+ void corner1(int32_t pos);
+ void corner2(int32_t pos);
+ void corner3(int32_t pos);
+ void corner4(int32_t pos);
};
#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_EdifactEncoder.cpp b/xfa/src/fxbarcode/datamatrix/BC_EdifactEncoder.cpp index cc46b8156d..60b796a196 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_EdifactEncoder.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_EdifactEncoder.cpp @@ -29,125 +29,126 @@ #include "BC_EncoderContext.h"
#include "BC_HighLevelEncoder.h"
#include "BC_EdifactEncoder.h"
-CBC_EdifactEncoder::CBC_EdifactEncoder()
-{
+CBC_EdifactEncoder::CBC_EdifactEncoder() {}
+CBC_EdifactEncoder::~CBC_EdifactEncoder() {}
+int32_t CBC_EdifactEncoder::getEncodingMode() {
+ return EDIFACT_ENCODATION;
}
-CBC_EdifactEncoder::~CBC_EdifactEncoder()
-{
-}
-int32_t CBC_EdifactEncoder::getEncodingMode()
-{
- return EDIFACT_ENCODATION;
-}
-void CBC_EdifactEncoder::Encode(CBC_EncoderContext &context, int32_t &e)
-{
- CFX_WideString buffer;
- while (context.hasMoreCharacters()) {
- FX_WCHAR c = context.getCurrentChar();
- encodeChar(c, buffer, e);
- if (e != BCExceptionNO) {
- return;
- }
- context.m_pos++;
- int32_t count = buffer.GetLength();
- if (count >= 4) {
- context.writeCodewords(encodeToCodewords(buffer, 0, e));
- if (e != BCExceptionNO) {
- return;
- }
- buffer.Delete(0, 4);
- int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(context.m_msg, context.m_pos, getEncodingMode());
- if (newMode != getEncodingMode()) {
- context.signalEncoderChange(ASCII_ENCODATION);
- break;
- }
- }
+void CBC_EdifactEncoder::Encode(CBC_EncoderContext& context, int32_t& e) {
+ CFX_WideString buffer;
+ while (context.hasMoreCharacters()) {
+ FX_WCHAR c = context.getCurrentChar();
+ encodeChar(c, buffer, e);
+ if (e != BCExceptionNO) {
+ return;
}
- buffer += (FX_WCHAR)31;
- handleEOD(context, buffer, e);
-}
-void CBC_EdifactEncoder::handleEOD(CBC_EncoderContext &context, CFX_WideString buffer, int32_t &e)
-{
+ context.m_pos++;
int32_t count = buffer.GetLength();
- if (count == 0) {
+ if (count >= 4) {
+ context.writeCodewords(encodeToCodewords(buffer, 0, e));
+ if (e != BCExceptionNO) {
return;
+ }
+ buffer.Delete(0, 4);
+ int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(
+ context.m_msg, context.m_pos, getEncodingMode());
+ if (newMode != getEncodingMode()) {
+ context.signalEncoderChange(ASCII_ENCODATION);
+ break;
+ }
}
- if (count == 1) {
- context.updateSymbolInfo(e);
- if (e != BCExceptionNO) {
- return;
- }
- int32_t available = context.m_symbolInfo->m_dataCapacity - context.getCodewordCount();
- int32_t remaining = context.getRemainingCharacters();
- if (remaining == 0 && available <= 2) {
- return;
- }
+ }
+ buffer += (FX_WCHAR)31;
+ handleEOD(context, buffer, e);
+}
+void CBC_EdifactEncoder::handleEOD(CBC_EncoderContext& context,
+ CFX_WideString buffer,
+ int32_t& e) {
+ int32_t count = buffer.GetLength();
+ if (count == 0) {
+ return;
+ }
+ if (count == 1) {
+ context.updateSymbolInfo(e);
+ if (e != BCExceptionNO) {
+ return;
}
- if (count > 4) {
- e = BCExceptionIllegalStateCountMustNotExceed4;
- return;
+ int32_t available =
+ context.m_symbolInfo->m_dataCapacity - context.getCodewordCount();
+ int32_t remaining = context.getRemainingCharacters();
+ if (remaining == 0 && available <= 2) {
+ return;
}
- int32_t restChars = count - 1;
- CFX_WideString encoded = encodeToCodewords(buffer, 0, e);
+ }
+ if (count > 4) {
+ e = BCExceptionIllegalStateCountMustNotExceed4;
+ return;
+ }
+ int32_t restChars = count - 1;
+ CFX_WideString encoded = encodeToCodewords(buffer, 0, e);
+ if (e != BCExceptionNO) {
+ return;
+ }
+ FX_BOOL endOfSymbolReached = !context.hasMoreCharacters();
+ FX_BOOL restInAscii = endOfSymbolReached && restChars <= 2;
+ if (restChars <= 2) {
+ context.updateSymbolInfo(context.getCodewordCount() + restChars, e);
if (e != BCExceptionNO) {
- return;
- }
- FX_BOOL endOfSymbolReached = !context.hasMoreCharacters();
- FX_BOOL restInAscii = endOfSymbolReached && restChars <= 2;
- if (restChars <= 2) {
- context.updateSymbolInfo(context.getCodewordCount() + restChars, e);
- if (e != BCExceptionNO) {
- return;
- }
- int32_t available = context.m_symbolInfo->m_dataCapacity - context.getCodewordCount();
- if (available >= 3) {
- restInAscii = FALSE;
- context.updateSymbolInfo(context.getCodewordCount() + encoded.GetLength(), e);
- if (e != BCExceptionNO) {
- return;
- }
- }
+ return;
}
- if (restInAscii) {
- context.resetSymbolInfo();
- context.m_pos -= restChars;
- } else {
- context.writeCodewords(encoded);
+ int32_t available =
+ context.m_symbolInfo->m_dataCapacity - context.getCodewordCount();
+ if (available >= 3) {
+ restInAscii = FALSE;
+ context.updateSymbolInfo(context.getCodewordCount() + encoded.GetLength(),
+ e);
+ if (e != BCExceptionNO) {
+ return;
+ }
}
- context.signalEncoderChange(ASCII_ENCODATION);
+ }
+ if (restInAscii) {
+ context.resetSymbolInfo();
+ context.m_pos -= restChars;
+ } else {
+ context.writeCodewords(encoded);
+ }
+ context.signalEncoderChange(ASCII_ENCODATION);
}
-void CBC_EdifactEncoder::encodeChar(FX_WCHAR c, CFX_WideString &sb, int32_t &e)
-{
- if (c >= ' ' && c <= '?') {
- sb += c;
- } else if (c >= '@' && c <= '^') {
- sb += (FX_WCHAR)(c - 64);
- } else {
- CBC_HighLevelEncoder::illegalCharacter(c, e);
- }
+void CBC_EdifactEncoder::encodeChar(FX_WCHAR c,
+ CFX_WideString& sb,
+ int32_t& e) {
+ if (c >= ' ' && c <= '?') {
+ sb += c;
+ } else if (c >= '@' && c <= '^') {
+ sb += (FX_WCHAR)(c - 64);
+ } else {
+ CBC_HighLevelEncoder::illegalCharacter(c, e);
+ }
}
-CFX_WideString CBC_EdifactEncoder::encodeToCodewords(CFX_WideString sb, int32_t startPos, int32_t &e)
-{
- int32_t len = sb.GetLength() - startPos;
- if (len == 0) {
- e = BCExceptionNoContents;
- return (FX_WCHAR*)"";
- }
- FX_WCHAR c1 = sb.GetAt(startPos);
- FX_WCHAR c2 = len >= 2 ? sb.GetAt(startPos + 1) : 0;
- FX_WCHAR c3 = len >= 3 ? sb.GetAt(startPos + 2) : 0;
- FX_WCHAR c4 = len >= 4 ? sb.GetAt(startPos + 3) : 0;
- int32_t v = (c1 << 18) + (c2 << 12) + (c3 << 6) + c4;
- FX_WCHAR cw1 = (FX_WCHAR) ((v >> 16) & 255);
- FX_WCHAR cw2 = (FX_WCHAR) ((v >> 8) & 255);
- FX_WCHAR cw3 = (FX_WCHAR) (v & 255);
- CFX_WideString res;
- res += cw1;
- if (len >= 2) {
- res += cw2;
- }
- if (len >= 3) {
- res += cw3;
- }
- return res;
+CFX_WideString CBC_EdifactEncoder::encodeToCodewords(CFX_WideString sb,
+ int32_t startPos,
+ int32_t& e) {
+ int32_t len = sb.GetLength() - startPos;
+ if (len == 0) {
+ e = BCExceptionNoContents;
+ return (FX_WCHAR*)"";
+ }
+ FX_WCHAR c1 = sb.GetAt(startPos);
+ FX_WCHAR c2 = len >= 2 ? sb.GetAt(startPos + 1) : 0;
+ FX_WCHAR c3 = len >= 3 ? sb.GetAt(startPos + 2) : 0;
+ FX_WCHAR c4 = len >= 4 ? sb.GetAt(startPos + 3) : 0;
+ int32_t v = (c1 << 18) + (c2 << 12) + (c3 << 6) + c4;
+ FX_WCHAR cw1 = (FX_WCHAR)((v >> 16) & 255);
+ FX_WCHAR cw2 = (FX_WCHAR)((v >> 8) & 255);
+ FX_WCHAR cw3 = (FX_WCHAR)(v & 255);
+ CFX_WideString res;
+ res += cw1;
+ if (len >= 2) {
+ res += cw2;
+ }
+ if (len >= 3) {
+ res += cw3;
+ }
+ return res;
}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_EdifactEncoder.h b/xfa/src/fxbarcode/datamatrix/BC_EdifactEncoder.h index 6b102c689c..7309c07fae 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_EdifactEncoder.h +++ b/xfa/src/fxbarcode/datamatrix/BC_EdifactEncoder.h @@ -8,16 +8,20 @@ #define _BC_EDIFACTENCODER_H_
class CBC_EncoderContext;
class CBC_EdifactEncoder;
-class CBC_EdifactEncoder : public CBC_Encoder
-{
-public:
- CBC_EdifactEncoder();
- virtual ~CBC_EdifactEncoder();
- int32_t getEncodingMode();
- void Encode(CBC_EncoderContext &context, int32_t &e);
-private:
- static void handleEOD(CBC_EncoderContext &context, CFX_WideString buffer, int32_t &e);
- static void encodeChar(FX_WCHAR c, CFX_WideString &sb, int32_t &e);
- static CFX_WideString encodeToCodewords(CFX_WideString sb, int32_t startPos, int32_t &e);
+class CBC_EdifactEncoder : public CBC_Encoder {
+ public:
+ CBC_EdifactEncoder();
+ virtual ~CBC_EdifactEncoder();
+ int32_t getEncodingMode();
+ void Encode(CBC_EncoderContext& context, int32_t& e);
+
+ private:
+ static void handleEOD(CBC_EncoderContext& context,
+ CFX_WideString buffer,
+ int32_t& e);
+ static void encodeChar(FX_WCHAR c, CFX_WideString& sb, int32_t& e);
+ static CFX_WideString encodeToCodewords(CFX_WideString sb,
+ int32_t startPos,
+ int32_t& e);
};
#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_Encoder.cpp b/xfa/src/fxbarcode/datamatrix/BC_Encoder.cpp index acae555afe..4858e19fb8 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_Encoder.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_Encoder.cpp @@ -6,9 +6,5 @@ #include "../barcode.h"
#include "BC_Encoder.h"
-CBC_Encoder::CBC_Encoder()
-{
-}
-CBC_Encoder::~CBC_Encoder()
-{
-}
+CBC_Encoder::CBC_Encoder() {}
+CBC_Encoder::~CBC_Encoder() {}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_Encoder.h b/xfa/src/fxbarcode/datamatrix/BC_Encoder.h index 9a51af06e9..76b02356d8 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_Encoder.h +++ b/xfa/src/fxbarcode/datamatrix/BC_Encoder.h @@ -7,12 +7,11 @@ #ifndef _BC_ENCODER_H_
#define _BC_ENCODER_H_
class CBC_EncoderContext;
-class CBC_Encoder
-{
-public:
- CBC_Encoder();
- virtual ~CBC_Encoder();
- virtual int32_t getEncodingMode() = 0;
- virtual void Encode(CBC_EncoderContext &context, int32_t &e) = 0;
+class CBC_Encoder {
+ public:
+ CBC_Encoder();
+ virtual ~CBC_Encoder();
+ virtual int32_t getEncodingMode() = 0;
+ virtual void Encode(CBC_EncoderContext& context, int32_t& e) = 0;
};
#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_EncoderContext.cpp b/xfa/src/fxbarcode/datamatrix/BC_EncoderContext.cpp index 066b4b2037..8b3093c836 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_EncoderContext.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_EncoderContext.cpp @@ -28,100 +28,84 @@ #include "BC_SymbolShapeHint.h"
#include "BC_SymbolInfo.h"
#include "BC_EncoderContext.h"
-CBC_EncoderContext::CBC_EncoderContext(const CFX_WideString msg, CFX_WideString ecLevel, int32_t &e)
-{
- CFX_ByteString dststr;
- CBC_UtilCodingConvert::UnicodeToUTF8(msg, dststr);
- CFX_WideString sb;
- int32_t c = dststr.GetLength();
- for (int32_t i = 0; i < c; i++) {
- FX_WCHAR ch = (FX_WCHAR)(dststr.GetAt(i) & 0xff);
- if (ch == '?' && dststr.GetAt(i) != '?') {
- e = BCExceptionCharactersOutsideISO88591Encoding;
- }
- sb += ch;
- }
- m_msg = sb;
- m_shape = FORCE_NONE;
- m_newEncoding = -1;
- m_pos = 0;
- m_symbolInfo = NULL;
- m_skipAtEnd = 0;
- m_maxSize = NULL;
- m_minSize = NULL;
-}
-CBC_EncoderContext::~CBC_EncoderContext()
-{
-}
-void CBC_EncoderContext::setSymbolShape(SymbolShapeHint shape)
-{
- m_shape = shape;
-}
-void CBC_EncoderContext::setSizeConstraints(CBC_Dimension* minSize, CBC_Dimension* maxSize)
-{
- m_maxSize = maxSize;
- m_minSize = minSize;
-}
-CFX_WideString CBC_EncoderContext::getMessage()
-{
- return m_msg;
-}
-void CBC_EncoderContext::setSkipAtEnd(int32_t count)
-{
- m_skipAtEnd = count;
-}
-FX_WCHAR CBC_EncoderContext::getCurrentChar()
-{
- return m_msg.GetAt(m_pos);
-}
-FX_WCHAR CBC_EncoderContext::getCurrent()
-{
- return m_msg.GetAt(m_pos);
-}
-void CBC_EncoderContext::writeCodewords(CFX_WideString codewords)
-{
- m_codewords += codewords;
-}
-void CBC_EncoderContext::writeCodeword(FX_WCHAR codeword)
-{
- m_codewords += codeword;
-}
-int32_t CBC_EncoderContext::getCodewordCount()
-{
- return m_codewords.GetLength();
-}
-void CBC_EncoderContext::signalEncoderChange(int32_t encoding)
-{
- m_newEncoding = encoding;
-}
-void CBC_EncoderContext::resetEncoderSignal()
-{
- m_newEncoding = -1;
-}
-FX_BOOL CBC_EncoderContext::hasMoreCharacters()
-{
- return m_pos < getTotalMessageCharCount();
-}
-int32_t CBC_EncoderContext::getRemainingCharacters()
-{
- return getTotalMessageCharCount() - m_pos;
-}
-void CBC_EncoderContext::updateSymbolInfo(int32_t &e)
-{
- updateSymbolInfo(getCodewordCount(), e);
-}
-void CBC_EncoderContext::updateSymbolInfo(int32_t len, int32_t &e)
-{
- if (m_symbolInfo == NULL || len > m_symbolInfo->m_dataCapacity) {
- m_symbolInfo = CBC_SymbolInfo::lookup(len, m_shape, m_minSize, m_maxSize, true, e);
- BC_EXCEPTION_CHECK_ReturnVoid(e);
+CBC_EncoderContext::CBC_EncoderContext(const CFX_WideString msg,
+ CFX_WideString ecLevel,
+ int32_t& e) {
+ CFX_ByteString dststr;
+ CBC_UtilCodingConvert::UnicodeToUTF8(msg, dststr);
+ CFX_WideString sb;
+ int32_t c = dststr.GetLength();
+ for (int32_t i = 0; i < c; i++) {
+ FX_WCHAR ch = (FX_WCHAR)(dststr.GetAt(i) & 0xff);
+ if (ch == '?' && dststr.GetAt(i) != '?') {
+ e = BCExceptionCharactersOutsideISO88591Encoding;
}
+ sb += ch;
+ }
+ m_msg = sb;
+ m_shape = FORCE_NONE;
+ m_newEncoding = -1;
+ m_pos = 0;
+ m_symbolInfo = NULL;
+ m_skipAtEnd = 0;
+ m_maxSize = NULL;
+ m_minSize = NULL;
+}
+CBC_EncoderContext::~CBC_EncoderContext() {}
+void CBC_EncoderContext::setSymbolShape(SymbolShapeHint shape) {
+ m_shape = shape;
+}
+void CBC_EncoderContext::setSizeConstraints(CBC_Dimension* minSize,
+ CBC_Dimension* maxSize) {
+ m_maxSize = maxSize;
+ m_minSize = minSize;
+}
+CFX_WideString CBC_EncoderContext::getMessage() {
+ return m_msg;
+}
+void CBC_EncoderContext::setSkipAtEnd(int32_t count) {
+ m_skipAtEnd = count;
+}
+FX_WCHAR CBC_EncoderContext::getCurrentChar() {
+ return m_msg.GetAt(m_pos);
+}
+FX_WCHAR CBC_EncoderContext::getCurrent() {
+ return m_msg.GetAt(m_pos);
+}
+void CBC_EncoderContext::writeCodewords(CFX_WideString codewords) {
+ m_codewords += codewords;
+}
+void CBC_EncoderContext::writeCodeword(FX_WCHAR codeword) {
+ m_codewords += codeword;
+}
+int32_t CBC_EncoderContext::getCodewordCount() {
+ return m_codewords.GetLength();
+}
+void CBC_EncoderContext::signalEncoderChange(int32_t encoding) {
+ m_newEncoding = encoding;
+}
+void CBC_EncoderContext::resetEncoderSignal() {
+ m_newEncoding = -1;
+}
+FX_BOOL CBC_EncoderContext::hasMoreCharacters() {
+ return m_pos < getTotalMessageCharCount();
+}
+int32_t CBC_EncoderContext::getRemainingCharacters() {
+ return getTotalMessageCharCount() - m_pos;
+}
+void CBC_EncoderContext::updateSymbolInfo(int32_t& e) {
+ updateSymbolInfo(getCodewordCount(), e);
+}
+void CBC_EncoderContext::updateSymbolInfo(int32_t len, int32_t& e) {
+ if (m_symbolInfo == NULL || len > m_symbolInfo->m_dataCapacity) {
+ m_symbolInfo =
+ CBC_SymbolInfo::lookup(len, m_shape, m_minSize, m_maxSize, true, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ }
}
-void CBC_EncoderContext::resetSymbolInfo()
-{
- m_shape = FORCE_NONE;
+void CBC_EncoderContext::resetSymbolInfo() {
+ m_shape = FORCE_NONE;
}
-int32_t CBC_EncoderContext::getTotalMessageCharCount()
-{
- return m_msg.GetLength() - m_skipAtEnd;
+int32_t CBC_EncoderContext::getTotalMessageCharCount() {
+ return m_msg.GetLength() - m_skipAtEnd;
}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_EncoderContext.h b/xfa/src/fxbarcode/datamatrix/BC_EncoderContext.h index e2dd0b35bb..45a23283b2 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_EncoderContext.h +++ b/xfa/src/fxbarcode/datamatrix/BC_EncoderContext.h @@ -10,39 +10,43 @@ class CBC_SymbolShapeHint; class CBC_SymbolInfo;
class CBC_Dimension;
class CBC_EncoderContext;
-class CBC_EncoderContext : public CBC_SymbolShapeHint
-{
-public:
- CBC_EncoderContext(const CFX_WideString msg, CFX_WideString ecLevel, int32_t &e);
- virtual ~CBC_EncoderContext();
- void setSymbolShape(SymbolShapeHint shape);
- void setSizeConstraints(CBC_Dimension* minSize, CBC_Dimension* maxSize);
- CFX_WideString getMessage();
- void setSkipAtEnd(int32_t count);
- FX_WCHAR getCurrentChar();
- FX_WCHAR getCurrent();
- void writeCodewords(CFX_WideString codewords);
- void writeCodeword(FX_WCHAR codeword);
- int32_t getCodewordCount();
- void signalEncoderChange(int32_t encoding);
- void resetEncoderSignal();
- FX_BOOL hasMoreCharacters();
- int32_t getRemainingCharacters();
- void updateSymbolInfo(int32_t &e);
- void updateSymbolInfo(int32_t len, int32_t &e);
- void resetSymbolInfo();
-public:
- CFX_WideString m_msg;
- CFX_WideString m_codewords;
- int32_t m_pos;
- int32_t m_newEncoding;
- CBC_SymbolInfo* m_symbolInfo;
-private:
- int32_t getTotalMessageCharCount();
-private:
- SymbolShapeHint m_shape;
- CBC_Dimension* m_minSize;
- CBC_Dimension* m_maxSize;
- int32_t m_skipAtEnd;
+class CBC_EncoderContext : public CBC_SymbolShapeHint {
+ public:
+ CBC_EncoderContext(const CFX_WideString msg,
+ CFX_WideString ecLevel,
+ int32_t& e);
+ virtual ~CBC_EncoderContext();
+ void setSymbolShape(SymbolShapeHint shape);
+ void setSizeConstraints(CBC_Dimension* minSize, CBC_Dimension* maxSize);
+ CFX_WideString getMessage();
+ void setSkipAtEnd(int32_t count);
+ FX_WCHAR getCurrentChar();
+ FX_WCHAR getCurrent();
+ void writeCodewords(CFX_WideString codewords);
+ void writeCodeword(FX_WCHAR codeword);
+ int32_t getCodewordCount();
+ void signalEncoderChange(int32_t encoding);
+ void resetEncoderSignal();
+ FX_BOOL hasMoreCharacters();
+ int32_t getRemainingCharacters();
+ void updateSymbolInfo(int32_t& e);
+ void updateSymbolInfo(int32_t len, int32_t& e);
+ void resetSymbolInfo();
+
+ public:
+ CFX_WideString m_msg;
+ CFX_WideString m_codewords;
+ int32_t m_pos;
+ int32_t m_newEncoding;
+ CBC_SymbolInfo* m_symbolInfo;
+
+ private:
+ int32_t getTotalMessageCharCount();
+
+ private:
+ SymbolShapeHint m_shape;
+ CBC_Dimension* m_minSize;
+ CBC_Dimension* m_maxSize;
+ int32_t m_skipAtEnd;
};
#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_ErrorCorrection.cpp b/xfa/src/fxbarcode/datamatrix/BC_ErrorCorrection.cpp index 9833f2871e..32dd416522 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_ErrorCorrection.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_ErrorCorrection.cpp @@ -25,7 +25,8 @@ #include "BC_SymbolShapeHint.h"
#include "BC_SymbolInfo.h"
#include "BC_ErrorCorrection.h"
-int32_t CBC_ErrorCorrection::FACTOR_SETS[] = {5, 7, 10, 11, 12, 14, 18, 20, 24, 28, 36, 42, 48, 56, 62, 68};
+int32_t CBC_ErrorCorrection::FACTOR_SETS[] = {5, 7, 10, 11, 12, 14, 18, 20,
+ 24, 28, 36, 42, 48, 56, 62, 68};
int32_t CBC_ErrorCorrection::FACTORS[][100] = {
{228, 48, 15, 111, 62},
{23, 68, 144, 134, 240, 92, 254},
@@ -33,162 +34,149 @@ int32_t CBC_ErrorCorrection::FACTORS[][100] = { {175, 138, 205, 12, 194, 168, 39, 245, 60, 97, 120},
{41, 153, 158, 91, 61, 42, 142, 213, 97, 178, 100, 242},
{156, 97, 192, 252, 95, 9, 157, 119, 138, 45, 18, 186, 83, 185},
- {83, 195, 100, 39, 188, 75, 66, 61, 241, 213, 109, 129, 94, 254, 225, 48, 90, 188},
- {15, 195, 244, 9, 233, 71, 168, 2, 188, 160, 153, 145, 253, 79, 108, 82, 27, 174, 186, 172},
- {
- 52, 190, 88, 205, 109, 39, 176, 21, 155, 197, 251, 223, 155, 21, 5, 172,
- 254, 124, 12, 181, 184, 96, 50, 193
- },
- {
- 211, 231, 43, 97, 71, 96, 103, 174, 37, 151, 170, 53, 75, 34, 249, 121,
- 17, 138, 110, 213, 141, 136, 120, 151, 233, 168, 93, 255
- },
- {
- 245, 127, 242, 218, 130, 250, 162, 181, 102, 120, 84, 179, 220, 251, 80, 182,
- 229, 18, 2, 4, 68, 33, 101, 137, 95, 119, 115, 44, 175, 184, 59, 25,
- 225, 98, 81, 112
- },
- {
- 77, 193, 137, 31, 19, 38, 22, 153, 247, 105, 122, 2, 245, 133, 242, 8,
- 175, 95, 100, 9, 167, 105, 214, 111, 57, 121, 21, 1, 253, 57, 54, 101,
- 248, 202, 69, 50, 150, 177, 226, 5, 9, 5
- },
- {
- 245, 132, 172, 223, 96, 32, 117, 22, 238, 133, 238, 231, 205, 188, 237, 87,
- 191, 106, 16, 147, 118, 23, 37, 90, 170, 205, 131, 88, 120, 100, 66, 138,
- 186, 240, 82, 44, 176, 87, 187, 147, 160, 175, 69, 213, 92, 253, 225, 19
- },
- {
- 175, 9, 223, 238, 12, 17, 220, 208, 100, 29, 175, 170, 230, 192, 215, 235,
- 150, 159, 36, 223, 38, 200, 132, 54, 228, 146, 218, 234, 117, 203, 29, 232,
- 144, 238, 22, 150, 201, 117, 62, 207, 164, 13, 137, 245, 127, 67, 247, 28,
- 155, 43, 203, 107, 233, 53, 143, 46
- },
- {
- 242, 93, 169, 50, 144, 210, 39, 118, 202, 188, 201, 189, 143, 108, 196, 37,
- 185, 112, 134, 230, 245, 63, 197, 190, 250, 106, 185, 221, 175, 64, 114, 71,
- 161, 44, 147, 6, 27, 218, 51, 63, 87, 10, 40, 130, 188, 17, 163, 31,
- 176, 170, 4, 107, 232, 7, 94, 166, 224, 124, 86, 47, 11, 204
- },
- {
- 220, 228, 173, 89, 251, 149, 159, 56, 89, 33, 147, 244, 154, 36, 73, 127,
- 213, 136, 248, 180, 234, 197, 158, 177, 68, 122, 93, 213, 15, 160, 227, 236,
- 66, 139, 153, 185, 202, 167, 179, 25, 220, 232, 96, 210, 231, 136, 223, 239,
- 181, 241, 59, 52, 172, 25, 49, 232, 211, 189, 64, 54, 108, 153, 132, 63,
- 96, 103, 82, 186
- }
-};
+ {83, 195, 100, 39, 188, 75, 66, 61, 241, 213, 109, 129, 94, 254, 225, 48,
+ 90, 188},
+ {15, 195, 244, 9, 233, 71, 168, 2, 188, 160, 153, 145, 253, 79, 108, 82, 27,
+ 174, 186, 172},
+ {52, 190, 88, 205, 109, 39, 176, 21, 155, 197, 251, 223, 155, 21, 5, 172,
+ 254, 124, 12, 181, 184, 96, 50, 193},
+ {211, 231, 43, 97, 71, 96, 103, 174, 37, 151, 170, 53, 75, 34, 249, 121, 17,
+ 138, 110, 213, 141, 136, 120, 151, 233, 168, 93, 255},
+ {245, 127, 242, 218, 130, 250, 162, 181, 102, 120, 84, 179, 220, 251, 80,
+ 182, 229, 18, 2, 4, 68, 33, 101, 137, 95, 119, 115, 44, 175, 184, 59, 25,
+ 225, 98, 81, 112},
+ {77, 193, 137, 31, 19, 38, 22, 153, 247, 105, 122, 2, 245, 133, 242, 8, 175,
+ 95, 100, 9, 167, 105, 214, 111, 57, 121, 21, 1, 253, 57, 54, 101, 248, 202,
+ 69, 50, 150, 177, 226, 5, 9, 5},
+ {245, 132, 172, 223, 96, 32, 117, 22, 238, 133, 238, 231, 205, 188, 237, 87,
+ 191, 106, 16, 147, 118, 23, 37, 90, 170, 205, 131, 88, 120, 100, 66, 138,
+ 186, 240, 82, 44, 176, 87, 187, 147, 160, 175, 69, 213, 92, 253, 225, 19},
+ {175, 9, 223, 238, 12, 17, 220, 208, 100, 29, 175, 170, 230, 192, 215, 235,
+ 150, 159, 36, 223, 38, 200, 132, 54, 228, 146, 218, 234, 117, 203, 29, 232,
+ 144, 238, 22, 150, 201, 117, 62, 207, 164, 13, 137, 245, 127, 67, 247, 28,
+ 155, 43, 203, 107, 233, 53, 143, 46},
+ {242, 93, 169, 50, 144, 210, 39, 118, 202, 188, 201, 189, 143, 108, 196, 37,
+ 185, 112, 134, 230, 245, 63, 197, 190, 250, 106, 185, 221, 175, 64, 114,
+ 71, 161, 44, 147, 6, 27, 218, 51, 63, 87, 10, 40, 130, 188, 17, 163, 31,
+ 176, 170, 4, 107, 232, 7, 94, 166, 224, 124, 86, 47, 11, 204},
+ {220, 228, 173, 89, 251, 149, 159, 56, 89, 33, 147, 244, 154, 36, 73, 127,
+ 213, 136, 248, 180, 234, 197, 158, 177, 68, 122, 93, 213, 15, 160, 227,
+ 236, 66, 139, 153, 185, 202, 167, 179, 25, 220, 232, 96, 210, 231, 136,
+ 223, 239, 181, 241, 59, 52, 172, 25, 49, 232, 211, 189, 64, 54, 108, 153,
+ 132, 63, 96, 103, 82, 186}};
int32_t CBC_ErrorCorrection::MODULO_VALUE = 0x12D;
int32_t CBC_ErrorCorrection::LOG[256] = {0};
int32_t CBC_ErrorCorrection::ALOG[256] = {0};
-void CBC_ErrorCorrection::Initialize()
-{
- int32_t p = 1;
- for (int32_t i = 0; i < 255; i++) {
- ALOG[i] = p;
- LOG[p] = i;
- p <<= 1;
- if (p >= 256) {
- p ^= MODULO_VALUE;
- }
+void CBC_ErrorCorrection::Initialize() {
+ int32_t p = 1;
+ for (int32_t i = 0; i < 255; i++) {
+ ALOG[i] = p;
+ LOG[p] = i;
+ p <<= 1;
+ if (p >= 256) {
+ p ^= MODULO_VALUE;
}
+ }
}
-void CBC_ErrorCorrection::Finalize()
-{
-}
-CBC_ErrorCorrection::CBC_ErrorCorrection()
-{
-}
-CBC_ErrorCorrection::~CBC_ErrorCorrection()
-{
-}
-CFX_WideString CBC_ErrorCorrection::encodeECC200(CFX_WideString codewords, CBC_SymbolInfo* symbolInfo, int32_t &e)
-{
- if (codewords.GetLength() != symbolInfo->m_dataCapacity) {
- e = BCExceptionIllegalArgument;
- return (FX_WCHAR*)"";
+void CBC_ErrorCorrection::Finalize() {}
+CBC_ErrorCorrection::CBC_ErrorCorrection() {}
+CBC_ErrorCorrection::~CBC_ErrorCorrection() {}
+CFX_WideString CBC_ErrorCorrection::encodeECC200(CFX_WideString codewords,
+ CBC_SymbolInfo* symbolInfo,
+ int32_t& e) {
+ if (codewords.GetLength() != symbolInfo->m_dataCapacity) {
+ e = BCExceptionIllegalArgument;
+ return (FX_WCHAR*)"";
+ }
+ CFX_WideString sb;
+ sb += codewords;
+ int32_t blockCount = symbolInfo->getInterleavedBlockCount();
+ if (blockCount == 1) {
+ CFX_WideString ecc =
+ createECCBlock(codewords, symbolInfo->m_errorCodewords, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)"");
+ sb += ecc;
+ } else {
+ CFX_Int32Array dataSizes;
+ dataSizes.SetSize(blockCount);
+ CFX_Int32Array errorSizes;
+ errorSizes.SetSize(blockCount);
+ CFX_Int32Array startPos;
+ startPos.SetSize(blockCount);
+ for (int32_t i = 0; i < blockCount; i++) {
+ dataSizes[i] = symbolInfo->getDataLengthForInterleavedBlock(i + 1);
+ errorSizes[i] = symbolInfo->getErrorLengthForInterleavedBlock(i + 1);
+ startPos[i] = 0;
+ if (i > 0) {
+ startPos[i] = startPos[i - 1] + dataSizes[i];
+ }
}
- CFX_WideString sb;
- sb += codewords;
- int32_t blockCount = symbolInfo->getInterleavedBlockCount();
- if (blockCount == 1) {
- CFX_WideString ecc = createECCBlock(codewords, symbolInfo->m_errorCodewords, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)"");
- sb += ecc;
- } else {
- CFX_Int32Array dataSizes;
- dataSizes.SetSize(blockCount);
- CFX_Int32Array errorSizes;
- errorSizes.SetSize(blockCount);
- CFX_Int32Array startPos;
- startPos.SetSize(blockCount);
- for (int32_t i = 0; i < blockCount; i++) {
- dataSizes[i] = symbolInfo->getDataLengthForInterleavedBlock(i + 1);
- errorSizes[i] = symbolInfo->getErrorLengthForInterleavedBlock(i + 1);
- startPos[i] = 0;
- if (i > 0) {
- startPos[i] = startPos[i - 1] + dataSizes[i];
- }
- }
- for (int32_t block = 0; block < blockCount; block++) {
- CFX_WideString temp;
- for (int32_t d = block; d < symbolInfo->m_dataCapacity; d += blockCount) {
- temp += (FX_WCHAR)codewords.GetAt(d);
- }
- CFX_WideString ecc = createECCBlock(temp, errorSizes[block], e);
- BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)"");
- int32_t pos = 0;
- for (int32_t l = block; l < errorSizes[block] * blockCount; l += blockCount) {
- sb.SetAt(symbolInfo->m_dataCapacity + l, ecc.GetAt(pos++));
- }
- }
+ for (int32_t block = 0; block < blockCount; block++) {
+ CFX_WideString temp;
+ for (int32_t d = block; d < symbolInfo->m_dataCapacity; d += blockCount) {
+ temp += (FX_WCHAR)codewords.GetAt(d);
+ }
+ CFX_WideString ecc = createECCBlock(temp, errorSizes[block], e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)"");
+ int32_t pos = 0;
+ for (int32_t l = block; l < errorSizes[block] * blockCount;
+ l += blockCount) {
+ sb.SetAt(symbolInfo->m_dataCapacity + l, ecc.GetAt(pos++));
+ }
}
- return sb;
+ }
+ return sb;
}
-CFX_WideString CBC_ErrorCorrection::createECCBlock(CFX_WideString codewords, int32_t numECWords, int32_t &e)
-{
- return createECCBlock(codewords, 0, codewords.GetLength(), numECWords, e);
+CFX_WideString CBC_ErrorCorrection::createECCBlock(CFX_WideString codewords,
+ int32_t numECWords,
+ int32_t& e) {
+ return createECCBlock(codewords, 0, codewords.GetLength(), numECWords, e);
}
-CFX_WideString CBC_ErrorCorrection::createECCBlock(CFX_WideString codewords, int32_t start, int32_t len, int32_t numECWords, int32_t &e)
-{
- int32_t table = -1;
- for (int32_t i = 0; i < sizeof(FACTOR_SETS) / sizeof(int32_t); i++) {
- if (FACTOR_SETS[i] == numECWords) {
- table = i;
- break;
- }
- }
- if (table < 0) {
- e = BCExceptionIllegalArgument;
- return (FX_WCHAR*)"";
+CFX_WideString CBC_ErrorCorrection::createECCBlock(CFX_WideString codewords,
+ int32_t start,
+ int32_t len,
+ int32_t numECWords,
+ int32_t& e) {
+ int32_t table = -1;
+ for (int32_t i = 0; i < sizeof(FACTOR_SETS) / sizeof(int32_t); i++) {
+ if (FACTOR_SETS[i] == numECWords) {
+ table = i;
+ break;
}
- FX_WORD* ecc = FX_Alloc(FX_WORD, numECWords);
- FXSYS_memset(ecc, 0, numECWords * sizeof(FX_WORD));
- for (int32_t l = start; l < start + len; l++) {
- uint8_t A = (uint8_t)codewords.GetAt(l);
- FX_WORD B = ecc[numECWords - 1];
- FX_WORD m = ecc[numECWords - 1] ^ codewords.GetAt(l);
- for (int32_t k = numECWords - 1; k > 0; k--) {
- if (m != 0 && FACTORS[table][k] != 0) {
- int32_t a = LOG[FACTORS[table][k]];
- int32_t b = ALOG[(LOG[m] + LOG[FACTORS[table][k]]) % 255];
- FX_WORD c = ecc[k - 1];
- FX_WORD D = (ecc[k - 1] ^ ALOG[(LOG[m] + LOG[FACTORS[table][k]]) % 255]);
- ecc[k] = (FX_WORD ) (ecc[k - 1] ^ ALOG[(LOG[m] + LOG[FACTORS[table][k]]) % 255]);
- } else {
- ecc[k] = ecc[k - 1];
- }
- }
- if (m != 0 && FACTORS[table][0] != 0) {
- ecc[0] = (FX_WORD) ALOG[(LOG[m] + LOG[FACTORS[table][0]]) % 255];
- } else {
- ecc[0] = 0;
- }
+ }
+ if (table < 0) {
+ e = BCExceptionIllegalArgument;
+ return (FX_WCHAR*)"";
+ }
+ FX_WORD* ecc = FX_Alloc(FX_WORD, numECWords);
+ FXSYS_memset(ecc, 0, numECWords * sizeof(FX_WORD));
+ for (int32_t l = start; l < start + len; l++) {
+ uint8_t A = (uint8_t)codewords.GetAt(l);
+ FX_WORD B = ecc[numECWords - 1];
+ FX_WORD m = ecc[numECWords - 1] ^ codewords.GetAt(l);
+ for (int32_t k = numECWords - 1; k > 0; k--) {
+ if (m != 0 && FACTORS[table][k] != 0) {
+ int32_t a = LOG[FACTORS[table][k]];
+ int32_t b = ALOG[(LOG[m] + LOG[FACTORS[table][k]]) % 255];
+ FX_WORD c = ecc[k - 1];
+ FX_WORD D =
+ (ecc[k - 1] ^ ALOG[(LOG[m] + LOG[FACTORS[table][k]]) % 255]);
+ ecc[k] = (FX_WORD)(ecc[k - 1] ^
+ ALOG[(LOG[m] + LOG[FACTORS[table][k]]) % 255]);
+ } else {
+ ecc[k] = ecc[k - 1];
+ }
}
- CFX_WideString strecc;
- for (int32_t j = 0; j < numECWords; j++) {
- strecc += (FX_WCHAR)ecc[numECWords - j - 1];
+ if (m != 0 && FACTORS[table][0] != 0) {
+ ecc[0] = (FX_WORD)ALOG[(LOG[m] + LOG[FACTORS[table][0]]) % 255];
+ } else {
+ ecc[0] = 0;
}
- FX_Free(ecc);
- return strecc;
+ }
+ CFX_WideString strecc;
+ for (int32_t j = 0; j < numECWords; j++) {
+ strecc += (FX_WCHAR)ecc[numECWords - j - 1];
+ }
+ FX_Free(ecc);
+ return strecc;
}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_ErrorCorrection.h b/xfa/src/fxbarcode/datamatrix/BC_ErrorCorrection.h index 2ec7b27aaa..4f8acc14ea 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_ErrorCorrection.h +++ b/xfa/src/fxbarcode/datamatrix/BC_ErrorCorrection.h @@ -7,22 +7,31 @@ #ifndef _BC_ERRORCORRECTION_H_
#define _BC_ERRORCORRECTION_H_
class CBC_SymbolInfo;
-class CBC_ErrorCorrection
-{
-public:
- CBC_ErrorCorrection();
- virtual ~CBC_ErrorCorrection();
- static void Initialize();
- static void Finalize();
- static CFX_WideString encodeECC200(CFX_WideString codewords, CBC_SymbolInfo* symbolInfo, int32_t &e);
-private:
- static int32_t FACTOR_SETS[];
- static int32_t FACTORS[][100];
- static int32_t MODULO_VALUE;
- static int32_t LOG[256];
- static int32_t ALOG[256];
-private:
- static CFX_WideString createECCBlock(CFX_WideString codewords, int32_t numECWords, int32_t &e);
- static CFX_WideString createECCBlock(CFX_WideString codewords, int32_t start, int32_t len, int32_t numECWords, int32_t &e);
+class CBC_ErrorCorrection {
+ public:
+ CBC_ErrorCorrection();
+ virtual ~CBC_ErrorCorrection();
+ static void Initialize();
+ static void Finalize();
+ static CFX_WideString encodeECC200(CFX_WideString codewords,
+ CBC_SymbolInfo* symbolInfo,
+ int32_t& e);
+
+ private:
+ static int32_t FACTOR_SETS[];
+ static int32_t FACTORS[][100];
+ static int32_t MODULO_VALUE;
+ static int32_t LOG[256];
+ static int32_t ALOG[256];
+
+ private:
+ static CFX_WideString createECCBlock(CFX_WideString codewords,
+ int32_t numECWords,
+ int32_t& e);
+ static CFX_WideString createECCBlock(CFX_WideString codewords,
+ int32_t start,
+ int32_t len,
+ int32_t numECWords,
+ int32_t& e);
};
#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp b/xfa/src/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp index 3aded2d349..986d6b2a7f 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp @@ -35,7 +35,7 @@ #include "BC_Base256Encoder.h"
#include "BC_ASCIIEncoder.h"
#include "BC_HighLevelEncoder.h"
-#define Integer_MAX_VALUE 2147483647
+#define Integer_MAX_VALUE 2147483647
FX_WCHAR CBC_HighLevelEncoder::LATCH_TO_C40 = 230;
FX_WCHAR CBC_HighLevelEncoder::LATCH_TO_BASE256 = 231;
FX_WCHAR CBC_HighLevelEncoder::UPPER_SHIFT = 235;
@@ -50,319 +50,322 @@ FX_WCHAR CBC_HighLevelEncoder::MACRO_06 = 237; const wchar_t* CBC_HighLevelEncoder::MACRO_05_HEADER = L"[)>05";
const wchar_t* CBC_HighLevelEncoder::MACRO_06_HEADER = L"[)>06";
const wchar_t CBC_HighLevelEncoder::MACRO_TRAILER = 0x0004;
-CBC_HighLevelEncoder::CBC_HighLevelEncoder()
-{
+CBC_HighLevelEncoder::CBC_HighLevelEncoder() {}
+CBC_HighLevelEncoder::~CBC_HighLevelEncoder() {}
+CFX_ByteArray& CBC_HighLevelEncoder::getBytesForMessage(CFX_WideString msg) {
+ CFX_ByteString bytestr;
+ CBC_UtilCodingConvert::UnicodeToUTF8(msg, bytestr);
+ for (int32_t i = 0; i < bytestr.GetLength(); i++) {
+ m_bytearray.Add(bytestr.GetAt(i));
+ }
+ return m_bytearray;
}
-CBC_HighLevelEncoder::~CBC_HighLevelEncoder()
-{
+CFX_WideString CBC_HighLevelEncoder::encodeHighLevel(CFX_WideString msg,
+ CFX_WideString ecLevel,
+ int32_t& e) {
+ return encodeHighLevel(msg, ecLevel, FORCE_NONE, NULL, NULL, e);
}
-CFX_ByteArray& CBC_HighLevelEncoder::getBytesForMessage(CFX_WideString msg)
-{
- CFX_ByteString bytestr;
- CBC_UtilCodingConvert::UnicodeToUTF8(msg, bytestr);
- for (int32_t i = 0; i < bytestr.GetLength(); i++) {
- m_bytearray.Add(bytestr.GetAt(i));
+CFX_WideString CBC_HighLevelEncoder::encodeHighLevel(CFX_WideString msg,
+ CFX_WideString ecLevel,
+ SymbolShapeHint shape,
+ CBC_Dimension* minSize,
+ CBC_Dimension* maxSize,
+ int32_t& e) {
+ CBC_EncoderContext context(msg, ecLevel, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)"");
+ context.setSymbolShape(shape);
+ context.setSizeConstraints(minSize, maxSize);
+ if ((msg.Mid(0, 6) == MACRO_05_HEADER) &&
+ (msg.Mid(msg.GetLength() - 1, 1) == MACRO_TRAILER)) {
+ context.writeCodeword(MACRO_05);
+ context.setSkipAtEnd(2);
+ context.m_pos += 6;
+ } else if ((msg.Mid(0, 6) == MACRO_06_HEADER) &&
+ (msg.Mid(msg.GetLength() - 1, 1) == MACRO_TRAILER)) {
+ context.writeCodeword(MACRO_06);
+ context.setSkipAtEnd(2);
+ context.m_pos += 6;
+ }
+ CFX_PtrArray encoders;
+ encoders.Add(FX_NEW CBC_ASCIIEncoder());
+ encoders.Add(FX_NEW CBC_C40Encoder());
+ encoders.Add(FX_NEW CBC_TextEncoder());
+ encoders.Add(FX_NEW CBC_X12Encoder());
+ encoders.Add(FX_NEW CBC_EdifactEncoder());
+ encoders.Add(FX_NEW CBC_Base256Encoder());
+ int32_t encodingMode = ASCII_ENCODATION;
+ while (context.hasMoreCharacters()) {
+ ((CBC_Encoder*)encoders.GetAt(encodingMode))->Encode(context, e);
+ if (e != BCExceptionNO) {
+ for (int32_t i = 0; i < encoders.GetSize(); i++) {
+ delete (CBC_Encoder*)encoders.GetAt(i);
+ }
+ encoders.RemoveAll();
+ return (FX_WCHAR*)"";
}
- return m_bytearray;
-}
-CFX_WideString CBC_HighLevelEncoder::encodeHighLevel(CFX_WideString msg, CFX_WideString ecLevel, int32_t &e)
-{
- return encodeHighLevel(msg, ecLevel, FORCE_NONE, NULL, NULL, e);
-}
-CFX_WideString CBC_HighLevelEncoder::encodeHighLevel(CFX_WideString msg, CFX_WideString ecLevel, SymbolShapeHint shape, CBC_Dimension* minSize, CBC_Dimension* maxSize, int32_t &e)
-{
- CBC_EncoderContext context(msg, ecLevel, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)"");
- context.setSymbolShape(shape);
- context.setSizeConstraints(minSize, maxSize);
- if ((msg.Mid(0, 6) == MACRO_05_HEADER) && (msg.Mid(msg.GetLength() - 1, 1) == MACRO_TRAILER)) {
- context.writeCodeword(MACRO_05);
- context.setSkipAtEnd(2);
- context.m_pos += 6;
- } else if ((msg.Mid(0, 6) == MACRO_06_HEADER) && (msg.Mid(msg.GetLength() - 1, 1) == MACRO_TRAILER)) {
- context.writeCodeword(MACRO_06);
- context.setSkipAtEnd(2);
- context.m_pos += 6;
+ if (context.m_newEncoding >= 0) {
+ encodingMode = context.m_newEncoding;
+ context.resetEncoderSignal();
}
- CFX_PtrArray encoders;
- encoders.Add(FX_NEW CBC_ASCIIEncoder());
- encoders.Add(FX_NEW CBC_C40Encoder());
- encoders.Add(FX_NEW CBC_TextEncoder());
- encoders.Add(FX_NEW CBC_X12Encoder());
- encoders.Add(FX_NEW CBC_EdifactEncoder());
- encoders.Add(FX_NEW CBC_Base256Encoder());
- int32_t encodingMode = ASCII_ENCODATION;
- while (context.hasMoreCharacters()) {
- ((CBC_Encoder*)encoders.GetAt(encodingMode))->Encode(context, e);
- if (e != BCExceptionNO) {
- for (int32_t i = 0; i < encoders.GetSize(); i++) {
- delete (CBC_Encoder*)encoders.GetAt(i);
- }
- encoders.RemoveAll();
- return (FX_WCHAR*)"";
- }
- if (context.m_newEncoding >= 0) {
- encodingMode = context.m_newEncoding;
- context.resetEncoderSignal();
- }
+ }
+ int32_t len = context.m_codewords.GetLength();
+ context.updateSymbolInfo(e);
+ if (e != BCExceptionNO) {
+ for (int32_t i = 0; i < encoders.GetSize(); i++) {
+ delete (CBC_Encoder*)encoders.GetAt(i);
}
- int32_t len = context.m_codewords.GetLength();
- context.updateSymbolInfo(e);
- if (e != BCExceptionNO) {
- for (int32_t i = 0; i < encoders.GetSize(); i++) {
- delete (CBC_Encoder*)encoders.GetAt(i);
- }
- encoders.RemoveAll();
- return (FX_WCHAR*)"";
+ encoders.RemoveAll();
+ return (FX_WCHAR*)"";
+ }
+ int32_t capacity = context.m_symbolInfo->m_dataCapacity;
+ if (len < capacity) {
+ if (encodingMode != ASCII_ENCODATION &&
+ encodingMode != BASE256_ENCODATION) {
+ context.writeCodeword(0x00fe);
}
- int32_t capacity = context.m_symbolInfo->m_dataCapacity;
- if (len < capacity) {
- if (encodingMode != ASCII_ENCODATION && encodingMode != BASE256_ENCODATION) {
- context.writeCodeword(0x00fe);
- }
+ }
+ CFX_WideString codewords = context.m_codewords;
+ if (codewords.GetLength() < capacity) {
+ codewords += PAD;
+ }
+ while (codewords.GetLength() < capacity) {
+ codewords += (randomize253State(PAD, codewords.GetLength() + 1));
+ }
+ for (int32_t i = 0; i < encoders.GetSize(); i++) {
+ delete (CBC_Encoder*)encoders.GetAt(i);
+ }
+ encoders.RemoveAll();
+ return codewords;
+}
+int32_t CBC_HighLevelEncoder::lookAheadTest(CFX_WideString msg,
+ int32_t startpos,
+ int32_t currentMode) {
+ if (startpos >= msg.GetLength()) {
+ return currentMode;
+ }
+ CFX_FloatArray charCounts;
+ if (currentMode == ASCII_ENCODATION) {
+ charCounts.Add(0);
+ charCounts.Add(1);
+ charCounts.Add(1);
+ charCounts.Add(1);
+ charCounts.Add(1);
+ charCounts.Add(1.25f);
+ } else {
+ charCounts.Add(1);
+ charCounts.Add(2);
+ charCounts.Add(2);
+ charCounts.Add(2);
+ charCounts.Add(2);
+ charCounts.Add(2.25f);
+ charCounts[currentMode] = 0;
+ }
+ int32_t charsProcessed = 0;
+ while (TRUE) {
+ if ((startpos + charsProcessed) == msg.GetLength()) {
+ FX_DWORD min = Integer_MAX_VALUE;
+ CFX_ByteArray mins;
+ mins.SetSize(6);
+ CFX_Int32Array intCharCounts;
+ intCharCounts.SetSize(6);
+ min = findMinimums(charCounts, intCharCounts, min, mins);
+ int32_t minCount = getMinimumCount(mins);
+ if (intCharCounts[ASCII_ENCODATION] == min) {
+ return ASCII_ENCODATION;
+ }
+ if (minCount == 1 && mins[BASE256_ENCODATION] > 0) {
+ return BASE256_ENCODATION;
+ }
+ if (minCount == 1 && mins[EDIFACT_ENCODATION] > 0) {
+ return EDIFACT_ENCODATION;
+ }
+ if (minCount == 1 && mins[TEXT_ENCODATION] > 0) {
+ return TEXT_ENCODATION;
+ }
+ if (minCount == 1 && mins[X12_ENCODATION] > 0) {
+ return X12_ENCODATION;
+ }
+ return C40_ENCODATION;
}
- CFX_WideString codewords = context.m_codewords;
- if (codewords.GetLength() < capacity) {
- codewords += PAD;
+ FX_WCHAR c = msg.GetAt(startpos + charsProcessed);
+ charsProcessed++;
+ if (isDigit(c)) {
+ charCounts[ASCII_ENCODATION] += 0.5;
+ } else if (isExtendedASCII(c)) {
+ charCounts[ASCII_ENCODATION] =
+ (FX_FLOAT)ceil(charCounts[ASCII_ENCODATION]);
+ charCounts[ASCII_ENCODATION] += 2;
+ } else {
+ charCounts[ASCII_ENCODATION] =
+ (FX_FLOAT)ceil(charCounts[ASCII_ENCODATION]);
+ charCounts[ASCII_ENCODATION]++;
}
- while (codewords.GetLength() < capacity) {
- codewords += (randomize253State(PAD, codewords.GetLength() + 1));
+ if (isNativeC40(c)) {
+ charCounts[C40_ENCODATION] += 2.0f / 3.0f;
+ } else if (isExtendedASCII(c)) {
+ charCounts[C40_ENCODATION] += 8.0f / 3.0f;
+ } else {
+ charCounts[C40_ENCODATION] += 4.0f / 3.0f;
}
- for (int32_t i = 0; i < encoders.GetSize(); i++) {
- delete (CBC_Encoder*)encoders.GetAt(i);
+ if (isNativeText(c)) {
+ charCounts[TEXT_ENCODATION] += 2.0f / 3.0f;
+ } else if (isExtendedASCII(c)) {
+ charCounts[TEXT_ENCODATION] += 8.0f / 3.0f;
+ } else {
+ charCounts[TEXT_ENCODATION] += 4.0f / 3.0f;
}
- encoders.RemoveAll();
- return codewords;
-}
-int32_t CBC_HighLevelEncoder::lookAheadTest(CFX_WideString msg, int32_t startpos, int32_t currentMode)
-{
- if (startpos >= msg.GetLength()) {
- return currentMode;
+ if (isNativeX12(c)) {
+ charCounts[X12_ENCODATION] += 2.0f / 3.0f;
+ } else if (isExtendedASCII(c)) {
+ charCounts[X12_ENCODATION] += 13.0f / 3.0f;
+ } else {
+ charCounts[X12_ENCODATION] += 10.0f / 3.0f;
}
- CFX_FloatArray charCounts;
- if (currentMode == ASCII_ENCODATION) {
- charCounts.Add(0);
- charCounts.Add(1);
- charCounts.Add(1);
- charCounts.Add(1);
- charCounts.Add(1);
- charCounts.Add(1.25f);
+ if (isNativeEDIFACT(c)) {
+ charCounts[EDIFACT_ENCODATION] += 3.0f / 4.0f;
+ } else if (isExtendedASCII(c)) {
+ charCounts[EDIFACT_ENCODATION] += 17.0f / 4.0f;
} else {
- charCounts.Add(1);
- charCounts.Add(2);
- charCounts.Add(2);
- charCounts.Add(2);
- charCounts.Add(2);
- charCounts.Add(2.25f);
- charCounts[currentMode] = 0;
+ charCounts[EDIFACT_ENCODATION] += 13.0f / 4.0f;
}
- int32_t charsProcessed = 0;
- while (TRUE) {
- if ((startpos + charsProcessed) == msg.GetLength()) {
- FX_DWORD min = Integer_MAX_VALUE;
- CFX_ByteArray mins;
- mins.SetSize(6);
- CFX_Int32Array intCharCounts;
- intCharCounts.SetSize(6);
- min = findMinimums(charCounts, intCharCounts, min, mins);
- int32_t minCount = getMinimumCount(mins);
- if (intCharCounts[ASCII_ENCODATION] == min) {
- return ASCII_ENCODATION;
- }
- if (minCount == 1 && mins[BASE256_ENCODATION] > 0) {
- return BASE256_ENCODATION;
- }
- if (minCount == 1 && mins[EDIFACT_ENCODATION] > 0) {
- return EDIFACT_ENCODATION;
- }
- if (minCount == 1 && mins[TEXT_ENCODATION] > 0) {
- return TEXT_ENCODATION;
- }
- if (minCount == 1 && mins[X12_ENCODATION] > 0) {
- return X12_ENCODATION;
- }
- return C40_ENCODATION;
- }
- FX_WCHAR c = msg.GetAt(startpos + charsProcessed);
- charsProcessed++;
- if (isDigit(c)) {
- charCounts[ASCII_ENCODATION] += 0.5;
- } else if (isExtendedASCII(c)) {
- charCounts[ASCII_ENCODATION] = (FX_FLOAT) ceil(charCounts[ASCII_ENCODATION]);
- charCounts[ASCII_ENCODATION] += 2;
- } else {
- charCounts[ASCII_ENCODATION] = (FX_FLOAT) ceil(charCounts[ASCII_ENCODATION]);
- charCounts[ASCII_ENCODATION]++;
- }
- if (isNativeC40(c)) {
- charCounts[C40_ENCODATION] += 2.0f / 3.0f;
- } else if (isExtendedASCII(c)) {
- charCounts[C40_ENCODATION] += 8.0f / 3.0f;
- } else {
- charCounts[C40_ENCODATION] += 4.0f / 3.0f;
- }
- if (isNativeText(c)) {
- charCounts[TEXT_ENCODATION] += 2.0f / 3.0f;
- } else if (isExtendedASCII(c)) {
- charCounts[TEXT_ENCODATION] += 8.0f / 3.0f;
- } else {
- charCounts[TEXT_ENCODATION] += 4.0f / 3.0f;
- }
- if (isNativeX12(c)) {
- charCounts[X12_ENCODATION] += 2.0f / 3.0f;
- } else if (isExtendedASCII(c)) {
- charCounts[X12_ENCODATION] += 13.0f / 3.0f;
- } else {
- charCounts[X12_ENCODATION] += 10.0f / 3.0f;
- }
- if (isNativeEDIFACT(c)) {
- charCounts[EDIFACT_ENCODATION] += 3.0f / 4.0f;
- } else if (isExtendedASCII(c)) {
- charCounts[EDIFACT_ENCODATION] += 17.0f / 4.0f;
- } else {
- charCounts[EDIFACT_ENCODATION] += 13.0f / 4.0f;
- }
- if (isSpecialB256(c)) {
- charCounts[BASE256_ENCODATION] += 4;
- } else {
- charCounts[BASE256_ENCODATION]++;
+ if (isSpecialB256(c)) {
+ charCounts[BASE256_ENCODATION] += 4;
+ } else {
+ charCounts[BASE256_ENCODATION]++;
+ }
+ if (charsProcessed >= 4) {
+ CFX_Int32Array intCharCounts;
+ intCharCounts.SetSize(6);
+ CFX_ByteArray mins;
+ mins.SetSize(6);
+ findMinimums(charCounts, intCharCounts, Integer_MAX_VALUE, mins);
+ int32_t minCount = getMinimumCount(mins);
+ if (intCharCounts[ASCII_ENCODATION] < intCharCounts[BASE256_ENCODATION] &&
+ intCharCounts[ASCII_ENCODATION] < intCharCounts[C40_ENCODATION] &&
+ intCharCounts[ASCII_ENCODATION] < intCharCounts[TEXT_ENCODATION] &&
+ intCharCounts[ASCII_ENCODATION] < intCharCounts[X12_ENCODATION] &&
+ intCharCounts[ASCII_ENCODATION] < intCharCounts[EDIFACT_ENCODATION]) {
+ return ASCII_ENCODATION;
+ }
+ if (intCharCounts[BASE256_ENCODATION] < intCharCounts[ASCII_ENCODATION] ||
+ (mins[C40_ENCODATION] + mins[TEXT_ENCODATION] + mins[X12_ENCODATION] +
+ mins[EDIFACT_ENCODATION]) == 0) {
+ return BASE256_ENCODATION;
+ }
+ if (minCount == 1 && mins[EDIFACT_ENCODATION] > 0) {
+ return EDIFACT_ENCODATION;
+ }
+ if (minCount == 1 && mins[TEXT_ENCODATION] > 0) {
+ return TEXT_ENCODATION;
+ }
+ if (minCount == 1 && mins[X12_ENCODATION] > 0) {
+ return X12_ENCODATION;
+ }
+ if (intCharCounts[C40_ENCODATION] + 1 < intCharCounts[ASCII_ENCODATION] &&
+ intCharCounts[C40_ENCODATION] + 1 <
+ intCharCounts[BASE256_ENCODATION] &&
+ intCharCounts[C40_ENCODATION] + 1 <
+ intCharCounts[EDIFACT_ENCODATION] &&
+ intCharCounts[C40_ENCODATION] + 1 < intCharCounts[TEXT_ENCODATION]) {
+ if (intCharCounts[C40_ENCODATION] < intCharCounts[X12_ENCODATION]) {
+ return C40_ENCODATION;
}
- if (charsProcessed >= 4) {
- CFX_Int32Array intCharCounts;
- intCharCounts.SetSize(6);
- CFX_ByteArray mins;
- mins.SetSize(6);
- findMinimums(charCounts, intCharCounts, Integer_MAX_VALUE, mins);
- int32_t minCount = getMinimumCount(mins);
- if (intCharCounts[ASCII_ENCODATION] < intCharCounts[BASE256_ENCODATION]
- && intCharCounts[ASCII_ENCODATION] < intCharCounts[C40_ENCODATION]
- && intCharCounts[ASCII_ENCODATION] < intCharCounts[TEXT_ENCODATION]
- && intCharCounts[ASCII_ENCODATION] < intCharCounts[X12_ENCODATION]
- && intCharCounts[ASCII_ENCODATION] < intCharCounts[EDIFACT_ENCODATION]) {
- return ASCII_ENCODATION;
- }
- if (intCharCounts[BASE256_ENCODATION] < intCharCounts[ASCII_ENCODATION]
- || (mins[C40_ENCODATION] + mins[TEXT_ENCODATION] + mins[X12_ENCODATION] + mins[EDIFACT_ENCODATION]) == 0) {
- return BASE256_ENCODATION;
- }
- if (minCount == 1 && mins[EDIFACT_ENCODATION] > 0) {
- return EDIFACT_ENCODATION;
+ if (intCharCounts[C40_ENCODATION] == intCharCounts[X12_ENCODATION]) {
+ int32_t p = startpos + charsProcessed + 1;
+ while (p < msg.GetLength()) {
+ FX_WCHAR tc = msg.GetAt(p);
+ if (isX12TermSep(tc)) {
+ return X12_ENCODATION;
}
- if (minCount == 1 && mins[TEXT_ENCODATION] > 0) {
- return TEXT_ENCODATION;
- }
- if (minCount == 1 && mins[X12_ENCODATION] > 0) {
- return X12_ENCODATION;
- }
- if (intCharCounts[C40_ENCODATION] + 1 < intCharCounts[ASCII_ENCODATION]
- && intCharCounts[C40_ENCODATION] + 1 < intCharCounts[BASE256_ENCODATION]
- && intCharCounts[C40_ENCODATION] + 1 < intCharCounts[EDIFACT_ENCODATION]
- && intCharCounts[C40_ENCODATION] + 1 < intCharCounts[TEXT_ENCODATION]) {
- if (intCharCounts[C40_ENCODATION] < intCharCounts[X12_ENCODATION]) {
- return C40_ENCODATION;
- }
- if (intCharCounts[C40_ENCODATION] == intCharCounts[X12_ENCODATION]) {
- int32_t p = startpos + charsProcessed + 1;
- while (p < msg.GetLength()) {
- FX_WCHAR tc = msg.GetAt(p);
- if (isX12TermSep(tc)) {
- return X12_ENCODATION;
- }
- if (!isNativeX12(tc)) {
- break;
- }
- p++;
- }
- return C40_ENCODATION;
- }
+ if (!isNativeX12(tc)) {
+ break;
}
+ p++;
+ }
+ return C40_ENCODATION;
}
+ }
}
+ }
}
-FX_BOOL CBC_HighLevelEncoder::isDigit(FX_WCHAR ch)
-{
- return ch >= '0' && ch <= '9';
+FX_BOOL CBC_HighLevelEncoder::isDigit(FX_WCHAR ch) {
+ return ch >= '0' && ch <= '9';
}
-FX_BOOL CBC_HighLevelEncoder::isExtendedASCII(FX_WCHAR ch)
-{
- return ch >= 128 && ch <= 255;
+FX_BOOL CBC_HighLevelEncoder::isExtendedASCII(FX_WCHAR ch) {
+ return ch >= 128 && ch <= 255;
}
-int32_t CBC_HighLevelEncoder::determineConsecutiveDigitCount(CFX_WideString msg, int32_t startpos)
-{
- int32_t count = 0;
- int32_t len = msg.GetLength();
- int32_t idx = startpos;
- if (idx < len) {
- FX_WCHAR ch = msg.GetAt(idx);
- while (isDigit(ch) && idx < len) {
- count++;
- idx++;
- if (idx < len) {
- ch = msg.GetAt(idx);
- }
- }
+int32_t CBC_HighLevelEncoder::determineConsecutiveDigitCount(CFX_WideString msg,
+ int32_t startpos) {
+ int32_t count = 0;
+ int32_t len = msg.GetLength();
+ int32_t idx = startpos;
+ if (idx < len) {
+ FX_WCHAR ch = msg.GetAt(idx);
+ while (isDigit(ch) && idx < len) {
+ count++;
+ idx++;
+ if (idx < len) {
+ ch = msg.GetAt(idx);
+ }
}
- return count;
+ }
+ return count;
}
-void CBC_HighLevelEncoder::illegalCharacter(FX_WCHAR c, int32_t &e)
-{
- e = BCExceptionIllegalArgument;
+void CBC_HighLevelEncoder::illegalCharacter(FX_WCHAR c, int32_t& e) {
+ e = BCExceptionIllegalArgument;
}
-FX_WCHAR CBC_HighLevelEncoder::randomize253State(FX_WCHAR ch, int32_t codewordPosition)
-{
- int32_t pseudoRandom = ((149 * codewordPosition) % 253) + 1;
- int32_t tempVariable = ch + pseudoRandom;
- return tempVariable <= 254 ? (FX_WCHAR) tempVariable : (FX_WCHAR) (tempVariable - 254);
+FX_WCHAR CBC_HighLevelEncoder::randomize253State(FX_WCHAR ch,
+ int32_t codewordPosition) {
+ int32_t pseudoRandom = ((149 * codewordPosition) % 253) + 1;
+ int32_t tempVariable = ch + pseudoRandom;
+ return tempVariable <= 254 ? (FX_WCHAR)tempVariable
+ : (FX_WCHAR)(tempVariable - 254);
}
-int32_t CBC_HighLevelEncoder::findMinimums(CFX_FloatArray &charCounts, CFX_Int32Array &intCharCounts, int32_t min, CFX_ByteArray &mins)
-{
- for (int32_t l = 0; l < mins.GetSize(); l++) {
- mins[l] = (uint8_t)0;
+int32_t CBC_HighLevelEncoder::findMinimums(CFX_FloatArray& charCounts,
+ CFX_Int32Array& intCharCounts,
+ int32_t min,
+ CFX_ByteArray& mins) {
+ for (int32_t l = 0; l < mins.GetSize(); l++) {
+ mins[l] = (uint8_t)0;
+ }
+ for (int32_t i = 0; i < 6; i++) {
+ intCharCounts[i] = (int32_t)ceil(charCounts[i]);
+ int32_t current = intCharCounts[i];
+ if (min > current) {
+ min = current;
+ for (int32_t j = 0; j < mins.GetSize(); j++) {
+ mins[j] = (uint8_t)0;
+ }
}
- for (int32_t i = 0; i < 6; i++) {
- intCharCounts[i] = (int32_t)ceil(charCounts[i]);
- int32_t current = intCharCounts[i];
- if (min > current) {
- min = current;
- for (int32_t j = 0; j < mins.GetSize(); j++) {
- mins[j] = (uint8_t)0;
- }
- }
- if (min == current) {
- mins[i]++;
- }
+ if (min == current) {
+ mins[i]++;
}
- return min;
+ }
+ return min;
}
-int32_t CBC_HighLevelEncoder::getMinimumCount(CFX_ByteArray &mins)
-{
- int32_t minCount = 0;
- for (int32_t i = 0; i < 6; i++) {
- minCount += mins[i];
- }
- return minCount;
+int32_t CBC_HighLevelEncoder::getMinimumCount(CFX_ByteArray& mins) {
+ int32_t minCount = 0;
+ for (int32_t i = 0; i < 6; i++) {
+ minCount += mins[i];
+ }
+ return minCount;
}
-FX_BOOL CBC_HighLevelEncoder::isNativeC40(FX_WCHAR ch)
-{
- return (ch == ' ') || (ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z');
+FX_BOOL CBC_HighLevelEncoder::isNativeC40(FX_WCHAR ch) {
+ return (ch == ' ') || (ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z');
}
-FX_BOOL CBC_HighLevelEncoder::isNativeText(FX_WCHAR ch)
-{
- return (ch == ' ') || (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z');
+FX_BOOL CBC_HighLevelEncoder::isNativeText(FX_WCHAR ch) {
+ return (ch == ' ') || (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z');
}
-FX_BOOL CBC_HighLevelEncoder::isNativeX12(FX_WCHAR ch)
-{
- return isX12TermSep(ch) || (ch == ' ') || (ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z');
+FX_BOOL CBC_HighLevelEncoder::isNativeX12(FX_WCHAR ch) {
+ return isX12TermSep(ch) || (ch == ' ') || (ch >= '0' && ch <= '9') ||
+ (ch >= 'A' && ch <= 'Z');
}
-FX_BOOL CBC_HighLevelEncoder::isX12TermSep(FX_WCHAR ch)
-{
- return (ch == '\r') || (ch == '*') || (ch == '>');
+FX_BOOL CBC_HighLevelEncoder::isX12TermSep(FX_WCHAR ch) {
+ return (ch == '\r') || (ch == '*') || (ch == '>');
}
-FX_BOOL CBC_HighLevelEncoder::isNativeEDIFACT(FX_WCHAR ch)
-{
- return ch >= ' ' && ch <= '^';
+FX_BOOL CBC_HighLevelEncoder::isNativeEDIFACT(FX_WCHAR ch) {
+ return ch >= ' ' && ch <= '^';
}
-FX_BOOL CBC_HighLevelEncoder::isSpecialB256(FX_WCHAR ch)
-{
- return FALSE;
+FX_BOOL CBC_HighLevelEncoder::isSpecialB256(FX_WCHAR ch) {
+ return FALSE;
}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_HighLevelEncoder.h b/xfa/src/fxbarcode/datamatrix/BC_HighLevelEncoder.h index c2bfdccb1b..8b2fa2c0e8 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_HighLevelEncoder.h +++ b/xfa/src/fxbarcode/datamatrix/BC_HighLevelEncoder.h @@ -8,53 +8,66 @@ #define _BC_HIGHLEVALENCODER_H_
class CBC_SymbolShapeHint;
class CBC_HighLevelEncoder;
-#define ASCII_ENCODATION 0
-#define C40_ENCODATION 1
-#define TEXT_ENCODATION 2
-#define X12_ENCODATION 3
-#define EDIFACT_ENCODATION 4
-#define BASE256_ENCODATION 5
-class CBC_HighLevelEncoder : public CBC_SymbolShapeHint
-{
-public:
- CBC_HighLevelEncoder();
- virtual ~CBC_HighLevelEncoder();
- CFX_ByteArray& getBytesForMessage(CFX_WideString msg);
- static CFX_WideString encodeHighLevel(CFX_WideString msg, CFX_WideString ecLevel, int32_t &e);
- static CFX_WideString encodeHighLevel(CFX_WideString msg, CFX_WideString ecLevel, SymbolShapeHint shape, CBC_Dimension* minSize, CBC_Dimension* maxSize, int32_t &e);
- static int32_t lookAheadTest(CFX_WideString msg, int32_t startpos, int32_t currentMode);
- static FX_BOOL isDigit(FX_WCHAR ch);
- static FX_BOOL isExtendedASCII(FX_WCHAR ch);
- static int32_t determineConsecutiveDigitCount(CFX_WideString msg, int32_t startpos);
- static void illegalCharacter(FX_WCHAR c, int32_t &e);
+#define ASCII_ENCODATION 0
+#define C40_ENCODATION 1
+#define TEXT_ENCODATION 2
+#define X12_ENCODATION 3
+#define EDIFACT_ENCODATION 4
+#define BASE256_ENCODATION 5
+class CBC_HighLevelEncoder : public CBC_SymbolShapeHint {
+ public:
+ CBC_HighLevelEncoder();
+ virtual ~CBC_HighLevelEncoder();
+ CFX_ByteArray& getBytesForMessage(CFX_WideString msg);
+ static CFX_WideString encodeHighLevel(CFX_WideString msg,
+ CFX_WideString ecLevel,
+ int32_t& e);
+ static CFX_WideString encodeHighLevel(CFX_WideString msg,
+ CFX_WideString ecLevel,
+ SymbolShapeHint shape,
+ CBC_Dimension* minSize,
+ CBC_Dimension* maxSize,
+ int32_t& e);
+ static int32_t lookAheadTest(CFX_WideString msg,
+ int32_t startpos,
+ int32_t currentMode);
+ static FX_BOOL isDigit(FX_WCHAR ch);
+ static FX_BOOL isExtendedASCII(FX_WCHAR ch);
+ static int32_t determineConsecutiveDigitCount(CFX_WideString msg,
+ int32_t startpos);
+ static void illegalCharacter(FX_WCHAR c, int32_t& e);
-public:
- static FX_WCHAR LATCH_TO_C40;
- static FX_WCHAR LATCH_TO_BASE256;
- static FX_WCHAR UPPER_SHIFT;
- static FX_WCHAR LATCH_TO_ANSIX12;
- static FX_WCHAR LATCH_TO_TEXT;
- static FX_WCHAR LATCH_TO_EDIFACT;
- static FX_WCHAR C40_UNLATCH;
- static FX_WCHAR X12_UNLATCH;
-private:
- static FX_WCHAR PAD;
- static FX_WCHAR MACRO_05;
- static FX_WCHAR MACRO_06;
- static const wchar_t* MACRO_05_HEADER;
- static const wchar_t* MACRO_06_HEADER;
- static const wchar_t MACRO_TRAILER;
- CFX_ByteArray m_bytearray;
-private:
- static FX_WCHAR randomize253State(FX_WCHAR ch, int32_t codewordPosition);
- static int32_t findMinimums(CFX_FloatArray &charCounts, CFX_Int32Array &intCharCounts, int32_t min, CFX_ByteArray &mins);
- static int32_t getMinimumCount(CFX_ByteArray &mins);
- static FX_BOOL isNativeC40(FX_WCHAR ch);
- static FX_BOOL isNativeText(FX_WCHAR ch);
- static FX_BOOL isNativeX12(FX_WCHAR ch);
- static FX_BOOL isX12TermSep(FX_WCHAR ch);
- static FX_BOOL isNativeEDIFACT(FX_WCHAR ch);
- static FX_BOOL isSpecialB256(FX_WCHAR ch);
+ public:
+ static FX_WCHAR LATCH_TO_C40;
+ static FX_WCHAR LATCH_TO_BASE256;
+ static FX_WCHAR UPPER_SHIFT;
+ static FX_WCHAR LATCH_TO_ANSIX12;
+ static FX_WCHAR LATCH_TO_TEXT;
+ static FX_WCHAR LATCH_TO_EDIFACT;
+ static FX_WCHAR C40_UNLATCH;
+ static FX_WCHAR X12_UNLATCH;
+ private:
+ static FX_WCHAR PAD;
+ static FX_WCHAR MACRO_05;
+ static FX_WCHAR MACRO_06;
+ static const wchar_t* MACRO_05_HEADER;
+ static const wchar_t* MACRO_06_HEADER;
+ static const wchar_t MACRO_TRAILER;
+ CFX_ByteArray m_bytearray;
+
+ private:
+ static FX_WCHAR randomize253State(FX_WCHAR ch, int32_t codewordPosition);
+ static int32_t findMinimums(CFX_FloatArray& charCounts,
+ CFX_Int32Array& intCharCounts,
+ int32_t min,
+ CFX_ByteArray& mins);
+ static int32_t getMinimumCount(CFX_ByteArray& mins);
+ static FX_BOOL isNativeC40(FX_WCHAR ch);
+ static FX_BOOL isNativeText(FX_WCHAR ch);
+ static FX_BOOL isNativeX12(FX_WCHAR ch);
+ static FX_BOOL isX12TermSep(FX_WCHAR ch);
+ static FX_BOOL isNativeEDIFACT(FX_WCHAR ch);
+ static FX_BOOL isSpecialB256(FX_WCHAR ch);
};
#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_SymbolInfo.cpp b/xfa/src/fxbarcode/datamatrix/BC_SymbolInfo.cpp index 587bdd3128..2ed4ee0003 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_SymbolInfo.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_SymbolInfo.cpp @@ -27,216 +27,237 @@ #include "BC_SymbolShapeHint.h"
#include "BC_SymbolInfo.h"
#include "BC_DataMatrixSymbolInfo144.h"
-#define SYMBOLS_COUNT 30
-CBC_SymbolInfo* CBC_SymbolInfo::m_PROD_SYMBOLS[30] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
-CBC_SymbolInfo* CBC_SymbolInfo::m_symbols[30] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
-void CBC_SymbolInfo::Initialize()
-{
- m_PROD_SYMBOLS[0] = FX_NEW CBC_SymbolInfo(FALSE, 3, 5, 8, 8, 1);
- m_PROD_SYMBOLS[1] = FX_NEW CBC_SymbolInfo(FALSE, 5, 7, 10, 10, 1);
- m_PROD_SYMBOLS[2] = FX_NEW CBC_SymbolInfo(TRUE, 5, 7, 16, 6, 1);
- m_PROD_SYMBOLS[3] = FX_NEW CBC_SymbolInfo(FALSE, 8, 10, 12, 12, 1);
- m_PROD_SYMBOLS[4] = FX_NEW CBC_SymbolInfo(TRUE, 10, 11, 14, 6, 2);
- m_PROD_SYMBOLS[5] = FX_NEW CBC_SymbolInfo(FALSE, 12, 12, 14, 14, 1);
- m_PROD_SYMBOLS[6] = FX_NEW CBC_SymbolInfo(TRUE, 16, 14, 24, 10, 1);
- m_PROD_SYMBOLS[7] = FX_NEW CBC_SymbolInfo(FALSE, 18, 14, 16, 16, 1);
- m_PROD_SYMBOLS[8] = FX_NEW CBC_SymbolInfo(FALSE, 22, 18, 18, 18, 1);
- m_PROD_SYMBOLS[9] = FX_NEW CBC_SymbolInfo(TRUE, 22, 18, 16, 10, 2);
- m_PROD_SYMBOLS[10] = FX_NEW CBC_SymbolInfo(FALSE, 30, 20, 20, 20, 1);
- m_PROD_SYMBOLS[11] = FX_NEW CBC_SymbolInfo(TRUE, 32, 24, 16, 14, 2);
- m_PROD_SYMBOLS[12] = FX_NEW CBC_SymbolInfo(FALSE, 36, 24, 22, 22, 1);
- m_PROD_SYMBOLS[13] = FX_NEW CBC_SymbolInfo(FALSE, 44, 28, 24, 24, 1);
- m_PROD_SYMBOLS[14] = FX_NEW CBC_SymbolInfo(TRUE, 49, 28, 22, 14, 2);
- m_PROD_SYMBOLS[15] = FX_NEW CBC_SymbolInfo(FALSE, 62, 36, 14, 14, 4);
- m_PROD_SYMBOLS[16] = FX_NEW CBC_SymbolInfo(FALSE, 86, 42, 16, 16, 4);
- m_PROD_SYMBOLS[17] = FX_NEW CBC_SymbolInfo(FALSE, 114, 48, 18, 18, 4);
- m_PROD_SYMBOLS[18] = FX_NEW CBC_SymbolInfo(FALSE, 144, 56, 20, 20, 4);
- m_PROD_SYMBOLS[19] = FX_NEW CBC_SymbolInfo(FALSE, 174, 68, 22, 22, 4);
- m_PROD_SYMBOLS[20] = FX_NEW CBC_SymbolInfo(FALSE, 204, 84, 24, 24, 4, 102, 42);
- m_PROD_SYMBOLS[21] = FX_NEW CBC_SymbolInfo(FALSE, 280, 112, 14, 14, 16, 140, 56);
- m_PROD_SYMBOLS[22] = FX_NEW CBC_SymbolInfo(FALSE, 368, 144, 16, 16, 16, 92, 36);
- m_PROD_SYMBOLS[23] = FX_NEW CBC_SymbolInfo(FALSE, 456, 192, 18, 18, 16, 114, 48);
- m_PROD_SYMBOLS[24] = FX_NEW CBC_SymbolInfo(FALSE, 576, 224, 20, 20, 16, 144, 56);
- m_PROD_SYMBOLS[25] = FX_NEW CBC_SymbolInfo(FALSE, 696, 272, 22, 22, 16, 174, 68);
- m_PROD_SYMBOLS[26] = FX_NEW CBC_SymbolInfo(FALSE, 816, 336, 24, 24, 16, 136, 56);
- m_PROD_SYMBOLS[27] = FX_NEW CBC_SymbolInfo(FALSE, 1050, 408, 18, 18, 36, 175, 68);
- m_PROD_SYMBOLS[28] = FX_NEW CBC_SymbolInfo(FALSE, 1304, 496, 20, 20, 36, 163, 62);
- m_PROD_SYMBOLS[29] = FX_NEW CBC_DataMatrixSymbolInfo144();
- for (int32_t i = 0; i < SYMBOLS_COUNT; i++) {
- m_symbols[i] = m_PROD_SYMBOLS[i];
- }
+#define SYMBOLS_COUNT 30
+CBC_SymbolInfo* CBC_SymbolInfo::m_PROD_SYMBOLS[30] = {
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
+CBC_SymbolInfo* CBC_SymbolInfo::m_symbols[30] = {
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
+void CBC_SymbolInfo::Initialize() {
+ m_PROD_SYMBOLS[0] = FX_NEW CBC_SymbolInfo(FALSE, 3, 5, 8, 8, 1);
+ m_PROD_SYMBOLS[1] = FX_NEW CBC_SymbolInfo(FALSE, 5, 7, 10, 10, 1);
+ m_PROD_SYMBOLS[2] = FX_NEW CBC_SymbolInfo(TRUE, 5, 7, 16, 6, 1);
+ m_PROD_SYMBOLS[3] = FX_NEW CBC_SymbolInfo(FALSE, 8, 10, 12, 12, 1);
+ m_PROD_SYMBOLS[4] = FX_NEW CBC_SymbolInfo(TRUE, 10, 11, 14, 6, 2);
+ m_PROD_SYMBOLS[5] = FX_NEW CBC_SymbolInfo(FALSE, 12, 12, 14, 14, 1);
+ m_PROD_SYMBOLS[6] = FX_NEW CBC_SymbolInfo(TRUE, 16, 14, 24, 10, 1);
+ m_PROD_SYMBOLS[7] = FX_NEW CBC_SymbolInfo(FALSE, 18, 14, 16, 16, 1);
+ m_PROD_SYMBOLS[8] = FX_NEW CBC_SymbolInfo(FALSE, 22, 18, 18, 18, 1);
+ m_PROD_SYMBOLS[9] = FX_NEW CBC_SymbolInfo(TRUE, 22, 18, 16, 10, 2);
+ m_PROD_SYMBOLS[10] = FX_NEW CBC_SymbolInfo(FALSE, 30, 20, 20, 20, 1);
+ m_PROD_SYMBOLS[11] = FX_NEW CBC_SymbolInfo(TRUE, 32, 24, 16, 14, 2);
+ m_PROD_SYMBOLS[12] = FX_NEW CBC_SymbolInfo(FALSE, 36, 24, 22, 22, 1);
+ m_PROD_SYMBOLS[13] = FX_NEW CBC_SymbolInfo(FALSE, 44, 28, 24, 24, 1);
+ m_PROD_SYMBOLS[14] = FX_NEW CBC_SymbolInfo(TRUE, 49, 28, 22, 14, 2);
+ m_PROD_SYMBOLS[15] = FX_NEW CBC_SymbolInfo(FALSE, 62, 36, 14, 14, 4);
+ m_PROD_SYMBOLS[16] = FX_NEW CBC_SymbolInfo(FALSE, 86, 42, 16, 16, 4);
+ m_PROD_SYMBOLS[17] = FX_NEW CBC_SymbolInfo(FALSE, 114, 48, 18, 18, 4);
+ m_PROD_SYMBOLS[18] = FX_NEW CBC_SymbolInfo(FALSE, 144, 56, 20, 20, 4);
+ m_PROD_SYMBOLS[19] = FX_NEW CBC_SymbolInfo(FALSE, 174, 68, 22, 22, 4);
+ m_PROD_SYMBOLS[20] =
+ FX_NEW CBC_SymbolInfo(FALSE, 204, 84, 24, 24, 4, 102, 42);
+ m_PROD_SYMBOLS[21] =
+ FX_NEW CBC_SymbolInfo(FALSE, 280, 112, 14, 14, 16, 140, 56);
+ m_PROD_SYMBOLS[22] =
+ FX_NEW CBC_SymbolInfo(FALSE, 368, 144, 16, 16, 16, 92, 36);
+ m_PROD_SYMBOLS[23] =
+ FX_NEW CBC_SymbolInfo(FALSE, 456, 192, 18, 18, 16, 114, 48);
+ m_PROD_SYMBOLS[24] =
+ FX_NEW CBC_SymbolInfo(FALSE, 576, 224, 20, 20, 16, 144, 56);
+ m_PROD_SYMBOLS[25] =
+ FX_NEW CBC_SymbolInfo(FALSE, 696, 272, 22, 22, 16, 174, 68);
+ m_PROD_SYMBOLS[26] =
+ FX_NEW CBC_SymbolInfo(FALSE, 816, 336, 24, 24, 16, 136, 56);
+ m_PROD_SYMBOLS[27] =
+ FX_NEW CBC_SymbolInfo(FALSE, 1050, 408, 18, 18, 36, 175, 68);
+ m_PROD_SYMBOLS[28] =
+ FX_NEW CBC_SymbolInfo(FALSE, 1304, 496, 20, 20, 36, 163, 62);
+ m_PROD_SYMBOLS[29] = FX_NEW CBC_DataMatrixSymbolInfo144();
+ for (int32_t i = 0; i < SYMBOLS_COUNT; i++) {
+ m_symbols[i] = m_PROD_SYMBOLS[i];
+ }
}
-void CBC_SymbolInfo::Finalize()
-{
- for (int32_t i = 0; i < SYMBOLS_COUNT; i++) {
- delete m_PROD_SYMBOLS[i];
- m_PROD_SYMBOLS[i] = NULL;
- m_symbols[i] = NULL;
- }
+void CBC_SymbolInfo::Finalize() {
+ for (int32_t i = 0; i < SYMBOLS_COUNT; i++) {
+ delete m_PROD_SYMBOLS[i];
+ m_PROD_SYMBOLS[i] = NULL;
+ m_symbols[i] = NULL;
+ }
+}
+CBC_SymbolInfo::CBC_SymbolInfo(FX_BOOL rectangular,
+ 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(FX_BOOL rectangular, 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(FX_BOOL rectangular, 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;
-}
-CBC_SymbolInfo::~CBC_SymbolInfo()
-{
+CBC_SymbolInfo::CBC_SymbolInfo(FX_BOOL rectangular,
+ 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;
}
+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, FX_BOOL allowRectangular, FX_BOOL fail, int32_t &e)
-{
- SymbolShapeHint shape = allowRectangular ? FORCE_NONE : FORCE_SQUARE;
- return lookup(dataCodewords, shape, fail, e);
-}
-CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, SymbolShapeHint shape, FX_BOOL fail, int32_t &e)
-{
- return lookup(dataCodewords, shape, NULL, NULL, fail, e);
-}
-CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, SymbolShapeHint shape, CBC_Dimension* minSize, CBC_Dimension* maxSize, FX_BOOL fail, int32_t &e)
-{
- for (int32_t i = 0; i < SYMBOLS_COUNT; i++) {
- CBC_SymbolInfo* symbol = m_symbols[i];
- if (shape == FORCE_SQUARE && symbol->m_rectangular) {
- continue;
- }
- if (shape == FORCE_RECTANGLE && !symbol->m_rectangular) {
- continue;
- }
- if (minSize != NULL && (symbol->getSymbolWidth(e) < minSize->getWidth() || symbol->getSymbolHeight(e) < minSize->getHeight())) {
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- continue;
- }
- if (maxSize != NULL && (symbol->getSymbolWidth(e) > maxSize->getWidth() || symbol->getSymbolHeight(e) > maxSize->getHeight())) {
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- continue;
- }
- if (dataCodewords <= symbol->m_dataCapacity) {
- return symbol;
- }
+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,
+ FX_BOOL allowRectangular,
+ FX_BOOL fail,
+ int32_t& e) {
+ SymbolShapeHint shape = allowRectangular ? FORCE_NONE : FORCE_SQUARE;
+ return lookup(dataCodewords, shape, fail, e);
+}
+CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords,
+ SymbolShapeHint shape,
+ FX_BOOL fail,
+ int32_t& e) {
+ return lookup(dataCodewords, shape, NULL, NULL, fail, e);
+}
+CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords,
+ SymbolShapeHint shape,
+ CBC_Dimension* minSize,
+ CBC_Dimension* maxSize,
+ FX_BOOL fail,
+ int32_t& e) {
+ for (int32_t i = 0; i < SYMBOLS_COUNT; i++) {
+ CBC_SymbolInfo* symbol = m_symbols[i];
+ if (shape == FORCE_SQUARE && symbol->m_rectangular) {
+ continue;
+ }
+ if (shape == FORCE_RECTANGLE && !symbol->m_rectangular) {
+ continue;
+ }
+ if (minSize != NULL &&
+ (symbol->getSymbolWidth(e) < minSize->getWidth() ||
+ symbol->getSymbolHeight(e) < minSize->getHeight())) {
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ continue;
+ }
+ if (maxSize != NULL &&
+ (symbol->getSymbolWidth(e) > maxSize->getWidth() ||
+ symbol->getSymbolHeight(e) > maxSize->getHeight())) {
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ continue;
}
- if (fail) {
- e = BCExceptionIllegalDataCodewords;
- return NULL;
+ if (dataCodewords <= symbol->m_dataCapacity) {
+ return symbol;
}
+ }
+ if (fail) {
+ e = BCExceptionIllegalDataCodewords;
return NULL;
+ }
+ return NULL;
}
-int32_t CBC_SymbolInfo::getHorizontalDataRegions(int32_t &e)
-{
- switch (m_dataRegions) {
- case 1:
- return 1;
- case 2:
- return 2;
- case 4:
- return 2;
- case 16:
- return 4;
- case 36:
- return 6;
- default:
- e = BCExceptionCannotHandleThisNumberOfDataRegions;
- return 0;
- }
+int32_t CBC_SymbolInfo::getHorizontalDataRegions(int32_t& e) {
+ switch (m_dataRegions) {
+ case 1:
+ return 1;
+ case 2:
+ return 2;
+ case 4:
+ return 2;
+ case 16:
+ return 4;
+ case 36:
+ return 6;
+ default:
+ e = BCExceptionCannotHandleThisNumberOfDataRegions;
+ return 0;
+ }
}
-int32_t CBC_SymbolInfo::getVerticalDataRegions(int32_t &e)
-{
- switch (m_dataRegions) {
- case 1:
- return 1;
- case 2:
- return 1;
- case 4:
- return 2;
- case 16:
- return 4;
- case 36:
- return 6;
- default:
- e = BCExceptionCannotHandleThisNumberOfDataRegions;
- return 0;
- }
+int32_t CBC_SymbolInfo::getVerticalDataRegions(int32_t& e) {
+ switch (m_dataRegions) {
+ case 1:
+ return 1;
+ case 2:
+ return 1;
+ case 4:
+ return 2;
+ case 16:
+ return 4;
+ case 36:
+ return 6;
+ default:
+ e = BCExceptionCannotHandleThisNumberOfDataRegions;
+ return 0;
+ }
+}
+int32_t CBC_SymbolInfo::getSymbolDataWidth(int32_t& e) {
+ return getHorizontalDataRegions(e) * m_matrixWidth;
+}
+int32_t CBC_SymbolInfo::getSymbolDataHeight(int32_t& e) {
+ return getVerticalDataRegions(e) * m_matrixHeight;
+}
+int32_t CBC_SymbolInfo::getSymbolWidth(int32_t& e) {
+ return getSymbolDataWidth(e) + (getHorizontalDataRegions(e) * 2);
+}
+int32_t CBC_SymbolInfo::getSymbolHeight(int32_t& e) {
+ return getSymbolDataHeight(e) + (getVerticalDataRegions(e) * 2);
+}
+int32_t CBC_SymbolInfo::getCodewordCount() {
+ return m_dataCapacity + m_errorCodewords;
+}
+int32_t CBC_SymbolInfo::getInterleavedBlockCount() {
+ return m_dataCapacity / m_rsBlockData;
+}
+int32_t CBC_SymbolInfo::getDataLengthForInterleavedBlock(int32_t index) {
+ return m_rsBlockData;
+}
+int32_t CBC_SymbolInfo::getErrorLengthForInterleavedBlock(int32_t index) {
+ return m_rsBlockError;
}
-int32_t CBC_SymbolInfo::getSymbolDataWidth(int32_t &e)
-{
- return getHorizontalDataRegions(e) * m_matrixWidth;
-}
-int32_t CBC_SymbolInfo::getSymbolDataHeight(int32_t &e)
-{
- return getVerticalDataRegions(e) * m_matrixHeight;
-}
-int32_t CBC_SymbolInfo::getSymbolWidth(int32_t &e)
-{
- return getSymbolDataWidth(e) + (getHorizontalDataRegions(e) * 2);
-}
-int32_t CBC_SymbolInfo::getSymbolHeight(int32_t &e)
-{
- return getSymbolDataHeight(e) + (getVerticalDataRegions(e) * 2);
-}
-int32_t CBC_SymbolInfo::getCodewordCount()
-{
- return m_dataCapacity + m_errorCodewords;
-}
-int32_t CBC_SymbolInfo::getInterleavedBlockCount()
-{
- return m_dataCapacity / m_rsBlockData;
-}
-int32_t CBC_SymbolInfo::getDataLengthForInterleavedBlock(int32_t index)
-{
- return m_rsBlockData;
-}
-int32_t CBC_SymbolInfo::getErrorLengthForInterleavedBlock(int32_t index)
-{
- return m_rsBlockError;
-}
-CFX_WideString CBC_SymbolInfo::toString(int32_t &e)
-{
- CFX_WideString sb;
- sb += (FX_WCHAR*)(m_rectangular ? "Rectangular Symbol:" : "Square Symbol:");
- sb += (FX_WCHAR*)" data region ";
- sb += m_matrixWidth;
- sb += (FX_WCHAR)'x';
- sb += m_matrixHeight;
- sb += (FX_WCHAR*)", symbol size ";
- sb += getSymbolWidth(e);
- BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)"");
- sb += (FX_WCHAR)'x';
- sb += getSymbolHeight(e);
- BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)"");
- sb += (FX_WCHAR*)", symbol data size ";
- sb += getSymbolDataWidth(e);
- BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)"");
- sb += (FX_WCHAR)'x';
- sb += getSymbolDataHeight(e);
- BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)"");
- sb += (FX_WCHAR*)", codewords ";
- sb += m_dataCapacity;
- sb += (FX_WCHAR)'+';
- sb += m_errorCodewords;
- return sb;
+CFX_WideString CBC_SymbolInfo::toString(int32_t& e) {
+ CFX_WideString sb;
+ sb += (FX_WCHAR*)(m_rectangular ? "Rectangular Symbol:" : "Square Symbol:");
+ sb += (FX_WCHAR*)" data region ";
+ sb += m_matrixWidth;
+ sb += (FX_WCHAR)'x';
+ sb += m_matrixHeight;
+ sb += (FX_WCHAR*)", symbol size ";
+ sb += getSymbolWidth(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)"");
+ sb += (FX_WCHAR)'x';
+ sb += getSymbolHeight(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)"");
+ sb += (FX_WCHAR*)", symbol data size ";
+ sb += getSymbolDataWidth(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)"");
+ sb += (FX_WCHAR)'x';
+ sb += getSymbolDataHeight(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)"");
+ sb += (FX_WCHAR*)", codewords ";
+ sb += m_dataCapacity;
+ sb += (FX_WCHAR)'+';
+ sb += m_errorCodewords;
+ return sb;
}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_SymbolInfo.h b/xfa/src/fxbarcode/datamatrix/BC_SymbolInfo.h index 5ace547442..27b810be9a 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_SymbolInfo.h +++ b/xfa/src/fxbarcode/datamatrix/BC_SymbolInfo.h @@ -9,45 +9,70 @@ class CBC_SymbolShapeHint;
class CBC_Dimension;
class CBC_SymbolInfo;
-class CBC_SymbolInfo : public CBC_SymbolShapeHint
-{
-public:
- CBC_SymbolInfo(FX_BOOL rectangular, int32_t dataCapacity, int32_t errorCodewords,
- int32_t matrixWidth, int32_t matrixHeight, int32_t dataRegions);
- virtual ~CBC_SymbolInfo();
- static void Initialize();
- static void Finalize();
- static void overrideSymbolSet(CBC_SymbolInfo* override);
- static CBC_SymbolInfo* lookup(int32_t dataCodewords, int32_t &e);
- static CBC_SymbolInfo* lookup(int32_t dataCodewords, SymbolShapeHint shape, int32_t &e);
- static CBC_SymbolInfo* lookup(int32_t dataCodewords, FX_BOOL allowRectangular, FX_BOOL fail, int32_t &e);
- static CBC_SymbolInfo* lookup(int32_t dataCodewords, SymbolShapeHint shape, FX_BOOL fail, int32_t &e);
- static CBC_SymbolInfo* lookup(int32_t dataCodewords, SymbolShapeHint shape, CBC_Dimension* minSize, CBC_Dimension* maxSize, FX_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);
- CFX_WideString toString(int32_t &e);
-public:
- int32_t m_dataCapacity;
- int32_t m_errorCodewords;
- int32_t m_matrixWidth;
- int32_t m_matrixHeight;
- int32_t m_rsBlockData;
- int32_t m_rsBlockError;
- static CBC_SymbolInfo* m_PROD_SYMBOLS[30];
-private:
- static CBC_SymbolInfo* m_symbols[30];
- FX_BOOL m_rectangular;
- int32_t m_dataRegions;
-private:
- CBC_SymbolInfo(FX_BOOL rectangular, int32_t dataCapacity, int32_t errorCodewords, int32_t matrixWidth, int32_t matrixHeight, int32_t dataRegions,
- int32_t rsBlockData, int32_t rsBlockError);
+class CBC_SymbolInfo : public CBC_SymbolShapeHint {
+ public:
+ CBC_SymbolInfo(FX_BOOL rectangular,
+ int32_t dataCapacity,
+ int32_t errorCodewords,
+ int32_t matrixWidth,
+ int32_t matrixHeight,
+ int32_t dataRegions);
+ virtual ~CBC_SymbolInfo();
+ static void Initialize();
+ static void Finalize();
+ static void overrideSymbolSet(CBC_SymbolInfo* override);
+ static CBC_SymbolInfo* lookup(int32_t dataCodewords, int32_t& e);
+ static CBC_SymbolInfo* lookup(int32_t dataCodewords,
+ SymbolShapeHint shape,
+ int32_t& e);
+ static CBC_SymbolInfo* lookup(int32_t dataCodewords,
+ FX_BOOL allowRectangular,
+ FX_BOOL fail,
+ int32_t& e);
+ static CBC_SymbolInfo* lookup(int32_t dataCodewords,
+ SymbolShapeHint shape,
+ FX_BOOL fail,
+ int32_t& e);
+ static CBC_SymbolInfo* lookup(int32_t dataCodewords,
+ SymbolShapeHint shape,
+ CBC_Dimension* minSize,
+ CBC_Dimension* maxSize,
+ FX_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);
+ CFX_WideString toString(int32_t& e);
+
+ public:
+ int32_t m_dataCapacity;
+ int32_t m_errorCodewords;
+ int32_t m_matrixWidth;
+ int32_t m_matrixHeight;
+ int32_t m_rsBlockData;
+ int32_t m_rsBlockError;
+ static CBC_SymbolInfo* m_PROD_SYMBOLS[30];
+
+ private:
+ static CBC_SymbolInfo* m_symbols[30];
+ FX_BOOL m_rectangular;
+ int32_t m_dataRegions;
+
+ private:
+ CBC_SymbolInfo(FX_BOOL rectangular,
+ int32_t dataCapacity,
+ int32_t errorCodewords,
+ int32_t matrixWidth,
+ int32_t matrixHeight,
+ int32_t dataRegions,
+ int32_t rsBlockData,
+ int32_t rsBlockError);
};
#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_SymbolShapeHint.cpp b/xfa/src/fxbarcode/datamatrix/BC_SymbolShapeHint.cpp index b7b477539c..d0f0e45846 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_SymbolShapeHint.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_SymbolShapeHint.cpp @@ -22,9 +22,5 @@ #include "../barcode.h"
#include "BC_SymbolShapeHint.h"
-CBC_SymbolShapeHint::CBC_SymbolShapeHint()
-{
-}
-CBC_SymbolShapeHint::~CBC_SymbolShapeHint()
-{
-}
+CBC_SymbolShapeHint::CBC_SymbolShapeHint() {}
+CBC_SymbolShapeHint::~CBC_SymbolShapeHint() {}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_SymbolShapeHint.h b/xfa/src/fxbarcode/datamatrix/BC_SymbolShapeHint.h index adda8c8ea8..246b6c2168 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_SymbolShapeHint.h +++ b/xfa/src/fxbarcode/datamatrix/BC_SymbolShapeHint.h @@ -6,15 +6,14 @@ #ifndef _BC_SYMBOLSHAPEHINT_H_
#define _BC_SYMBOLSHAPEHINT_H_
-class CBC_SymbolShapeHint
-{
-public:
- CBC_SymbolShapeHint();
- virtual ~CBC_SymbolShapeHint();
- enum SymbolShapeHint {
- FORCE_NONE,
- FORCE_SQUARE,
- FORCE_RECTANGLE,
- };
+class CBC_SymbolShapeHint {
+ public:
+ CBC_SymbolShapeHint();
+ virtual ~CBC_SymbolShapeHint();
+ enum SymbolShapeHint {
+ FORCE_NONE,
+ FORCE_SQUARE,
+ FORCE_RECTANGLE,
+ };
};
#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_TextEncoder.cpp b/xfa/src/fxbarcode/datamatrix/BC_TextEncoder.cpp index afccce598f..ecd20cd5e5 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_TextEncoder.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_TextEncoder.cpp @@ -30,73 +30,69 @@ #include "BC_HighLevelEncoder.h"
#include "BC_C40Encoder.h"
#include "BC_TextEncoder.h"
-CBC_TextEncoder::CBC_TextEncoder()
-{
+CBC_TextEncoder::CBC_TextEncoder() {}
+CBC_TextEncoder::~CBC_TextEncoder() {}
+int32_t CBC_TextEncoder::getEncodingMode() {
+ return TEXT_ENCODATION;
}
-CBC_TextEncoder::~CBC_TextEncoder()
-{
-}
-int32_t CBC_TextEncoder::getEncodingMode()
-{
- return TEXT_ENCODATION;
-}
-int32_t CBC_TextEncoder::encodeChar(FX_WCHAR c, CFX_WideString &sb, int32_t &e)
-{
- if (c == ' ') {
- sb += (FX_WCHAR)'\3';
- return 1;
- }
- if (c >= '0' && c <= '9') {
- sb += (FX_WCHAR) (c - 48 + 4);
- return 1;
- }
- if (c >= 'a' && c <= 'z') {
- sb += (FX_WCHAR) (c - 97 + 14);
- return 1;
- }
- if (c >= '\0' && c <= 0x1f) {
- sb += (FX_WCHAR)'\0';
- sb += c;
- return 2;
- }
- if (c >= '!' && c <= '/') {
- sb += (FX_WCHAR) '\1';
- sb += (FX_WCHAR) (c - 33);
- return 2;
- }
- if (c >= ':' && c <= '@') {
- sb += (FX_WCHAR)'\1';
- sb += (FX_WCHAR) (c - 58 + 15);
- return 2;
- }
- if (c >= '[' && c <= '_') {
- sb += (FX_WCHAR) '\1';
- sb += (FX_WCHAR) (c - 91 + 22);
- return 2;
- }
- if (c == 0x0060) {
- sb += (FX_WCHAR) '\2';
- sb += (FX_WCHAR) (c - 96);
- return 2;
- }
- if (c >= 'A' && c <= 'Z') {
- sb += (FX_WCHAR)'\2';
- sb += (FX_WCHAR) (c - 65 + 1);
- return 2;
- }
- if (c >= '{' && c <= 0x007f) {
- sb += (FX_WCHAR)'\2';
- sb += (FX_WCHAR) (c - 123 + 27);
- return 2;
- }
- if (c >= 0x0080) {
- sb += (FX_WCHAR)'\1';
- sb += (FX_WCHAR)0x001e;
- int32_t len = 2;
- len += encodeChar((FX_WCHAR) (c - 128), sb, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, -1);
- return len;
- }
- CBC_HighLevelEncoder::illegalCharacter(c, e);
- return -1;
+int32_t CBC_TextEncoder::encodeChar(FX_WCHAR c,
+ CFX_WideString& sb,
+ int32_t& e) {
+ if (c == ' ') {
+ sb += (FX_WCHAR)'\3';
+ return 1;
+ }
+ if (c >= '0' && c <= '9') {
+ sb += (FX_WCHAR)(c - 48 + 4);
+ return 1;
+ }
+ if (c >= 'a' && c <= 'z') {
+ sb += (FX_WCHAR)(c - 97 + 14);
+ return 1;
+ }
+ if (c >= '\0' && c <= 0x1f) {
+ sb += (FX_WCHAR)'\0';
+ sb += c;
+ return 2;
+ }
+ if (c >= '!' && c <= '/') {
+ sb += (FX_WCHAR)'\1';
+ sb += (FX_WCHAR)(c - 33);
+ return 2;
+ }
+ if (c >= ':' && c <= '@') {
+ sb += (FX_WCHAR)'\1';
+ sb += (FX_WCHAR)(c - 58 + 15);
+ return 2;
+ }
+ if (c >= '[' && c <= '_') {
+ sb += (FX_WCHAR)'\1';
+ sb += (FX_WCHAR)(c - 91 + 22);
+ return 2;
+ }
+ if (c == 0x0060) {
+ sb += (FX_WCHAR)'\2';
+ sb += (FX_WCHAR)(c - 96);
+ return 2;
+ }
+ if (c >= 'A' && c <= 'Z') {
+ sb += (FX_WCHAR)'\2';
+ sb += (FX_WCHAR)(c - 65 + 1);
+ return 2;
+ }
+ if (c >= '{' && c <= 0x007f) {
+ sb += (FX_WCHAR)'\2';
+ sb += (FX_WCHAR)(c - 123 + 27);
+ return 2;
+ }
+ if (c >= 0x0080) {
+ sb += (FX_WCHAR)'\1';
+ sb += (FX_WCHAR)0x001e;
+ int32_t len = 2;
+ len += encodeChar((FX_WCHAR)(c - 128), sb, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, -1);
+ return len;
+ }
+ CBC_HighLevelEncoder::illegalCharacter(c, e);
+ return -1;
}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_TextEncoder.h b/xfa/src/fxbarcode/datamatrix/BC_TextEncoder.h index 7d46e92d5d..c93b0da4db 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_TextEncoder.h +++ b/xfa/src/fxbarcode/datamatrix/BC_TextEncoder.h @@ -7,12 +7,11 @@ #ifndef _BC_TEXTENCODER_H_
#define _BC_TEXTENCODER_H_
class CBC_TextEncoder;
-class CBC_TextEncoder : public CBC_C40Encoder
-{
-public:
- CBC_TextEncoder();
- virtual ~CBC_TextEncoder();
- int32_t getEncodingMode();
- int32_t encodeChar(FX_WCHAR c, CFX_WideString &sb, int32_t &e);
+class CBC_TextEncoder : public CBC_C40Encoder {
+ public:
+ CBC_TextEncoder();
+ virtual ~CBC_TextEncoder();
+ int32_t getEncodingMode();
+ int32_t encodeChar(FX_WCHAR c, CFX_WideString& sb, int32_t& e);
};
#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_X12Encoder.cpp b/xfa/src/fxbarcode/datamatrix/BC_X12Encoder.cpp index 7f56de7aed..a15362f542 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_X12Encoder.cpp +++ b/xfa/src/fxbarcode/datamatrix/BC_X12Encoder.cpp @@ -30,75 +30,71 @@ #include "BC_HighLevelEncoder.h"
#include "BC_C40Encoder.h"
#include "BC_X12Encoder.h"
-CBC_X12Encoder::CBC_X12Encoder()
-{
+CBC_X12Encoder::CBC_X12Encoder() {}
+CBC_X12Encoder::~CBC_X12Encoder() {}
+int32_t CBC_X12Encoder::getEncodingMode() {
+ return X12_ENCODATION;
}
-CBC_X12Encoder::~CBC_X12Encoder()
-{
-}
-int32_t CBC_X12Encoder::getEncodingMode()
-{
- return X12_ENCODATION;
-}
-void CBC_X12Encoder::Encode(CBC_EncoderContext &context, int32_t &e)
-{
- CFX_WideString buffer;
- while (context.hasMoreCharacters()) {
- FX_WCHAR c = context.getCurrentChar();
- context.m_pos++;
- encodeChar(c, buffer, e);
- if (e != BCExceptionNO) {
- return;
- }
- int32_t count = buffer.GetLength();
- if ((count % 3) == 0) {
- writeNextTriplet(context, buffer);
- int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(context.m_msg, context.m_pos, getEncodingMode());
- if (newMode != getEncodingMode()) {
- context.signalEncoderChange(newMode);
- break;
- }
- }
- }
- handleEOD(context, buffer, e);
-}
-void CBC_X12Encoder::handleEOD(CBC_EncoderContext &context, CFX_WideString &buffer, int32_t &e)
-{
- context.updateSymbolInfo(e);
+void CBC_X12Encoder::Encode(CBC_EncoderContext& context, int32_t& e) {
+ CFX_WideString buffer;
+ while (context.hasMoreCharacters()) {
+ FX_WCHAR c = context.getCurrentChar();
+ context.m_pos++;
+ encodeChar(c, buffer, e);
if (e != BCExceptionNO) {
- return;
+ return;
}
- int32_t available = context.m_symbolInfo->m_dataCapacity - context.getCodewordCount();
int32_t count = buffer.GetLength();
- if (count == 2) {
- context.writeCodeword(CBC_HighLevelEncoder::X12_UNLATCH);
- context.m_pos -= 2;
- context.signalEncoderChange(ASCII_ENCODATION);
- } else if (count == 1) {
- context.m_pos--;
- if (available > 1) {
- context.writeCodeword(CBC_HighLevelEncoder::X12_UNLATCH);
- }
- context.signalEncoderChange(ASCII_ENCODATION);
+ if ((count % 3) == 0) {
+ writeNextTriplet(context, buffer);
+ int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(
+ context.m_msg, context.m_pos, getEncodingMode());
+ if (newMode != getEncodingMode()) {
+ context.signalEncoderChange(newMode);
+ break;
+ }
}
+ }
+ handleEOD(context, buffer, e);
}
-int32_t CBC_X12Encoder::encodeChar(FX_WCHAR c, CFX_WideString &sb, int32_t &e)
-{
- if (c == '\r') {
- sb += (FX_WCHAR)'\0';
- } else if (c == '*') {
- sb += (FX_WCHAR)'\1';
- } else if (c == '>') {
- sb += (FX_WCHAR)'\2';
- } else if (c == ' ') {
- sb += (FX_WCHAR)'\3';
- } else if (c >= '0' && c <= '9') {
- sb += (FX_WCHAR) (c - 48 + 4);
- } else if (c >= 'A' && c <= 'Z') {
- sb += (FX_WCHAR) (c - 65 + 14);
- } else {
- CBC_HighLevelEncoder::illegalCharacter(c, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, -1);
+void CBC_X12Encoder::handleEOD(CBC_EncoderContext& context,
+ CFX_WideString& buffer,
+ int32_t& e) {
+ context.updateSymbolInfo(e);
+ if (e != BCExceptionNO) {
+ return;
+ }
+ int32_t available =
+ context.m_symbolInfo->m_dataCapacity - context.getCodewordCount();
+ int32_t count = buffer.GetLength();
+ if (count == 2) {
+ context.writeCodeword(CBC_HighLevelEncoder::X12_UNLATCH);
+ context.m_pos -= 2;
+ context.signalEncoderChange(ASCII_ENCODATION);
+ } else if (count == 1) {
+ context.m_pos--;
+ if (available > 1) {
+ context.writeCodeword(CBC_HighLevelEncoder::X12_UNLATCH);
}
- return 1;
+ context.signalEncoderChange(ASCII_ENCODATION);
+ }
+}
+int32_t CBC_X12Encoder::encodeChar(FX_WCHAR c, CFX_WideString& sb, int32_t& e) {
+ if (c == '\r') {
+ sb += (FX_WCHAR)'\0';
+ } else if (c == '*') {
+ sb += (FX_WCHAR)'\1';
+ } else if (c == '>') {
+ sb += (FX_WCHAR)'\2';
+ } else if (c == ' ') {
+ sb += (FX_WCHAR)'\3';
+ } else if (c >= '0' && c <= '9') {
+ sb += (FX_WCHAR)(c - 48 + 4);
+ } else if (c >= 'A' && c <= 'Z') {
+ sb += (FX_WCHAR)(c - 65 + 14);
+ } else {
+ CBC_HighLevelEncoder::illegalCharacter(c, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, -1);
+ }
+ return 1;
}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_X12Encoder.h b/xfa/src/fxbarcode/datamatrix/BC_X12Encoder.h index 210f07a5d9..ea3fd92d0c 100644 --- a/xfa/src/fxbarcode/datamatrix/BC_X12Encoder.h +++ b/xfa/src/fxbarcode/datamatrix/BC_X12Encoder.h @@ -8,14 +8,15 @@ #define _BC_X12ENCODER_H_
class CBC_C40Encoder;
class CBC_X12Encoder;
-class CBC_X12Encoder : public CBC_C40Encoder
-{
-public:
- CBC_X12Encoder();
- virtual ~CBC_X12Encoder();
- int32_t getEncodingMode();
- void Encode(CBC_EncoderContext &context, int32_t &e);
- void handleEOD(CBC_EncoderContext &context, CFX_WideString &buffer, int32_t &e);
- int32_t encodeChar(FX_WCHAR c, CFX_WideString &sb, int32_t &e);
+class CBC_X12Encoder : public CBC_C40Encoder {
+ public:
+ CBC_X12Encoder();
+ virtual ~CBC_X12Encoder();
+ int32_t getEncodingMode();
+ void Encode(CBC_EncoderContext& context, int32_t& e);
+ void handleEOD(CBC_EncoderContext& context,
+ CFX_WideString& buffer,
+ int32_t& e);
+ int32_t encodeChar(FX_WCHAR c, CFX_WideString& sb, int32_t& e);
};
#endif
|