diff options
author | Bo Xu <bo_xu@foxitsoftware.com> | 2015-01-09 17:27:21 -0800 |
---|---|---|
committer | Bo Xu <bo_xu@foxitsoftware.com> | 2015-01-09 17:27:21 -0800 |
commit | a902979f7c6a39fbdd8e9fc1b2ce00553b655eeb (patch) | |
tree | 854a51dbf1577ee8493db769ba7c8ab07cc72140 /xfa/src/fxbarcode/datamatrix | |
parent | 5f21e9ddd181fc344f8d6070351858f98a25547e (diff) | |
download | pdfium-a902979f7c6a39fbdd8e9fc1b2ce00553b655eeb.tar.xz |
Organize barcode codes into modules.
Previously all the files in barcode are lumped together.
The naming of some files are inconsistent,
leading to difficult understanding of the structure.
Now files are grouped based on different barcode type like in zxing.
This also matches what it looks like in other xfa folders.
The file names in each folder could be further modified to be consistent.
R=tsepez@chromium.org
Review URL: https://codereview.chromium.org/842043002
Diffstat (limited to 'xfa/src/fxbarcode/datamatrix')
44 files changed, 4483 insertions, 0 deletions
diff --git a/xfa/src/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp b/xfa/src/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp new file mode 100644 index 0000000000..bc29b7d6ce --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp @@ -0,0 +1,99 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows: +/*
+ * Copyright 2006-2007 Jeremias Maerki.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../barcode.h"
+#include "../BC_Dimension.h"
+#include "BC_Encoder.h"
+#include "BC_SymbolShapeHint.h"
+#include "BC_SymbolInfo.h"
+#include "BC_EncoderContext.h"
+#include "BC_HighLevelEncoder.h"
+#include "BC_ASCIIEncoder.h"
+CBC_ASCIIEncoder::CBC_ASCIIEncoder()
+{
+}
+CBC_ASCIIEncoder::~CBC_ASCIIEncoder()
+{
+}
+FX_INT32 CBC_ASCIIEncoder::getEncodingMode()
+{
+ return ASCII_ENCODATION;
+}
+void CBC_ASCIIEncoder::Encode(CBC_EncoderContext &context, FX_INT32 &e)
+{
+ FX_INT32 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();
+ FX_INT32 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++;
+ }
+ }
+}
+FX_WCHAR CBC_ASCIIEncoder::encodeASCIIDigits(FX_WCHAR digit1, FX_WCHAR digit2, FX_INT32 &e)
+{
+ if (CBC_HighLevelEncoder::isDigit(digit1) && CBC_HighLevelEncoder::isDigit(digit2)) {
+ FX_INT32 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 new file mode 100644 index 0000000000..9a48b8762f --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_ASCIIEncoder.h @@ -0,0 +1,22 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_ASCIIENCODER_H_
+#define _BC_ASCIIENCODER_H_
+class CBC_Encoder;
+class CBC_EncoderContext;
+class CBC_ASCIIEncoder;
+class CBC_ASCIIEncoder : public CBC_Encoder
+{
+public:
+ CBC_ASCIIEncoder();
+ virtual ~CBC_ASCIIEncoder();
+ FX_INT32 getEncodingMode();
+ void Encode(CBC_EncoderContext &context, FX_INT32 &e);
+private:
+ static FX_WCHAR encodeASCIIDigits(FX_WCHAR digit1, FX_WCHAR digit2, FX_INT32 &e);
+};
+#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_Base256Encoder.cpp b/xfa/src/fxbarcode/datamatrix/BC_Base256Encoder.cpp new file mode 100644 index 0000000000..d896cf6445 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_Base256Encoder.cpp @@ -0,0 +1,95 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows: +/*
+ * Copyright 2006-2007 Jeremias Maerki.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../barcode.h"
+#include "../BC_Dimension.h"
+#include "BC_Encoder.h"
+#include "BC_SymbolShapeHint.h"
+#include "BC_SymbolInfo.h"
+#include "BC_EncoderContext.h"
+#include "BC_HighLevelEncoder.h"
+#include "BC_Base256Encoder.h"
+CBC_Base256Encoder::CBC_Base256Encoder()
+{
+}
+CBC_Base256Encoder::~CBC_Base256Encoder()
+{
+}
+FX_INT32 CBC_Base256Encoder::getEncodingMode()
+{
+ return BASE256_ENCODATION;
+}
+void CBC_Base256Encoder::Encode(CBC_EncoderContext &context, FX_INT32 &e)
+{
+ CFX_WideString buffer;
+ buffer += (FX_WCHAR)'\0';
+ while (context.hasMoreCharacters()) {
+ FX_WCHAR c = context.getCurrentChar();
+ buffer += c;
+ context.m_pos++;
+ FX_INT32 newMode = CBC_HighLevelEncoder::lookAheadTest(context.m_msg, context.m_pos, getEncodingMode());
+ if (newMode != getEncodingMode()) {
+ context.signalEncoderChange(newMode);
+ break;
+ }
+ }
+ FX_INT32 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);
+#else
+ FXSYS_itoa(dataCount, buf, 10);
+#endif
+ buffer.SetAt(0, FX_WCHAR(*buf) - '0');
+ FX_INT32 lengthFieldSize = 1;
+ FX_INT32 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 (FX_INT32 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, FX_INT32 codewordPosition)
+{
+ FX_INT32 pseudoRandom = ((149 * codewordPosition) % 255) + 1;
+ FX_INT32 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 new file mode 100644 index 0000000000..96110b1d08 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_Base256Encoder.h @@ -0,0 +1,21 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_BASE256ENCODER_H_
+#define _BC_BASE256ENCODER_H_
+class CBC_Encoder;
+class CBC_Base256Encoder;
+class CBC_Base256Encoder : public CBC_Encoder
+{
+public:
+ CBC_Base256Encoder();
+ virtual ~CBC_Base256Encoder();
+ FX_INT32 getEncodingMode();
+ void Encode(CBC_EncoderContext &context, FX_INT32 &e);
+private:
+ static FX_WCHAR randomize255State(FX_WCHAR ch, FX_INT32 codewordPosition);
+};
+#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_C40Encoder.cpp b/xfa/src/fxbarcode/datamatrix/BC_C40Encoder.cpp new file mode 100644 index 0000000000..4c3b458afa --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_C40Encoder.cpp @@ -0,0 +1,198 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2006-2007 Jeremias Maerki.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../barcode.h"
+#include "../BC_Dimension.h"
+#include "../common/BC_CommonBitMatrix.h"
+#include "BC_Encoder.h"
+#include "BC_SymbolShapeHint.h"
+#include "BC_SymbolInfo.h"
+#include "BC_EncoderContext.h"
+#include "BC_HighLevelEncoder.h"
+#include "BC_C40Encoder.h"
+CBC_C40Encoder::CBC_C40Encoder()
+{
+}
+CBC_C40Encoder::~CBC_C40Encoder()
+{
+}
+FX_INT32 CBC_C40Encoder::getEncodingMode()
+{
+ return C40_ENCODATION;
+}
+void CBC_C40Encoder::Encode(CBC_EncoderContext &context, FX_INT32 &e)
+{
+ CFX_WideString buffer;
+ while (context.hasMoreCharacters()) {
+ FX_WCHAR c = context.getCurrentChar();
+ context.m_pos++;
+ FX_INT32 lastCharSize = encodeChar(c, buffer, e);
+ if (e != BCExceptionNO) {
+ return;
+ }
+ FX_INT32 unwritten = (buffer.GetLength() / 3) * 2;
+ FX_INT32 curCodewordCount = context.getCodewordCount() + unwritten;
+ context.updateSymbolInfo(curCodewordCount, e);
+ if (e != BCExceptionNO) {
+ return;
+ }
+ FX_INT32 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;
+ }
+ FX_INT32 count = buffer.GetLength();
+ if ((count % 3) == 0) {
+ FX_INT32 newMode = CBC_HighLevelEncoder::lookAheadTest(context.m_msg, context.m_pos, getEncodingMode());
+ if (newMode != getEncodingMode()) {
+ context.signalEncoderChange(newMode);
+ break;
+ }
+ }
+ }
+ 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, FX_INT32 &e)
+{
+ FX_INT32 unwritten = (buffer.GetLength() / 3) * 2;
+ FX_INT32 rest = buffer.GetLength() % 3;
+ FX_INT32 curCodewordCount = context.getCodewordCount() + unwritten;
+ context.updateSymbolInfo(curCodewordCount, e);
+ if (e != BCExceptionNO) {
+ return;
+ }
+ FX_INT32 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 (available > 0 || context.hasMoreCharacters()) {
+ context.writeCodeword(CBC_HighLevelEncoder::C40_UNLATCH);
+ }
+ } else {
+ e = BCExceptionIllegalStateUnexpectedCase;
+ return;
+ }
+ context.signalEncoderChange(ASCII_ENCODATION);
+}
+FX_INT32 CBC_C40Encoder::encodeChar(FX_WCHAR c, CFX_WideString &sb, FX_INT32 &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;
+ FX_INT32 len = 2;
+ len += encodeChar((c - 128), sb, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, 0);
+ return len;
+ } else {
+ e = BCExceptionIllegalArgument;
+ return 0;
+ }
+}
+FX_INT32 CBC_C40Encoder::backtrackOneCharacter(CBC_EncoderContext &context, CFX_WideString &buffer, CFX_WideString &removed, FX_INT32 lastCharSize, FX_INT32 &e)
+{
+ FX_INT32 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, FX_INT32 startPos)
+{
+ FX_WCHAR c1 = sb.GetAt(startPos);
+ FX_WCHAR c2 = sb.GetAt(startPos + 1);
+ FX_WCHAR c3 = sb.GetAt(startPos + 2);
+ FX_INT32 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 new file mode 100644 index 0000000000..7f2d2f7e79 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_C40Encoder.h @@ -0,0 +1,24 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_C40ENCODER_H_
+#define _BC_C40ENCODER_H_
+class CBC_C40Encoder;
+class CBC_C40Encoder : public CBC_Encoder
+{
+public:
+ CBC_C40Encoder();
+ virtual ~CBC_C40Encoder();
+ virtual FX_INT32 getEncodingMode();
+ virtual void Encode(CBC_EncoderContext &context, FX_INT32 &e);
+ static void writeNextTriplet(CBC_EncoderContext &context, CFX_WideString &buffer);
+ virtual void handleEOD(CBC_EncoderContext &context, CFX_WideString &buffer, FX_INT32 &e);
+ virtual FX_INT32 encodeChar(FX_WCHAR c, CFX_WideString &sb, FX_INT32 &e);
+private:
+ FX_INT32 backtrackOneCharacter(CBC_EncoderContext &context, CFX_WideString &buffer, CFX_WideString &removed, FX_INT32 lastCharSize, FX_INT32 &e);
+ static CFX_WideString encodeToCodewords(CFX_WideString sb, FX_INT32 startPos);
+};
+#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.cpp b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.cpp new file mode 100644 index 0000000000..cfb676b0a7 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.cpp @@ -0,0 +1,366 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2007 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../barcode.h"
+#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;
+}
+void CBC_DataMatrixBitMatrixParser::Init(CBC_CommonBitMatrix *bitMatrix, FX_INT32 &e)
+{
+ FX_INT32 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_DataMatrixVersion *CBC_DataMatrixBitMatrixParser::GetVersion()
+{
+ return m_version;
+}
+CBC_DataMatrixVersion *CBC_DataMatrixBitMatrixParser::ReadVersion(CBC_CommonBitMatrix *bitMatrix, FX_INT32 &e)
+{
+ FX_INT32 rows = bitMatrix->GetHeight();
+ FX_INT32 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(FX_INT32 &e)
+{
+ CBC_AutoPtr<CFX_ByteArray> result(FX_NEW CFX_ByteArray());
+ result->SetSize(m_version->GetTotalCodewords());
+ FX_INT32 resultOffset = 0;
+ FX_INT32 row = 4;
+ FX_INT32 column = 0;
+ FX_INT32 numRows = m_mappingBitMatrix->GetHeight();
+ FX_INT32 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++] = (FX_BYTE) ReadCorner1(numRows, numColumns);
+ row -= 2;
+ column += 2;
+ corner1Read = TRUE;
+ } else if ((row == numRows - 2) && (column == 0) && ((numColumns & 0x03) != 0) && !corner2Read) {
+ (*result)[resultOffset++] = (FX_BYTE) ReadCorner2(numRows, numColumns);
+ row -= 2;
+ column += 2;
+ corner2Read = TRUE;
+ } else if ((row == numRows + 4) && (column == 2) && ((numColumns & 0x07) == 0) && !corner3Read) {
+ (*result)[resultOffset++] = (FX_BYTE) ReadCorner3(numRows, numColumns);
+ row -= 2;
+ column += 2;
+ corner3Read = TRUE;
+ } else if ((row == numRows - 2) && (column == 0) && ((numColumns & 0x07) == 4) && !corner4Read) {
+ (*result)[resultOffset++] = (FX_BYTE) 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++] = (FX_BYTE) 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++] = (FX_BYTE) 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(FX_INT32 row, FX_INT32 column, FX_INT32 numRows, FX_INT32 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_INT32 CBC_DataMatrixBitMatrixParser::ReadUtah(FX_INT32 row, FX_INT32 column, FX_INT32 numRows, FX_INT32 numColumns)
+{
+ FX_INT32 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;
+}
+FX_INT32 CBC_DataMatrixBitMatrixParser::ReadCorner1(FX_INT32 numRows, FX_INT32 numColumns)
+{
+ FX_INT32 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;
+}
+FX_INT32 CBC_DataMatrixBitMatrixParser::ReadCorner2(FX_INT32 numRows, FX_INT32 numColumns)
+{
+ FX_INT32 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;
+}
+FX_INT32 CBC_DataMatrixBitMatrixParser::ReadCorner3(FX_INT32 numRows, FX_INT32 numColumns)
+{
+ FX_INT32 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;
+}
+FX_INT32 CBC_DataMatrixBitMatrixParser::ReadCorner4(FX_INT32 numRows, FX_INT32 numColumns)
+{
+ FX_INT32 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 , FX_INT32 &e)
+{
+ FX_INT32 symbolSizeRows = m_version->GetSymbolSizeRows();
+ FX_INT32 symbolSizeColumns = m_version->GetSymbolSizeColumns();
+ if (bitMatrix->GetHeight() != symbolSizeRows) {
+ e = BCExceptionCanNotCallGetDimensionOnNonSquareMatrix;
+ return NULL;
+ }
+ FX_INT32 dataRegionSizeRows = m_version->GetDataRegionSizeRows();
+ FX_INT32 dataRegionSizeColumns = m_version->GetDataRegionSizeColumns();
+ FX_INT32 numDataRegionsRow = symbolSizeRows / dataRegionSizeRows;
+ FX_INT32 numDataRegionsColumn = symbolSizeColumns / dataRegionSizeColumns;
+ FX_INT32 sizeDataRegionRow = numDataRegionsRow * dataRegionSizeRows;
+ FX_INT32 sizeDataRegionColumn = numDataRegionsColumn * dataRegionSizeColumns;
+ CBC_CommonBitMatrix *bitMatrixWithoutAlignment = FX_NEW CBC_CommonBitMatrix();
+ bitMatrixWithoutAlignment->Init(sizeDataRegionColumn, sizeDataRegionRow);
+ FX_INT32 dataRegionRow;
+ for (dataRegionRow = 0; dataRegionRow < numDataRegionsRow; ++dataRegionRow) {
+ FX_INT32 dataRegionRowOffset = dataRegionRow * dataRegionSizeRows;
+ FX_INT32 dataRegionColumn;
+ for (dataRegionColumn = 0; dataRegionColumn < numDataRegionsColumn; ++dataRegionColumn) {
+ FX_INT32 dataRegionColumnOffset = dataRegionColumn * dataRegionSizeColumns;
+ FX_INT32 i;
+ for (i = 0; i < dataRegionSizeRows; ++i) {
+ FX_INT32 readRowOffset = dataRegionRow * (dataRegionSizeRows + 2) + 1 + i;
+ FX_INT32 writeRowOffset = dataRegionRowOffset + i;
+ FX_INT32 j;
+ for (j = 0; j < dataRegionSizeColumns; ++j) {
+ FX_INT32 readColumnOffset = dataRegionColumn * (dataRegionSizeColumns + 2) + 1 + j;
+ if (bitMatrix->Get(readColumnOffset, readRowOffset)) {
+ FX_INT32 writeColumnOffset = dataRegionColumnOffset + j;
+ bitMatrixWithoutAlignment->Set(writeColumnOffset, writeRowOffset);
+ }
+ }
+ }
+ }
+ }
+ return bitMatrixWithoutAlignment;
+}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.h b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.h new file mode 100644 index 0000000000..c5f1f3f7a0 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.h @@ -0,0 +1,33 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_DATAMATRIXBITMATRIXPARSER_H_
+#define _BC_DATAMATRIXBITMATRIXPARSER_H_
+class CBC_CommonBitMatrix;
+class CBC_DataMatrixVersion;
+class CBC_DataMatrixBitMatrixParser;
+class CBC_DataMatrixBitMatrixParser : public CFX_Object
+{
+public:
+ CBC_DataMatrixBitMatrixParser();
+ virtual ~CBC_DataMatrixBitMatrixParser();
+ CBC_DataMatrixVersion *GetVersion();
+ CFX_ByteArray *ReadCodewords(FX_INT32 &e);
+ FX_BOOL ReadModule(FX_INT32 row, FX_INT32 column, FX_INT32 numRows, FX_INT32 numColumns);
+ FX_INT32 ReadUtah(FX_INT32 row, FX_INT32 column, FX_INT32 numRows, FX_INT32 numColumns);
+ FX_INT32 ReadCorner1(FX_INT32 numRows, FX_INT32 numColumns);
+ FX_INT32 ReadCorner2(FX_INT32 numRows, FX_INT32 numColumns);
+ FX_INT32 ReadCorner3(FX_INT32 numRows, FX_INT32 numColumns);
+ FX_INT32 ReadCorner4(FX_INT32 numRows, FX_INT32 numColumns);
+ CBC_CommonBitMatrix *ExtractDataRegion(CBC_CommonBitMatrix *bitMatrix, FX_INT32 &e);
+ virtual void Init(CBC_CommonBitMatrix *bitMatrix, FX_INT32 &e);
+private:
+ static CBC_DataMatrixVersion* ReadVersion(CBC_CommonBitMatrix *bitMatrix, FX_INT32 &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 new file mode 100644 index 0000000000..c884834fa9 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDataBlock.cpp @@ -0,0 +1,99 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2008 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../barcode.h"
+#include "BC_DataMatrixVersion.h"
+#include "BC_DataMatrixDataBlock.h"
+CBC_DataMatrixDataBlock::~CBC_DataMatrixDataBlock()
+{
+}
+CBC_DataMatrixDataBlock::CBC_DataMatrixDataBlock(FX_INT32 numDataCodewords, CFX_ByteArray *codewords)
+{
+ m_codewords.Copy(*codewords);
+ m_numDataCodewords = numDataCodewords;
+}
+CFX_PtrArray *CBC_DataMatrixDataBlock::GetDataBlocks(CFX_ByteArray* rawCodewords, CBC_DataMatrixVersion *version, FX_INT32 &e)
+{
+ ECBlocks *ecBlocks = version->GetECBlocks();
+ FX_INT32 totalBlocks = 0;
+ const CFX_PtrArray &ecBlockArray = ecBlocks->GetECBlocks();
+ FX_INT32 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);
+ FX_INT32 numResultBlocks = 0;
+ FX_INT32 j;
+ for (j = 0; j < ecBlockArray.GetSize(); j++) {
+ for (i = 0; i < ((ECB*)ecBlockArray[j])->GetCount(); i++) {
+ FX_INT32 numDataCodewords = ((ECB*)ecBlockArray[j])->GetDataCodewords();
+ FX_INT32 numBlockCodewords = ecBlocks->GetECCodewords() + numDataCodewords;
+ CFX_ByteArray codewords;
+ codewords.SetSize(numBlockCodewords);
+ (*result)[numResultBlocks++] = FX_NEW CBC_DataMatrixDataBlock(numDataCodewords, &codewords);
+ codewords.SetSize(0);
+ }
+ }
+ FX_INT32 longerBlocksTotalCodewords = ((CBC_DataMatrixDataBlock*)(*result)[0])->GetCodewords()->GetSize();
+ FX_INT32 longerBlocksNumDataCodewords = longerBlocksTotalCodewords - ecBlocks->GetECCodewords();
+ FX_INT32 shorterBlocksNumDataCodewords = longerBlocksNumDataCodewords - 1;
+ FX_INT32 rawCodewordsOffset = 0;
+ for (i = 0; i < shorterBlocksNumDataCodewords; i++) {
+ FX_INT32 j;
+ 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;
+ FX_INT32 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_INT32 max = ((CBC_DataMatrixDataBlock*)(*result)[0])->GetCodewords()->GetSize();
+ for (i = longerBlocksNumDataCodewords; i < max; i++) {
+ FX_INT32 j;
+ for (j = 0; j < numResultBlocks; j++) {
+ FX_INT32 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;
+ }
+ return result.release();
+}
+FX_INT32 CBC_DataMatrixDataBlock::GetNumDataCodewords()
+{
+ return m_numDataCodewords;
+}
+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 new file mode 100644 index 0000000000..1dd62fe1fe --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDataBlock.h @@ -0,0 +1,26 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_DATAMATRIXDATABLOCK_H_
+#define _BC_DATAMATRIXDATABLOCK_H_
+class CBC_DataMatrixVersion;
+class CBC_DataMatrixDataBlock;
+class CBC_DataMatrixDataBlock : public CFX_Object
+{
+public:
+ virtual ~CBC_DataMatrixDataBlock();
+
+ FX_INT32 GetNumDataCodewords();
+ CFX_ByteArray* GetCodewords();
+
+ static CFX_PtrArray *GetDataBlocks(CFX_ByteArray* rawCodewords, CBC_DataMatrixVersion *version, FX_INT32 &e);
+private:
+ FX_INT32 m_numDataCodewords;
+ CFX_ByteArray m_codewords;
+
+ CBC_DataMatrixDataBlock(FX_INT32 numDataCodewords, CFX_ByteArray *codewords);
+};
+#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.cpp b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.cpp new file mode 100644 index 0000000000..e934d9313d --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.cpp @@ -0,0 +1,472 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2008 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../barcode.h"
+#include "../common/BC_CommonDecoderResult.h"
+#include "../common/BC_CommonBitSource.h"
+#include "BC_DataMatrixDecodedBitStreamParser.h"
+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'
+};
+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'
+};
+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
+};
+const FX_INT32 CBC_DataMatrixDecodedBitStreamParser::PAD_ENCODE = 0;
+const FX_INT32 CBC_DataMatrixDecodedBitStreamParser::ASCII_ENCODE = 1;
+const FX_INT32 CBC_DataMatrixDecodedBitStreamParser::C40_ENCODE = 2;
+const FX_INT32 CBC_DataMatrixDecodedBitStreamParser::TEXT_ENCODE = 3;
+const FX_INT32 CBC_DataMatrixDecodedBitStreamParser::ANSIX12_ENCODE = 4;
+const FX_INT32 CBC_DataMatrixDecodedBitStreamParser::EDIFACT_ENCODE = 5;
+const FX_INT32 CBC_DataMatrixDecodedBitStreamParser::BASE256_ENCODE = 6;
+CBC_DataMatrixDecodedBitStreamParser::CBC_DataMatrixDecodedBitStreamParser()
+{
+}
+CBC_DataMatrixDecodedBitStreamParser::~CBC_DataMatrixDecodedBitStreamParser()
+{
+}
+CBC_CommonDecoderResult *CBC_DataMatrixDecodedBitStreamParser::Decode(CFX_ByteArray &bytes, FX_INT32 &e)
+{
+ CBC_CommonBitSource bits(&bytes);
+ CFX_ByteString result;
+ CFX_ByteString resultTrailer;
+ CFX_Int32Array byteSegments;
+ FX_INT32 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_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;
+}
+FX_INT32 CBC_DataMatrixDecodedBitStreamParser::DecodeAsciiSegment(CBC_CommonBitSource *bits, CFX_ByteString &result, CFX_ByteString &resultTrailer, FX_INT32 &e)
+{
+ FX_CHAR buffer[128];
+ FX_BOOL upperShift = FALSE;
+ do {
+ FX_INT32 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) {
+ FX_INT32 value = oneByte - 130;
+#if defined(_FX_WINAPI_PARTITION_APP_)
+ memset(buffer, 0, sizeof(FX_CHAR) * 128);
+ _itoa_s(value, buffer, 128, 10);
+#else
+ FXSYS_itoa(value, buffer, 10);
+#endif
+ 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, FX_INT32 &e)
+{
+ FX_BOOL upperShift = FALSE;
+ CFX_Int32Array cValues;
+ cValues.SetSize(3);
+ do {
+ if (bits->Available() == 8) {
+ return;
+ }
+ FX_INT32 firstByte = bits->ReadBits(8, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ if (firstByte == 254) {
+ return;
+ }
+ FX_INT32 tempp = bits->ReadBits(8, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ ParseTwoBytes(firstByte, tempp, cValues);
+ FX_INT32 shift = 0;
+ FX_INT32 i;
+ for (i = 0; i < 3; i++) {
+ FX_INT32 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);
+}
+void CBC_DataMatrixDecodedBitStreamParser::DecodeTextSegment(CBC_CommonBitSource *bits, CFX_ByteString &result, FX_INT32 &e)
+{
+ FX_BOOL upperShift = FALSE;
+ CFX_Int32Array cValues;
+ cValues.SetSize(3);
+ FX_INT32 shift = 0;
+ do {
+ if (bits->Available() == 8) {
+ return;
+ }
+ FX_INT32 firstByte = bits->ReadBits(8, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ if (firstByte == 254) {
+ return;
+ }
+ FX_INT32 inTp = bits->ReadBits(8, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ ParseTwoBytes(firstByte, inTp, cValues);
+ for (FX_INT32 i = 0; i < 3; i++) {
+ FX_INT32 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;
+ }
+ }
+ } while (bits->Available() > 0);
+}
+void CBC_DataMatrixDecodedBitStreamParser::DecodeAnsiX12Segment(CBC_CommonBitSource *bits, CFX_ByteString &result, FX_INT32 &e)
+{
+ CFX_Int32Array cValues;
+ cValues.SetSize(3);
+ do {
+ if (bits->Available() == 8) {
+ return;
+ }
+ FX_INT32 firstByte = bits->ReadBits(8, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ if (firstByte == 254) {
+ return;
+ }
+ FX_INT32 iTemp1 = bits->ReadBits(8, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ ParseTwoBytes(firstByte, iTemp1, cValues);
+ FX_INT32 i;
+ for (i = 0; i < 3; i++) {
+ FX_INT32 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(FX_INT32 firstByte, FX_INT32 secondByte, CFX_Int32Array &result)
+{
+ FX_INT32 fullBitValue = (firstByte << 8) + secondByte - 1;
+ FX_INT32 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, FX_INT32 &e)
+{
+ FX_CHAR buffer[128];
+ FX_BOOL unlatch = FALSE;
+ do {
+ if (bits->Available() <= 16) {
+ return;
+ }
+ FX_INT32 i;
+ for (i = 0; i < 4; i++) {
+ FX_INT32 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);
+}
+void CBC_DataMatrixDecodedBitStreamParser::DecodeBase256Segment(CBC_CommonBitSource *bits, CFX_ByteString &result, CFX_Int32Array &byteSegments, FX_INT32 &e)
+{
+ FX_INT32 codewordPosition = 1 + bits->getByteOffset();
+ FX_INT32 iTmp = bits->ReadBits(8, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ FX_INT32 d1 = Unrandomize255State(iTmp, codewordPosition++);
+ FX_INT32 count;
+ if (d1 == 0) {
+ count = bits->Available() / 8;
+ } else if (d1 < 250) {
+ count = d1;
+ } else {
+ FX_INT32 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);
+ FX_INT32 i;
+ for (i = 0; i < count; i++) {
+ if (bits->Available() < 8) {
+ e = BCExceptionFormatException;
+ delete bytes;
+ return;
+ }
+ FX_INT32 iTemp5 = bits->ReadBits(8, e);
+ if (e != BCExceptionNO) {
+ delete bytes;
+ return;
+ }
+ bytes->SetAt(i, Unrandomize255State(iTemp5, codewordPosition++));
+ }
+ BC_FX_ByteString_Append(result, *bytes);
+ delete bytes;
+}
+FX_BYTE CBC_DataMatrixDecodedBitStreamParser::Unrandomize255State(FX_INT32 randomizedBase256Codeword, FX_INT32 base256CodewordPosition)
+{
+ FX_INT32 pseudoRandomNumber = ((149 * base256CodewordPosition) % 255) + 1;
+ FX_INT32 tempVariable = randomizedBase256Codeword - pseudoRandomNumber;
+ return (FX_BYTE) (tempVariable >= 0 ? tempVariable : tempVariable + 256);
+}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.h b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.h new file mode 100644 index 0000000000..060972d53a --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.h @@ -0,0 +1,43 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_DATAMATRIXDECODEDBITSTREAMPARSER_H_
+#define _BC_DATAMATRIXDECODEDBITSTREAMPARSER_H_
+class CBC_CommonDecoderResult;
+class CBC_CommonBitSource;
+class CBC_DataMatrixDecodedBitStreamParser;
+class CBC_DataMatrixDecodedBitStreamParser : public CFX_Object
+{
+public:
+ CBC_DataMatrixDecodedBitStreamParser();
+ virtual ~CBC_DataMatrixDecodedBitStreamParser();
+ static CBC_CommonDecoderResult *Decode(CFX_ByteArray &bytes, FX_INT32 &e);
+
+private:
+ static FX_INT32 DecodeAsciiSegment(CBC_CommonBitSource *bits, CFX_ByteString &result, CFX_ByteString &resultTrailer, FX_INT32 &e);
+ static void DecodeC40Segment(CBC_CommonBitSource *bits, CFX_ByteString &result, FX_INT32 &e);
+ static void DecodeTextSegment(CBC_CommonBitSource *bits, CFX_ByteString &result, FX_INT32 &e);
+ static void DecodeAnsiX12Segment(CBC_CommonBitSource *bits, CFX_ByteString &result, FX_INT32 &e);
+ static void ParseTwoBytes(FX_INT32 firstByte, FX_INT32 secondByte, CFX_Int32Array &result);
+ static void DecodeEdifactSegment(CBC_CommonBitSource *bits, CFX_ByteString &result, FX_INT32 &e);
+ static void DecodeBase256Segment(CBC_CommonBitSource *bits, CFX_ByteString &result, CFX_Int32Array &byteSegments, FX_INT32 &e);
+ static FX_BYTE Unrandomize255State(FX_INT32 randomizedBase256Codeword, FX_INT32 base256CodewordPosition);
+
+ 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 FX_INT32 PAD_ENCODE;
+ const static FX_INT32 ASCII_ENCODE;
+ const static FX_INT32 C40_ENCODE;
+ const static FX_INT32 TEXT_ENCODE;
+ const static FX_INT32 ANSIX12_ENCODE;
+ const static FX_INT32 EDIFACT_ENCODE;
+ const static FX_INT32 BASE256_ENCODE;
+};
+#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp new file mode 100644 index 0000000000..e9eb32cf84 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp @@ -0,0 +1,110 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2007 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../barcode.h"
+#include "../common/BC_CommonBitMatrix.h"
+#include "../common/reedsolomon/BC_ReedSolomonDecoder.h"
+#include "../common/reedsolomon/BC_ReedSolomonGF256.h"
+#include "BC_DataMatrixDecoder.h"
+#include "BC_DataMatrixBitMatrixParser.h"
+#include "BC_DataMatrixVersion.h"
+#include "BC_DataMatrixDataBlock.h"
+#include "BC_DataMatrixDecodedBitStreamParser.h"
+CBC_DataMatrixDecoder::CBC_DataMatrixDecoder()
+{
+ m_rsDecoder = NULL;
+}
+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_CommonDecoderResult *CBC_DataMatrixDecoder::Decode(CBC_CommonBitMatrix *bits, FX_INT32 &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);
+ FX_INT32 dataBlocksCount = dataBlocks->GetSize();
+ FX_INT32 totalBytes = 0;
+ FX_INT32 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();
+ FX_INT32 numDataCodewords = ((CBC_DataMatrixDataBlock*)(*dataBlocks)[j])->GetNumDataCodewords();
+ CorrectErrors(*codewordBytes, numDataCodewords, e);
+ if (e != BCExceptionNO) {
+ for(FX_INT32 i = 0; i < dataBlocks->GetSize(); i++) {
+ delete (CBC_DataMatrixDataBlock*)(*dataBlocks)[i];
+ }
+ delete dataBlocks;
+ dataBlocks = NULL;
+ return NULL;
+ }
+ FX_INT32 i;
+ for (i = 0; i < numDataCodewords; 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, FX_INT32 numDataCodewords, FX_INT32 &e)
+{
+ FX_INT32 numCodewords = codewordBytes.GetSize();
+ CFX_Int32Array codewordsInts;
+ codewordsInts.SetSize(numCodewords);
+ FX_INT32 i;
+ for (i = 0; i < numCodewords; i++) {
+ codewordsInts[i] = codewordBytes[i] & 0xFF;
+ }
+ FX_INT32 numECCodewords = codewordBytes.GetSize() - numDataCodewords;
+ m_rsDecoder->Decode(&codewordsInts, numECCodewords, e);
+ if (e != BCExceptionNO) {
+ e = BCExceptionChecksumException;
+ return ;
+ }
+ for (i = 0; i < numDataCodewords; i++) {
+ codewordBytes[i] = (FX_BYTE) codewordsInts[i];
+ }
+}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecoder.h b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecoder.h new file mode 100644 index 0000000000..44f7efc7b7 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDecoder.h @@ -0,0 +1,24 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_DATAMATRIXDECODER_H_
+#define _BC_DATAMATRIXDECODER_H_
+class CBC_ReedSolomonDecoder;
+class CBC_CommonDecoderResult;
+class CBC_CommonBitMatrix;
+class CBC_DataMatrixDecoder;
+class CBC_DataMatrixDecoder : public CFX_Object
+{
+public:
+ CBC_DataMatrixDecoder();
+ virtual ~CBC_DataMatrixDecoder();
+ CBC_CommonDecoderResult *Decode(CBC_CommonBitMatrix *bits, FX_INT32 &e);
+ virtual void Init();
+private:
+ void CorrectErrors(CFX_ByteArray &codewordBytes, FX_INT32 numDataCodewords, FX_INT32 &e);
+ CBC_ReedSolomonDecoder *m_rsDecoder;
+};
+#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp new file mode 100644 index 0000000000..12877c5c3a --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp @@ -0,0 +1,368 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2008 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../barcode.h"
+#include "../BC_ResultPoint.h"
+#include "../common/BC_WhiteRectangleDetector.h"
+#include "../common/BC_CommonBitMatrix.h"
+#include "../qrcode/BC_QRFinderPatternFinder.h"
+#include "../qrcode/BC_QRDetectorResult.h"
+#include "../qrcode/BC_QRGridSampler.h"
+#include "BC_DataMatrixDetector.h"
+const FX_INT32 CBC_DataMatrixDetector::INTEGERS[5] = {0, 1, 2, 3, 4};
+CBC_DataMatrixDetector::CBC_DataMatrixDetector(CBC_CommonBitMatrix *image):
+ m_image(image), m_rectangleDetector(NULL)
+{
+}
+void CBC_DataMatrixDetector::Init(FX_INT32 &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;
+}
+inline FX_BOOL ResultPointsAndTransitionsComparator(FX_LPVOID a, FX_LPVOID b)
+{
+ return ((CBC_ResultPointsAndTransitions *)b)->GetTransitions() > ((CBC_ResultPointsAndTransitions *)a)->GetTransitions();
+}
+CBC_QRDetectorResult *CBC_DataMatrixDetector::Detect(FX_INT32 &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*, FX_INT32> 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;
+ FX_INT32 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;
+ }
+ 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;
+ FX_INT32 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;
+ }
+ FX_INT32 dimensionTop = CBC_AutoPtr<CBC_ResultPointsAndTransitions>(TransitionsBetween(topLeft, topRight))->GetTransitions();
+ FX_INT32 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 {
+ 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);
+ } else {
+ FX_INT32 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;
+ }
+ FX_INT32 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);
+ }
+ 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, FX_INT32 dimensionTop, FX_INT32 dimensionRight)
+{
+ FX_FLOAT corr = Distance(bottomLeft, bottomRight) / (FX_FLOAT)dimensionTop;
+ FX_INT32 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();
+ }
+ FX_INT32 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());
+ FX_INT32 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, FX_INT32 dimension)
+{
+ FX_FLOAT corr = Distance(bottomLeft, bottomRight) / (FX_FLOAT) dimension;
+ FX_INT32 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();
+ }
+ FX_INT32 l1 = FXSYS_abs(CBC_AutoPtr<CBC_ResultPointsAndTransitions>(TransitionsBetween(topLeft, c1.get()))->GetTransitions() -
+ CBC_AutoPtr<CBC_ResultPointsAndTransitions>(TransitionsBetween(bottomRight, c1.get()))->GetTransitions());
+ FX_INT32 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_INT32 CBC_DataMatrixDetector::Round(FX_FLOAT d)
+{
+ return (FX_INT32) (d + 0.5f);
+}
+FX_INT32 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*, FX_INT32> &table, CBC_ResultPoint *key)
+{
+ FX_INT32 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,
+ FX_INT32 dimensionX, FX_INT32 dimensionY, FX_INT32 &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)
+{
+ FX_INT32 fromX = (FX_INT32) from->GetX();
+ FX_INT32 fromY = (FX_INT32) from->GetY();
+ FX_INT32 toX = (FX_INT32) to->GetX();
+ FX_INT32 toY = (FX_INT32) to->GetY();
+ FX_BOOL steep = FXSYS_abs(toY - fromY) > FXSYS_abs(toX - fromX);
+ if (steep) {
+ FX_INT32 temp = fromX;
+ fromX = fromY;
+ fromY = temp;
+ temp = toX;
+ toX = toY;
+ toY = temp;
+ }
+ FX_INT32 dx = FXSYS_abs(toX - fromX);
+ FX_INT32 dy = FXSYS_abs(toY - fromY);
+ FX_INT32 error = -dx >> 1;
+ FX_INT32 ystep = fromY < toY ? 1 : -1;
+ FX_INT32 xstep = fromX < toX ? 1 : -1;
+ FX_INT32 transitions = 0;
+ FX_BOOL inBlack = m_image->Get(steep ? fromY : fromX, steep ? fromX : fromY);
+ for (FX_INT32 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;
+ }
+ }
+ 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;
+}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.h b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.h new file mode 100644 index 0000000000..2d3ca744fe --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixDetector.h @@ -0,0 +1,78 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_DATAMATRIXDETECTOR_H_
+#define _BC_DATAMATRIXDETECTOR_H_
+class CBC_CommonBitMatrix;
+class CBC_WhiteRectangleDetector;
+class CBC_ResultPoint;
+class CBC_QRDetectorResult;
+class CBC_DataMatrixDetector;
+class ResultPointsAndTransitions;
+class CBC_ResultPointsAndTransitions : public CFX_Object
+{
+public:
+ CBC_ResultPointsAndTransitions(CBC_ResultPoint *from, CBC_ResultPoint *to, FX_INT32 transitions)
+ {
+ m_from = from;
+ m_to = to;
+ m_transitions = transitions;
+ }
+ ~CBC_ResultPointsAndTransitions()
+ {
+ }
+ CBC_ResultPoint *GetFrom()
+ {
+ return m_from;
+ }
+ CBC_ResultPoint *GetTo()
+ {
+ return m_to;
+ }
+ FX_INT32 GetTransitions()
+ {
+ return m_transitions;
+ }
+private:
+ CBC_ResultPoint *m_from;
+ CBC_ResultPoint *m_to;
+ FX_INT32 m_transitions;
+};
+class CBC_DataMatrixDetector
+{
+public:
+ CBC_DataMatrixDetector(CBC_CommonBitMatrix *image);
+ virtual ~CBC_DataMatrixDetector();
+ CBC_QRDetectorResult *Detect(FX_INT32 &e);
+ CBC_ResultPoint *CorrectTopRightRectangular(CBC_ResultPoint *bottomLeft,
+ CBC_ResultPoint *bottomRight,
+ CBC_ResultPoint *topLeft,
+ CBC_ResultPoint *topRight,
+ FX_INT32 dimensionTop, FX_INT32 dimensionRight);
+ CBC_ResultPoint *CorrectTopRight(CBC_ResultPoint *bottomLeft,
+ CBC_ResultPoint *bottomRight,
+ CBC_ResultPoint *topLeft,
+ CBC_ResultPoint *topRight,
+ FX_INT32 dimension);
+ CBC_CommonBitMatrix *SampleGrid(CBC_CommonBitMatrix *image,
+ CBC_ResultPoint *topLeft,
+ CBC_ResultPoint *bottomLeft,
+ CBC_ResultPoint *bottomRight,
+ CBC_ResultPoint *topRight,
+ FX_INT32 dimensionX, FX_INT32 dimensionY, FX_INT32 &e);
+ CBC_ResultPointsAndTransitions *TransitionsBetween(CBC_ResultPoint *from, CBC_ResultPoint *to);
+ FX_BOOL IsValid(CBC_ResultPoint *p);
+ FX_INT32 Distance(CBC_ResultPoint *a, CBC_ResultPoint *b);
+ void Increment(CFX_MapPtrTemplate<CBC_ResultPoint*, FX_INT32> &table, CBC_ResultPoint *key);
+ FX_INT32 Round(FX_FLOAT d);
+ void OrderBestPatterns(CFX_PtrArray *patterns);
+ virtual void Init(FX_INT32 &e);
+private:
+ CBC_CommonBitMatrix *m_image;
+ CBC_WhiteRectangleDetector *m_rectangleDetector;
+ const static FX_INT32 INTEGERS[5];
+};
+#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixReader.cpp b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixReader.cpp new file mode 100644 index 0000000000..cf076cd313 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixReader.cpp @@ -0,0 +1,67 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2007 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../barcode.h"
+#include "../BC_BinaryBitmap.h"
+#include "../BC_Reader.h"
+#include "../qrcode/BC_QRDetectorResult.h"
+#include "../common/BC_CommonDecoderResult.h"
+#include "BC_DataMatrixDecoder.h"
+#include "BC_DataMatrixDetector.h"
+#include "BC_DataMatrixReader.h"
+CBC_DataMatrixReader::CBC_DataMatrixReader()
+{
+ m_decoder = NULL;
+}
+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;
+}
+CFX_ByteString CBC_DataMatrixReader::Decode(CBC_BinaryBitmap *image, FX_INT32 hints, FX_INT32 &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, FX_INT32 &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 new file mode 100644 index 0000000000..4301512d70 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixReader.h @@ -0,0 +1,25 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_DATAMATRIXREADER_H_
+#define _BC_DATAMATRIXREADER_H_
+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, FX_INT32 &e);
+ CFX_ByteString Decode(CBC_BinaryBitmap *image, int hints, FX_INT32 &e);
+
+ 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 new file mode 100644 index 0000000000..256117883d --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.cpp @@ -0,0 +1,43 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2006 Jeremias Maerki
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../barcode.h"
+#include "BC_Encoder.h"
+#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()
+{
+}
+FX_INT32 CBC_DataMatrixSymbolInfo144::getInterleavedBlockCount()
+{
+ return 10;
+}
+FX_INT32 CBC_DataMatrixSymbolInfo144getDataLengthForInterleavedBlock(FX_INT32 index)
+{
+ return (index <= 8) ? 156 : 155;
+}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.h b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.h new file mode 100644 index 0000000000..e749b27d86 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.h @@ -0,0 +1,19 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_DATAMATRIXSYMBOLINFO144_H_
+#define _BC_DATAMATRIXSYMBOLINFO144_H_
+class CBC_SymbolInfo;
+class CBC_DataMatrixSymbolInfo144;
+class CBC_DataMatrixSymbolInfo144 : public CBC_SymbolInfo
+{
+public:
+ CBC_DataMatrixSymbolInfo144();
+ virtual ~CBC_DataMatrixSymbolInfo144();
+ FX_INT32 getInterleavedBlockCount();
+ FX_INT32 getDataLengthForInterleavedBlock(FX_INT32 index);
+};
+#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixVersion.cpp b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixVersion.cpp new file mode 100644 index 0000000000..1a4e59864e --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixVersion.cpp @@ -0,0 +1,147 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2007 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#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::Finalize()
+{
+ for (FX_INT32 i = 0; i < VERSIONS->GetSize(); i++) {
+ delete ( (CBC_DataMatrixVersion*)(VERSIONS->GetAt(i)) );
+ }
+ VERSIONS->RemoveAll();
+ delete VERSIONS;
+}
+CBC_DataMatrixVersion::CBC_DataMatrixVersion(FX_INT32 versionNumber,
+ FX_INT32 symbolSizeRows,
+ FX_INT32 symbolSizeColumns,
+ FX_INT32 dataRegionSizeRows,
+ FX_INT32 dataRegionSizeColumns,
+ ECBlocks *ecBlocks)
+{
+ m_versionNumber = versionNumber;
+ m_symbolSizeRows = symbolSizeRows;
+ m_symbolSizeColumns = symbolSizeColumns;
+ m_dataRegionSizeRows = dataRegionSizeRows;
+ m_dataRegionSizeColumns = dataRegionSizeColumns;
+ m_ecBlocks = ecBlocks;
+ FX_INT32 total = 0;
+ FX_INT32 ecCodewords = ecBlocks->GetECCodewords();
+ const CFX_PtrArray &ecbArray = ecBlocks->GetECBlocks();
+ for (FX_INT32 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;
+}
+FX_INT32 CBC_DataMatrixVersion::GetVersionNumber()
+{
+ return m_versionNumber;
+}
+FX_INT32 CBC_DataMatrixVersion::GetSymbolSizeRows()
+{
+ return m_symbolSizeRows;
+}
+FX_INT32 CBC_DataMatrixVersion::GetSymbolSizeColumns()
+{
+ return m_symbolSizeColumns;
+}
+FX_INT32 CBC_DataMatrixVersion::GetDataRegionSizeRows()
+{
+ return m_dataRegionSizeRows;
+}
+FX_INT32 CBC_DataMatrixVersion::GetDataRegionSizeColumns()
+{
+ return m_dataRegionSizeColumns;
+}
+FX_INT32 CBC_DataMatrixVersion::GetTotalCodewords()
+{
+ return m_totalCodewords;
+}
+ECBlocks *CBC_DataMatrixVersion::GetECBlocks()
+{
+ return m_ecBlocks;
+}
+void CBC_DataMatrixVersion::ReleaseAll()
+{
+ for (FX_INT32 i = 0; i < VERSIONS->GetSize(); i++) {
+ delete (CBC_DataMatrixVersion*)VERSIONS->GetAt(i);
+ }
+ VERSIONS->RemoveAll();
+}
+CBC_DataMatrixVersion *CBC_DataMatrixVersion::GetVersionForDimensions(FX_INT32 numRows, FX_INT32 numColumns, FX_INT32 &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))));
+ }
+ FX_INT32 numVersions = VERSIONS->GetSize();
+ for (FX_INT32 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 new file mode 100644 index 0000000000..41d2f23db6 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixVersion.h @@ -0,0 +1,101 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_DATAMATRIXVERSION_H_
+#define _BC_DATAMATRIXVERSION_H_
+class ECB;
+class ECBlocks;
+class CBC_DataMatrixVersion;
+class ECB : public CFX_Object
+{
+public:
+ ECB(FX_INT32 count, FX_INT32 dataCodewords)
+ {
+ m_count = count;
+ m_dataCodewords = dataCodewords;
+ }
+
+ FX_INT32 GetCount()
+ {
+ return m_count;
+ }
+
+ FX_INT32 GetDataCodewords()
+ {
+ return m_dataCodewords;
+ }
+private:
+ FX_INT32 m_count;
+ FX_INT32 m_dataCodewords;
+};
+class ECBlocks : public CFX_Object
+{
+public:
+ ECBlocks(FX_INT32 ecCodewords, ECB *ecBlocks)
+ {
+ m_ecCodewords = ecCodewords;
+ m_ecBlocks.Add(ecBlocks);
+ }
+
+ ECBlocks(FX_INT32 ecCodewords, ECB *ecBlocks1, ECB *ecBlocks2)
+ {
+ m_ecCodewords = ecCodewords;
+ m_ecBlocks.Add(ecBlocks1);
+ m_ecBlocks.Add(ecBlocks2);
+ }
+ ~ECBlocks()
+ {
+ for(FX_INT32 i = 0; i < m_ecBlocks.GetSize(); i++) {
+ delete (ECB*)m_ecBlocks[i];
+ }
+ m_ecBlocks.RemoveAll();
+ }
+
+ FX_INT32 GetECCodewords()
+ {
+ return m_ecCodewords;
+ }
+
+ const CFX_PtrArray &GetECBlocks()
+ {
+ return m_ecBlocks;
+ }
+private:
+ FX_INT32 m_ecCodewords;
+ CFX_PtrArray m_ecBlocks;
+};
+class CBC_DataMatrixVersion : public CFX_Object
+{
+public:
+ CBC_DataMatrixVersion(FX_INT32 versionNumber,
+ FX_INT32 symbolSizeRows,
+ FX_INT32 symbolSizeColumns,
+ FX_INT32 dataRegionSizeRows,
+ FX_INT32 dataRegionSizeColumns,
+ ECBlocks *ecBlocks);
+ virtual ~CBC_DataMatrixVersion();
+ static void Initialize();
+ static void Finalize();
+ FX_INT32 GetVersionNumber();
+ FX_INT32 GetSymbolSizeRows();
+ FX_INT32 GetSymbolSizeColumns();
+ FX_INT32 GetDataRegionSizeRows();
+ FX_INT32 GetDataRegionSizeColumns();
+ FX_INT32 GetTotalCodewords();
+ ECBlocks *GetECBlocks();
+ static CBC_DataMatrixVersion *GetVersionForDimensions(FX_INT32 numRows, FX_INT32 numColumns, FX_INT32 &e);
+ static void ReleaseAll();
+private:
+ FX_INT32 m_versionNumber;
+ FX_INT32 m_symbolSizeRows;
+ FX_INT32 m_symbolSizeColumns;
+ FX_INT32 m_dataRegionSizeRows;
+ FX_INT32 m_dataRegionSizeColumns;
+ ECBlocks *m_ecBlocks;
+ FX_INT32 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 new file mode 100644 index 0000000000..652758a635 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp @@ -0,0 +1,138 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2008 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../barcode.h"
+#include "../BC_Writer.h"
+#include "../BC_TwoDimWriter.h"
+#include "../BC_Dimension.h"
+#include "../BC_BinaryBitmap.h"
+#include "../BC_UtilCodingConvert.h"
+#include "../common/BC_CommonBitMatrix.h"
+#include "../common/BC_CommonByteMatrix.h"
+#include "BC_Encoder.h"
+#include "BC_DefaultPlacement.h"
+#include "BC_SymbolShapeHint.h"
+#include "BC_SymbolInfo.h"
+#include "BC_DataMatrixSymbolInfo144.h"
+#include "BC_ErrorCorrection.h"
+#include "BC_EncoderContext.h"
+#include "BC_C40Encoder.h"
+#include "BC_TextEncoder.h"
+#include "BC_X12Encoder.h"
+#include "BC_EdifactEncoder.h"
+#include "BC_Base256Encoder.h"
+#include "BC_ASCIIEncoder.h"
+#include "BC_HighLevelEncoder.h"
+#include "BC_DataMatrixWriter.h"
+CBC_DataMatrixWriter::CBC_DataMatrixWriter()
+{
+}
+CBC_DataMatrixWriter::~CBC_DataMatrixWriter()
+{
+}
+FX_BOOL CBC_DataMatrixWriter::SetErrorCorrectionLevel (FX_INT32 level)
+{
+ m_iCorrectLevel = level;
+ return TRUE;
+}
+FX_BYTE* CBC_DataMatrixWriter::Encode(const CFX_WideString &contents, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 &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();
+ FX_BYTE* result = FX_Alloc(FX_BYTE, outWidth * outHeight);
+ FXSYS_memcpy32(result, bytematrix->GetArray(), outWidth * outHeight);
+ delete bytematrix;
+ delete placement;
+ return result;
+}
+FX_BYTE *CBC_DataMatrixWriter::Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 &e)
+{
+ return NULL;
+}
+FX_BYTE *CBC_DataMatrixWriter::Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 hints, FX_INT32 &e)
+{
+ return NULL;
+}
+CBC_CommonByteMatrix* CBC_DataMatrixWriter::encodeLowLevel(CBC_DefaultPlacement* placement, CBC_SymbolInfo* symbolInfo, FX_INT32 &e)
+{
+ FX_INT32 symbolWidth = symbolInfo->getSymbolDataWidth(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ FX_INT32 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();
+ FX_INT32 matrixY = 0;
+ for (FX_INT32 y = 0; y < symbolHeight; y++) {
+ FX_INT32 matrixX;
+ if ((y % symbolInfo->m_matrixHeight) == 0) {
+ matrixX = 0;
+ for (FX_INT32 x = 0; x < symbolInfo->getSymbolWidth(e); x++) {
+ matrix->Set(matrixX, matrixY, (x % 2) == 0);
+ matrixX++;
+ }
+ matrixY++;
+ }
+ matrixX = 0;
+ for (FX_INT32 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 (FX_INT32 x = 0; x < symbolInfo->getSymbolWidth(e); x++) {
+ matrix->Set(matrixX, matrixY, TRUE);
+ matrixX++;
+ }
+ matrixY++;
+ }
+ }
+ return matrix;
+}
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixWriter.h b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixWriter.h new file mode 100644 index 0000000000..c8a6bdd823 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixWriter.h @@ -0,0 +1,30 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_DATAMATRIXWRITER_H_
+#define _BC_DATAMATRIXWRITER_H_
+class CBC_CommonByteMatrix;
+class CBC_CommonBitMatrix;
+class CBC_DefaultPlacement;
+class CBC_SymbolShapeHint;
+class CBC_SymbolInfo;
+class CBC_TwoDimWriter;
+class CBC_DataMatrixWriter;
+class CBC_DataMatrixWriter : public CBC_TwoDimWriter
+{
+public:
+ CBC_DataMatrixWriter();
+ virtual ~CBC_DataMatrixWriter();
+ FX_BYTE* Encode(const CFX_WideString &contents, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 &e);
+ FX_BYTE * Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 &e);
+ FX_BYTE * Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 hints, FX_INT32 &e);
+ FX_BOOL SetErrorCorrectionLevel (FX_INT32 level);
+
+private:
+ static CBC_CommonByteMatrix* encodeLowLevel(CBC_DefaultPlacement* placement, CBC_SymbolInfo* symbolInfo, FX_INT32 &e);
+ FX_INT32 m_iCorrectLevel;
+};
+#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DefaultPlacement.cpp b/xfa/src/fxbarcode/datamatrix/BC_DefaultPlacement.cpp new file mode 100644 index 0000000000..e6bab5a65e --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_DefaultPlacement.cpp @@ -0,0 +1,174 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2006 Jeremias Maerki.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../barcode.h"
+#include "BC_Encoder.h"
+#include "BC_DefaultPlacement.h"
+CBC_DefaultPlacement::CBC_DefaultPlacement(CFX_WideString codewords, FX_INT32 numcols, FX_INT32 numrows)
+{
+ m_codewords = codewords;
+ m_numcols = numcols;
+ m_numrows = numrows;
+ m_bits.SetSize(numcols * numrows);
+ for (FX_INT32 i = 0; i < numcols * numrows; i++) {
+ m_bits[i] = (FX_BYTE) 2;
+ }
+}
+CBC_DefaultPlacement::~CBC_DefaultPlacement()
+{
+ m_bits.RemoveAll();
+}
+FX_INT32 CBC_DefaultPlacement::getNumrows()
+{
+ return m_numrows;
+}
+FX_INT32 CBC_DefaultPlacement::getNumcols()
+{
+ return m_numcols;
+}
+CFX_ByteArray& CBC_DefaultPlacement::getBits()
+{
+ return m_bits;
+}
+FX_BOOL CBC_DefaultPlacement::getBit(FX_INT32 col, FX_INT32 row)
+{
+ return m_bits[row * m_numcols + col] == 1;
+}
+void CBC_DefaultPlacement::setBit(FX_INT32 col, FX_INT32 row, FX_BOOL bit)
+{
+ m_bits[row * m_numcols + col] = bit ? (FX_BYTE) 1 : (FX_BYTE) 0;
+}
+FX_BOOL CBC_DefaultPlacement::hasBit(FX_INT32 col, FX_INT32 row)
+{
+ return m_bits[row * m_numcols + col] != 2;
+}
+void CBC_DefaultPlacement::place()
+{
+ FX_INT32 pos = 0;
+ FX_INT32 row = 4;
+ FX_INT32 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::module(FX_INT32 row, FX_INT32 col, FX_INT32 pos, FX_INT32 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);
+ }
+ FX_INT32 v = m_codewords.GetAt(pos);
+ v &= 1 << (8 - bit);
+ setBit(col, row, v != 0);
+}
+void CBC_DefaultPlacement::utah(FX_INT32 row, FX_INT32 col, FX_INT32 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(FX_INT32 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(FX_INT32 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(FX_INT32 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(FX_INT32 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 new file mode 100644 index 0000000000..ba2da03408 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_DefaultPlacement.h @@ -0,0 +1,35 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_DEFAULTPLACEMENT_H_
+#define _BC_DEFAULTPLACEMENT_H_
+class CBC_DefaultPlacement;
+class CBC_DefaultPlacement : public CFX_Object
+{
+public:
+ CBC_DefaultPlacement(CFX_WideString codewords, FX_INT32 numcols, FX_INT32 numrows);
+ virtual ~CBC_DefaultPlacement();
+
+ FX_INT32 getNumrows();
+ FX_INT32 getNumcols();
+ CFX_ByteArray& getBits();
+ FX_BOOL getBit(FX_INT32 col, FX_INT32 row);
+ void setBit(FX_INT32 col, FX_INT32 row, FX_BOOL bit);
+ FX_BOOL hasBit(FX_INT32 col, FX_INT32 row);
+ void place();
+private:
+ CFX_WideString m_codewords;
+ FX_INT32 m_numrows;
+ FX_INT32 m_numcols;
+ CFX_ByteArray m_bits;
+ void module(FX_INT32 row, FX_INT32 col, FX_INT32 pos, FX_INT32 bit);
+ void utah(FX_INT32 row, FX_INT32 col, FX_INT32 pos);
+ void corner1(FX_INT32 pos);
+ void corner2(FX_INT32 pos);
+ void corner3(FX_INT32 pos);
+ void corner4(FX_INT32 pos);
+};
+#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_EdifactEncoder.cpp b/xfa/src/fxbarcode/datamatrix/BC_EdifactEncoder.cpp new file mode 100644 index 0000000000..d1e84af73e --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_EdifactEncoder.cpp @@ -0,0 +1,153 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2006-2007 Jeremias Maerki.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../barcode.h"
+#include "../common/BC_CommonBitMatrix.h"
+#include "../BC_Dimension.h"
+#include "BC_Encoder.h"
+#include "BC_SymbolShapeHint.h"
+#include "BC_SymbolInfo.h"
+#include "BC_EncoderContext.h"
+#include "BC_HighLevelEncoder.h"
+#include "BC_EdifactEncoder.h"
+CBC_EdifactEncoder::CBC_EdifactEncoder()
+{
+}
+CBC_EdifactEncoder::~CBC_EdifactEncoder()
+{
+}
+FX_INT32 CBC_EdifactEncoder::getEncodingMode()
+{
+ return EDIFACT_ENCODATION;
+}
+void CBC_EdifactEncoder::Encode(CBC_EncoderContext &context, FX_INT32 &e)
+{
+ CFX_WideString buffer;
+ while (context.hasMoreCharacters()) {
+ FX_WCHAR c = context.getCurrentChar();
+ encodeChar(c, buffer, e);
+ if (e != BCExceptionNO) {
+ return;
+ }
+ context.m_pos++;
+ FX_INT32 count = buffer.GetLength();
+ if (count >= 4) {
+ context.writeCodewords(encodeToCodewords(buffer, 0, e));
+ if (e != BCExceptionNO) {
+ return;
+ }
+ buffer.Delete(0, 4);
+ FX_INT32 newMode = CBC_HighLevelEncoder::lookAheadTest(context.m_msg, context.m_pos, getEncodingMode());
+ if (newMode != getEncodingMode()) {
+ context.signalEncoderChange(ASCII_ENCODATION);
+ break;
+ }
+ }
+ }
+ buffer += (FX_WCHAR)31;
+ handleEOD(context, buffer, e);
+}
+void CBC_EdifactEncoder::handleEOD(CBC_EncoderContext &context, CFX_WideString buffer, FX_INT32 &e)
+{
+ FX_INT32 count = buffer.GetLength();
+ if (count == 0) {
+ return;
+ }
+ if (count == 1) {
+ context.updateSymbolInfo(e);
+ if (e != BCExceptionNO) {
+ return;
+ }
+ FX_INT32 available = context.m_symbolInfo->m_dataCapacity - context.getCodewordCount();
+ FX_INT32 remaining = context.getRemainingCharacters();
+ if (remaining == 0 && available <= 2) {
+ return;
+ }
+ }
+ if (count > 4) {
+ e = BCExceptionIllegalStateCountMustNotExceed4;
+ return;
+ }
+ FX_INT32 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_INT32 available = context.m_symbolInfo->m_dataCapacity - context.getCodewordCount();
+ if (available >= 3) {
+ restInAscii = FALSE;
+ context.updateSymbolInfo(context.getCodewordCount() + encoded.GetLength(), e);
+ if (e != BCExceptionNO) {
+ return;
+ }
+ }
+ }
+ 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, FX_INT32 &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, FX_INT32 startPos, FX_INT32 &e)
+{
+ FX_INT32 len = sb.GetLength() - startPos;
+ if (len == 0) {
+ e = BCExceptionNoContents;
+ return (FX_LPWSTR)"";
+ }
+ 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;
+ FX_INT32 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 new file mode 100644 index 0000000000..7e2453a71d --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_EdifactEncoder.h @@ -0,0 +1,23 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_EDIFACTENCODER_H_
+#define _BC_EDIFACTENCODER_H_
+class CBC_EncoderContext;
+class CBC_EdifactEncoder;
+class CBC_EdifactEncoder : public CBC_Encoder
+{
+public:
+ CBC_EdifactEncoder();
+ virtual ~CBC_EdifactEncoder();
+ FX_INT32 getEncodingMode();
+ void Encode(CBC_EncoderContext &context, FX_INT32 &e);
+private:
+ static void handleEOD(CBC_EncoderContext &context, CFX_WideString buffer, FX_INT32 &e);
+ static void encodeChar(FX_WCHAR c, CFX_WideString &sb, FX_INT32 &e);
+ static CFX_WideString encodeToCodewords(CFX_WideString sb, FX_INT32 startPos, FX_INT32 &e);
+};
+#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_Encoder.cpp b/xfa/src/fxbarcode/datamatrix/BC_Encoder.cpp new file mode 100644 index 0000000000..acae555afe --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_Encoder.cpp @@ -0,0 +1,14 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../barcode.h"
+#include "BC_Encoder.h"
+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 new file mode 100644 index 0000000000..10ac8763e5 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_Encoder.h @@ -0,0 +1,19 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_ENCODER_H_
+#define _BC_ENCODER_H_
+class CBC_EncoderContext;
+class CBC_Encoder;
+class CBC_Encoder : public CFX_Object
+{
+public:
+ CBC_Encoder();
+ virtual ~CBC_Encoder();
+ virtual FX_INT32 getEncodingMode() = 0;
+ virtual void Encode(CBC_EncoderContext &context, FX_INT32 &e) = 0;
+};
+#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_EncoderContext.cpp b/xfa/src/fxbarcode/datamatrix/BC_EncoderContext.cpp new file mode 100644 index 0000000000..f65c9f29bc --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_EncoderContext.cpp @@ -0,0 +1,127 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2006-2007 Jeremias Maerki.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../barcode.h"
+#include "../BC_Dimension.h"
+#include "../BC_UtilCodingConvert.h"
+#include "../common/BC_CommonBitMatrix.h"
+#include "BC_Encoder.h"
+#include "BC_SymbolShapeHint.h"
+#include "BC_SymbolInfo.h"
+#include "BC_EncoderContext.h"
+CBC_EncoderContext::CBC_EncoderContext(const CFX_WideString msg, CFX_WideString ecLevel, FX_INT32 &e)
+{
+ CFX_ByteString dststr;
+ CBC_UtilCodingConvert::UnicodeToUTF8(msg, dststr);
+ CFX_WideString sb;
+ FX_INT32 c = dststr.GetLength();
+ for (FX_INT32 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(FX_INT32 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;
+}
+FX_INT32 CBC_EncoderContext::getCodewordCount()
+{
+ return m_codewords.GetLength();
+}
+void CBC_EncoderContext::signalEncoderChange(FX_INT32 encoding)
+{
+ m_newEncoding = encoding;
+}
+void CBC_EncoderContext::resetEncoderSignal()
+{
+ m_newEncoding = -1;
+}
+FX_BOOL CBC_EncoderContext::hasMoreCharacters()
+{
+ return m_pos < getTotalMessageCharCount();
+}
+FX_INT32 CBC_EncoderContext::getRemainingCharacters()
+{
+ return getTotalMessageCharCount() - m_pos;
+}
+void CBC_EncoderContext::updateSymbolInfo(FX_INT32 &e)
+{
+ updateSymbolInfo(getCodewordCount(), e);
+}
+void CBC_EncoderContext::updateSymbolInfo(FX_INT32 len, FX_INT32 &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;
+}
+FX_INT32 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 new file mode 100644 index 0000000000..0099dbc9f0 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_EncoderContext.h @@ -0,0 +1,48 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_ENCODERCONTEXT_H_
+#define _BC_ENCODERCONTEXT_H_
+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, FX_INT32 &e);
+ virtual ~CBC_EncoderContext();
+ void setSymbolShape(SymbolShapeHint shape);
+ void setSizeConstraints(CBC_Dimension* minSize, CBC_Dimension* maxSize);
+ CFX_WideString getMessage();
+ void setSkipAtEnd(FX_INT32 count);
+ FX_WCHAR getCurrentChar();
+ FX_WCHAR getCurrent();
+ void writeCodewords(CFX_WideString codewords);
+ void writeCodeword(FX_WCHAR codeword);
+ FX_INT32 getCodewordCount();
+ void signalEncoderChange(FX_INT32 encoding);
+ void resetEncoderSignal();
+ FX_BOOL hasMoreCharacters();
+ FX_INT32 getRemainingCharacters();
+ void updateSymbolInfo(FX_INT32 &e);
+ void updateSymbolInfo(FX_INT32 len, FX_INT32 &e);
+ void resetSymbolInfo();
+public:
+ CFX_WideString m_msg;
+ CFX_WideString m_codewords;
+ FX_INT32 m_pos;
+ FX_INT32 m_newEncoding;
+ CBC_SymbolInfo* m_symbolInfo;
+private:
+ FX_INT32 getTotalMessageCharCount();
+private:
+ SymbolShapeHint m_shape;
+ CBC_Dimension* m_minSize;
+ CBC_Dimension* m_maxSize;
+ FX_INT32 m_skipAtEnd;
+};
+#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_ErrorCorrection.cpp b/xfa/src/fxbarcode/datamatrix/BC_ErrorCorrection.cpp new file mode 100644 index 0000000000..f346072499 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_ErrorCorrection.cpp @@ -0,0 +1,194 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2006 Jeremias Maerki.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../barcode.h"
+#include "BC_Encoder.h"
+#include "BC_SymbolShapeHint.h"
+#include "BC_SymbolInfo.h"
+#include "BC_ErrorCorrection.h"
+FX_INT32 CBC_ErrorCorrection::FACTOR_SETS[] = {5, 7, 10, 11, 12, 14, 18, 20, 24, 28, 36, 42, 48, 56, 62, 68};
+FX_INT32 CBC_ErrorCorrection::FACTORS[][100] = {
+ {228, 48, 15, 111, 62},
+ {23, 68, 144, 134, 240, 92, 254},
+ {28, 24, 185, 166, 223, 248, 116, 255, 110, 61},
+ {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
+ }
+};
+FX_INT32 CBC_ErrorCorrection::MODULO_VALUE = 0x12D;
+FX_INT32 CBC_ErrorCorrection::LOG[256] = {0};
+FX_INT32 CBC_ErrorCorrection::ALOG[256] = {0};
+void CBC_ErrorCorrection::Initialize()
+{
+ FX_INT32 p = 1;
+ for (FX_INT32 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, FX_INT32 &e)
+{
+ if (codewords.GetLength() != symbolInfo->m_dataCapacity) {
+ e = BCExceptionIllegalArgument;
+ return (FX_LPWSTR)"";
+ }
+ CFX_WideString sb;
+ sb += codewords;
+ FX_INT32 blockCount = symbolInfo->getInterleavedBlockCount();
+ if (blockCount == 1) {
+ CFX_WideString ecc = createECCBlock(codewords, symbolInfo->m_errorCodewords, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, (FX_LPWSTR)"");
+ sb += ecc;
+ } else {
+ CFX_Int32Array dataSizes;
+ dataSizes.SetSize(blockCount);
+ CFX_Int32Array errorSizes;
+ errorSizes.SetSize(blockCount);
+ CFX_Int32Array startPos;
+ startPos.SetSize(blockCount);
+ for (FX_INT32 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 (FX_INT32 block = 0; block < blockCount; block++) {
+ CFX_WideString temp;
+ for (FX_INT32 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_LPWSTR)"");
+ FX_INT32 pos = 0;
+ for (FX_INT32 l = block; l < errorSizes[block] * blockCount; l += blockCount) {
+ sb.SetAt(symbolInfo->m_dataCapacity + l, ecc.GetAt(pos++));
+ }
+ }
+ }
+ return sb;
+}
+CFX_WideString CBC_ErrorCorrection::createECCBlock(CFX_WideString codewords, FX_INT32 numECWords, FX_INT32 &e)
+{
+ return createECCBlock(codewords, 0, codewords.GetLength(), numECWords, e);
+}
+CFX_WideString CBC_ErrorCorrection::createECCBlock(CFX_WideString codewords, FX_INT32 start, FX_INT32 len, FX_INT32 numECWords, FX_INT32 &e)
+{
+ FX_INT32 table = -1;
+ for (FX_INT32 i = 0; i < sizeof(FACTOR_SETS) / sizeof(FX_INT32); i++) {
+ if (FACTOR_SETS[i] == numECWords) {
+ table = i;
+ break;
+ }
+ }
+ if (table < 0) {
+ e = BCExceptionIllegalArgument;
+ return (FX_LPWSTR)"";
+ }
+ FX_WORD* ecc = FX_Alloc(FX_WORD, numECWords);
+ FXSYS_memset32(ecc, 0, numECWords * sizeof(FX_WORD));
+ for (FX_INT32 l = start; l < start + len; l++) {
+ FX_BYTE A = (FX_BYTE)codewords.GetAt(l);
+ FX_WORD B = ecc[numECWords - 1];
+ FX_WORD m = ecc[numECWords - 1] ^ codewords.GetAt(l);
+ for (FX_INT32 k = numECWords - 1; k > 0; k--) {
+ if (m != 0 && FACTORS[table][k] != 0) {
+ FX_INT32 a = LOG[FACTORS[table][k]];
+ FX_INT32 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;
+ }
+ }
+ CFX_WideString strecc;
+ for (FX_INT32 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 new file mode 100644 index 0000000000..973ff33b8e --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_ErrorCorrection.h @@ -0,0 +1,29 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_ERRORCORRECTION_H_
+#define _BC_ERRORCORRECTION_H_
+class CBC_SymbolInfo;
+class CBC_ErrorCorrection;
+class CBC_ErrorCorrection : public CFX_Object
+{
+public:
+ CBC_ErrorCorrection();
+ virtual ~CBC_ErrorCorrection();
+ static void Initialize();
+ static void Finalize();
+ static CFX_WideString encodeECC200(CFX_WideString codewords, CBC_SymbolInfo* symbolInfo, FX_INT32 &e);
+private:
+ static FX_INT32 FACTOR_SETS[];
+ static FX_INT32 FACTORS[][100];
+ static FX_INT32 MODULO_VALUE;
+ static FX_INT32 LOG[256];
+ static FX_INT32 ALOG[256];
+private:
+ static CFX_WideString createECCBlock(CFX_WideString codewords, FX_INT32 numECWords, FX_INT32 &e);
+ static CFX_WideString createECCBlock(CFX_WideString codewords, FX_INT32 start, FX_INT32 len, FX_INT32 numECWords, FX_INT32 &e);
+};
+#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp b/xfa/src/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp new file mode 100644 index 0000000000..5b46612d62 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp @@ -0,0 +1,368 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2006-2007 Jeremias Maerki.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../barcode.h"
+#include "../BC_Dimension.h"
+#include "../BC_UtilCodingConvert.h"
+#include "../common/BC_CommonBitMatrix.h"
+#include "BC_Encoder.h"
+#include "BC_SymbolShapeHint.h"
+#include "BC_SymbolInfo.h"
+#include "BC_EncoderContext.h"
+#include "BC_C40Encoder.h"
+#include "BC_TextEncoder.h"
+#include "BC_X12Encoder.h"
+#include "BC_EdifactEncoder.h"
+#include "BC_Base256Encoder.h"
+#include "BC_ASCIIEncoder.h"
+#include "BC_HighLevelEncoder.h"
+#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;
+FX_WCHAR CBC_HighLevelEncoder::LATCH_TO_ANSIX12 = 238;
+FX_WCHAR CBC_HighLevelEncoder::LATCH_TO_TEXT = 239;
+FX_WCHAR CBC_HighLevelEncoder::LATCH_TO_EDIFACT = 240;
+FX_WCHAR CBC_HighLevelEncoder::C40_UNLATCH = 254;
+FX_WCHAR CBC_HighLevelEncoder::X12_UNLATCH = 254;
+FX_WCHAR CBC_HighLevelEncoder::PAD = 129;
+FX_WCHAR CBC_HighLevelEncoder::MACRO_05 = 236;
+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()
+{
+}
+CFX_ByteArray& CBC_HighLevelEncoder::getBytesForMessage(CFX_WideString msg)
+{
+ CFX_ByteString bytestr;
+ CBC_UtilCodingConvert::UnicodeToUTF8(msg, bytestr);
+ for (FX_INT32 i = 0; i < bytestr.GetLength(); i++) {
+ m_bytearray.Add(bytestr.GetAt(i));
+ }
+ return m_bytearray;
+}
+CFX_WideString CBC_HighLevelEncoder::encodeHighLevel(CFX_WideString msg, CFX_WideString ecLevel, FX_INT32 &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, FX_INT32 &e)
+{
+ CBC_EncoderContext context(msg, ecLevel, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, (FX_LPWSTR)"");
+ 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());
+ FX_INT32 encodingMode = ASCII_ENCODATION;
+ while (context.hasMoreCharacters()) {
+ ((CBC_Encoder*)encoders.GetAt(encodingMode))->Encode(context, e);
+ if (e != BCExceptionNO) {
+ for (FX_INT32 i = 0; i < encoders.GetSize(); i++) {
+ delete (CBC_Encoder*)encoders.GetAt(i);
+ }
+ encoders.RemoveAll();
+ return (FX_LPWSTR)"";
+ }
+ if (context.m_newEncoding >= 0) {
+ encodingMode = context.m_newEncoding;
+ context.resetEncoderSignal();
+ }
+ }
+ FX_INT32 len = context.m_codewords.GetLength();
+ context.updateSymbolInfo(e);
+ if (e != BCExceptionNO) {
+ for (FX_INT32 i = 0; i < encoders.GetSize(); i++) {
+ delete (CBC_Encoder*)encoders.GetAt(i);
+ }
+ encoders.RemoveAll();
+ return (FX_LPWSTR)"";
+ }
+ FX_INT32 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 (FX_INT32 i = 0; i < encoders.GetSize(); i++) {
+ delete (CBC_Encoder*)encoders.GetAt(i);
+ }
+ encoders.RemoveAll();
+ return codewords;
+}
+FX_INT32 CBC_HighLevelEncoder::lookAheadTest(CFX_WideString msg, FX_INT32 startpos, FX_INT32 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;
+ }
+ FX_INT32 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);
+ FX_INT32 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 (charsProcessed >= 4) {
+ CFX_Int32Array intCharCounts;
+ intCharCounts.SetSize(6);
+ CFX_ByteArray mins;
+ mins.SetSize(6);
+ findMinimums(charCounts, intCharCounts, Integer_MAX_VALUE, mins);
+ FX_INT32 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 (intCharCounts[C40_ENCODATION] == intCharCounts[X12_ENCODATION]) {
+ FX_INT32 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;
+ }
+ }
+ }
+ }
+}
+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_INT32 CBC_HighLevelEncoder::determineConsecutiveDigitCount(CFX_WideString msg, FX_INT32 startpos)
+{
+ FX_INT32 count = 0;
+ FX_INT32 len = msg.GetLength();
+ FX_INT32 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;
+}
+void CBC_HighLevelEncoder::illegalCharacter(FX_WCHAR c, FX_INT32 &e)
+{
+ e = BCExceptionIllegalArgument;
+}
+FX_WCHAR CBC_HighLevelEncoder::randomize253State(FX_WCHAR ch, FX_INT32 codewordPosition)
+{
+ FX_INT32 pseudoRandom = ((149 * codewordPosition) % 253) + 1;
+ FX_INT32 tempVariable = ch + pseudoRandom;
+ return tempVariable <= 254 ? (FX_WCHAR) tempVariable : (FX_WCHAR) (tempVariable - 254);
+}
+FX_INT32 CBC_HighLevelEncoder::findMinimums(CFX_FloatArray &charCounts, CFX_Int32Array &intCharCounts, FX_INT32 min, CFX_ByteArray &mins)
+{
+ for (FX_INT32 l = 0; l < mins.GetSize(); l++) {
+ mins[l] = (FX_BYTE)0;
+ }
+ for (FX_INT32 i = 0; i < 6; i++) {
+ intCharCounts[i] = (FX_INT32)ceil(charCounts[i]);
+ FX_INT32 current = intCharCounts[i];
+ if (min > current) {
+ min = current;
+ for (FX_INT32 j = 0; j < mins.GetSize(); j++) {
+ mins[j] = (FX_BYTE)0;
+ }
+ }
+ if (min == current) {
+ mins[i]++;
+ }
+ }
+ return min;
+}
+FX_INT32 CBC_HighLevelEncoder::getMinimumCount(CFX_ByteArray &mins)
+{
+ FX_INT32 minCount = 0;
+ for (FX_INT32 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::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::isX12TermSep(FX_WCHAR ch)
+{
+ return (ch == '\r') || (ch == '*') || (ch == '>');
+}
+FX_BOOL CBC_HighLevelEncoder::isNativeEDIFACT(FX_WCHAR ch)
+{
+ return ch >= ' ' && ch <= '^';
+}
+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 new file mode 100644 index 0000000000..170ca9f8fa --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_HighLevelEncoder.h @@ -0,0 +1,60 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_HIGHLEVALENCODER_H_
+#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, FX_INT32 &e);
+ static CFX_WideString encodeHighLevel(CFX_WideString msg, CFX_WideString ecLevel, SymbolShapeHint shape, CBC_Dimension* minSize, CBC_Dimension* maxSize, FX_INT32 &e);
+ static FX_INT32 lookAheadTest(CFX_WideString msg, FX_INT32 startpos, FX_INT32 currentMode);
+ static FX_BOOL isDigit(FX_WCHAR ch);
+ static FX_BOOL isExtendedASCII(FX_WCHAR ch);
+ static FX_INT32 determineConsecutiveDigitCount(CFX_WideString msg, FX_INT32 startpos);
+ static void illegalCharacter(FX_WCHAR c, FX_INT32 &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, FX_INT32 codewordPosition);
+ static FX_INT32 findMinimums(CFX_FloatArray &charCounts, CFX_Int32Array &intCharCounts, FX_INT32 min, CFX_ByteArray &mins);
+ static FX_INT32 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 new file mode 100644 index 0000000000..415cbd6b3c --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_SymbolInfo.cpp @@ -0,0 +1,242 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2006 Jeremias Maerki
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../barcode.h"
+#include "../BC_Dimension.h"
+#include "../common/BC_CommonBitMatrix.h"
+#include "BC_Encoder.h"
+#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 (FX_INT32 i = 0; i < SYMBOLS_COUNT; i++) {
+ m_symbols[i] = m_PROD_SYMBOLS[i];
+ }
+}
+void CBC_SymbolInfo::Finalize()
+{
+ for (FX_INT32 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, FX_INT32 dataCapacity, FX_INT32 errorCodewords, FX_INT32 matrixWidth, FX_INT32 matrixHeight, FX_INT32 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, FX_INT32 dataCapacity, FX_INT32 errorCodewords, FX_INT32 matrixWidth, FX_INT32 matrixHeight, FX_INT32 dataRegions,
+ FX_INT32 rsBlockData, FX_INT32 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(FX_INT32 dataCodewords, FX_INT32 &e)
+{
+ return lookup(dataCodewords, FORCE_NONE, TRUE, e);
+}
+CBC_SymbolInfo* CBC_SymbolInfo::lookup(FX_INT32 dataCodewords, SymbolShapeHint shape, FX_INT32 &e)
+{
+ return lookup(dataCodewords, shape, TRUE, e);
+}
+CBC_SymbolInfo* CBC_SymbolInfo::lookup(FX_INT32 dataCodewords, FX_BOOL allowRectangular, FX_BOOL fail, FX_INT32 &e)
+{
+ SymbolShapeHint shape = allowRectangular ? FORCE_NONE : FORCE_SQUARE;
+ return lookup(dataCodewords, shape, fail, e);
+}
+CBC_SymbolInfo* CBC_SymbolInfo::lookup(FX_INT32 dataCodewords, SymbolShapeHint shape, FX_BOOL fail, FX_INT32 &e)
+{
+ return lookup(dataCodewords, shape, NULL, NULL, fail, e);
+}
+CBC_SymbolInfo* CBC_SymbolInfo::lookup(FX_INT32 dataCodewords, SymbolShapeHint shape, CBC_Dimension* minSize, CBC_Dimension* maxSize, FX_BOOL fail, FX_INT32 &e)
+{
+ for (FX_INT32 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;
+ }
+ }
+ if (fail) {
+ e = BCExceptionIllegalDataCodewords;
+ return NULL;
+ }
+ return NULL;
+}
+FX_INT32 CBC_SymbolInfo::getHorizontalDataRegions(FX_INT32 &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;
+ }
+}
+FX_INT32 CBC_SymbolInfo::getVerticalDataRegions(FX_INT32 &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;
+ }
+}
+FX_INT32 CBC_SymbolInfo::getSymbolDataWidth(FX_INT32 &e)
+{
+ return getHorizontalDataRegions(e) * m_matrixWidth;
+}
+FX_INT32 CBC_SymbolInfo::getSymbolDataHeight(FX_INT32 &e)
+{
+ return getVerticalDataRegions(e) * m_matrixHeight;
+}
+FX_INT32 CBC_SymbolInfo::getSymbolWidth(FX_INT32 &e)
+{
+ return getSymbolDataWidth(e) + (getHorizontalDataRegions(e) * 2);
+}
+FX_INT32 CBC_SymbolInfo::getSymbolHeight(FX_INT32 &e)
+{
+ return getSymbolDataHeight(e) + (getVerticalDataRegions(e) * 2);
+}
+FX_INT32 CBC_SymbolInfo::getCodewordCount()
+{
+ return m_dataCapacity + m_errorCodewords;
+}
+FX_INT32 CBC_SymbolInfo::getInterleavedBlockCount()
+{
+ return m_dataCapacity / m_rsBlockData;
+}
+FX_INT32 CBC_SymbolInfo::getDataLengthForInterleavedBlock(FX_INT32 index)
+{
+ return m_rsBlockData;
+}
+FX_INT32 CBC_SymbolInfo::getErrorLengthForInterleavedBlock(FX_INT32 index)
+{
+ return m_rsBlockError;
+}
+CFX_WideString CBC_SymbolInfo::toString(FX_INT32 &e)
+{
+ CFX_WideString sb;
+ sb += (FX_LPWSTR)(m_rectangular ? "Rectangular Symbol:" : "Square Symbol:");
+ sb += (FX_LPWSTR)" data region ";
+ sb += m_matrixWidth;
+ sb += (FX_WCHAR)'x';
+ sb += m_matrixHeight;
+ sb += (FX_LPWSTR)", symbol size ";
+ sb += getSymbolWidth(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, (FX_LPWSTR)"");
+ sb += (FX_WCHAR)'x';
+ sb += getSymbolHeight(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, (FX_LPWSTR)"");
+ sb += (FX_LPWSTR)", symbol data size ";
+ sb += getSymbolDataWidth(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, (FX_LPWSTR)"");
+ sb += (FX_WCHAR)'x';
+ sb += getSymbolDataHeight(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, (FX_LPWSTR)"");
+ sb += (FX_LPWSTR)", 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 new file mode 100644 index 0000000000..0450a28725 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_SymbolInfo.h @@ -0,0 +1,53 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_SYMBOLINFO_H_
+#define _BC_SYMBOLINFO_H_
+class CBC_SymbolShapeHint;
+class CBC_Dimension;
+class CBC_SymbolInfo;
+class CBC_SymbolInfo : public CBC_SymbolShapeHint
+{
+public:
+ CBC_SymbolInfo(FX_BOOL rectangular, FX_INT32 dataCapacity, FX_INT32 errorCodewords,
+ FX_INT32 matrixWidth, FX_INT32 matrixHeight, FX_INT32 dataRegions);
+ virtual ~CBC_SymbolInfo();
+ static void Initialize();
+ static void Finalize();
+ static void overrideSymbolSet(CBC_SymbolInfo* override);
+ static CBC_SymbolInfo* lookup(FX_INT32 dataCodewords, FX_INT32 &e);
+ static CBC_SymbolInfo* lookup(FX_INT32 dataCodewords, SymbolShapeHint shape, FX_INT32 &e);
+ static CBC_SymbolInfo* lookup(FX_INT32 dataCodewords, FX_BOOL allowRectangular, FX_BOOL fail, FX_INT32 &e);
+ static CBC_SymbolInfo* lookup(FX_INT32 dataCodewords, SymbolShapeHint shape, FX_BOOL fail, FX_INT32 &e);
+ static CBC_SymbolInfo* lookup(FX_INT32 dataCodewords, SymbolShapeHint shape, CBC_Dimension* minSize, CBC_Dimension* maxSize, FX_BOOL fail, FX_INT32 &e);
+ FX_INT32 getHorizontalDataRegions(FX_INT32 &e);
+ FX_INT32 getVerticalDataRegions(FX_INT32 &e);
+ FX_INT32 getSymbolDataWidth(FX_INT32 &e);
+ FX_INT32 getSymbolDataHeight(FX_INT32 &e);
+ FX_INT32 getSymbolWidth(FX_INT32 &e);
+ FX_INT32 getSymbolHeight(FX_INT32 &e);
+ FX_INT32 getCodewordCount();
+ FX_INT32 getInterleavedBlockCount();
+ FX_INT32 getDataLengthForInterleavedBlock(FX_INT32 index);
+ FX_INT32 getErrorLengthForInterleavedBlock(FX_INT32 index);
+ CFX_WideString toString(FX_INT32 &e);
+public:
+ FX_INT32 m_dataCapacity;
+ FX_INT32 m_errorCodewords;
+ FX_INT32 m_matrixWidth;
+ FX_INT32 m_matrixHeight;
+ FX_INT32 m_rsBlockData;
+ FX_INT32 m_rsBlockError;
+ static CBC_SymbolInfo* m_PROD_SYMBOLS[30];
+private:
+ static CBC_SymbolInfo* m_symbols[30];
+ FX_BOOL m_rectangular;
+ FX_INT32 m_dataRegions;
+private:
+ CBC_SymbolInfo(FX_BOOL rectangular, FX_INT32 dataCapacity, FX_INT32 errorCodewords, FX_INT32 matrixWidth, FX_INT32 matrixHeight, FX_INT32 dataRegions,
+ FX_INT32 rsBlockData, FX_INT32 rsBlockError);
+};
+#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_SymbolShapeHint.cpp b/xfa/src/fxbarcode/datamatrix/BC_SymbolShapeHint.cpp new file mode 100644 index 0000000000..b7b477539c --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_SymbolShapeHint.cpp @@ -0,0 +1,30 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2007 Jeremias Maerki.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../barcode.h"
+#include "BC_SymbolShapeHint.h"
+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 new file mode 100644 index 0000000000..2b030012a3 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_SymbolShapeHint.h @@ -0,0 +1,21 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_SYMBOLSHAPEHINT_H_
+#define _BC_SYMBOLSHAPEHINT_H_
+class CBC_SymbolShapeHint;
+class CBC_SymbolShapeHint : public CFX_Object
+{
+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 new file mode 100644 index 0000000000..45abec4d4a --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_TextEncoder.cpp @@ -0,0 +1,102 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2006-2007 Jeremias Maerki.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../barcode.h"
+#include "../common/BC_CommonBitMatrix.h"
+#include "../BC_Dimension.h"
+#include "BC_Encoder.h"
+#include "BC_SymbolShapeHint.h"
+#include "BC_SymbolInfo.h"
+#include "BC_EncoderContext.h"
+#include "BC_HighLevelEncoder.h"
+#include "BC_C40Encoder.h"
+#include "BC_TextEncoder.h"
+CBC_TextEncoder::CBC_TextEncoder()
+{
+}
+CBC_TextEncoder::~CBC_TextEncoder()
+{
+}
+FX_INT32 CBC_TextEncoder::getEncodingMode()
+{
+ return TEXT_ENCODATION;
+}
+FX_INT32 CBC_TextEncoder::encodeChar(FX_WCHAR c, CFX_WideString &sb, FX_INT32 &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;
+ FX_INT32 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 new file mode 100644 index 0000000000..f1168679a6 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_TextEncoder.h @@ -0,0 +1,18 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_TEXTENCODER_H_
+#define _BC_TEXTENCODER_H_
+class CBC_TextEncoder;
+class CBC_TextEncoder : public CBC_C40Encoder
+{
+public:
+ CBC_TextEncoder();
+ virtual ~CBC_TextEncoder();
+ FX_INT32 getEncodingMode();
+ FX_INT32 encodeChar(FX_WCHAR c, CFX_WideString &sb, FX_INT32 &e);
+};
+#endif
diff --git a/xfa/src/fxbarcode/datamatrix/BC_X12Encoder.cpp b/xfa/src/fxbarcode/datamatrix/BC_X12Encoder.cpp new file mode 100644 index 0000000000..f6263f6777 --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_X12Encoder.cpp @@ -0,0 +1,104 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2006-2007 Jeremias Maerki.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../barcode.h"
+#include "../common/BC_CommonBitMatrix.h"
+#include "../BC_Dimension.h"
+#include "BC_Encoder.h"
+#include "BC_SymbolShapeHint.h"
+#include "BC_SymbolInfo.h"
+#include "BC_EncoderContext.h"
+#include "BC_HighLevelEncoder.h"
+#include "BC_C40Encoder.h"
+#include "BC_X12Encoder.h"
+CBC_X12Encoder::CBC_X12Encoder()
+{
+}
+CBC_X12Encoder::~CBC_X12Encoder()
+{
+}
+FX_INT32 CBC_X12Encoder::getEncodingMode()
+{
+ return X12_ENCODATION;
+}
+void CBC_X12Encoder::Encode(CBC_EncoderContext &context, FX_INT32 &e)
+{
+ CFX_WideString buffer;
+ while (context.hasMoreCharacters()) {
+ FX_WCHAR c = context.getCurrentChar();
+ context.m_pos++;
+ encodeChar(c, buffer, e);
+ if (e != BCExceptionNO) {
+ return;
+ }
+ FX_INT32 count = buffer.GetLength();
+ if ((count % 3) == 0) {
+ writeNextTriplet(context, buffer);
+ FX_INT32 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, FX_INT32 &e)
+{
+ context.updateSymbolInfo(e);
+ if (e != BCExceptionNO) {
+ return;
+ }
+ FX_INT32 available = context.m_symbolInfo->m_dataCapacity - context.getCodewordCount();
+ FX_INT32 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);
+ }
+}
+FX_INT32 CBC_X12Encoder::encodeChar(FX_WCHAR c, CFX_WideString &sb, FX_INT32 &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 new file mode 100644 index 0000000000..21111bc5cc --- /dev/null +++ b/xfa/src/fxbarcode/datamatrix/BC_X12Encoder.h @@ -0,0 +1,21 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_X12ENCODER_H_
+#define _BC_X12ENCODER_H_
+class CBC_C40Encoder;
+class CBC_X12Encoder;
+class CBC_X12Encoder : public CBC_C40Encoder
+{
+public:
+ CBC_X12Encoder();
+ virtual ~CBC_X12Encoder();
+ FX_INT32 getEncodingMode();
+ void Encode(CBC_EncoderContext &context, FX_INT32 &e);
+ void handleEOD(CBC_EncoderContext &context, CFX_WideString &buffer, FX_INT32 &e);
+ FX_INT32 encodeChar(FX_WCHAR c, CFX_WideString &sb, FX_INT32 &e);
+};
+#endif
|