summaryrefslogtreecommitdiff
path: root/xfa/src/fxbarcode/oned
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/src/fxbarcode/oned')
-rw-r--r--xfa/src/fxbarcode/oned/BC_OneDReader.cpp179
-rw-r--r--xfa/src/fxbarcode/oned/BC_OneDReader.h34
-rw-r--r--xfa/src/fxbarcode/oned/BC_OneDimReader.cpp235
-rw-r--r--xfa/src/fxbarcode/oned/BC_OneDimReader.h39
-rw-r--r--xfa/src/fxbarcode/oned/BC_OneDimWriter.cpp415
-rw-r--r--xfa/src/fxbarcode/oned/BC_OneDimWriter.h70
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.cpp206
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.h30
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedCodaBarWriter.cpp222
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedCodaBarWriter.h38
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedCode128Reader.cpp430
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedCode128Reader.h40
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedCode128Writer.cpp230
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedCode128Writer.h37
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedCode39Reader.cpp293
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedCode39Reader.h32
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedCode39Writer.cpp351
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedCode39Writer.h37
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedEAN13Reader.cpp94
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedEAN13Reader.h24
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedEAN13Writer.cpp294
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedEAN13Writer.h31
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedEAN8Reader.cpp81
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedEAN8Reader.h20
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedEAN8Writer.cpp261
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedEAN8Writer.h32
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedUPCAReader.cpp93
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedUPCAReader.h30
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedUPCAWriter.cpp285
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedUPCAWriter.h31
30 files changed, 4194 insertions, 0 deletions
diff --git a/xfa/src/fxbarcode/oned/BC_OneDReader.cpp b/xfa/src/fxbarcode/oned/BC_OneDReader.cpp
new file mode 100644
index 0000000000..1079c348d0
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OneDReader.cpp
@@ -0,0 +1,179 @@
+// 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_Reader.h"
+#include "../BC_BinaryBitmap.h"
+#include "../common/BC_CommonBitArray.h"
+#include "BC_OneDReader.h"
+const FX_INT32 CBC_OneDReader::INTEGER_MATH_SHIFT = 8;
+const FX_INT32 CBC_OneDReader::PATTERN_MATCH_RESULT_SCALE_FACTOR = 1 << 8;
+CBC_OneDReader::CBC_OneDReader()
+{
+}
+CBC_OneDReader::~CBC_OneDReader()
+{
+}
+CFX_ByteString CBC_OneDReader::Decode(CBC_BinaryBitmap *image, FX_INT32 &e)
+{
+ CFX_ByteString strtemp = Decode(image, 0, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ return strtemp;
+}
+CFX_ByteString CBC_OneDReader::Decode(CBC_BinaryBitmap *image, FX_INT32 hints, FX_INT32 &e)
+{
+ CFX_ByteString strtemp = DeDecode(image, hints, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ return strtemp;
+}
+CFX_ByteString CBC_OneDReader::DeDecode(CBC_BinaryBitmap *image, FX_INT32 hints, FX_INT32 &e)
+{
+ FX_INT32 width = image->GetWidth();
+ FX_INT32 height = image->GetHeight();
+ CBC_CommonBitArray *row = NULL;
+ FX_INT32 middle = height >> 1;
+ FX_BOOL tryHarder = FALSE;
+ FX_INT32 rowStep = FX_MAX(1, height >> (tryHarder ? 8 : 5));
+ FX_INT32 maxLines;
+ if (tryHarder) {
+ maxLines = height;
+ } else {
+ maxLines = 15;
+ }
+ for (FX_INT32 x = 0; x < maxLines; x++) {
+ FX_INT32 rowStepsAboveOrBelow = (x + 1) >> 1;
+ FX_BOOL isAbove = (x & 0x01) == 0;
+ FX_INT32 rowNumber = middle + rowStep * (isAbove ? rowStepsAboveOrBelow : -rowStepsAboveOrBelow);
+ if (rowNumber < 0 || rowNumber >= height) {
+ break;
+ }
+ row = image->GetBlackRow(rowNumber, NULL, e);
+ if (e != BCExceptionNO) {
+ e = BCExceptionNO;
+ if(row != NULL) {
+ delete row;
+ row = NULL;
+ }
+ continue;
+ }
+ for (FX_INT32 attempt = 0; attempt < 2; attempt++) {
+ if (attempt == 1) {
+ row->Reverse();
+ }
+ CFX_ByteString result = DecodeRow(rowNumber, row, hints, e);
+ if (e != BCExceptionNO) {
+ e = BCExceptionNO;
+ continue;
+ }
+ if(row != NULL) {
+ delete row;
+ row = NULL;
+ }
+ return result;
+ }
+ if(row != NULL) {
+ delete row;
+ row = NULL;
+ }
+ }
+ e = BCExceptionNotFound;
+ return "";
+}
+void CBC_OneDReader::RecordPattern(CBC_CommonBitArray *row, FX_INT32 start, CFX_Int32Array *counters, FX_INT32 &e)
+{
+ FX_INT32 numCounters = counters->GetSize();
+ for (FX_INT32 i = 0; i < numCounters; i++) {
+ (*counters)[i] = 0;
+ }
+ FX_INT32 end = row->GetSize();
+ if (start >= end) {
+ e = BCExceptionNotFound;
+ return;
+ }
+ FX_BOOL isWhite = !row->Get(start);
+ FX_INT32 counterPosition = 0;
+ FX_INT32 j = start;
+ while (j < end) {
+ FX_BOOL pixel = row->Get(j);
+ if (pixel ^ isWhite) {
+ (*counters)[counterPosition]++;
+ } else {
+ counterPosition++;
+ if (counterPosition == numCounters) {
+ break;
+ } else {
+ (*counters)[counterPosition] = 1;
+ isWhite = !isWhite;
+ }
+ }
+ j++;
+ }
+ if (!(counterPosition == numCounters || (counterPosition == numCounters - 1 && j == end))) {
+ e = BCExceptionNotFound;
+ return;
+ }
+}
+void CBC_OneDReader::RecordPatternInReverse(CBC_CommonBitArray *row, FX_INT32 start, CFX_Int32Array *counters, FX_INT32 &e)
+{
+ FX_INT32 numTransitionsLeft = counters->GetSize();
+ FX_BOOL last = row->Get(start);
+ while (start > 0 && numTransitionsLeft >= 0) {
+ if (row->Get(--start) != last) {
+ numTransitionsLeft--;
+ last = !last;
+ }
+ }
+ if (numTransitionsLeft >= 0) {
+ e = BCExceptionNotFound;
+ return;
+ }
+ RecordPattern(row, start + 1, counters, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+}
+FX_INT32 CBC_OneDReader::PatternMatchVariance(CFX_Int32Array *counters, const FX_INT32 *pattern, FX_INT32 maxIndividualVariance)
+{
+ FX_INT32 numCounters = counters->GetSize();
+ FX_INT32 total = 0;
+ FX_INT32 patternLength = 0;
+ for (FX_INT32 i = 0; i < numCounters; i++) {
+ total += (*counters)[i];
+ patternLength += pattern[i];
+ }
+ if (total < patternLength) {
+#undef max
+ return FXSYS_IntMax;
+ }
+ FX_INT32 unitBarWidth = (total << INTEGER_MATH_SHIFT) / patternLength;
+ maxIndividualVariance = (maxIndividualVariance * unitBarWidth) >> INTEGER_MATH_SHIFT;
+ FX_INT32 totalVariance = 0;
+ for (FX_INT32 x = 0; x < numCounters; x++) {
+ FX_INT32 counter = (*counters)[x] << INTEGER_MATH_SHIFT;
+ FX_INT32 scaledPattern = pattern[x] * unitBarWidth;
+ FX_INT32 variance = counter > scaledPattern ? counter - scaledPattern : scaledPattern - counter;
+ if (variance > maxIndividualVariance) {
+#undef max
+ return FXSYS_IntMax;
+ }
+ totalVariance += variance;
+ }
+ return totalVariance / total;
+}
diff --git a/xfa/src/fxbarcode/oned/BC_OneDReader.h b/xfa/src/fxbarcode/oned/BC_OneDReader.h
new file mode 100644
index 0000000000..8645c9edf9
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OneDReader.h
@@ -0,0 +1,34 @@
+// 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_ONEDREADER_H_
+#define _BC_ONEDREADER_H_
+class CBC_Reader;
+class CBC_BinaryBitmap;
+class CBC_CommonBitArray;
+class CBC_OneDReader;
+class CBC_OneDReader : public CBC_Reader
+{
+public:
+ CBC_OneDReader();
+ virtual ~CBC_OneDReader();
+ virtual CFX_ByteString Decode(CBC_BinaryBitmap *image, FX_INT32 &e);
+ virtual CFX_ByteString Decode(CBC_BinaryBitmap *image, FX_INT32 hints, FX_INT32 &e);
+ virtual CFX_ByteString DecodeRow(FX_INT32 rowNumber, CBC_CommonBitArray *row, FX_INT32 hints, FX_INT32 &e)
+ {
+ return "";
+ }
+private:
+ CFX_ByteString DeDecode(CBC_BinaryBitmap *image, FX_INT32 hints, FX_INT32 &e);
+
+protected:
+ const static FX_INT32 INTEGER_MATH_SHIFT;
+ const static FX_INT32 PATTERN_MATCH_RESULT_SCALE_FACTOR;
+ void RecordPattern(CBC_CommonBitArray *row, FX_INT32 start, CFX_Int32Array *counters, FX_INT32 &e);
+ void RecordPatternInReverse(CBC_CommonBitArray *row, FX_INT32 start, CFX_Int32Array *counters, FX_INT32 &e);
+ FX_INT32 PatternMatchVariance(CFX_Int32Array *counters, const FX_INT32 *pattern, FX_INT32 maxIndividualVariance);
+};
+#endif
diff --git a/xfa/src/fxbarcode/oned/BC_OneDimReader.cpp b/xfa/src/fxbarcode/oned/BC_OneDimReader.cpp
new file mode 100644
index 0000000000..f1db94a6a1
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OneDimReader.cpp
@@ -0,0 +1,235 @@
+// 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_Reader.h"
+#include "../common/BC_CommonBitArray.h"
+#include "BC_OneDReader.h"
+#include "BC_OneDimReader.h"
+const FX_INT32 CBC_OneDimReader::MAX_AVG_VARIANCE = (FX_INT32)(256 * 0.48f);
+const FX_INT32 CBC_OneDimReader::MAX_INDIVIDUAL_VARIANCE = (FX_INT32)(256 * 0.7f);
+const FX_INT32 CBC_OneDimReader::START_END_PATTERN[3] = {1, 1, 1};
+const FX_INT32 CBC_OneDimReader::MIDDLE_PATTERN[5] = {1, 1, 1, 1, 1};
+const FX_INT32 CBC_OneDimReader::L_PATTERNS[10][4] = {
+ {3, 2, 1, 1},
+ {2, 2, 2, 1},
+ {2, 1, 2, 2},
+ {1, 4, 1, 1},
+ {1, 1, 3, 2},
+ {1, 2, 3, 1},
+ {1, 1, 1, 4},
+ {1, 3, 1, 2},
+ {1, 2, 1, 3},
+ {3, 1, 1, 2}
+};
+const FX_INT32 CBC_OneDimReader::L_AND_G_PATTERNS[20][4] = {
+ {3, 2, 1, 1},
+ {2, 2, 2, 1},
+ {2, 1, 2, 2},
+ {1, 4, 1, 1},
+ {1, 1, 3, 2},
+ {1, 2, 3, 1},
+ {1, 1, 1, 4},
+ {1, 3, 1, 2},
+ {1, 2, 1, 3},
+ {3, 1, 1, 2},
+ {1, 1, 2, 3},
+ {1, 2, 2, 2},
+ {2, 2, 1, 2},
+ {1, 1, 4, 1},
+ {2, 3, 1, 1},
+ {1, 3, 2, 1},
+ {4, 1, 1, 1},
+ {2, 1, 3, 1},
+ {3, 1, 2, 1},
+ {2, 1, 1, 3}
+};
+CBC_OneDimReader::CBC_OneDimReader()
+{
+}
+CBC_OneDimReader::~CBC_OneDimReader()
+{
+}
+CFX_Int32Array *CBC_OneDimReader::FindStartGuardPattern(CBC_CommonBitArray *row, FX_INT32 &e)
+{
+ FX_BOOL foundStart = FALSE;
+ CFX_Int32Array *startRange = NULL;
+ CFX_Int32Array startEndPattern;
+ startEndPattern.SetSize(3);
+ startEndPattern[0] = START_END_PATTERN[0];
+ startEndPattern[1] = START_END_PATTERN[1];
+ startEndPattern[2] = START_END_PATTERN[2];
+ FX_INT32 nextStart = 0;
+ while (!foundStart) {
+ if(startRange != NULL) {
+ delete startRange;
+ startRange = NULL;
+ }
+ startRange = FindGuardPattern(row, nextStart, FALSE, &startEndPattern, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ FX_INT32 start = (*startRange)[0];
+ nextStart = (*startRange)[1];
+ if (start <= 1) {
+ break;
+ }
+ FX_INT32 quietStart = start - (nextStart - start);
+ if (quietStart >= 0) {
+ FX_BOOL booT = row->IsRange(quietStart, start, FALSE, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ foundStart = booT;
+ }
+ }
+ return startRange;
+}
+CFX_ByteString CBC_OneDimReader::DecodeRow(FX_INT32 rowNumber, CBC_CommonBitArray *row, FX_INT32 hints, FX_INT32 &e)
+{
+ CFX_Int32Array* StartPattern = FindStartGuardPattern(row, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ CBC_AutoPtr<CFX_Int32Array > result(StartPattern);
+ CFX_ByteString temp = DecodeRow(rowNumber, row, result.get(), hints, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ return temp;
+}
+CFX_ByteString CBC_OneDimReader::DecodeRow(FX_INT32 rowNumber, CBC_CommonBitArray *row, CFX_Int32Array *startGuardRange, FX_INT32 hints, FX_INT32 &e)
+{
+ CFX_ByteString result;
+ FX_INT32 endStart = DecodeMiddle(row, startGuardRange, result, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ FX_BOOL b = CheckChecksum(result, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ if (!b) {
+ e = BCExceptionChecksumException;
+ return "";
+ }
+ return result;
+}
+FX_BOOL CBC_OneDimReader::CheckChecksum(CFX_ByteString &s, FX_INT32 &e)
+{
+ FX_BOOL temp = CheckStandardUPCEANChecksum(s, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
+ return temp;
+}
+FX_BOOL CBC_OneDimReader::CheckStandardUPCEANChecksum(CFX_ByteString &s, FX_INT32 &e)
+{
+ FX_INT32 length = s.GetLength();
+ if (length == 0) {
+ return FALSE;
+ }
+ FX_INT32 sum = 0;
+ for (FX_INT32 i = length - 2; i >= 0; i -= 2) {
+ FX_INT32 digit = (FX_INT32) s[i] - (FX_INT32) '0';
+ if (digit < 0 || digit > 9) {
+ e = BCExceptionFormatException;
+ return FALSE;
+ }
+ sum += digit;
+ }
+ sum *= 3;
+ for (FX_INT32 j = length - 1; j >= 0; j -= 2) {
+ FX_INT32 digit = (FX_INT32) s[j] - (FX_INT32) '0';
+ if (digit < 0 || digit > 9) {
+ e = BCExceptionFormatException;
+ return FALSE;
+ }
+ sum += digit;
+ }
+ return sum % 10 == 0;
+}
+CFX_Int32Array *CBC_OneDimReader::DecodeEnd(CBC_CommonBitArray* row, FX_INT32 endStart, FX_INT32 &e)
+{
+ CFX_Int32Array startEndPattern;
+ startEndPattern.Add(START_END_PATTERN[0]);
+ startEndPattern.Add(START_END_PATTERN[1]);
+ startEndPattern.Add(START_END_PATTERN[2]);
+ CFX_Int32Array* FindGuard = FindGuardPattern(row, endStart, FALSE, &startEndPattern, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return FindGuard;
+}
+CFX_Int32Array *CBC_OneDimReader::FindGuardPattern(CBC_CommonBitArray *row, FX_INT32 rowOffset, FX_BOOL whiteFirst, CFX_Int32Array *pattern, FX_INT32 &e)
+{
+ FX_INT32 patternLength = pattern->GetSize();
+ CFX_Int32Array counters;
+ counters.SetSize(patternLength);
+ FX_INT32 width = row->GetSize();
+ FX_BOOL isWhite = FALSE;
+ while (rowOffset < width) {
+ isWhite = !row->Get(rowOffset);
+ if (whiteFirst == isWhite) {
+ break;
+ }
+ rowOffset++;
+ }
+ FX_INT32 counterPosition = 0;
+ FX_INT32 patternStart = rowOffset;
+ for (FX_INT32 x = rowOffset; x < width; x++) {
+ FX_BOOL pixel = row->Get(x);
+ if (pixel ^ isWhite) {
+ counters[counterPosition]++;
+ } else {
+ if (counterPosition == patternLength - 1) {
+ if (PatternMatchVariance(&counters, &(*pattern)[0], MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) {
+ CFX_Int32Array *result = FX_NEW CFX_Int32Array();
+ result->SetSize(2);
+ (*result)[0] = patternStart;
+ (*result)[1] = x;
+ return result;
+ }
+ patternStart += counters[0] + counters[1];
+ for (FX_INT32 y = 2; y < patternLength; y++) {
+ counters[y - 2] = counters[y];
+ }
+ counters[patternLength - 2] = 0;
+ counters[patternLength - 1] = 0;
+ counterPosition--;
+ } else {
+ counterPosition++;
+ }
+ counters[counterPosition] = 1;
+ isWhite = !isWhite;
+ }
+ }
+ e = BCExceptionNotFound;
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return NULL;
+}
+FX_INT32 CBC_OneDimReader::DecodeDigit(CBC_CommonBitArray *row, CFX_Int32Array *counters, FX_INT32 rowOffset, const FX_INT32* patterns, FX_INT32 patternLength, FX_INT32 &e)
+{
+ RecordPattern(row, rowOffset, counters, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, 0);
+ FX_INT32 bestVariance = MAX_AVG_VARIANCE;
+ FX_INT32 bestMatch = -1;
+ FX_INT32 max = patternLength;
+ for (FX_INT32 i = 0; i < max; i++) {
+ FX_INT32 variance = PatternMatchVariance(counters, &patterns[i * 4], MAX_INDIVIDUAL_VARIANCE);
+ if (variance < bestVariance) {
+ bestVariance = variance;
+ bestMatch = i;
+ }
+ }
+ if (bestMatch >= 0) {
+ return bestMatch;
+ } else {
+ e = BCExceptionNotFound;
+ return 0;
+ }
+ return 0;
+}
diff --git a/xfa/src/fxbarcode/oned/BC_OneDimReader.h b/xfa/src/fxbarcode/oned/BC_OneDimReader.h
new file mode 100644
index 0000000000..bb10060ba3
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OneDimReader.h
@@ -0,0 +1,39 @@
+// 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_ONEDUPCEANREADER_H_
+#define _BC_ONEDUPCEANREADER_H_
+class CBC_OneDReader;
+class CBC_CommonBitArray;
+class CBC_OneDimReader;
+class CBC_OneDimReader : public CBC_OneDReader
+{
+private:
+ const static FX_INT32 MAX_AVG_VARIANCE;
+ const static FX_INT32 MAX_INDIVIDUAL_VARIANCE;
+
+ FX_BOOL CheckStandardUPCEANChecksum(CFX_ByteString &s, FX_INT32 &e);
+public:
+ const static FX_INT32 START_END_PATTERN[3];
+ const static FX_INT32 MIDDLE_PATTERN[5];
+ const static FX_INT32 L_PATTERNS[10][4];
+ const static FX_INT32 L_AND_G_PATTERNS[20][4];
+ CBC_OneDimReader();
+ virtual ~CBC_OneDimReader();
+ CFX_ByteString DecodeRow(FX_INT32 rowNumber, CBC_CommonBitArray *row, FX_INT32 hints, FX_INT32 &e);
+ CFX_ByteString DecodeRow(FX_INT32 rowNumber, CBC_CommonBitArray *row, CFX_Int32Array *startGuardRange, FX_INT32 hints, FX_INT32 &e);
+protected:
+ CFX_Int32Array *FindStartGuardPattern(CBC_CommonBitArray *row, FX_INT32 &e);
+ virtual FX_BOOL CheckChecksum(CFX_ByteString &s, FX_INT32 &e);
+ CFX_Int32Array *FindGuardPattern(CBC_CommonBitArray *row, FX_INT32 rowOffset, FX_BOOL whiteFirst, CFX_Int32Array *pattern, FX_INT32 &e);
+ FX_INT32 DecodeDigit(CBC_CommonBitArray *row, CFX_Int32Array *counters, FX_INT32 rowOffset, const FX_INT32* patterns, FX_INT32 patternLength, FX_INT32 &e);
+ virtual FX_INT32 DecodeMiddle(CBC_CommonBitArray *row, CFX_Int32Array *startRange, CFX_ByteString &resultResult, FX_INT32 &e)
+ {
+ return 0;
+ }
+ virtual CFX_Int32Array *DecodeEnd(CBC_CommonBitArray *row, FX_INT32 endStart, FX_INT32 &e);
+};
+#endif
diff --git a/xfa/src/fxbarcode/oned/BC_OneDimWriter.cpp b/xfa/src/fxbarcode/oned/BC_OneDimWriter.cpp
new file mode 100644
index 0000000000..25f3fa5f6c
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OneDimWriter.cpp
@@ -0,0 +1,415 @@
+// 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 2011 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 "../common/BC_CommonBitMatrix.h"
+#include "BC_OneDimWriter.h"
+CBC_OneDimWriter::CBC_OneDimWriter()
+{
+ m_locTextLoc = BC_TEXT_LOC_BELOWEMBED;
+ m_bPrintChecksum = TRUE;
+ m_iDataLenth = 0;
+ m_bCalcChecksum = FALSE;
+ m_pFont = NULL;
+ m_fFontSize = 10; ;
+ m_iFontStyle = 0;
+ m_fontColor = 0xff000000;
+ m_iContentLen = 0;
+ m_bLeftPadding = FALSE;
+ m_bRightPadding = FALSE;
+ m_output = NULL;
+}
+CBC_OneDimWriter::~CBC_OneDimWriter()
+{
+ if (m_output != NULL) {
+ delete m_output;
+ m_output = NULL;
+ }
+}
+void CBC_OneDimWriter::SetPrintChecksum(FX_BOOL checksum)
+{
+ m_bPrintChecksum = checksum;
+}
+void CBC_OneDimWriter::SetDataLength(FX_INT32 length)
+{
+ m_iDataLenth = length;
+}
+void CBC_OneDimWriter::SetCalcChecksum(FX_INT32 state)
+{
+ m_bCalcChecksum = state;
+}
+FX_BOOL CBC_OneDimWriter::SetFont(CFX_Font * cFont)
+{
+ if (cFont == NULL) {
+ return FALSE;
+ }
+ m_pFont = cFont;
+ return TRUE;
+}
+void CBC_OneDimWriter::SetFontSize(FX_FLOAT size)
+{
+ m_fFontSize = size;
+}
+void CBC_OneDimWriter::SetFontStyle(FX_INT32 style)
+{
+ m_iFontStyle = style;
+}
+void CBC_OneDimWriter::SetFontColor(FX_ARGB color)
+{
+ m_fontColor = color;
+}
+FX_WCHAR CBC_OneDimWriter::Upper(FX_WCHAR ch)
+{
+ if(ch >= 'a' && ch <= 'z') {
+ ch = ch - ('a' - 'A');
+ }
+ return ch;
+}
+FX_BYTE* CBC_OneDimWriter::Encode(const CFX_ByteString &contents, BCFORMAT format,
+ FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 hints, FX_INT32 &e)
+{
+ FX_BYTE *ret = NULL;
+ outHeight = 1;
+ if (m_Width >= 20) {
+ ret = Encode(contents, outWidth, e);
+ } else {
+ ret = Encode(contents, outWidth, e);
+ }
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return ret;
+}
+FX_BYTE *CBC_OneDimWriter::Encode(const CFX_ByteString &contents, BCFORMAT format,
+ FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 &e)
+{
+ FX_BYTE *ret = Encode(contents, format, outWidth, outHeight, 0, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return ret;
+}
+FX_INT32 CBC_OneDimWriter::AppendPattern(FX_BYTE* target, FX_INT32 pos, const FX_INT32* pattern , FX_INT32 patternLength, FX_INT32 startColor, FX_INT32 &e)
+{
+ if (startColor != 0 && startColor != 1) {
+ e = BCExceptionValueMustBeEither0or1;
+ return 0;
+ }
+ FX_BYTE color = (FX_BYTE) startColor;
+ FX_INT32 numAdded = 0;
+ for (FX_INT32 i = 0; i < patternLength; i++) {
+ for (FX_INT32 j = 0; j < pattern[i]; j++) {
+ target[pos] = color;
+ pos += 1;
+ numAdded += 1;
+ }
+ color ^= 1;
+ }
+ return numAdded;
+}
+void CBC_OneDimWriter::CalcTextInfo(const CFX_ByteString &text, FXTEXT_CHARPOS *charPos, CFX_Font *cFont, FX_FLOAT geWidth, FX_INT32 fontSize, FX_FLOAT &charsLen)
+{
+#ifdef FXFM_ENCODING_NONE
+ IFX_FontEncodingEx* encoding = FX_CreateFontEncodingEx(cFont);
+#else
+ IFX_FontEncoding * encoding = FXGE_CreateUnicodeEncoding(cFont);
+#endif
+ FX_INT32 length = text.GetLength();
+ FX_DWORD *pCharCode = FX_Alloc(FX_DWORD, text.GetLength());
+ FX_FLOAT charWidth = 0;
+ for (FX_INT32 j = 0; j < text.GetLength(); j++) {
+ pCharCode[j] = encoding->CharCodeFromUnicode(text[j]);
+ FX_INT32 glyp_code = encoding->GlyphFromCharCode(pCharCode[j]);
+ FX_INT32 glyp_value = cFont->GetGlyphWidth(glyp_code);
+ FX_FLOAT temp = (FX_FLOAT)((glyp_value) * fontSize / 1000.0);
+ charWidth += temp;
+ }
+ charsLen = charWidth;
+ FX_FLOAT leftPositon = (FX_FLOAT)(geWidth - charsLen) / 2.0f;
+ if (leftPositon < 0 && geWidth == 0) {
+ leftPositon = 0;
+ }
+ FX_FLOAT penX = 0.0;
+ FX_FLOAT penY = (FX_FLOAT)FXSYS_abs(cFont->GetDescent()) * (FX_FLOAT)fontSize / 1000.0f;
+ FX_FLOAT left = leftPositon;
+ FX_FLOAT top = 0.0;
+ charPos[0].m_OriginX = penX + left;
+ charPos[0].m_OriginY = penY + top;
+ charPos[0].m_GlyphIndex = encoding->GlyphFromCharCode(pCharCode[0]);
+ charPos[0].m_FontCharWidth = cFont->GetGlyphWidth(charPos[0].m_GlyphIndex);
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ charPos[0].m_ExtGID = charPos[0].m_GlyphIndex;
+#endif
+ penX += (FX_FLOAT)(charPos[0].m_FontCharWidth) * (FX_FLOAT)fontSize / 1000.0f;
+ for (FX_INT32 i = 1; i < length; i++) {
+ charPos[i].m_OriginX = penX + left;
+ charPos[i].m_OriginY = penY + top;
+ charPos[i].m_GlyphIndex = encoding->GlyphFromCharCode(pCharCode[i]);
+ charPos[i].m_FontCharWidth = cFont->GetGlyphWidth(charPos[i].m_GlyphIndex);
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ charPos[i].m_ExtGID = charPos[i].m_GlyphIndex;
+#endif
+ penX += (FX_FLOAT)(charPos[i].m_FontCharWidth) * (FX_FLOAT)fontSize / 1000.0f;
+ }
+ FX_Free (pCharCode);
+ delete encoding;
+ encoding = NULL;
+}
+void CBC_OneDimWriter::ShowDeviceChars(CFX_RenderDevice *device, const CFX_Matrix* matrix, const CFX_ByteString str, FX_FLOAT geWidth, FXTEXT_CHARPOS* pCharPos, FX_FLOAT locX, FX_FLOAT locY, FX_INT32 barWidth)
+{
+ FX_INT32 iFontSize = (FX_INT32)fabs(m_fFontSize);
+ FX_INT32 iTextHeight = iFontSize + 1;
+ CFX_FloatRect rect((FX_FLOAT)locX, (FX_FLOAT)locY, (FX_FLOAT)(locX + geWidth), (FX_FLOAT)(locY + iTextHeight));
+ if (geWidth != m_Width) {
+ rect.right -= 1;
+ }
+ matrix->TransformRect(rect);
+ FX_RECT re = rect.GetOutterRect();
+ device->FillRect(&re, m_backgroundColor);
+ CFX_Matrix affine_matrix(1.0, 0.0, 0.0, -1.0, (FX_FLOAT)locX, (FX_FLOAT)(locY + iFontSize));
+ if (matrix != NULL) {
+ affine_matrix.Concat(*matrix);
+ }
+ FX_BOOL ret = device->DrawNormalText(str.GetLength(),
+ pCharPos,
+ m_pFont,
+ CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize,
+ (CFX_AffineMatrix *) &affine_matrix,
+ m_fontColor, FXTEXT_CLEARTYPE);
+}
+void CBC_OneDimWriter::ShowBitmapChars(CFX_DIBitmap *pOutBitmap, const CFX_ByteString str, FX_FLOAT geWidth, FXTEXT_CHARPOS* pCharPos, FX_FLOAT locX, FX_FLOAT locY, FX_INT32 barWidth)
+{
+ FX_INT32 iFontSize = (FX_INT32)fabs(m_fFontSize);
+ FX_INT32 iTextHeight = iFontSize + 1;
+ CFX_FxgeDevice ge;
+ ge.Create((int)geWidth, iTextHeight , m_colorSpace);
+ FX_RECT geRect(0, 0, (int)geWidth, iTextHeight);
+ ge.FillRect(&geRect, m_backgroundColor);
+ CFX_AffineMatrix affine_matrix(1.0, 0.0, 0.0, -1.0, 0.0, (FX_FLOAT)iFontSize);
+ FX_BOOL ret = ge.DrawNormalText(str.GetLength(),
+ pCharPos,
+ m_pFont,
+ CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize,
+ (CFX_AffineMatrix *) &affine_matrix,
+ m_fontColor, FXTEXT_CLEARTYPE);
+ CFX_FxgeDevice geBitmap;
+ geBitmap.Attach(pOutBitmap);
+ geBitmap.SetDIBits(ge.GetBitmap(), (int)locX, (int)locY);
+}
+void CBC_OneDimWriter::ShowChars(FX_WSTR contents, CFX_DIBitmap *pOutBitmap, CFX_RenderDevice *device, const CFX_Matrix* matrix, FX_INT32 barWidth, FX_INT32 multiple, FX_INT32 &e)
+{
+ if (device == NULL && pOutBitmap == NULL) {
+ e = BCExceptionIllegalArgument;
+ return;
+ }
+ if (m_pFont == NULL) {
+ e = BCExceptionNullPointer;
+ return;
+ }
+ CFX_ByteString str = FX_UTF8Encode(contents);
+ FX_INT32 iLen = str.GetLength();
+ FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, iLen);
+ if (!pCharPos) {
+ return;
+ }
+ FXSYS_memset32(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLen);
+ FX_FLOAT charsLen = 0;
+ FX_FLOAT geWidth = 0;
+ if ( m_locTextLoc == BC_TEXT_LOC_ABOVEEMBED ||
+ m_locTextLoc == BC_TEXT_LOC_BELOWEMBED ) {
+ geWidth = 0;
+ } else if ( m_locTextLoc == BC_TEXT_LOC_ABOVE ||
+ m_locTextLoc == BC_TEXT_LOC_BELOW ) {
+ geWidth = (FX_FLOAT)barWidth;
+ }
+ FX_INT32 iFontSize = (FX_INT32)fabs(m_fFontSize);
+ FX_INT32 iTextHeight = iFontSize + 1;
+ CalcTextInfo(str, pCharPos, m_pFont, geWidth, iFontSize, charsLen);
+ if (charsLen < 1) {
+ return;
+ }
+ FX_INT32 locX = 0;
+ FX_INT32 locY = 0;
+ switch (m_locTextLoc) {
+ case BC_TEXT_LOC_ABOVEEMBED:
+ locX = (FX_INT32)(barWidth - charsLen) / 2;
+ locY = 0;
+ geWidth = charsLen;
+ break;
+ case BC_TEXT_LOC_ABOVE:
+ locX = 0;
+ locY = 0;
+ geWidth = (FX_FLOAT)barWidth;
+ break;
+ case BC_TEXT_LOC_BELOWEMBED:
+ locX = (FX_INT32)(barWidth - charsLen) / 2;
+ locY = m_Height - iTextHeight;
+ geWidth = charsLen;
+ break;
+ case BC_TEXT_LOC_BELOW:
+ default:
+ locX = 0;
+ locY = m_Height - iTextHeight;
+ geWidth = (FX_FLOAT)barWidth;
+ break;
+ }
+ if (device != NULL) {
+ ShowDeviceChars(device, matrix, str, geWidth, pCharPos, (FX_FLOAT)locX, (FX_FLOAT)locY, barWidth);
+ } else {
+ ShowBitmapChars(pOutBitmap, str, geWidth, pCharPos, (FX_FLOAT)locX, (FX_FLOAT)locY, barWidth);
+ }
+ FX_Free(pCharPos);
+}
+void CBC_OneDimWriter::RenderBitmapResult(CFX_DIBitmap *&pOutBitmap, FX_WSTR contents, FX_INT32 &e)
+{
+ if (m_output == NULL) {
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ }
+ pOutBitmap = CreateDIBitmap(m_output->GetWidth(), m_output->GetHeight());
+ pOutBitmap->Clear(m_backgroundColor);
+ if (!pOutBitmap) {
+ e = BCExceptionFailToCreateBitmap;
+ return;
+ }
+ for (FX_INT32 x = 0; x < m_output->GetWidth(); x++) {
+ for (FX_INT32 y = 0; y < m_output->GetHeight(); y++) {
+ if (m_output->Get(x, y)) {
+ pOutBitmap->SetPixel(x, y, m_barColor);
+ }
+ }
+ }
+ FX_INT32 i = 0;
+ for (; i < contents.GetLength(); i++)
+ if (contents.GetAt(i) != ' ') {
+ break;
+ }
+ if (m_locTextLoc != BC_TEXT_LOC_NONE && i < contents.GetLength()) {
+ ShowChars(contents, pOutBitmap, NULL, NULL, m_barWidth, m_multiple, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ }
+ CFX_DIBitmap * pStretchBitmap = pOutBitmap->StretchTo(m_Width, m_Height);
+ if (pOutBitmap) {
+ delete pOutBitmap;
+ }
+ pOutBitmap = pStretchBitmap;
+}
+void CBC_OneDimWriter::RenderDeviceResult(CFX_RenderDevice* device, const CFX_Matrix* matrix, FX_WSTR contents, FX_INT32 &e)
+{
+ if (m_output == NULL) {
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ }
+ CFX_GraphStateData stateData;
+ CFX_PathData path;
+ path.AppendRect(0, 0, (FX_FLOAT)m_Width, (FX_FLOAT)m_Height);
+ device->DrawPath(&path, matrix, &stateData, m_backgroundColor, m_backgroundColor, FXFILL_ALTERNATE);
+ CFX_Matrix matri(m_outputHScale, 0.0, 0.0, (FX_FLOAT)m_Height, 0.0, 0.0);
+ matri.Concat(*matrix);
+ for (FX_INT32 x = 0; x < m_output->GetWidth(); x++) {
+ for (FX_INT32 y = 0; y < m_output->GetHeight(); y++) {
+ CFX_PathData rect;
+ rect.AppendRect((FX_FLOAT)x, (FX_FLOAT)y, (FX_FLOAT)(x + 1), (FX_FLOAT)(y + 1));
+ CFX_GraphStateData stateData;
+ if (m_output->Get(x, y)) {
+ device->DrawPath(&rect, &matri, &stateData, m_barColor, 0, FXFILL_WINDING);
+ }
+ }
+ }
+ FX_INT32 i = 0;
+ for (; i < contents.GetLength(); i++)
+ if (contents.GetAt(i) != ' ') {
+ break;
+ }
+ if (m_locTextLoc != BC_TEXT_LOC_NONE && i < contents.GetLength()) {
+ ShowChars(contents, NULL, device, matrix, m_barWidth, m_multiple, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ }
+}
+void CBC_OneDimWriter::RenderResult(FX_WSTR contents, FX_BYTE* code, FX_INT32 codeLength, FX_BOOL isDevice, FX_INT32 &e)
+{
+ if (codeLength < 1) {
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ }
+ if (m_ModuleHeight < 20.0) {
+ m_ModuleHeight = 20;
+ }
+ FX_INT32 codeOldLength = codeLength;
+ FX_INT32 leftPadding = 0;
+ FX_INT32 rightPadding = 0;
+ if (m_bLeftPadding) {
+ leftPadding = 7;
+ }
+ if (m_bRightPadding) {
+ rightPadding = 7;
+ }
+ codeLength += leftPadding;
+ codeLength += rightPadding;
+ m_outputHScale = 1.0;
+ if (m_Width > 0) {
+ m_outputHScale = (FX_FLOAT)m_Width / (FX_FLOAT)codeLength;
+ }
+ if (!isDevice) {
+ m_outputHScale = FX_MAX(m_outputHScale, m_ModuleWidth);
+ }
+ FX_FLOAT dataLengthScale = 1.0;
+ if (m_iDataLenth > 0 && contents.GetLength() != 0) {
+ dataLengthScale = FX_FLOAT(contents.GetLength()) / FX_FLOAT(m_iDataLenth);
+ }
+ if (m_iDataLenth > 0 && contents.GetLength() == 0) {
+ dataLengthScale = FX_FLOAT(1) / FX_FLOAT(m_iDataLenth);
+ }
+ m_multiple = 1;
+ if (!isDevice) {
+ m_multiple = (FX_INT32)ceil(m_outputHScale * dataLengthScale);
+ }
+ FX_INT32 outputHeight = 1;
+ if (!isDevice) {
+ if (m_Height == 0) {
+ outputHeight = FX_MAX(20, m_ModuleHeight);
+ } else {
+ outputHeight = m_Height;
+ }
+ }
+ FX_INT32 outputWidth = codeLength;
+ if (!isDevice) {
+ outputWidth = (FX_INT32)(codeLength * m_multiple / dataLengthScale);
+ }
+ m_barWidth = m_Width;
+ if (!isDevice) {
+ m_barWidth = codeLength * m_multiple;
+ }
+ m_output = FX_NEW CBC_CommonBitMatrix;
+ m_output->Init(outputWidth, outputHeight);
+ FX_INT32 outputX = leftPadding * m_multiple;
+ for (FX_INT32 inputX = 0; inputX < codeOldLength; inputX++) {
+ if (code[inputX] == 1) {
+ if (outputX >= outputWidth ) {
+ break;
+ }
+ if (outputX + m_multiple > outputWidth && outputWidth - outputX > 0) {
+ m_output->SetRegion(outputX, 0, outputWidth - outputX , outputHeight, e);
+ break;
+ }
+ m_output->SetRegion(outputX, 0, m_multiple, outputHeight, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ }
+ outputX += m_multiple;
+ }
+}
diff --git a/xfa/src/fxbarcode/oned/BC_OneDimWriter.h b/xfa/src/fxbarcode/oned/BC_OneDimWriter.h
new file mode 100644
index 0000000000..cd5d937aca
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OneDimWriter.h
@@ -0,0 +1,70 @@
+// 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_ONEDIMWRITER_H_
+#define _BC_ONEDIMWRITER_H_
+class CBC_Writer;
+class CBC_CommonBitMatrix;
+class CBC_OneDimWriter;
+class CBC_OneDimWriter : public CBC_Writer
+{
+public:
+ CBC_OneDimWriter();
+ virtual ~CBC_OneDimWriter();
+ 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);
+ virtual FX_BYTE *Encode(const CFX_ByteString &contents, FX_INT32 &outLength, FX_INT32 &e)
+ {
+ return NULL;
+ };
+ virtual void RenderResult(FX_WSTR contents, FX_BYTE* code, FX_INT32 codeLength, FX_BOOL isDevice, FX_INT32 &e);
+ virtual void RenderBitmapResult(CFX_DIBitmap *&pOutBitmap, FX_WSTR contents, FX_INT32 &e);
+ virtual void RenderDeviceResult(CFX_RenderDevice* device, const CFX_Matrix* matrix, FX_WSTR contents, FX_INT32 &e);
+ virtual FX_BOOL CheckContentValidity(FX_WSTR contents)
+ {
+ return TRUE;
+ };
+ virtual CFX_WideString FilterContents(FX_WSTR contents)
+ {
+ return CFX_WideString();
+ }
+ virtual CFX_WideString RenderTextContents(FX_WSTR contents)
+ {
+ return CFX_WideString();
+ }
+ virtual void SetPrintChecksum(FX_BOOL checksum);
+ virtual void SetDataLength(FX_INT32 length);
+ virtual void SetCalcChecksum(FX_INT32 state);
+ virtual void SetFontSize(FX_FLOAT size);
+ virtual void SetFontStyle(FX_INT32 style);
+ virtual void SetFontColor(FX_ARGB color);
+ virtual FX_BOOL SetFont(CFX_Font * cFont);
+protected:
+ FX_BOOL m_bPrintChecksum;
+ FX_INT32 m_iDataLenth;
+ FX_BOOL m_bCalcChecksum;
+ CFX_Font* m_pFont;
+ FX_FLOAT m_fFontSize;
+ FX_INT32 m_iFontStyle;
+ FX_DWORD m_fontColor;
+ BC_TEXT_LOC m_locTextLoc;
+ FX_INT32 m_iContentLen;
+ FX_BOOL m_bLeftPadding;
+ FX_BOOL m_bRightPadding;
+ CBC_CommonBitMatrix* m_output;
+ FX_INT32 m_barWidth;
+ FX_INT32 m_multiple;
+ FX_FLOAT m_outputHScale;
+ void CalcTextInfo(const CFX_ByteString &text, FXTEXT_CHARPOS *charPos, CFX_Font *cFont, FX_FLOAT geWidth, FX_INT32 fontSize, FX_FLOAT &charsLen);
+ virtual void ShowChars(FX_WSTR contents, CFX_DIBitmap *pOutBitmap, CFX_RenderDevice *device, const CFX_Matrix* matrix, FX_INT32 barWidth, FX_INT32 multiple, FX_INT32 &e);
+ virtual void ShowBitmapChars(CFX_DIBitmap *pOutBitmap, const CFX_ByteString str, FX_FLOAT geWidth, FXTEXT_CHARPOS* pCharPos, FX_FLOAT locX, FX_FLOAT locY, FX_INT32 barWidth);
+ virtual void ShowDeviceChars(CFX_RenderDevice *device, const CFX_Matrix* matrix, const CFX_ByteString str, FX_FLOAT geWidth, FXTEXT_CHARPOS* pCharPos, FX_FLOAT locX, FX_FLOAT locY, FX_INT32 barWidth);
+ FX_INT32 AppendPattern(FX_BYTE* target, FX_INT32 pos, const FX_INT32* pattern, FX_INT32 patternLength, FX_INT32 startColor, FX_INT32 &e);
+ FX_WCHAR Upper(FX_WCHAR ch);
+};
+#endif
diff --git a/xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.cpp b/xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.cpp
new file mode 100644
index 0000000000..5d94d7ac06
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.cpp
@@ -0,0 +1,206 @@
+// 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_Reader.h"
+#include "../common/BC_CommonBitArray.h"
+#include "../oned/BC_OneDReader.h"
+#include "../oned/BC_OnedCode39Reader.h"
+#include "../oned/BC_OnedCodaBarReader.h"
+FX_LPCSTR CBC_OnedCodaBarReader::ALPHABET_STRING = "0123456789-$:/.+ABCDTN";
+const FX_INT32 CBC_OnedCodaBarReader::CHARACTER_ENCODINGS[22] = {
+ 0x003, 0x006, 0x009, 0x060, 0x012, 0x042, 0x021, 0x024, 0x030, 0x048,
+ 0x00c, 0x018, 0x045, 0x051, 0x054, 0x015, 0x01A, 0x029, 0x00B, 0x00E,
+ 0x01A, 0x029
+};
+const FX_INT32 CBC_OnedCodaBarReader::minCharacterLength = 3;
+const FX_CHAR CBC_OnedCodaBarReader::STARTEND_ENCODING[8] = {'E', '*', 'A', 'B', 'C', 'D', 'T', 'N'};
+CBC_OnedCodaBarReader::CBC_OnedCodaBarReader()
+{
+}
+CBC_OnedCodaBarReader::~CBC_OnedCodaBarReader()
+{
+}
+CFX_ByteString CBC_OnedCodaBarReader::DecodeRow(FX_INT32 rowNumber, CBC_CommonBitArray *row, FX_INT32 hints, FX_INT32 &e)
+{
+ CFX_Int32Array *int32Ptr = FindAsteriskPattern(row, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ CBC_AutoPtr<CFX_Int32Array> start(int32Ptr);
+ (*start)[1] = 0;
+ FX_INT32 nextStart = (*start)[1];
+ FX_INT32 end = row->GetSize();
+ while (nextStart < end && !row->Get(nextStart)) {
+ nextStart++;
+ }
+ CFX_ByteString result;
+ CFX_Int32Array counters;
+ counters.SetSize(7);
+ FX_CHAR decodedChar;
+ FX_INT32 lastStart;
+ do {
+ RecordPattern(row, nextStart, &counters, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ decodedChar = ToNarrowWidePattern(&counters);
+ if (decodedChar == '!') {
+ e = BCExceptionNotFound;
+ return "";
+ }
+ result += decodedChar;
+ lastStart = nextStart;
+ for (FX_INT32 i = 0; i < counters.GetSize(); i++) {
+ nextStart += counters[i];
+ }
+ while (nextStart < end && !row->Get(nextStart)) {
+ nextStart++;
+ }
+ } while (nextStart < end);
+ FX_INT32 lastPatternSize = 0;
+ for (FX_INT32 j = 0; j < counters.GetSize(); j++) {
+ lastPatternSize += counters[j];
+ }
+ FX_INT32 whiteSpaceAfterEnd = nextStart - lastStart - lastPatternSize;
+ if (nextStart != end && (whiteSpaceAfterEnd / 2 < lastPatternSize)) {
+ e = BCExceptionNotFound;
+ return "";
+ }
+ if (result.GetLength() < 2) {
+ e = BCExceptionNotFound;
+ return "";
+ }
+ FX_CHAR startchar = result[0];
+ if (!ArrayContains(STARTEND_ENCODING, startchar)) {
+ e = BCExceptionNotFound;
+ return "";
+ }
+ FX_INT32 len = result.GetLength();
+ CFX_ByteString temp = result;
+ for (FX_INT32 k = 1; k < result.GetLength(); k++) {
+ if (ArrayContains(STARTEND_ENCODING, result[k])) {
+ if ((k + 1) != result.GetLength()) {
+ result.Delete(1, k);
+ k = 1;
+ }
+ }
+ }
+ if (result.GetLength() < 5) {
+ FX_INT32 index = temp.Find(result.Mid(1, result.GetLength() - 1));
+ if (index == len - (result.GetLength() - 1)) {
+ e = BCExceptionNotFound;
+ return "";
+ }
+ }
+ if (result.GetLength() > minCharacterLength) {
+ result = result.Mid(1, result.GetLength() - 2);
+ } else {
+ e = BCExceptionNotFound;
+ return "";
+ }
+ return result;
+}
+CFX_Int32Array *CBC_OnedCodaBarReader::FindAsteriskPattern(CBC_CommonBitArray *row, FX_INT32 &e)
+{
+ FX_INT32 width = row->GetSize();
+ FX_INT32 rowOffset = 0;
+ while (rowOffset < width) {
+ if (row->Get(rowOffset)) {
+ break;
+ }
+ rowOffset++;
+ }
+ FX_INT32 counterPosition = 0;
+ CFX_Int32Array counters;
+ counters.SetSize(7);
+ FX_INT32 patternStart = rowOffset;
+ FX_BOOL isWhite = FALSE;
+ FX_INT32 patternLength = counters.GetSize();
+ for (FX_INT32 i = rowOffset; i < width; i++) {
+ FX_BOOL pixel = row->Get(i);
+ if (pixel ^ isWhite) {
+ counters[counterPosition]++;
+ } else {
+ if (counterPosition == patternLength - 1) {
+ if (ArrayContains(STARTEND_ENCODING, ToNarrowWidePattern(&counters))) {
+ FX_BOOL btemp3 = row->IsRange(FX_MAX(0, patternStart - (i - patternStart) / 2), patternStart, FALSE, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ if (btemp3) {
+ CFX_Int32Array *result = FX_NEW CFX_Int32Array();
+ result->SetSize(2);
+ (*result)[0] = patternStart;
+ (*result)[1] = i;
+ return result;
+ }
+ }
+ patternStart += counters[0] + counters[1];
+ for (FX_INT32 y = 2; y < patternLength; y++) {
+ counters[y - 2] = counters[y];
+ }
+ counters[patternLength - 2] = 0;
+ counters[patternLength - 1] = 0;
+ counterPosition--;
+ } else {
+ counterPosition++;
+ }
+ counters[counterPosition] = 1;
+ isWhite = !isWhite;
+ }
+ }
+ e = BCExceptionNotFound;
+ return NULL;
+}
+FX_BOOL CBC_OnedCodaBarReader::ArrayContains(const FX_CHAR array[], FX_CHAR key)
+{
+ for(FX_INT32 i = 0; i < 8; i++) {
+ if(array[i] == key) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+FX_CHAR CBC_OnedCodaBarReader::ToNarrowWidePattern(CFX_Int32Array *counter)
+{
+ FX_INT32 numCounters = counter->GetSize();
+ if (numCounters < 1) {
+ return '!';
+ }
+ FX_INT32 averageCounter = 0;
+ FX_INT32 totalCounters = 0;
+ for (FX_INT32 i = 0; i < numCounters; i++) {
+ totalCounters += (*counter)[i];
+ }
+ averageCounter = totalCounters / numCounters;
+ FX_INT32 pattern = 0;
+ FX_INT32 wideCounters = 0;
+ for (FX_INT32 j = 0; j < numCounters; j++) {
+ if ((*counter)[j] > averageCounter) {
+ pattern |= 1 << (numCounters - 1 - j);
+ wideCounters++;
+ }
+ }
+ if ((wideCounters == 2) || (wideCounters == 3)) {
+ for (FX_INT32 k = 0; k < 22; k++) {
+ if (CHARACTER_ENCODINGS[k] == pattern) {
+ return (ALPHABET_STRING)[k];
+ }
+ }
+ }
+ return '!';
+}
diff --git a/xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.h b/xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.h
new file mode 100644
index 0000000000..1d03491841
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.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_ONEDCODABARREADER_H_
+#define _BC_ONEDCODABARREADER_H_
+class CBC_CommonBitArray;
+class CBC_OneDReader;
+class CBC_OnedCodaBarReader;
+class CBC_OnedCodaBarReader : public CBC_OneDReader
+{
+public:
+ CBC_OnedCodaBarReader();
+ virtual ~CBC_OnedCodaBarReader();
+ CFX_ByteString DecodeRow(FX_INT32 rowNumber, CBC_CommonBitArray *row, FX_INT32 hints, FX_INT32 &e);
+ CFX_Int32Array *FindAsteriskPattern(CBC_CommonBitArray *row, FX_INT32 &e);
+ FX_BOOL ArrayContains(const FX_CHAR array[], FX_CHAR key);
+ FX_CHAR ToNarrowWidePattern(CFX_Int32Array *counter);
+ static FX_LPCSTR ALPHABET_STRING;
+
+
+ const static FX_INT32 CHARACTER_ENCODINGS[22];
+
+ const static FX_INT32 minCharacterLength;
+
+ const static FX_CHAR STARTEND_ENCODING[8];
+};
+#endif
diff --git a/xfa/src/fxbarcode/oned/BC_OnedCodaBarWriter.cpp b/xfa/src/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
new file mode 100644
index 0000000000..059d2d7df5
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
@@ -0,0 +1,222 @@
+// 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 2011 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_Reader.h"
+#include "../common/BC_CommonBitMatrix.h"
+#include "../common/BC_CommonBitArray.h"
+#include "BC_OneDReader.h"
+#include "BC_OneDimWriter.h"
+#include "BC_OnedCodaBarReader.h"
+#include "BC_OnedCodaBarWriter.h"
+const FX_CHAR CBC_OnedCodaBarWriter::START_END_CHARS[] = {'A', 'B', 'C', 'D', 'T', 'N', '*', 'E', 'a', 'b', 'c', 'd', 't', 'n', 'e'};
+const FX_CHAR CBC_OnedCodaBarWriter::CONTENT_CHARS[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '$', '/', ':', '+', '.'};
+CBC_OnedCodaBarWriter::CBC_OnedCodaBarWriter()
+{
+ m_chStart = 'A';
+ m_chEnd = 'B';
+ m_iWideNarrRatio = 2;
+}
+CBC_OnedCodaBarWriter::~CBC_OnedCodaBarWriter()
+{
+}
+FX_BOOL CBC_OnedCodaBarWriter::SetStartChar(FX_CHAR start)
+{
+ for (FX_INT32 i = 0; i < sizeof(START_END_CHARS) / sizeof(FX_CHAR); i++) {
+ if (START_END_CHARS[i] == start) {
+ m_chStart = start;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+FX_BOOL CBC_OnedCodaBarWriter::SetEndChar(FX_CHAR end)
+{
+ for (FX_INT32 i = 0; i < sizeof(START_END_CHARS) / sizeof(FX_CHAR); i++) {
+ if (START_END_CHARS[i] == end) {
+ m_chEnd = end;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+void CBC_OnedCodaBarWriter::SetDataLength(FX_INT32 length)
+{
+ m_iDataLenth = length + 2;
+}
+FX_BOOL CBC_OnedCodaBarWriter::SetTextLocation(BC_TEXT_LOC location)
+{
+ if ( location < BC_TEXT_LOC_NONE || location > BC_TEXT_LOC_BELOWEMBED) {
+ return FALSE;
+ }
+ m_locTextLoc = location;
+ return TRUE;
+}
+FX_BOOL CBC_OnedCodaBarWriter::SetWideNarrowRatio(FX_INT32 ratio)
+{
+ if(ratio < 2 || ratio > 3) {
+ return FALSE;
+ }
+ m_iWideNarrRatio = ratio;
+ return TRUE;
+}
+FX_BOOL CBC_OnedCodaBarWriter::FindChar(FX_WCHAR ch, FX_BOOL isContent)
+{
+ if(isContent) {
+ for(FX_INT32 i = 0 ; i < sizeof(CONTENT_CHARS) / sizeof(FX_CHAR) ; i++) {
+ if(ch == (FX_WCHAR)CONTENT_CHARS[i]) {
+ return TRUE;
+ }
+ }
+ for(FX_INT32 j = 0 ; j < sizeof(START_END_CHARS) / sizeof(FX_CHAR) ; j++) {
+ if(ch == (FX_WCHAR)START_END_CHARS[j]) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+ } else {
+ for(FX_INT32 i = 0 ; i < sizeof(CONTENT_CHARS) / sizeof(FX_CHAR) ; i++) {
+ if(ch == (FX_WCHAR)CONTENT_CHARS[i]) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+ }
+}
+FX_BOOL CBC_OnedCodaBarWriter::CheckContentValidity(FX_WSTR contents)
+{
+ FX_WCHAR ch;
+ FX_INT32 index = 0;
+ for (index = 0; index < contents.GetLength(); index++) {
+ ch = contents.GetAt(index);
+ if (FindChar(ch, FALSE)) {
+ continue;
+ } else {
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+CFX_WideString CBC_OnedCodaBarWriter::FilterContents(FX_WSTR contents)
+{
+ CFX_WideString filtercontents;
+ FX_WCHAR ch;
+ for (FX_INT32 index = 0; index < contents.GetLength(); index ++) {
+ ch = contents.GetAt(index);
+ if(ch > 175) {
+ index++;
+ continue;
+ }
+ if (FindChar(ch, TRUE)) {
+ filtercontents += ch;
+ } else {
+ continue;
+ }
+ }
+ return filtercontents;
+}
+FX_BYTE *CBC_OnedCodaBarWriter::Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 &e)
+{
+ FX_BYTE *ret = Encode(contents, format, outWidth, outHeight, 0 , e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return ret;
+}
+FX_BYTE *CBC_OnedCodaBarWriter::Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 hints, FX_INT32 &e)
+{
+ if(format != BCFORMAT_CODABAR) {
+ e = BCExceptionOnlyEncodeCODEBAR;
+ return NULL;
+ }
+ FX_BYTE *ret = CBC_OneDimWriter::Encode(contents, format, outWidth, outHeight, hints, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return ret;
+}
+FX_BYTE* CBC_OnedCodaBarWriter::Encode(const CFX_ByteString &contents, FX_INT32 &outLength, FX_INT32 &e)
+{
+ CBC_OnedCodaBarReader CodaBarR;
+ CFX_ByteString data = m_chStart + contents + m_chEnd;
+ m_iContentLen = data.GetLength();
+ FX_BYTE *result = FX_Alloc(FX_BYTE, m_iWideNarrRatio * 7 * data.GetLength());
+ FX_CHAR ch;
+ FX_INT32 position = 0;
+ for (FX_INT32 index = 0; index < data.GetLength(); index++) {
+ ch = data.GetAt(index);
+ if (((ch >= 'a') && (ch <= 'z'))) {
+ ch = ch - 32;
+ }
+ switch (ch) {
+ case 'T':
+ ch = 'A';
+ break;
+ case 'N':
+ ch = 'B';
+ break;
+ case '*':
+ ch = 'C';
+ break;
+ case 'E':
+ ch = 'D';
+ break;
+ default:
+ break;
+ }
+ FX_INT32 code = 0;
+ FX_INT32 len = (FX_INT32)strlen(CodaBarR.ALPHABET_STRING);
+ for (FX_INT32 i = 0; i < len; i++) {
+ if (ch == CodaBarR.ALPHABET_STRING[i]) {
+ code = CodaBarR.CHARACTER_ENCODINGS[i];
+ break;
+ }
+ }
+ FX_BYTE color = 1;
+ FX_INT32 counter = 0;
+ FX_INT32 bit = 0;
+ while (bit < 7) {
+ result[position] = color;
+ position++;
+ if (((code >> (6 - bit)) & 1) == 0 || counter == m_iWideNarrRatio - 1) {
+ color = !color;
+ bit++;
+ counter = 0;
+ } else {
+ counter++;
+ }
+ }
+ if (index < data.GetLength() - 1) {
+ result[position] = 0;
+ position ++;
+ }
+ }
+ outLength = position;
+ return result;
+}
+CFX_WideString CBC_OnedCodaBarWriter::encodedContents(FX_WSTR contents)
+{
+ CFX_WideString strStart(m_chStart);
+ CFX_WideString strEnd(m_chEnd);
+ return strStart + contents + strEnd;
+}
+void CBC_OnedCodaBarWriter::RenderResult(FX_WSTR contents, FX_BYTE* code, FX_INT32 codeLength, FX_BOOL isDevice, FX_INT32 &e)
+{
+ CBC_OneDimWriter::RenderResult(encodedContents(contents), code, codeLength, isDevice, e);
+}
diff --git a/xfa/src/fxbarcode/oned/BC_OnedCodaBarWriter.h b/xfa/src/fxbarcode/oned/BC_OnedCodaBarWriter.h
new file mode 100644
index 0000000000..b81839ca4a
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedCodaBarWriter.h
@@ -0,0 +1,38 @@
+// 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_ONEDCODABARWRITER_H_
+#define _BC_ONEDCODABARWRITER_H_
+enum BC_TEXT_LOC;
+class CBC_OneDimWriter;
+class CBC_OnedCodaBarWriter;
+class CBC_OnedCodaBarWriter : public CBC_OneDimWriter
+{
+public:
+ CBC_OnedCodaBarWriter();
+ virtual ~CBC_OnedCodaBarWriter();
+ FX_BYTE* Encode(const CFX_ByteString &contents, FX_INT32 &outLength, 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);
+ CFX_WideString encodedContents(FX_WSTR contents);
+ FX_BOOL CheckContentValidity(FX_WSTR contents);
+ CFX_WideString FilterContents(FX_WSTR contents);
+ FX_BOOL SetStartChar(FX_CHAR start);
+ FX_BOOL SetEndChar(FX_CHAR end);
+ void SetDataLength(FX_INT32 length);
+ FX_BOOL SetTextLocation(BC_TEXT_LOC location);
+ FX_BOOL SetWideNarrowRatio(FX_INT32 ratio);
+ FX_BOOL FindChar(FX_WCHAR ch, FX_BOOL isContent);
+private:
+ void RenderResult(FX_WSTR contents, FX_BYTE* code, FX_INT32 codeLength, FX_BOOL isDevice, FX_INT32 &e);
+ const static FX_CHAR START_END_CHARS[];
+ const static FX_CHAR CONTENT_CHARS[];
+ FX_CHAR m_chStart;
+ FX_CHAR m_chEnd;
+ FX_INT32 m_iWideNarrRatio;
+
+};
+#endif
diff --git a/xfa/src/fxbarcode/oned/BC_OnedCode128Reader.cpp b/xfa/src/fxbarcode/oned/BC_OnedCode128Reader.cpp
new file mode 100644
index 0000000000..9dd9f629cf
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedCode128Reader.cpp
@@ -0,0 +1,430 @@
+// 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_Reader.h"
+#include "../common/BC_CommonBitArray.h"
+#include "BC_OneDReader.h"
+#include "BC_OnedCode128Reader.h"
+const FX_INT32 CBC_OnedCode128Reader::CODE_PATTERNS[107][7] = {
+ {2, 1, 2, 2, 2, 2, 0},
+ {2, 2, 2, 1, 2, 2, 0},
+ {2, 2, 2, 2, 2, 1, 0},
+ {1, 2, 1, 2, 2, 3, 0},
+ {1, 2, 1, 3, 2, 2, 0},
+ {1, 3, 1, 2, 2, 2, 0},
+ {1, 2, 2, 2, 1, 3, 0},
+ {1, 2, 2, 3, 1, 2, 0},
+ {1, 3, 2, 2, 1, 2, 0},
+ {2, 2, 1, 2, 1, 3, 0},
+ {2, 2, 1, 3, 1, 2, 0},
+ {2, 3, 1, 2, 1, 2, 0},
+ {1, 1, 2, 2, 3, 2, 0},
+ {1, 2, 2, 1, 3, 2, 0},
+ {1, 2, 2, 2, 3, 1, 0},
+ {1, 1, 3, 2, 2, 2, 0},
+ {1, 2, 3, 1, 2, 2, 0},
+ {1, 2, 3, 2, 2, 1, 0},
+ {2, 2, 3, 2, 1, 1, 0},
+ {2, 2, 1, 1, 3, 2, 0},
+ {2, 2, 1, 2, 3, 1, 0},
+ {2, 1, 3, 2, 1, 2, 0},
+ {2, 2, 3, 1, 1, 2, 0},
+ {3, 1, 2, 1, 3, 1, 0},
+ {3, 1, 1, 2, 2, 2, 0},
+ {3, 2, 1, 1, 2, 2, 0},
+ {3, 2, 1, 2, 2, 1, 0},
+ {3, 1, 2, 2, 1, 2, 0},
+ {3, 2, 2, 1, 1, 2, 0},
+ {3, 2, 2, 2, 1, 1, 0},
+ {2, 1, 2, 1, 2, 3, 0},
+ {2, 1, 2, 3, 2, 1, 0},
+ {2, 3, 2, 1, 2, 1, 0},
+ {1, 1, 1, 3, 2, 3, 0},
+ {1, 3, 1, 1, 2, 3, 0},
+ {1, 3, 1, 3, 2, 1, 0},
+ {1, 1, 2, 3, 1, 3, 0},
+ {1, 3, 2, 1, 1, 3, 0},
+ {1, 3, 2, 3, 1, 1, 0},
+ {2, 1, 1, 3, 1, 3, 0},
+ {2, 3, 1, 1, 1, 3, 0},
+ {2, 3, 1, 3, 1, 1, 0},
+ {1, 1, 2, 1, 3, 3, 0},
+ {1, 1, 2, 3, 3, 1, 0},
+ {1, 3, 2, 1, 3, 1, 0},
+ {1, 1, 3, 1, 2, 3, 0},
+ {1, 1, 3, 3, 2, 1, 0},
+ {1, 3, 3, 1, 2, 1, 0},
+ {3, 1, 3, 1, 2, 1, 0},
+ {2, 1, 1, 3, 3, 1, 0},
+ {2, 3, 1, 1, 3, 1, 0},
+ {2, 1, 3, 1, 1, 3, 0},
+ {2, 1, 3, 3, 1, 1, 0},
+ {2, 1, 3, 1, 3, 1, 0},
+ {3, 1, 1, 1, 2, 3, 0},
+ {3, 1, 1, 3, 2, 1, 0},
+ {3, 3, 1, 1, 2, 1, 0},
+ {3, 1, 2, 1, 1, 3, 0},
+ {3, 1, 2, 3, 1, 1, 0},
+ {3, 3, 2, 1, 1, 1, 0},
+ {3, 1, 4, 1, 1, 1, 0},
+ {2, 2, 1, 4, 1, 1, 0},
+ {4, 3, 1, 1, 1, 1, 0},
+ {1, 1, 1, 2, 2, 4, 0},
+ {1, 1, 1, 4, 2, 2, 0},
+ {1, 2, 1, 1, 2, 4, 0},
+ {1, 2, 1, 4, 2, 1, 0},
+ {1, 4, 1, 1, 2, 2, 0},
+ {1, 4, 1, 2, 2, 1, 0},
+ {1, 1, 2, 2, 1, 4, 0},
+ {1, 1, 2, 4, 1, 2, 0},
+ {1, 2, 2, 1, 1, 4, 0},
+ {1, 2, 2, 4, 1, 1, 0},
+ {1, 4, 2, 1, 1, 2, 0},
+ {1, 4, 2, 2, 1, 1, 0},
+ {2, 4, 1, 2, 1, 1, 0},
+ {2, 2, 1, 1, 1, 4, 0},
+ {4, 1, 3, 1, 1, 1, 0},
+ {2, 4, 1, 1, 1, 2, 0},
+ {1, 3, 4, 1, 1, 1, 0},
+ {1, 1, 1, 2, 4, 2, 0},
+ {1, 2, 1, 1, 4, 2, 0},
+ {1, 2, 1, 2, 4, 1, 0},
+ {1, 1, 4, 2, 1, 2, 0},
+ {1, 2, 4, 1, 1, 2, 0},
+ {1, 2, 4, 2, 1, 1, 0},
+ {4, 1, 1, 2, 1, 2, 0},
+ {4, 2, 1, 1, 1, 2, 0},
+ {4, 2, 1, 2, 1, 1, 0},
+ {2, 1, 2, 1, 4, 1, 0},
+ {2, 1, 4, 1, 2, 1, 0},
+ {4, 1, 2, 1, 2, 1, 0},
+ {1, 1, 1, 1, 4, 3, 0},
+ {1, 1, 1, 3, 4, 1, 0},
+ {1, 3, 1, 1, 4, 1, 0},
+ {1, 1, 4, 1, 1, 3, 0},
+ {1, 1, 4, 3, 1, 1, 0},
+ {4, 1, 1, 1, 1, 3, 0},
+ {4, 1, 1, 3, 1, 1, 0},
+ {1, 1, 3, 1, 4, 1, 0},
+ {1, 1, 4, 1, 3, 1, 0},
+ {3, 1, 1, 1, 4, 1, 0},
+ {4, 1, 1, 1, 3, 1, 0},
+ {2, 1, 1, 4, 1, 2, 0},
+ {2, 1, 1, 2, 1, 4, 0},
+ {2, 1, 1, 2, 3, 2, 0},
+ {2, 3, 3, 1, 1, 1, 2}
+};
+const FX_INT32 CBC_OnedCode128Reader::MAX_AVG_VARIANCE = (FX_INT32) (256 * 0.25f);
+const FX_INT32 CBC_OnedCode128Reader::MAX_INDIVIDUAL_VARIANCE = (FX_INT32) (256 * 0.7f);
+const FX_INT32 CBC_OnedCode128Reader::CODE_SHIFT = 98;
+const FX_INT32 CBC_OnedCode128Reader::CODE_CODE_C = 99;
+const FX_INT32 CBC_OnedCode128Reader::CODE_CODE_B = 100;
+const FX_INT32 CBC_OnedCode128Reader::CODE_CODE_A = 101;
+const FX_INT32 CBC_OnedCode128Reader::CODE_FNC_1 = 102;
+const FX_INT32 CBC_OnedCode128Reader::CODE_FNC_2 = 97;
+const FX_INT32 CBC_OnedCode128Reader::CODE_FNC_3 = 96;
+const FX_INT32 CBC_OnedCode128Reader::CODE_FNC_4_A = 101;
+const FX_INT32 CBC_OnedCode128Reader::CODE_FNC_4_B = 100;
+const FX_INT32 CBC_OnedCode128Reader::CODE_START_A = 103;
+const FX_INT32 CBC_OnedCode128Reader::CODE_START_B = 104;
+const FX_INT32 CBC_OnedCode128Reader::CODE_START_C = 105;
+const FX_INT32 CBC_OnedCode128Reader::CODE_STOP = 106;
+CBC_OnedCode128Reader::CBC_OnedCode128Reader()
+{
+}
+CBC_OnedCode128Reader::~CBC_OnedCode128Reader()
+{
+}
+CFX_Int32Array *CBC_OnedCode128Reader::FindStartPattern(CBC_CommonBitArray *row, FX_INT32 &e)
+{
+ FX_INT32 width = row->GetSize();
+ FX_INT32 rowOffset = 0;
+ while (rowOffset < width) {
+ if (row->Get(rowOffset)) {
+ break;
+ }
+ rowOffset++;
+ }
+ FX_INT32 counterPosition = 0;
+ CFX_Int32Array counters;
+ counters.SetSize(6);
+ FX_INT32 patternStart = rowOffset;
+ FX_BOOL isWhite = FALSE;
+ FX_INT32 patternLength = counters.GetSize();
+ for (FX_INT32 i = rowOffset; i < width; i++) {
+ FX_BOOL pixel = row->Get(i);
+ if (pixel ^ isWhite) {
+ counters[counterPosition]++;
+ } else {
+ if (counterPosition == patternLength - 1) {
+ FX_INT32 bestVariance = MAX_AVG_VARIANCE;
+ FX_INT32 bestMatch = -1;
+ for (FX_INT32 startCode = CODE_START_A; startCode <= CODE_START_C; startCode++) {
+ FX_INT32 variance = PatternMatchVariance(&counters, &CODE_PATTERNS[startCode][0], MAX_INDIVIDUAL_VARIANCE);
+ if (variance < bestVariance) {
+ bestVariance = variance;
+ bestMatch = startCode;
+ }
+ }
+ if (bestMatch >= 0) {
+ FX_BOOL btemp2 = row->IsRange(FX_MAX(0, patternStart - (i - patternStart) / 2), patternStart, FALSE, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ if (btemp2) {
+ CFX_Int32Array *result = FX_NEW CFX_Int32Array;
+ result->SetSize(3);
+ (*result)[0] = patternStart;
+ (*result)[1] = i;
+ (*result)[2] = bestMatch;
+ return result;
+ }
+ }
+ patternStart += counters[0] + counters[1];
+ for (FX_INT32 y = 2; y < patternLength; y++) {
+ counters[y - 2] = counters[y];
+ }
+ counters[patternLength - 2] = 0;
+ counters[patternLength - 1] = 0;
+ counterPosition--;
+ } else {
+ counterPosition++;
+ }
+ counters[counterPosition] = 1;
+ isWhite = !isWhite;
+ }
+ }
+ e = BCExceptionNotFound;
+ return NULL;
+}
+FX_INT32 CBC_OnedCode128Reader::DecodeCode(CBC_CommonBitArray *row, CFX_Int32Array *counters, FX_INT32 rowOffset, FX_INT32 &e)
+{
+ RecordPattern(row, rowOffset, counters, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, 0);
+ FX_INT32 bestVariance = MAX_AVG_VARIANCE;
+ FX_INT32 bestMatch = -1;
+ for (FX_INT32 d = 0; d < 107; d++) {
+ FX_INT32 variance = PatternMatchVariance(counters, &CODE_PATTERNS[d][0], MAX_INDIVIDUAL_VARIANCE);
+ if (variance < bestVariance) {
+ bestVariance = variance;
+ bestMatch = d;
+ }
+ }
+ if (bestMatch >= 0) {
+ return bestMatch;
+ } else {
+ e = BCExceptionNotFound;
+ return 0;
+ }
+ return 0;
+}
+CFX_ByteString CBC_OnedCode128Reader::DecodeRow(FX_INT32 rowNumber, CBC_CommonBitArray *row, FX_INT32 hints, FX_INT32 &e)
+{
+ CFX_Int32Array *startPatternInfo = FindStartPattern(row, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ FX_INT32 startCode = (*startPatternInfo)[2];
+ FX_INT32 codeSet;
+ switch (startCode) {
+ case 103:
+ codeSet = CODE_CODE_A;
+ break;
+ case 104:
+ codeSet = CODE_CODE_B;
+ break;
+ case 105:
+ codeSet = CODE_CODE_C;
+ break;
+ default:
+ if(startPatternInfo != NULL) {
+ startPatternInfo->RemoveAll();
+ delete startPatternInfo;
+ startPatternInfo = NULL;
+ }
+ e = BCExceptionFormatException;
+ return "";
+ }
+ FX_BOOL done = FALSE;
+ FX_BOOL isNextShifted = FALSE;
+ CFX_ByteString result;
+ FX_INT32 lastStart = (*startPatternInfo)[0];
+ FX_INT32 nextStart = (*startPatternInfo)[1];
+ if(startPatternInfo != NULL) {
+ startPatternInfo->RemoveAll();
+ delete startPatternInfo;
+ startPatternInfo = NULL;
+ }
+ CFX_Int32Array counters;
+ counters.SetSize(6);
+ FX_INT32 lastCode = 0;
+ FX_INT32 code = 0;
+ FX_INT32 checksumTotal = startCode;
+ FX_INT32 multiplier = 0;
+ FX_BOOL lastCharacterWasPrintable = TRUE;
+ while (!done) {
+ FX_BOOL unshift = isNextShifted;
+ isNextShifted = FALSE;
+ lastCode = code;
+ code = DecodeCode(row, &counters, nextStart, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ if (code != CODE_STOP) {
+ lastCharacterWasPrintable = TRUE;
+ }
+ if (code != CODE_STOP) {
+ multiplier++;
+ checksumTotal += multiplier * code;
+ }
+ lastStart = nextStart;
+ for (FX_INT32 i = 0; i < counters.GetSize(); i++) {
+ nextStart += counters[i];
+ }
+ switch (code) {
+ case 103:
+ case 104:
+ case 105:
+ e = BCExceptionFormatException;
+ return "";
+ }
+ switch (codeSet) {
+ case 101:
+ if (code < 64) {
+ result += (FX_CHAR) (' ' + code);
+ } else if (code < 96) {
+ result += (FX_CHAR) (code - 64);
+ } else {
+ if (code != CODE_STOP) {
+ lastCharacterWasPrintable = FALSE;
+ }
+ switch (code) {
+ case 102:
+ case 97:
+ case 96:
+ case 101:
+ break;
+ case 98:
+ isNextShifted = TRUE;
+ codeSet = CODE_CODE_B;
+ break;
+ case 100:
+ codeSet = CODE_CODE_B;
+ break;
+ case 99:
+ codeSet = CODE_CODE_C;
+ break;
+ case 106:
+ done = TRUE;
+ break;
+ }
+ }
+ break;
+ case 100:
+ if (code < 96) {
+ result += (FX_CHAR) (' ' + code);
+ } else {
+ if (code != CODE_STOP) {
+ lastCharacterWasPrintable = FALSE;
+ }
+ switch (code) {
+ case 102:
+ case 97:
+ case 96:
+ case 100:
+ break;
+ case 98:
+ isNextShifted = TRUE;
+ codeSet = CODE_CODE_A;
+ break;
+ case 101:
+ codeSet = CODE_CODE_A;
+ break;
+ case 99:
+ codeSet = CODE_CODE_C;
+ break;
+ case 106:
+ done = TRUE;
+ break;
+ }
+ }
+ break;
+ case 99:
+ if (code < 100) {
+ if (code < 10) {
+ result += '0';
+ }
+ FX_CHAR temp[128];
+#if defined(_FX_WINAPI_PARTITION_APP_)
+ sprintf_s(temp, 128, "%d", code);
+#else
+ sprintf(temp, "%d", code);
+#endif
+ result += temp;
+ } else {
+ if (code != CODE_STOP) {
+ lastCharacterWasPrintable = FALSE;
+ }
+ switch (code) {
+ case 102:
+ break;
+ case 101:
+ codeSet = CODE_CODE_A;
+ break;
+ case 100:
+ codeSet = CODE_CODE_B;
+ break;
+ case 106:
+ done = TRUE;
+ break;
+ }
+ }
+ break;
+ }
+ if (unshift) {
+ codeSet = codeSet == CODE_CODE_A ? CODE_CODE_B : CODE_CODE_A;
+ }
+ }
+ FX_INT32 width = row->GetSize();
+ while (nextStart < width && row->Get(nextStart)) {
+ nextStart++;
+ }
+ FX_BOOL boolT1 = row->IsRange(nextStart, FX_MIN(width, nextStart + (nextStart - lastStart) / 2), FALSE, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ if (!boolT1) {
+ e = BCExceptionNotFound;
+ return "";
+ }
+ checksumTotal -= multiplier * lastCode;
+ if (checksumTotal % 103 != lastCode) {
+ e = BCExceptionChecksumException;
+ return "";
+ }
+ FX_INT32 resultLength = result.GetLength();
+ if (resultLength > 0 && lastCharacterWasPrintable) {
+ if (codeSet == CODE_CODE_C) {
+ result = result.Mid(0, result.GetLength() - 2);
+ } else {
+ result = result.Mid(0, result.GetLength() - 1);
+ }
+ }
+ if (result.GetLength() == 0) {
+ e = BCExceptionFormatException;
+ return "";
+ }
+ return result;
+}
diff --git a/xfa/src/fxbarcode/oned/BC_OnedCode128Reader.h b/xfa/src/fxbarcode/oned/BC_OnedCode128Reader.h
new file mode 100644
index 0000000000..94e1a6388b
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedCode128Reader.h
@@ -0,0 +1,40 @@
+// 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_ONEDCODA128READER_H_
+#define _BC_ONEDCODA128READER_H_
+class CBC_OneDReader;
+class CBC_CommonBitArray;
+class CBC_OnedCoda128Reader;
+class CBC_OnedCode128Reader : public CBC_OneDReader
+{
+public:
+ CBC_OnedCode128Reader();
+ virtual ~CBC_OnedCode128Reader();
+ virtual CFX_ByteString DecodeRow(FX_INT32 rowNumber, CBC_CommonBitArray *row, FX_INT32 hints, FX_INT32 &e);
+ const static FX_INT32 CODE_PATTERNS[107][7];
+ const static FX_INT32 MAX_AVG_VARIANCE;
+ const static FX_INT32 MAX_INDIVIDUAL_VARIANCE;
+
+ const static FX_INT32 CODE_SHIFT;
+ const static FX_INT32 CODE_CODE_C;
+ const static FX_INT32 CODE_CODE_B;
+ const static FX_INT32 CODE_CODE_A;
+ const static FX_INT32 CODE_FNC_1;
+ const static FX_INT32 CODE_FNC_2;
+ const static FX_INT32 CODE_FNC_3;
+ const static FX_INT32 CODE_FNC_4_A;
+ const static FX_INT32 CODE_FNC_4_B ;
+
+ const static FX_INT32 CODE_START_A;
+ const static FX_INT32 CODE_START_B;
+ const static FX_INT32 CODE_START_C;
+ const static FX_INT32 CODE_STOP;
+private:
+ CFX_Int32Array *FindStartPattern(CBC_CommonBitArray *row, FX_INT32 &e);
+ FX_INT32 DecodeCode(CBC_CommonBitArray *row, CFX_Int32Array *counters, FX_INT32 rowOffset, FX_INT32 &e);
+};
+#endif
diff --git a/xfa/src/fxbarcode/oned/BC_OnedCode128Writer.cpp b/xfa/src/fxbarcode/oned/BC_OnedCode128Writer.cpp
new file mode 100644
index 0000000000..6dd3cbe8a5
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedCode128Writer.cpp
@@ -0,0 +1,230 @@
+// 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 2010 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_Reader.h"
+#include "BC_OneDReader.h"
+#include "BC_OneDimWriter.h"
+#include "BC_OnedCode128Reader.h"
+#include "BC_OnedCode128Writer.h"
+const FX_INT32 CBC_OnedCode128Writer::CODE_CODE_B = 100;
+const FX_INT32 CBC_OnedCode128Writer::CODE_CODE_C = 99;
+const FX_INT32 CBC_OnedCode128Writer::CODE_START_B = 104;
+const FX_INT32 CBC_OnedCode128Writer::CODE_START_C = 105;
+const FX_INT32 CBC_OnedCode128Writer::CODE_STOP = 106;
+CBC_OnedCode128Writer::CBC_OnedCode128Writer()
+{
+ m_codeFormat = BC_CODE128_B;
+}
+CBC_OnedCode128Writer::CBC_OnedCode128Writer(BC_TYPE type)
+{
+ m_codeFormat = type;
+}
+CBC_OnedCode128Writer::~CBC_OnedCode128Writer()
+{
+}
+BC_TYPE CBC_OnedCode128Writer::GetType()
+{
+ return m_codeFormat;
+}
+FX_BOOL CBC_OnedCode128Writer::CheckContentValidity(FX_WSTR contents)
+{
+ FX_BOOL ret = TRUE;
+ FX_INT32 position = 0;
+ FX_INT32 patternIndex = -1;
+ if (m_codeFormat == BC_CODE128_B || m_codeFormat == BC_CODE128_C) {
+ while (position < contents.GetLength()) {
+ patternIndex = (FX_INT32)contents.GetAt(position);
+ if (patternIndex >= 32 && patternIndex <= 126 && patternIndex != 34) {
+ position++;
+ continue;
+ } else {
+ ret = FALSE;
+ break;
+ }
+ position ++;
+ }
+ } else {
+ ret = FALSE;
+ }
+ return ret;
+}
+CFX_WideString CBC_OnedCode128Writer::FilterContents(FX_WSTR contents)
+{
+ CFX_WideString filterChineseChar;
+ FX_WCHAR ch;
+ for (FX_INT32 i = 0; i < contents.GetLength(); i++) {
+ ch = contents.GetAt(i);
+ if(ch > 175) {
+ i++;
+ continue;
+ }
+ filterChineseChar += ch;
+ }
+ CFX_WideString filtercontents;
+ if (m_codeFormat == BC_CODE128_B) {
+ for (FX_INT32 i = 0; i < filterChineseChar.GetLength(); i++) {
+ ch = filterChineseChar.GetAt(i);
+ if (ch >= 32 && ch <= 126) {
+ filtercontents += ch;
+ } else {
+ continue;
+ }
+ }
+ } else if (m_codeFormat == BC_CODE128_C) {
+ for (FX_INT32 i = 0; i < filterChineseChar.GetLength(); i++) {
+ ch = filterChineseChar.GetAt(i);
+ if (ch >= 32 && ch <= 106) {
+ filtercontents += ch;
+ } else {
+ continue;
+ }
+ }
+ } else {
+ filtercontents = contents;
+ }
+ return filtercontents;
+}
+FX_BOOL CBC_OnedCode128Writer::SetTextLocation(BC_TEXT_LOC location)
+{
+ if ( location < BC_TEXT_LOC_NONE || location > BC_TEXT_LOC_BELOWEMBED) {
+ return FALSE;
+ }
+ m_locTextLoc = location;
+ return TRUE;
+}
+FX_BYTE *CBC_OnedCode128Writer::Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 hints, FX_INT32 &e)
+{
+ if(format != BCFORMAT_CODE_128) {
+ e = BCExceptionOnlyEncodeCODE_128;
+ return NULL;
+ }
+ FX_BYTE *ret = CBC_OneDimWriter::Encode(contents, format, outWidth, outHeight, hints, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return ret;
+}
+FX_BYTE *CBC_OnedCode128Writer::Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 &e)
+{
+ FX_BYTE *ret = Encode(contents, format, outWidth, outHeight, 0, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return ret;
+}
+FX_BOOL CBC_OnedCode128Writer::IsDigits(const CFX_ByteString &contents, FX_INT32 start, FX_INT32 length)
+{
+ FX_INT32 end = start + length;
+ for (FX_INT32 i = start; i < end; i++) {
+ if (contents[i] < '0' || contents[i] > '9') {
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+FX_BYTE *CBC_OnedCode128Writer::Encode(const CFX_ByteString &contents, FX_INT32 &outLength, FX_INT32 &e)
+{
+ FX_INT32 length = contents.GetLength();
+ if(contents.GetLength() < 1 || contents.GetLength() > 80) {
+ e = BCExceptionContentsLengthShouldBetween1and80;
+ return NULL;
+ }
+ CFX_PtrArray patterns;
+ FX_INT32 checkSum = 0;
+ if (m_codeFormat == BC_CODE128_B) {
+ checkSum = Encode128B(contents, patterns);
+ } else if (m_codeFormat == BC_CODE128_C) {
+ checkSum = Encode128C(contents, patterns);
+ } else {
+ e = BCExceptionFormatException;
+ return NULL;
+ }
+ checkSum %= 103;
+ patterns.Add((FX_INT32*)CBC_OnedCode128Reader::CODE_PATTERNS[checkSum]);
+ patterns.Add((FX_INT32*)CBC_OnedCode128Reader::CODE_PATTERNS[CODE_STOP]);
+ m_iContentLen = contents.GetLength() + 3;
+ FX_INT32 codeWidth = 0;
+ for(FX_INT32 k = 0; k < patterns.GetSize(); k++) {
+ FX_INT32 *pattern = (FX_INT32*)patterns[k];
+ for(FX_INT32 j = 0; j < 7; j++) {
+ codeWidth += pattern[j];
+ }
+ }
+ outLength = codeWidth;
+ FX_BYTE *result = FX_Alloc(FX_BYTE, outLength);
+ FX_INT32 pos = 0;
+ for(FX_INT32 j = 0; j < patterns.GetSize(); j++) {
+ FX_INT32* pattern = (FX_INT32*)patterns[j];
+ pos += AppendPattern(result, pos, pattern, 7, 1, e);
+ if (e != BCExceptionNO) {
+ FX_Free (result);
+ return NULL;
+ }
+ }
+ return result;
+}
+FX_INT32 CBC_OnedCode128Writer::Encode128B(const CFX_ByteString &contents, CFX_PtrArray &patterns)
+{
+ FX_INT32 checkSum = 0;
+ FX_INT32 checkWeight = 1;
+ FX_INT32 position = 0;
+ patterns.Add((FX_INT32*)CBC_OnedCode128Reader::CODE_PATTERNS[CODE_START_B]);
+ checkSum += CODE_START_B * checkWeight;
+ while (position < contents.GetLength()) {
+ FX_INT32 patternIndex = 0;
+ patternIndex = contents[position] - ' ';
+ position += 1;
+ patterns.Add((FX_INT32*)CBC_OnedCode128Reader::CODE_PATTERNS[patternIndex]);
+ checkSum += patternIndex * checkWeight;
+ if (position != 0) {
+ checkWeight++;
+ }
+ }
+ return checkSum;
+}
+FX_INT32 CBC_OnedCode128Writer::Encode128C(const CFX_ByteString &contents, CFX_PtrArray &patterns)
+{
+ FX_INT32 checkSum = 0;
+ FX_INT32 checkWeight = 1;
+ FX_INT32 position = 0;
+ patterns.Add((FX_INT32*)CBC_OnedCode128Reader::CODE_PATTERNS[CODE_START_C]);
+ checkSum += CODE_START_C * checkWeight;
+ while (position < contents.GetLength()) {
+ FX_INT32 patternIndex = 0;
+ FX_CHAR ch = contents.GetAt(position);
+ if (ch < '0' || ch > '9') {
+ patternIndex = (FX_INT32)ch;
+ position++;
+ } else {
+ patternIndex = FXSYS_atoi(contents.Mid(position, 2));
+ if (contents.GetAt(position + 1) < '0' || contents.GetAt(position + 1) > '9') {
+ position += 1;
+ } else {
+ position += 2;
+ }
+ }
+ patterns.Add((FX_INT32*)CBC_OnedCode128Reader::CODE_PATTERNS[patternIndex]);
+ checkSum += patternIndex * checkWeight;
+ if (position != 0) {
+ checkWeight++;
+ }
+ }
+ return checkSum;
+}
diff --git a/xfa/src/fxbarcode/oned/BC_OnedCode128Writer.h b/xfa/src/fxbarcode/oned/BC_OnedCode128Writer.h
new file mode 100644
index 0000000000..daa48eca51
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedCode128Writer.h
@@ -0,0 +1,37 @@
+// 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_ONEDCODA128WRITER_H_
+#define _BC_ONEDCODA128WRITER_H_
+class CBC_OneDimWriter;
+class CBC_OnedCoda128Writer;
+class CBC_OnedCode128Writer : public CBC_OneDimWriter
+{
+public:
+ CBC_OnedCode128Writer();
+ CBC_OnedCode128Writer(BC_TYPE type);
+ virtual ~CBC_OnedCode128Writer();
+ FX_BYTE * Encode(const CFX_ByteString &contents, BCFORMAT format,
+ FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 hints, 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, FX_INT32 &outLength , FX_INT32 &e);
+ FX_BOOL CheckContentValidity(FX_WSTR contents);
+ CFX_WideString FilterContents(FX_WSTR contents);
+ FX_BOOL SetTextLocation(BC_TEXT_LOC location);
+ BC_TYPE GetType();
+private:
+ FX_BOOL IsDigits(const CFX_ByteString &contents, FX_INT32 start, FX_INT32 length);
+ FX_INT32 Encode128B(const CFX_ByteString &contents, CFX_PtrArray &patterns);
+ FX_INT32 Encode128C(const CFX_ByteString &contents, CFX_PtrArray &patterns);
+ BC_TYPE m_codeFormat;
+ const static FX_INT32 CODE_START_B;
+ const static FX_INT32 CODE_START_C;
+ const static FX_INT32 CODE_CODE_B;
+ const static FX_INT32 CODE_CODE_C;
+ const static FX_INT32 CODE_STOP;
+};
+#endif
diff --git a/xfa/src/fxbarcode/oned/BC_OnedCode39Reader.cpp b/xfa/src/fxbarcode/oned/BC_OnedCode39Reader.cpp
new file mode 100644
index 0000000000..b19343943b
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedCode39Reader.cpp
@@ -0,0 +1,293 @@
+// 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_Reader.h"
+#include "../common/BC_CommonBitArray.h"
+#include "BC_OneDReader.h"
+#include "BC_OnedCode39Reader.h"
+FX_LPCSTR CBC_OnedCode39Reader::ALPHABET_STRING = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *$/+%";
+FX_LPCSTR CBC_OnedCode39Reader::CHECKSUM_STRING = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%";
+const FX_INT32 CBC_OnedCode39Reader::CHARACTER_ENCODINGS[44] = {
+ 0x034, 0x121, 0x061, 0x160, 0x031, 0x130, 0x070, 0x025, 0x124, 0x064,
+ 0x109, 0x049, 0x148, 0x019, 0x118, 0x058, 0x00D, 0x10C, 0x04C, 0x01C,
+ 0x103, 0x043, 0x142, 0x013, 0x112, 0x052, 0x007, 0x106, 0x046, 0x016,
+ 0x181, 0x0C1, 0x1C0, 0x091, 0x190, 0x0D0, 0x085, 0x184, 0x0C4, 0x094,
+ 0x0A8, 0x0A2, 0x08A, 0x02A
+};
+const FX_INT32 CBC_OnedCode39Reader::ASTERISK_ENCODING = 0x094;
+CBC_OnedCode39Reader::CBC_OnedCode39Reader(): m_extendedMode(FALSE), m_usingCheckDigit(FALSE)
+{
+}
+CBC_OnedCode39Reader::CBC_OnedCode39Reader(FX_BOOL usingCheckDigit)
+{
+ m_usingCheckDigit = usingCheckDigit;
+ m_extendedMode = FALSE;
+}
+CBC_OnedCode39Reader::CBC_OnedCode39Reader(FX_BOOL usingCheckDigit, FX_BOOL extendedMode)
+{
+ m_extendedMode = extendedMode;
+ m_usingCheckDigit = usingCheckDigit;
+}
+CBC_OnedCode39Reader::~CBC_OnedCode39Reader()
+{
+}
+CFX_ByteString CBC_OnedCode39Reader::DecodeRow(FX_INT32 rowNumber, CBC_CommonBitArray *row, FX_INT32 hints, FX_INT32 &e)
+{
+ CFX_Int32Array *start = FindAsteriskPattern(row, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ FX_INT32 nextStart = (*start)[1];
+ if(start != NULL) {
+ delete start;
+ start = NULL;
+ }
+ FX_INT32 end = row->GetSize();
+ while (nextStart < end && !row->Get(nextStart)) {
+ nextStart++;
+ }
+ CFX_ByteString result;
+ CFX_Int32Array counters;
+ counters.SetSize(9);
+ FX_CHAR decodedChar;
+ FX_INT32 lastStart;
+ do {
+ RecordPattern(row, nextStart, &counters, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ FX_INT32 pattern = ToNarrowWidePattern(&counters);
+ if (pattern < 0) {
+ e = BCExceptionNotFound;
+ return "";
+ }
+ decodedChar = PatternToChar(pattern, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ result += decodedChar;
+ lastStart = nextStart;
+ for (FX_INT32 i = 0; i < counters.GetSize(); i++) {
+ nextStart += counters[i];
+ }
+ while (nextStart < end && !row->Get(nextStart)) {
+ nextStart++;
+ }
+ } while (decodedChar != '*');
+ result = result.Mid(0, result.GetLength() - 1);
+ FX_INT32 lastPatternSize = 0;
+ for (FX_INT32 j = 0; j < counters.GetSize(); j++) {
+ lastPatternSize += counters[j];
+ }
+ FX_INT32 whiteSpaceAfterEnd = nextStart - lastStart - lastPatternSize;
+ if(m_usingCheckDigit) {
+ FX_INT32 max = result.GetLength() - 1;
+ FX_INT32 total = 0;
+ FX_INT32 len = (FX_INT32)strlen(ALPHABET_STRING);
+ for (FX_INT32 k = 0; k < max; k++) {
+ for (FX_INT32 j = 0; j < len; j++)
+ if (ALPHABET_STRING[j] == result[k]) {
+ total += j;
+ }
+ }
+ if (result[max] != (ALPHABET_STRING)[total % 43]) {
+ e = BCExceptionChecksumException;
+ return "";
+ }
+ result = result.Mid(0, result.GetLength() - 1);
+ }
+ if (result.GetLength() == 0) {
+ e = BCExceptionNotFound;
+ return "";
+ }
+ if(m_extendedMode) {
+ CFX_ByteString bytestr = DecodeExtended(result, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ return bytestr;
+ } else {
+ return result;
+ }
+}
+CFX_Int32Array *CBC_OnedCode39Reader::FindAsteriskPattern(CBC_CommonBitArray *row, FX_INT32 &e)
+{
+ FX_INT32 width = row->GetSize();
+ FX_INT32 rowOffset = 0;
+ while (rowOffset < width) {
+ if (row->Get(rowOffset)) {
+ break;
+ }
+ rowOffset++;
+ }
+ FX_INT32 counterPosition = 0;
+ CFX_Int32Array counters;
+ counters.SetSize(9);
+ FX_INT32 patternStart = rowOffset;
+ FX_BOOL isWhite = FALSE;
+ FX_INT32 patternLength = counters.GetSize();
+ for (FX_INT32 i = rowOffset; i < width; i++) {
+ FX_BOOL pixel = row->Get(i);
+ if (pixel ^ isWhite) {
+ counters[counterPosition]++;
+ } else {
+ if (counterPosition == patternLength - 1) {
+ if (ToNarrowWidePattern(&counters) == ASTERISK_ENCODING) {
+ FX_BOOL bT1 = row->IsRange(FX_MAX(0, patternStart - (i - patternStart) / 2), patternStart, FALSE, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ if (bT1) {
+ CFX_Int32Array *result = FX_NEW CFX_Int32Array;
+ result->SetSize(2);
+ (*result)[0] = patternStart;
+ (*result)[1] = i;
+ return result;
+ }
+ }
+ patternStart += counters[0] + counters[1];
+ for (FX_INT32 y = 2; y < patternLength; y++) {
+ counters[y - 2] = counters[y];
+ }
+ counters[patternLength - 2] = 0;
+ counters[patternLength - 1] = 0;
+ counterPosition--;
+ } else {
+ counterPosition++;
+ }
+ counters[counterPosition] = 1;
+ isWhite = !isWhite;
+ }
+ }
+ e = BCExceptionNotFound;
+ return NULL;
+}
+FX_INT32 CBC_OnedCode39Reader::ToNarrowWidePattern(CFX_Int32Array *counters)
+{
+ FX_INT32 numCounters = counters->GetSize();
+ FX_INT32 maxNarrowCounter = 0;
+ FX_INT32 wideCounters;
+ do {
+#undef max
+ FX_INT32 minCounter = FXSYS_IntMax;
+ for (FX_INT32 i = 0; i < numCounters; i++) {
+ FX_INT32 counter = (*counters)[i];
+ if (counter < minCounter && counter > maxNarrowCounter) {
+ minCounter = counter;
+ }
+ }
+ maxNarrowCounter = minCounter;
+ wideCounters = 0;
+ FX_INT32 totalWideCountersWidth = 0;
+ FX_INT32 pattern = 0;
+ for (FX_INT32 j = 0; j < numCounters; j++) {
+ FX_INT32 counter = (*counters)[j];
+ if ((*counters)[j] > maxNarrowCounter) {
+ pattern |= 1 << (numCounters - 1 - j);
+ wideCounters++;
+ totalWideCountersWidth += counter;
+ }
+ }
+ if (wideCounters == 3) {
+ for (FX_INT32 k = 0; k < numCounters && wideCounters > 0; k++) {
+ FX_INT32 counter = (*counters)[k];
+ if ((*counters)[k] > maxNarrowCounter) {
+ wideCounters--;
+ if ((counter << 1) >= totalWideCountersWidth) {
+ return -1;
+ }
+ }
+ }
+ return pattern;
+ }
+ } while (wideCounters > 3);
+ return -1;
+}
+FX_CHAR CBC_OnedCode39Reader::PatternToChar(FX_INT32 pattern, FX_INT32 &e)
+{
+ for (FX_INT32 i = 0; i < 44; i++) {
+ if (CHARACTER_ENCODINGS[i] == pattern) {
+ return (ALPHABET_STRING)[i];
+ }
+ }
+ e = BCExceptionNotFound;
+ return 0;
+}
+CFX_ByteString CBC_OnedCode39Reader::DecodeExtended(CFX_ByteString &encoded, FX_INT32 &e)
+{
+ FX_INT32 length = encoded.GetLength();
+ CFX_ByteString decoded;
+ FX_CHAR c, next;
+ for(FX_INT32 i = 0; i < length; i++) {
+ c = encoded[i];
+ if(c == '+' || c == '$' || c == '%' || c == '/') {
+ next = encoded[i + 1];
+ FX_CHAR decodedChar = '\0';
+ switch (c) {
+ case '+':
+ if (next >= 'A' && next <= 'Z') {
+ decodedChar = (FX_CHAR) (next + 32);
+ } else {
+ e = BCExceptionFormatException;
+ return "";
+ }
+ break;
+ case '$':
+ if (next >= 'A' && next <= 'Z') {
+ decodedChar = (FX_CHAR) (next - 64);
+ } else {
+ e = BCExceptionFormatException;
+ return "";
+ }
+ break;
+ case '%':
+ if (next >= 'A' && next <= 'E') {
+ decodedChar = (FX_CHAR) (next - 38);
+ } else if (next >= 'F' && next <= 'J') {
+ decodedChar = (FX_CHAR) (next - 11);
+ } else if (next >= 'K' && next <= 'O' && next != 'M' && next != 'N') {
+ decodedChar = (FX_CHAR) (next + 16);
+ } else if (next >= 'P' && next <= 'S') {
+ decodedChar = (FX_CHAR) (next + 43);
+ } else if (next == 'U') {
+ decodedChar = (FX_CHAR) 0;
+ } else if (next == 'V') {
+ decodedChar = (FX_CHAR) 64;
+ } else if (next == 'W') {
+ decodedChar = (FX_CHAR) 96;
+ } else if (next == 'T' || next == 'X' || next == 'Y' || next == 'Z') {
+ decodedChar = (FX_CHAR) 127;
+ } else {
+ e = BCExceptionFormatException;
+ return "";
+ }
+ break;
+ case '/':
+ if (next >= 'A' && next <= 'O') {
+ decodedChar = (FX_CHAR) (next - 32);
+ } else if (next == 'Z') {
+ decodedChar = ':';
+ } else {
+ e = BCExceptionFormatException;
+ return "";
+ }
+ break;
+ }
+ decoded += decodedChar;
+ i++;
+ } else {
+ decoded += c;
+ }
+ }
+ return decoded;
+}
diff --git a/xfa/src/fxbarcode/oned/BC_OnedCode39Reader.h b/xfa/src/fxbarcode/oned/BC_OnedCode39Reader.h
new file mode 100644
index 0000000000..81fd6b79e9
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedCode39Reader.h
@@ -0,0 +1,32 @@
+// 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_ONEDCODA39READER_H_
+#define _BC_ONEDCODA39READER_H_
+class CBC_OneDReader;
+class CBC_CommonBitArray;
+class CBC_OnedCoda39Reader;
+class CBC_OnedCode39Reader : public CBC_OneDReader
+{
+public:
+ static FX_LPCSTR ALPHABET_STRING;
+ static FX_LPCSTR CHECKSUM_STRING;
+ const static FX_INT32 CHARACTER_ENCODINGS[44];
+ const static FX_INT32 ASTERISK_ENCODING;
+ CBC_OnedCode39Reader();
+ CBC_OnedCode39Reader(FX_BOOL usingCheckDigit);
+ CBC_OnedCode39Reader(FX_BOOL usingCheckDigit, FX_BOOL extendedMode);
+ virtual ~CBC_OnedCode39Reader();
+ CFX_ByteString DecodeRow(FX_INT32 rowNumber, CBC_CommonBitArray *row, FX_INT32 hints, FX_INT32 &e);
+private:
+ FX_BOOL m_usingCheckDigit;
+ FX_BOOL m_extendedMode;
+ CFX_Int32Array *FindAsteriskPattern(CBC_CommonBitArray *row, FX_INT32 &e);
+ FX_INT32 ToNarrowWidePattern(CFX_Int32Array *counters);
+ FX_CHAR PatternToChar(FX_INT32 pattern, FX_INT32 &e);
+ CFX_ByteString DecodeExtended(CFX_ByteString &encoded, FX_INT32 &e);
+};
+#endif
diff --git a/xfa/src/fxbarcode/oned/BC_OnedCode39Writer.cpp b/xfa/src/fxbarcode/oned/BC_OnedCode39Writer.cpp
new file mode 100644
index 0000000000..d9c77460ac
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedCode39Writer.cpp
@@ -0,0 +1,351 @@
+// 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 2010 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_Reader.h"
+#include "../common/BC_CommonBitMatrix.h"
+#include "BC_OneDReader.h"
+#include "BC_OneDimWriter.h"
+#include "BC_OnedCode39Reader.h"
+#include "BC_OnedCode39Writer.h"
+CBC_OnedCode39Writer::CBC_OnedCode39Writer()
+{
+ m_extendedMode = FALSE;
+ m_iWideNarrRatio = 3;
+}
+CBC_OnedCode39Writer::CBC_OnedCode39Writer(FX_BOOL extendedMode)
+{
+ m_iWideNarrRatio = 3;
+ m_extendedMode = extendedMode;
+}
+CBC_OnedCode39Writer::~CBC_OnedCode39Writer()
+{
+}
+FX_BOOL CBC_OnedCode39Writer::CheckContentValidity(FX_WSTR contents)
+{
+ if (m_extendedMode) {
+ return CheckExtendedContentValidity(contents);
+ }
+ for(FX_INT32 i = 0; i < contents.GetLength(); i++) {
+ FX_WCHAR ch = contents.GetAt(i);
+ if ((ch >= (FX_WCHAR)'0' && ch <= (FX_WCHAR)'9') || (ch >= (FX_WCHAR)'A' && ch <= (FX_WCHAR)'Z')
+ || ch == (FX_WCHAR)'-' || ch == (FX_WCHAR)'.' || ch == (FX_WCHAR)' ' || ch == (FX_WCHAR)'*'
+ || ch == (FX_WCHAR)'$' || ch == (FX_WCHAR)'/' || ch == (FX_WCHAR)'+' || ch == (FX_WCHAR)'%') {
+ continue;
+ }
+ return FALSE;
+ }
+ return TRUE;
+}
+FX_BOOL CBC_OnedCode39Writer::CheckExtendedContentValidity(FX_WSTR contents)
+{
+ for(FX_INT32 i = 0; i < contents.GetLength(); i++) {
+ FX_WCHAR ch = contents.GetAt(i);
+ if (ch > 127) {
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+CFX_WideString CBC_OnedCode39Writer::FilterContents(FX_WSTR contents)
+{
+ if (m_extendedMode) {
+ return FilterExtendedContents(contents);
+ }
+ CFX_WideString filtercontents;
+ for(FX_INT32 i = 0; i < contents.GetLength(); i++) {
+ FX_WCHAR ch = contents.GetAt(i);
+ if ( ch == (FX_WCHAR)'*' && (i == 0 || i == contents.GetLength() - 1) ) {
+ continue;
+ }
+ if(ch > 175) {
+ i++;
+ continue;
+ } else {
+ ch = Upper(ch);
+ }
+ if ((ch >= (FX_WCHAR)'0' && ch <= (FX_WCHAR)'9') || (ch >= (FX_WCHAR)'A' && ch <= (FX_WCHAR)'Z')
+ || ch == (FX_WCHAR)'-' || ch == (FX_WCHAR)'.' || ch == (FX_WCHAR)' ' || ch == (FX_WCHAR)'*'
+ || ch == (FX_WCHAR)'$' || ch == (FX_WCHAR)'/' || ch == (FX_WCHAR)'+' || ch == (FX_WCHAR)'%') {
+ filtercontents += ch;
+ }
+ }
+ return filtercontents;
+}
+CFX_WideString CBC_OnedCode39Writer::FilterExtendedContents(FX_WSTR contents)
+{
+ CFX_WideString filtercontents;
+ for(FX_INT32 i = 0; i < contents.GetLength(); i++) {
+ FX_WCHAR ch = contents.GetAt(i);
+ if ( ch == (FX_WCHAR)'*' && (i == 0 || i == contents.GetLength() - 1) ) {
+ continue;
+ }
+ if(ch > 175) {
+ i++;
+ continue;
+ }
+ if (ch > 127 && ch < 176) {
+ continue;
+ }
+ if (ch == 0) {
+ filtercontents += '%';
+ filtercontents += 'U';
+ } else if(ch >= 1 && ch <= 26) {
+ filtercontents += '$';
+ filtercontents += (ch + 64);
+ } else if (ch >= 27 && ch <= 31) {
+ filtercontents += '%';
+ filtercontents += (ch + 38);
+ } else if (ch >= 33 && ch <= 47 && ch != 45 && ch != 46) {
+ filtercontents += '/';
+ filtercontents += (ch + 32);
+ } else if (ch == 58) {
+ filtercontents += '/';
+ filtercontents += 'Z';
+ } else if (ch >= 59 && ch <= 63) {
+ filtercontents += '%';
+ filtercontents += ch + 11;
+ } else if (ch == 64) {
+ filtercontents += '%';
+ filtercontents += 'V';
+ } else if (ch >= 91 && ch <= 95) {
+ filtercontents += '%';
+ filtercontents += ch - 16;
+ } else if (ch == 96) {
+ filtercontents += '%';
+ filtercontents += 'W';
+ } else if (ch >= 97 && ch <= 122) {
+ filtercontents += '+';
+ filtercontents += ch - 32;
+ } else if (ch >= 123 && ch <= 126) {
+ filtercontents += '%';
+ filtercontents += ch - 43;
+ } else if (ch == 127) {
+ filtercontents += '%';
+ filtercontents += 'T';
+ } else {
+ filtercontents += ch;
+ }
+ }
+ return filtercontents;
+}
+CFX_WideString CBC_OnedCode39Writer::RenderTextContents(FX_WSTR contents)
+{
+ if (m_extendedMode) {
+ return RenderExtendedTextContents(contents);
+ }
+ CFX_WideString renderContents;
+ for(FX_INT32 i = 0; i < contents.GetLength(); i++) {
+ FX_WCHAR ch = contents.GetAt(i);
+ if ( ch == (FX_WCHAR)'*' && (i == 0 || i == contents.GetLength() - 1) ) {
+ continue;
+ }
+ if(ch > 175) {
+ i++;
+ continue;
+ }
+ if ((ch >= (FX_WCHAR)'0' && ch <= (FX_WCHAR)'9') || (ch >= (FX_WCHAR)'A' && ch <= (FX_WCHAR)'Z')
+ || (ch >= (FX_WCHAR)'a' && ch <= (FX_WCHAR)'z') || ch == (FX_WCHAR)'-' || ch == (FX_WCHAR)'.'
+ || ch == (FX_WCHAR)' ' || ch == (FX_WCHAR)'*' || ch == (FX_WCHAR)'$' || ch == (FX_WCHAR)'/'
+ || ch == (FX_WCHAR)'+' || ch == (FX_WCHAR)'%') {
+ renderContents += ch;
+ }
+ }
+ return renderContents;
+}
+CFX_WideString CBC_OnedCode39Writer::RenderExtendedTextContents(FX_WSTR contents)
+{
+ CFX_WideString renderContents;
+ for(FX_INT32 i = 0; i < contents.GetLength(); i++) {
+ FX_WCHAR ch = contents.GetAt(i);
+ if ( ch == (FX_WCHAR)'*' && (i == 0 || i == contents.GetLength() - 1) ) {
+ continue;
+ }
+ if(ch > 175) {
+ i++;
+ continue;
+ }
+ if (ch > 127 && ch < 176) {
+ continue;
+ }
+ renderContents += ch;
+ }
+ return renderContents;
+}
+FX_BOOL CBC_OnedCode39Writer::SetTextLocation(BC_TEXT_LOC location)
+{
+ if ( location < BC_TEXT_LOC_NONE || location > BC_TEXT_LOC_BELOWEMBED) {
+ return FALSE;
+ }
+ m_locTextLoc = location;
+ return TRUE;
+}
+FX_BOOL CBC_OnedCode39Writer::SetWideNarrowRatio(FX_INT32 ratio)
+{
+ if ( ratio < 2 || ratio > 3) {
+ return FALSE;
+ }
+ m_iWideNarrRatio = ratio;
+ return TRUE;
+}
+FX_BYTE *CBC_OnedCode39Writer::Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 &e)
+{
+ FX_BYTE *ret = Encode(contents, format, outWidth, outHeight, 0 , e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return ret;
+}
+FX_BYTE *CBC_OnedCode39Writer::Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 hints, FX_INT32 &e)
+{
+ if(format != BCFORMAT_CODE_39) {
+ e = BCExceptionOnlyEncodeCODE_39;
+ return NULL;
+ }
+ FX_BYTE *ret = CBC_OneDimWriter::Encode(contents, format, outWidth, outHeight, hints, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return ret;
+}
+void CBC_OnedCode39Writer::ToIntArray(FX_INT32 a, FX_INT32 *toReturn)
+{
+ for(FX_INT32 i = 0; i < 9; i++) {
+ toReturn[i] = (a & (1 << i) ) == 0 ? 1 : m_iWideNarrRatio;
+ }
+}
+FX_CHAR CBC_OnedCode39Writer::CalcCheckSum(const CFX_ByteString &contents, FX_INT32 &e)
+{
+ FX_INT32 length = contents.GetLength();
+ if (length > 80) {
+ e = BCExceptionContentsLengthShouldBetween1and80;
+ return '*';
+ }
+ FX_INT32 checksum = 0;
+ FX_INT32 len = (FX_INT32)strlen(CBC_OnedCode39Reader::ALPHABET_STRING);
+ for(FX_INT32 i = 0; i < contents.GetLength(); i++) {
+ FX_INT32 j = 0;
+ for (; j < len; j++) {
+ if (CBC_OnedCode39Reader::ALPHABET_STRING[j] == contents[i]) {
+ if(contents[i] != '*') {
+ checksum += j;
+ break;
+ } else {
+ break;
+ }
+ }
+ }
+ if (j >= len) {
+ e = BCExceptionUnSupportedString;
+ return '*';
+ }
+ }
+ checksum = checksum % 43;
+ return CBC_OnedCode39Reader::CHECKSUM_STRING[checksum];
+}
+FX_BYTE *CBC_OnedCode39Writer::Encode(const CFX_ByteString &contents, FX_INT32 &outlength , FX_INT32 &e)
+{
+ FX_CHAR checksum = CalcCheckSum(contents, e);
+ if (checksum == '*') {
+ return NULL;
+ }
+ FX_INT32 widths[9] = {0};
+ FX_INT32 wideStrideNum = 3;
+ FX_INT32 narrStrideNum = 9 - wideStrideNum;
+ CFX_ByteString encodedContents = contents;
+ if ( m_bCalcChecksum ) {
+ encodedContents += checksum;
+ }
+ m_iContentLen = encodedContents.GetLength();
+ FX_INT32 codeWidth = (wideStrideNum * m_iWideNarrRatio + narrStrideNum) * 2 + 1 + m_iContentLen;
+ FX_INT32 len = (FX_INT32)strlen(CBC_OnedCode39Reader::ALPHABET_STRING);
+ for (FX_INT32 j = 0; j < m_iContentLen; j++) {
+ for (FX_INT32 i = 0; i < len; i++) {
+ if (CBC_OnedCode39Reader::ALPHABET_STRING[i] == encodedContents[j]) {
+ ToIntArray(CBC_OnedCode39Reader::CHARACTER_ENCODINGS[i], widths);
+ for(FX_INT32 k = 0; k < 9; k++) {
+ codeWidth += widths[k];
+ }
+ }
+ }
+ }
+ outlength = codeWidth;
+ FX_BYTE *result = FX_Alloc(FX_BYTE, codeWidth);
+ ToIntArray(CBC_OnedCode39Reader::CHARACTER_ENCODINGS[39], widths);
+ FX_INT32 pos = AppendPattern(result, 0, widths, 9, 1 , e);
+ if (e != BCExceptionNO) {
+ FX_Free (result);
+ return NULL;
+ }
+ FX_INT32 narrowWhite[] = {1};
+ pos += AppendPattern(result, pos, narrowWhite, 1, 0, e);
+ if (e != BCExceptionNO) {
+ FX_Free (result);
+ return NULL;
+ }
+ for(FX_INT32 l = m_iContentLen - 1; l >= 0; l--) {
+ for (FX_INT32 i = 0; i < len; i++) {
+ if (CBC_OnedCode39Reader::ALPHABET_STRING[i] == encodedContents[l]) {
+ ToIntArray(CBC_OnedCode39Reader::CHARACTER_ENCODINGS[i], widths);
+ pos += AppendPattern(result, pos, widths, 9, 1, e);
+ if (e != BCExceptionNO) {
+ FX_Free (result);
+ return NULL;
+ }
+ }
+ }
+ pos += AppendPattern(result, pos, narrowWhite, 1, 0, e);
+ if (e != BCExceptionNO) {
+ FX_Free (result);
+ return NULL;
+ }
+ }
+ ToIntArray(CBC_OnedCode39Reader::CHARACTER_ENCODINGS[39], widths);
+ pos += AppendPattern(result, pos, widths, 9, 1, e);
+ if (e != BCExceptionNO) {
+ FX_Free (result);
+ return NULL;
+ }
+ for (FX_INT32 i = 0; i < codeWidth / 2; i++) {
+ result[i] ^= result[codeWidth - 1 - i];
+ result[codeWidth - 1 - i] ^= result[i];
+ result[i] ^= result[codeWidth - 1 - i];
+ }
+ return result;
+}
+CFX_WideString CBC_OnedCode39Writer::encodedContents(FX_WSTR contents, FX_INT32 &e)
+{
+ CFX_WideString encodedContents = contents;
+ if (m_bCalcChecksum && m_bPrintChecksum) {
+ CFX_WideString checksumContent = FilterContents(contents);
+ CFX_ByteString str = checksumContent.UTF8Encode();
+ FX_CHAR checksum;
+ checksum = CalcCheckSum(str, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, FX_WSTRC(L""));
+ str += checksum;
+ encodedContents += checksum;
+ }
+ return encodedContents;
+}
+void CBC_OnedCode39Writer::RenderResult(FX_WSTR contents, FX_BYTE* code, FX_INT32 codeLength, FX_BOOL isDevice, FX_INT32 &e)
+{
+ CFX_WideString encodedCon = encodedContents(contents, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ CBC_OneDimWriter::RenderResult(encodedCon, code, codeLength, isDevice, e);
+}
diff --git a/xfa/src/fxbarcode/oned/BC_OnedCode39Writer.h b/xfa/src/fxbarcode/oned/BC_OnedCode39Writer.h
new file mode 100644
index 0000000000..b37d9d8e19
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedCode39Writer.h
@@ -0,0 +1,37 @@
+// 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_ONEDCODA39WRITER_H_
+#define _BC_ONEDCODA39WRITER_H_
+enum BC_TEXT_LOC;
+class CBC_OneDimWriter;
+class CBC_OnedCoda39Writer;
+class CBC_OnedCode39Writer : public CBC_OneDimWriter
+{
+public:
+ CBC_OnedCode39Writer();
+ CBC_OnedCode39Writer(FX_BOOL extendedMode);
+ virtual ~CBC_OnedCode39Writer();
+ 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_BYTE *Encode(const CFX_ByteString &contents, FX_INT32 &outLength, FX_INT32 &e);
+ void RenderResult(FX_WSTR contents, FX_BYTE* code, FX_INT32 codeLength, FX_BOOL isDevice, FX_INT32 &e);
+ CFX_WideString encodedContents(FX_WSTR contents, FX_INT32 &e);
+ FX_BOOL CheckContentValidity(FX_WSTR contents);
+ FX_BOOL CheckExtendedContentValidity(FX_WSTR contents);
+ CFX_WideString FilterContents(FX_WSTR contents);
+ CFX_WideString FilterExtendedContents(FX_WSTR contents);
+ CFX_WideString RenderTextContents(FX_WSTR contents);
+ CFX_WideString RenderExtendedTextContents(FX_WSTR contents);
+ FX_BOOL SetTextLocation(BC_TEXT_LOC loction);
+ FX_BOOL SetWideNarrowRatio(FX_INT32 ratio);
+private:
+ void ToIntArray(FX_INT32 a, FX_INT32 *toReturn);
+ FX_CHAR CalcCheckSum(const CFX_ByteString &contents, FX_INT32 &e);
+ FX_INT32 m_iWideNarrRatio;
+ FX_BOOL m_extendedMode;
+};
+#endif
diff --git a/xfa/src/fxbarcode/oned/BC_OnedEAN13Reader.cpp b/xfa/src/fxbarcode/oned/BC_OnedEAN13Reader.cpp
new file mode 100644
index 0000000000..ddce736bb8
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedEAN13Reader.cpp
@@ -0,0 +1,94 @@
+// 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_Reader.h"
+#include "../common/BC_CommonBitArray.h"
+#include "BC_OneDReader.h"
+#include "BC_OneDimReader.h"
+#include "BC_OnedEAN13Reader.h"
+const FX_INT32 CBC_OnedEAN13Reader::FIRST_DIGIT_ENCODINGS[10] = {
+ 0x00, 0x0B, 0x0D, 0xE, 0x13, 0x19, 0x1C, 0x15, 0x16, 0x1A
+};
+CBC_OnedEAN13Reader::CBC_OnedEAN13Reader()
+{
+}
+CBC_OnedEAN13Reader::~CBC_OnedEAN13Reader()
+{
+}
+void CBC_OnedEAN13Reader::DetermineFirstDigit(CFX_ByteString &result, FX_INT32 lgPatternFound, FX_INT32 &e)
+{
+ for (FX_INT32 d = 0; d < 10; d++) {
+ if (lgPatternFound == FIRST_DIGIT_ENCODINGS[d]) {
+ result.Insert(0, (FX_CHAR) ('0' + d));
+ return;
+ }
+ }
+ e = BCExceptionNotFound;
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+}
+FX_INT32 CBC_OnedEAN13Reader::DecodeMiddle(CBC_CommonBitArray *row, CFX_Int32Array *startRange, CFX_ByteString &resultString, FX_INT32 &e)
+{
+ CFX_Int32Array counters;
+ counters.Add(0);
+ counters.Add(0);
+ counters.Add(0);
+ counters.Add(0);
+ FX_INT32 end = row->GetSize();
+ FX_INT32 rowOffset = (*startRange)[1];
+ FX_INT32 lgPatternFound = 0;
+ for (FX_INT32 x = 0; x < 6 && rowOffset < end; x++) {
+ FX_INT32 bestMatch = DecodeDigit(row, &counters, rowOffset, &(CBC_OneDimReader::L_AND_G_PATTERNS[0][0]), 20, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, 0);
+ resultString += (FX_CHAR) ('0' + bestMatch % 10);
+ for (FX_INT32 i = 0; i < counters.GetSize(); i++) {
+ rowOffset += counters[i];
+ }
+ if (bestMatch >= 10) {
+ lgPatternFound |= 1 << (5 - x);
+ }
+ }
+ DetermineFirstDigit(resultString, lgPatternFound, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, 0);
+ CFX_Int32Array result;
+ result.Add(CBC_OneDimReader::MIDDLE_PATTERN[0]);
+ result.Add(CBC_OneDimReader::MIDDLE_PATTERN[1]);
+ result.Add(CBC_OneDimReader::MIDDLE_PATTERN[2]);
+ result.Add(CBC_OneDimReader::MIDDLE_PATTERN[3]);
+ result.Add(CBC_OneDimReader::MIDDLE_PATTERN[4]);
+ CFX_Int32Array *middleRange = FindGuardPattern(row, rowOffset, TRUE, &result, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, 0);
+ rowOffset = (*middleRange)[1];
+ if(middleRange != NULL) {
+ delete middleRange;
+ middleRange = NULL;
+ }
+ for (FX_INT32 Y = 0; Y < 6 && rowOffset < end; Y++) {
+ FX_INT32 bestMatch = DecodeDigit(row, &counters, rowOffset, &(CBC_OneDimReader::L_PATTERNS[0][0]), 10, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, 0);
+ resultString += (FX_CHAR) ('0' + bestMatch);
+ for (FX_INT32 k = 0; k < counters.GetSize(); k++) {
+ rowOffset += counters[k];
+ }
+ }
+ return rowOffset;
+}
diff --git a/xfa/src/fxbarcode/oned/BC_OnedEAN13Reader.h b/xfa/src/fxbarcode/oned/BC_OnedEAN13Reader.h
new file mode 100644
index 0000000000..9afb9b6418
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedEAN13Reader.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_ONEDEAN13READER_H_
+#define _BC_ONEDEAN13READER_H_
+class CBC_OneDimReader;
+class CBC_CommonBitArray;
+class CBC_OnedEAN13Reader;
+class CBC_OnedEAN13Reader : public CBC_OneDimReader
+{
+public:
+ const static FX_INT32 FIRST_DIGIT_ENCODINGS[10];
+ CBC_OnedEAN13Reader();
+ virtual ~CBC_OnedEAN13Reader();
+private:
+ void DetermineFirstDigit(CFX_ByteString &result, FX_INT32 lgPatternFound, FX_INT32 &e);
+protected:
+ FX_INT32 DecodeMiddle(CBC_CommonBitArray *row, CFX_Int32Array *startRange, CFX_ByteString &resultString, FX_INT32 &e);
+ friend class CBC_OnedUPCAReader;
+};
+#endif
diff --git a/xfa/src/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/xfa/src/fxbarcode/oned/BC_OnedEAN13Writer.cpp
new file mode 100644
index 0000000000..788cd8f7da
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedEAN13Writer.cpp
@@ -0,0 +1,294 @@
+// 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 2009 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_Reader.h"
+#include "BC_OneDReader.h"
+#include "BC_OneDimReader.h"
+#include "BC_OneDimWriter.h"
+#include "BC_OnedEAN13Reader.h"
+#include "BC_OnedEAN13Writer.h"
+CBC_OnedEAN13Writer::CBC_OnedEAN13Writer()
+{
+ m_bLeftPadding = TRUE;
+ m_codeWidth = 3 +
+ (7 * 6) +
+ 5 +
+ (7 * 6) +
+ 3;
+}
+CBC_OnedEAN13Writer::~CBC_OnedEAN13Writer()
+{
+}
+FX_BOOL CBC_OnedEAN13Writer::CheckContentValidity(FX_WSTR contents)
+{
+ for (FX_INT32 i = 0; i < contents.GetLength(); i++) {
+ if (contents.GetAt(i) >= '0' && contents.GetAt(i) <= '9') {
+ continue;
+ } else {
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+CFX_WideString CBC_OnedEAN13Writer::FilterContents(FX_WSTR contents)
+{
+ CFX_WideString filtercontents;
+ FX_WCHAR ch;
+ for (FX_INT32 i = 0; i < contents.GetLength(); i++) {
+ ch = contents.GetAt(i);
+ if(ch > 175) {
+ i++;
+ continue;
+ }
+ if (ch >= '0' && ch <= '9') {
+ filtercontents += ch;
+ }
+ }
+ return filtercontents;
+}
+FX_INT32 CBC_OnedEAN13Writer::CalcChecksum(const CFX_ByteString &contents)
+{
+ FX_INT32 odd = 0;
+ FX_INT32 even = 0;
+ FX_INT32 j = 1;
+ for(FX_INT32 i = contents.GetLength() - 1; i >= 0; i--) {
+ if(j % 2) {
+ odd += FXSYS_atoi(contents.Mid(i, 1));
+ } else {
+ even += FXSYS_atoi(contents.Mid(i, 1));
+ }
+ j++;
+ }
+ FX_INT32 checksum = (odd * 3 + even) % 10;
+ checksum = (10 - checksum) % 10;
+ return (checksum);
+}
+FX_BYTE *CBC_OnedEAN13Writer::Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 &e)
+{
+ FX_BYTE *ret = Encode(contents, format, outWidth, outHeight, 0, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return ret;
+}
+FX_BYTE *CBC_OnedEAN13Writer::Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 hints, FX_INT32 &e)
+{
+ if(format != BCFORMAT_EAN_13) {
+ e = BCExceptionOnlyEncodeEAN_13;
+ }
+ FX_BYTE *ret = CBC_OneDimWriter::Encode(contents, format, outWidth, outHeight, hints, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return ret;
+}
+FX_BYTE *CBC_OnedEAN13Writer::Encode(const CFX_ByteString &contents, FX_INT32 &outLength, FX_INT32 &e)
+{
+ if (contents.GetLength() != 13) {
+ e = BCExceptionDigitLengthShould13;
+ return NULL;
+ }
+ m_iDataLenth = 13;
+ FX_INT32 firstDigit = FXSYS_atoi(contents.Mid(0, 1));
+ FX_INT32 parities = CBC_OnedEAN13Reader::FIRST_DIGIT_ENCODINGS[firstDigit];
+ outLength = m_codeWidth;
+ FX_BYTE *result = FX_Alloc(FX_BYTE, m_codeWidth);
+ FX_INT32 pos = 0;
+ pos += AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e);
+ if (e != BCExceptionNO) {
+ FX_Free (result);
+ return NULL;
+ }
+ FX_INT32 i = 0;
+ for ( i = 1; i <= 6; i++) {
+ FX_INT32 digit = FXSYS_atoi(contents.Mid(i, 1));
+ if ((parities >> (6 - i) & 1) == 1) {
+ digit += 10;
+ }
+ pos += AppendPattern(result, pos, CBC_OneDimReader::L_AND_G_PATTERNS[digit], 4, 0, e);
+ if (e != BCExceptionNO) {
+ FX_Free (result);
+ return NULL;
+ }
+ }
+ pos += AppendPattern(result, pos, CBC_OneDimReader::MIDDLE_PATTERN, 5, 0, e);
+ if (e != BCExceptionNO) {
+ FX_Free (result);
+ return NULL;
+ }
+ for (i = 7; i <= 12; i++) {
+ FX_INT32 digit = FXSYS_atoi(contents.Mid(i, 1));
+ pos += AppendPattern(result, pos, CBC_OneDimReader::L_PATTERNS[digit], 4, 1, e);
+ if (e != BCExceptionNO) {
+ FX_Free (result);
+ return NULL;
+ }
+ }
+ pos += AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e);
+ if (e != BCExceptionNO) {
+ FX_Free (result);
+ return NULL;
+ }
+ return result;
+}
+void CBC_OnedEAN13Writer::ShowChars(FX_WSTR contents, CFX_DIBitmap *pOutBitmap, CFX_RenderDevice* device, const CFX_Matrix* matrix, FX_INT32 barWidth, FX_INT32 multiple, FX_INT32 &e)
+{
+ if (device == NULL && pOutBitmap == NULL) {
+ e = BCExceptionIllegalArgument;
+ return;
+ }
+ FX_INT32 leftPadding = 7 * multiple;
+ FX_INT32 leftPosition = 3 * multiple + leftPadding;
+ CFX_ByteString str = FX_UTF8Encode(contents);
+ FX_INT32 iLen = str.GetLength();
+ FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, iLen);
+ if (!pCharPos) {
+ return;
+ }
+ FXSYS_memset32(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLen);
+ CFX_FxgeDevice geBitmap;
+ if (pOutBitmap != NULL) {
+ geBitmap.Attach(pOutBitmap);
+ }
+ FX_INT32 iFontSize = (FX_INT32)fabs(m_fFontSize);
+ FX_INT32 iTextHeight = iFontSize + 1;
+ CFX_ByteString tempStr = str.Mid(1, 6);
+ FX_INT32 strWidth = multiple * 42;
+ if (pOutBitmap == NULL) {
+ CFX_Matrix matr(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
+ CFX_FloatRect rect((FX_FLOAT)leftPosition, (FX_FLOAT)(m_Height - iTextHeight), (FX_FLOAT)(leftPosition + strWidth - 0.5), (FX_FLOAT)m_Height);
+ matr.Concat(*matrix);
+ matr.TransformRect(rect);
+ FX_RECT re = rect.GetOutterRect();
+ device->FillRect(&re, m_backgroundColor);
+ CFX_FloatRect rect1((FX_FLOAT)(leftPosition + 47 * multiple), (FX_FLOAT)(m_Height - iTextHeight), (FX_FLOAT)(leftPosition + 47 * multiple + strWidth - 0.5), (FX_FLOAT)m_Height);
+ CFX_Matrix matr1(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
+ matr1.Concat(*matrix);
+ matr1.TransformRect(rect1);
+ re = rect1.GetOutterRect();
+ device->FillRect(&re, m_backgroundColor);
+ FX_INT32 strWidth1 = multiple * 7;
+ CFX_Matrix matr2(m_outputHScale, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f);
+ CFX_FloatRect rect2(0.0f, (FX_FLOAT)(m_Height - iTextHeight), (FX_FLOAT)strWidth1 - 0.5f, (FX_FLOAT)m_Height);
+ matr2.Concat(*matrix);
+ matr2.TransformRect(rect2);
+ re = rect2.GetOutterRect();
+ device->FillRect(&re, m_backgroundColor);
+ }
+ FX_FLOAT blank = 0.0;
+ FX_FLOAT charsWidth = 0;
+ iLen = tempStr.GetLength();
+ if (pOutBitmap == NULL) {
+ strWidth = (FX_INT32)(strWidth * m_outputHScale);
+ }
+ CalcTextInfo(tempStr, pCharPos + 1, m_pFont, (FX_FLOAT)strWidth, iFontSize, blank);
+ CFX_AffineMatrix affine_matrix(1.0, 0.0, 0.0, -1.0, 0.0, (FX_FLOAT)iFontSize);
+ CFX_FxgeDevice ge;
+ if (pOutBitmap != NULL) {
+ ge.Create(strWidth, iTextHeight, FXDIB_Argb);
+ FX_RECT rect(0, 0, strWidth, iTextHeight);
+ ge.FillRect(&rect, m_backgroundColor);
+ ge.DrawNormalText(iLen,
+ pCharPos + 1,
+ m_pFont,
+ CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize ,
+ (CFX_AffineMatrix *) &affine_matrix,
+ m_fontColor, FXTEXT_CLEARTYPE);
+ geBitmap.SetDIBits(ge.GetBitmap(), leftPosition, m_Height - iTextHeight);
+ } else {
+ CFX_AffineMatrix affine_matrix1(1.0, 0.0, 0.0, -1.0, (FX_FLOAT)leftPosition * m_outputHScale, (FX_FLOAT)(m_Height - iTextHeight) + iFontSize);
+ if (matrix != NULL) {
+ affine_matrix1.Concat(*matrix);
+ }
+ device->DrawNormalText(iLen,
+ pCharPos + 1,
+ m_pFont,
+ CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize ,
+ (CFX_AffineMatrix *) &affine_matrix1,
+ m_fontColor, FXTEXT_CLEARTYPE);
+ }
+ tempStr = str.Mid(7, 6);
+ iLen = tempStr.GetLength();
+ charsWidth = 0.0f;
+ CalcTextInfo(tempStr, pCharPos + 7, m_pFont, (FX_FLOAT)strWidth, iFontSize, blank);
+ if(pOutBitmap != NULL) {
+ FX_RECT rect1(0, 0, strWidth, iTextHeight);
+ ge.FillRect(&rect1, m_backgroundColor);
+ ge.DrawNormalText(iLen,
+ pCharPos + 7,
+ m_pFont,
+ CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize ,
+ (CFX_AffineMatrix *) &affine_matrix,
+ m_fontColor, FXTEXT_CLEARTYPE);
+ geBitmap.SetDIBits(ge.GetBitmap(), leftPosition + 47 * multiple, m_Height - iTextHeight);
+ } else {
+ CFX_AffineMatrix affine_matrix1(1.0, 0.0, 0.0, -1.0, (FX_FLOAT)(leftPosition + 47 * multiple) * m_outputHScale, (FX_FLOAT)(m_Height - iTextHeight + iFontSize));
+ if (matrix != NULL) {
+ affine_matrix1.Concat(*matrix);
+ }
+ device->DrawNormalText(iLen,
+ pCharPos + 7,
+ m_pFont,
+ CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize ,
+ (CFX_AffineMatrix *) &affine_matrix1,
+ m_fontColor, FXTEXT_CLEARTYPE);
+ }
+ tempStr = str.Mid(0, 1);
+ iLen = tempStr.GetLength();
+ strWidth = multiple * 7;
+ if (pOutBitmap == NULL) {
+ strWidth = (FX_INT32)(strWidth * m_outputHScale);
+ }
+ CalcTextInfo(tempStr, pCharPos, m_pFont, (FX_FLOAT)strWidth, iFontSize, blank);
+ if(pOutBitmap != NULL) {
+ delete ge.GetBitmap();
+ ge.Create(strWidth, iTextHeight, FXDIB_Argb);
+ ge.GetBitmap()->Clear(m_backgroundColor);
+ ge.DrawNormalText(iLen,
+ pCharPos,
+ m_pFont,
+ CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize ,
+ (CFX_AffineMatrix *) &affine_matrix,
+ m_fontColor, FXTEXT_CLEARTYPE);
+ geBitmap.SetDIBits(ge.GetBitmap(), 0, m_Height - iTextHeight);
+ } else {
+ CFX_AffineMatrix affine_matrix1(1.0, 0.0, 0.0, -1.0, 0.0, (FX_FLOAT)(m_Height - iTextHeight + iFontSize));
+ if (matrix != NULL) {
+ affine_matrix1.Concat(*matrix);
+ }
+ device->DrawNormalText(iLen,
+ pCharPos,
+ m_pFont,
+ CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize ,
+ (CFX_AffineMatrix *) &affine_matrix1,
+ m_fontColor, FXTEXT_CLEARTYPE);
+ }
+ FX_Free(pCharPos);
+}
+void CBC_OnedEAN13Writer::RenderResult(FX_WSTR contents, FX_BYTE* code, FX_INT32 codeLength, FX_BOOL isDevice, FX_INT32 &e)
+{
+ CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e);
+}
diff --git a/xfa/src/fxbarcode/oned/BC_OnedEAN13Writer.h b/xfa/src/fxbarcode/oned/BC_OnedEAN13Writer.h
new file mode 100644
index 0000000000..2353cfda95
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedEAN13Writer.h
@@ -0,0 +1,31 @@
+// 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_ONEDEAN13WRITER_H_
+#define _BC_ONEDEAN13WRITER_H_
+class CBC_OneDimWriter;
+class CBC_OnedEAN13Writer;
+class CBC_OnedEAN13Writer : public CBC_OneDimWriter
+{
+private:
+ FX_INT32 m_codeWidth;
+public:
+ CBC_OnedEAN13Writer();
+ virtual ~CBC_OnedEAN13Writer();
+
+ 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_BYTE* Encode(const CFX_ByteString &contents, FX_INT32 &outLength, FX_INT32 &e);
+ void RenderResult(FX_WSTR contents, FX_BYTE* code, FX_INT32 codeLength, FX_BOOL isDevice, FX_INT32 &e);
+ FX_BOOL CheckContentValidity(FX_WSTR contents);
+ CFX_WideString FilterContents(FX_WSTR contents);
+ FX_INT32 CalcChecksum(const CFX_ByteString &contents);
+protected:
+ void ShowChars(FX_WSTR contents, CFX_DIBitmap *pOutBitmap, CFX_RenderDevice* device, const CFX_Matrix* matrix, FX_INT32 barWidth, FX_INT32 multiple, FX_INT32 &e);
+};
+#endif
diff --git a/xfa/src/fxbarcode/oned/BC_OnedEAN8Reader.cpp b/xfa/src/fxbarcode/oned/BC_OnedEAN8Reader.cpp
new file mode 100644
index 0000000000..48e24681df
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedEAN8Reader.cpp
@@ -0,0 +1,81 @@
+// 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_Reader.h"
+#include "../common/BC_CommonBitArray.h"
+#include "BC_OneDReader.h"
+#include "BC_OneDimReader.h"
+#include "BC_OnedEAN8Reader.h"
+CBC_OnedEAN8Reader::CBC_OnedEAN8Reader()
+{
+}
+CBC_OnedEAN8Reader::~CBC_OnedEAN8Reader()
+{
+}
+FX_INT32 CBC_OnedEAN8Reader::DecodeMiddle(CBC_CommonBitArray *row, CFX_Int32Array *startRange, CFX_ByteString &resultResult, FX_INT32 &e)
+{
+ CFX_Int32Array counters;
+ counters.Add(0);
+ counters.Add(0);
+ counters.Add(0);
+ counters.Add(0);
+ FX_INT32 end = row->GetSize();
+ FX_INT32 rowOffset = (*startRange)[1];
+ FX_INT32 rowOffsetLeft = rowOffset;
+ for (FX_INT32 x = 0; x < 4 && rowOffset < end; x++) {
+ FX_INT32 bestMatch = DecodeDigit(row, &counters, rowOffset, &(CBC_OneDimReader::L_PATTERNS[0][0]), 10, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, 0);
+ resultResult += (FX_CHAR) ('0' + bestMatch);
+ for (FX_INT32 i = 0; i < counters.GetSize(); i++) {
+ rowOffset += counters[i];
+ }
+ }
+ FX_INT32 RowOffsetLen = (rowOffset - rowOffsetLeft) / 4;
+ CFX_Int32Array result;
+ result.Add(CBC_OneDimReader::MIDDLE_PATTERN[0]);
+ result.Add(CBC_OneDimReader::MIDDLE_PATTERN[1]);
+ result.Add(CBC_OneDimReader::MIDDLE_PATTERN[2]);
+ result.Add(CBC_OneDimReader::MIDDLE_PATTERN[3]);
+ result.Add(CBC_OneDimReader::MIDDLE_PATTERN[4]);
+ CFX_Int32Array *middleRange = FindGuardPattern(row, rowOffset, TRUE, &result, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, 0);
+ FX_INT32 rowOffsetMid = rowOffset;
+ rowOffset = (*middleRange)[1];
+ if((rowOffset - rowOffsetMid) > RowOffsetLen) {
+ e = BCExceptionNotFound;
+ BC_EXCEPTION_CHECK_ReturnValue(e, 0);
+ }
+ if(middleRange != NULL) {
+ delete middleRange;
+ middleRange = NULL;
+ }
+ for (FX_INT32 y = 0; y < 4 && rowOffset < end; y++) {
+ FX_INT32 bestMatch = DecodeDigit(row, & counters, rowOffset, &(CBC_OneDimReader::L_PATTERNS[0][0]), 10, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, 0);
+ resultResult += (FX_CHAR) ('0' + bestMatch);
+ for (FX_INT32 i = 0; i < counters.GetSize(); i++) {
+ rowOffset += counters[i];
+ }
+ }
+ return rowOffset;
+}
diff --git a/xfa/src/fxbarcode/oned/BC_OnedEAN8Reader.h b/xfa/src/fxbarcode/oned/BC_OnedEAN8Reader.h
new file mode 100644
index 0000000000..a32bb63083
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedEAN8Reader.h
@@ -0,0 +1,20 @@
+// 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_ONEDEAN8READER_H_
+#define _BC_ONEDEAN8READER_H_
+class CBC_OneDimReader;
+class CBC_CommonBitArray;
+class CBC_OnedEAN8Reader;
+class CBC_OnedEAN8Reader : public CBC_OneDimReader
+{
+public:
+ CBC_OnedEAN8Reader();
+ virtual ~CBC_OnedEAN8Reader();
+protected:
+ FX_INT32 DecodeMiddle(CBC_CommonBitArray*, CFX_Int32Array *startRange, CFX_ByteString &result, FX_INT32 &e);
+};
+#endif
diff --git a/xfa/src/fxbarcode/oned/BC_OnedEAN8Writer.cpp b/xfa/src/fxbarcode/oned/BC_OnedEAN8Writer.cpp
new file mode 100644
index 0000000000..19f7f7cede
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedEAN8Writer.cpp
@@ -0,0 +1,261 @@
+// 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 2009 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_Reader.h"
+#include "../common/BC_CommonBitMatrix.h"
+#include "BC_OneDReader.h"
+#include "BC_OneDimWriter.h"
+#include "BC_OneDimReader.h"
+#include "BC_OnedEAN8Writer.h"
+CBC_OnedEAN8Writer::CBC_OnedEAN8Writer()
+{
+ m_iDataLenth = 8;
+ m_codeWidth = 3 +
+ (7 * 4) +
+ 5 +
+ (7 * 4) +
+ 3;
+}
+CBC_OnedEAN8Writer::~CBC_OnedEAN8Writer()
+{
+}
+void CBC_OnedEAN8Writer::SetDataLength(FX_INT32 length)
+{
+ m_iDataLenth = 8;
+}
+FX_BOOL CBC_OnedEAN8Writer::SetTextLocation(BC_TEXT_LOC location)
+{
+ if ( location == BC_TEXT_LOC_BELOWEMBED) {
+ m_locTextLoc = location;
+ return TRUE;
+ }
+ return FALSE;
+}
+FX_BOOL CBC_OnedEAN8Writer::CheckContentValidity(FX_WSTR contents)
+{
+ for (FX_INT32 i = 0; i < contents.GetLength(); i++) {
+ if (contents.GetAt(i) >= '0' && contents.GetAt(i) <= '9') {
+ continue;
+ } else {
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+CFX_WideString CBC_OnedEAN8Writer::FilterContents(FX_WSTR contents)
+{
+ CFX_WideString filtercontents;
+ FX_WCHAR ch;
+ for (FX_INT32 i = 0; i < contents.GetLength(); i++) {
+ ch = contents.GetAt(i);
+ if(ch > 175) {
+ i++;
+ continue;
+ }
+ if (ch >= '0' && ch <= '9') {
+ filtercontents += ch;
+ }
+ }
+ return filtercontents;
+}
+FX_INT32 CBC_OnedEAN8Writer::CalcChecksum(const CFX_ByteString &contents)
+{
+ FX_INT32 odd = 0;
+ FX_INT32 even = 0;
+ FX_INT32 j = 1;
+ for(FX_INT32 i = contents.GetLength() - 1; i >= 0; i--) {
+ if(j % 2) {
+ odd += FXSYS_atoi(contents.Mid(i, 1));
+ } else {
+ even += FXSYS_atoi(contents.Mid(i, 1));
+ }
+ j++;
+ }
+ FX_INT32 checksum = (odd * 3 + even) % 10;
+ checksum = (10 - checksum) % 10;
+ return (checksum);
+}
+FX_BYTE *CBC_OnedEAN8Writer::Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight , FX_INT32 &e)
+{
+ FX_BYTE *ret = Encode(contents, format, outWidth, outHeight, 0, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return ret;
+}
+FX_BYTE *CBC_OnedEAN8Writer::Encode(const CFX_ByteString &contents, BCFORMAT format,
+ FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 hints , FX_INT32 &e)
+{
+ if (format != BCFORMAT_EAN_8) {
+ e = BCExceptionOnlyEncodeEAN_8;
+ return NULL;
+ }
+ FX_BYTE *ret = CBC_OneDimWriter::Encode(contents, format, outWidth, outHeight, hints, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return ret;
+}
+FX_BYTE *CBC_OnedEAN8Writer::Encode(const CFX_ByteString &contents, FX_INT32 &outLength , FX_INT32 &e)
+{
+ if (contents.GetLength() != 8) {
+ e = BCExceptionDigitLengthMustBe8;
+ return NULL;
+ }
+ outLength = m_codeWidth;
+ FX_BYTE *result = FX_Alloc(FX_BYTE, m_codeWidth);
+ FX_INT32 pos = 0;
+ pos += AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e);
+ if (e != BCExceptionNO) {
+ FX_Free (result);
+ return NULL;
+ }
+ FX_INT32 i = 0;
+ for (i = 0; i <= 3; i++) {
+ FX_INT32 digit = FXSYS_atoi(contents.Mid(i, 1));
+ pos += AppendPattern(result, pos, CBC_OneDimReader::L_PATTERNS[digit], 4, 0, e);
+ if (e != BCExceptionNO) {
+ FX_Free (result);
+ return NULL;
+ }
+ }
+ pos += AppendPattern(result, pos, CBC_OneDimReader::MIDDLE_PATTERN, 5, 0, e);
+ if (e != BCExceptionNO) {
+ FX_Free (result);
+ return NULL;
+ }
+ for (i = 4; i <= 7; i++) {
+ FX_INT32 digit = FXSYS_atoi(contents.Mid(i, 1));
+ pos += AppendPattern(result, pos, CBC_OneDimReader::L_PATTERNS[digit], 4, 1, e);
+ if (e != BCExceptionNO) {
+ FX_Free (result);
+ return NULL;
+ }
+ }
+ pos += AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e);
+ if (e != BCExceptionNO) {
+ FX_Free (result);
+ return NULL;
+ }
+ return result;
+}
+void CBC_OnedEAN8Writer::ShowChars(FX_WSTR contents, CFX_DIBitmap *pOutBitmap, CFX_RenderDevice* device, const CFX_Matrix* matrix, FX_INT32 barWidth, FX_INT32 multiple, FX_INT32 &e)
+{
+ if (device == NULL && pOutBitmap == NULL) {
+ e = BCExceptionIllegalArgument;
+ return;
+ }
+ FX_INT32 leftPosition = 3 * multiple;
+ CFX_ByteString str = FX_UTF8Encode(contents);
+ FX_INT32 iLength = str.GetLength();
+ FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, iLength);
+ if (!pCharPos) {
+ return;
+ }
+ FXSYS_memset32(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLength);
+ CFX_ByteString tempStr = str.Mid(0, 4);
+ FX_INT32 iLen = tempStr.GetLength();
+ FX_INT32 strWidth = 7 * multiple * 4;
+ FX_FLOAT blank = 0.0;
+ CFX_FxgeDevice geBitmap;
+ if (pOutBitmap != NULL) {
+ geBitmap.Attach(pOutBitmap);
+ }
+ FX_FLOAT charsWidth = 0;
+ FX_INT32 iFontSize = (FX_INT32)fabs(m_fFontSize);
+ FX_INT32 iTextHeight = iFontSize + 1;
+ if (pOutBitmap == NULL) {
+ CFX_Matrix matr(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
+ CFX_FloatRect rect((FX_FLOAT)leftPosition, (FX_FLOAT)(m_Height - iTextHeight), (FX_FLOAT)(leftPosition + strWidth - 0.5), (FX_FLOAT)m_Height);
+ matr.Concat(*matrix);
+ matr.TransformRect(rect);
+ FX_RECT re = rect.GetOutterRect();
+ device->FillRect(&re, m_backgroundColor);
+ CFX_Matrix matr1(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
+ CFX_FloatRect rect1((FX_FLOAT)(leftPosition + 33 * multiple), (FX_FLOAT)(m_Height - iTextHeight), (FX_FLOAT)(leftPosition + 33 * multiple + strWidth - 0.5), (FX_FLOAT)m_Height);
+ matr1.Concat(*matrix);
+ matr1.TransformRect(rect1);
+ re = rect1.GetOutterRect();
+ device->FillRect(&re, m_backgroundColor);
+ }
+ if (pOutBitmap == NULL) {
+ strWidth = (FX_INT32)(strWidth * m_outputHScale);
+ }
+ CalcTextInfo(tempStr, pCharPos, m_pFont, (FX_FLOAT)strWidth, iFontSize, blank);
+ CFX_AffineMatrix affine_matrix(1.0, 0.0, 0.0, -1.0, 0.0, (FX_FLOAT)iFontSize);
+ CFX_FxgeDevice ge;
+ if (pOutBitmap != NULL) {
+ delete ge.GetBitmap();
+ ge.Create(strWidth, iTextHeight, FXDIB_Argb);
+ ge.GetBitmap()->Clear(m_backgroundColor);
+ ge.DrawNormalText(iLen,
+ pCharPos,
+ m_pFont,
+ CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize ,
+ (CFX_AffineMatrix *) &affine_matrix,
+ m_fontColor, FXTEXT_CLEARTYPE);
+ geBitmap.SetDIBits(ge.GetBitmap(), leftPosition, m_Height - iTextHeight);
+ } else {
+ CFX_AffineMatrix affine_matrix1(1.0, 0.0, 0.0, -1.0, (FX_FLOAT)leftPosition * m_outputHScale, (FX_FLOAT)(m_Height - iTextHeight + iFontSize));
+ affine_matrix1.Concat(*matrix);
+ FX_BOOL ret = device->DrawNormalText(iLen,
+ pCharPos,
+ m_pFont,
+ CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize,
+ (CFX_AffineMatrix *) &affine_matrix1,
+ m_fontColor, FXTEXT_CLEARTYPE);
+ }
+ tempStr = str.Mid(4, 4);
+ iLen = tempStr.GetLength();
+ charsWidth = 0.0f;
+ CalcTextInfo(tempStr, pCharPos + 4, m_pFont, (FX_FLOAT)strWidth, iFontSize, blank);
+ if (pOutBitmap != NULL) {
+ delete ge.GetBitmap();
+ ge.Create(strWidth, iTextHeight, FXDIB_Argb);
+ ge.GetBitmap()->Clear(m_backgroundColor);
+ ge.DrawNormalText(iLen,
+ pCharPos + 4,
+ m_pFont,
+ CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize ,
+ (CFX_AffineMatrix *) &affine_matrix,
+ m_fontColor, FXTEXT_CLEARTYPE);
+ geBitmap.SetDIBits(ge.GetBitmap(), leftPosition + 33 * multiple, m_Height - iTextHeight);
+ } else {
+ CFX_AffineMatrix affine_matrix1(1.0, 0.0, 0.0, -1.0, (FX_FLOAT)(leftPosition + 33 * multiple) * m_outputHScale, (FX_FLOAT)(m_Height - iTextHeight + iFontSize));
+ if (matrix != NULL) {
+ affine_matrix1.Concat(*matrix);
+ }
+ FX_BOOL ret = device->DrawNormalText(iLen,
+ pCharPos + 4,
+ m_pFont,
+ CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize ,
+ (CFX_AffineMatrix *) &affine_matrix1,
+ m_fontColor, FXTEXT_CLEARTYPE);
+ }
+ FX_Free(pCharPos);
+}
+void CBC_OnedEAN8Writer::RenderResult(FX_WSTR contents, FX_BYTE* code, FX_INT32 codeLength, FX_BOOL isDevice, FX_INT32 &e)
+{
+ CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e);
+}
diff --git a/xfa/src/fxbarcode/oned/BC_OnedEAN8Writer.h b/xfa/src/fxbarcode/oned/BC_OnedEAN8Writer.h
new file mode 100644
index 0000000000..2b55734538
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedEAN8Writer.h
@@ -0,0 +1,32 @@
+// 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_ONEDEAN8WRITER_H_
+#define _BC_ONEDEAN8WRITER_H_
+enum BC_TEXT_LOC;
+class CBC_OneDimWriter;
+class CBC_OnedEAN8Writer;
+class CBC_OnedEAN8Writer : public CBC_OneDimWriter
+{
+private:
+ FX_INT32 m_codeWidth;
+public:
+ CBC_OnedEAN8Writer();
+ virtual ~CBC_OnedEAN8Writer();
+ 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_BYTE * Encode(const CFX_ByteString &contents, FX_INT32 &outLength, FX_INT32 &e);
+ void RenderResult(FX_WSTR contents, FX_BYTE* code, FX_INT32 codeLength, FX_BOOL isDevice, FX_INT32 &e);
+ FX_BOOL CheckContentValidity(FX_WSTR contents);
+ CFX_WideString FilterContents(FX_WSTR contents);
+ void SetDataLength(FX_INT32 length);
+ FX_BOOL SetTextLocation(BC_TEXT_LOC location);
+ FX_INT32 CalcChecksum(const CFX_ByteString &contents);
+protected:
+
+ void ShowChars(FX_WSTR contents, CFX_DIBitmap *pOutBitmap, CFX_RenderDevice* device, const CFX_Matrix* matrix, FX_INT32 barWidth, FX_INT32 multiple, FX_INT32 &e);
+};
+#endif
diff --git a/xfa/src/fxbarcode/oned/BC_OnedUPCAReader.cpp b/xfa/src/fxbarcode/oned/BC_OnedUPCAReader.cpp
new file mode 100644
index 0000000000..44c26acf7e
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedUPCAReader.cpp
@@ -0,0 +1,93 @@
+// 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_Reader.h"
+#include "BC_OneDReader.h"
+#include "BC_OneDimReader.h"
+#include "BC_OnedEAN13Reader.h"
+#include "BC_OnedUPCAReader.h"
+CBC_OnedUPCAReader::CBC_OnedUPCAReader()
+{
+ m_ean13Reader = NULL;
+}
+void CBC_OnedUPCAReader::Init()
+{
+ m_ean13Reader = FX_NEW CBC_OnedEAN13Reader;
+}
+CBC_OnedUPCAReader::~CBC_OnedUPCAReader()
+{
+ if(m_ean13Reader != NULL) {
+ delete m_ean13Reader;
+ }
+ m_ean13Reader = NULL;
+}
+CFX_ByteString CBC_OnedUPCAReader::DecodeRow(FX_INT32 rowNumber, CBC_CommonBitArray *row, FX_INT32 hints, FX_INT32 &e)
+{
+ CFX_ByteString bytestring = m_ean13Reader->DecodeRow(rowNumber, row, hints, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ CFX_ByteString temp = MaybeReturnResult(bytestring, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ return temp;
+}
+CFX_ByteString CBC_OnedUPCAReader::DecodeRow(FX_INT32 rowNumber, CBC_CommonBitArray *row, CFX_Int32Array *startGuardRange, FX_INT32 hints, FX_INT32 &e)
+{
+ CFX_ByteString bytestring = m_ean13Reader->DecodeRow(rowNumber, row, startGuardRange, hints, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ CFX_ByteString temp = MaybeReturnResult(bytestring, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ return temp;
+}
+CFX_ByteString CBC_OnedUPCAReader::Decode(CBC_BinaryBitmap *image, FX_INT32 &e)
+{
+ CFX_ByteString bytestring = m_ean13Reader->Decode(image, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ CFX_ByteString temp = MaybeReturnResult(bytestring, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ return temp;
+}
+CFX_ByteString CBC_OnedUPCAReader::Decode(CBC_BinaryBitmap *image, FX_INT32 hints, FX_INT32 &e)
+{
+ CFX_ByteString bytestring = m_ean13Reader->Decode(image, hints, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ CFX_ByteString temp = MaybeReturnResult(bytestring, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ return temp;
+}
+FX_INT32 CBC_OnedUPCAReader::DecodeMiddle(CBC_CommonBitArray *row, CFX_Int32Array *startRange, CFX_ByteString &resultString, FX_INT32 &e)
+{
+ FX_INT32 temp = m_ean13Reader->DecodeMiddle(row, startRange, resultString, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, 0);
+ return temp;
+}
+CFX_ByteString CBC_OnedUPCAReader::MaybeReturnResult(CFX_ByteString &result, FX_INT32 &e)
+{
+ if(result[0] == '0') {
+ result.Delete(0);
+ return result;
+ } else {
+ e = BCExceptionFormatException;
+ return "";
+ }
+ return "";
+}
diff --git a/xfa/src/fxbarcode/oned/BC_OnedUPCAReader.h b/xfa/src/fxbarcode/oned/BC_OnedUPCAReader.h
new file mode 100644
index 0000000000..5df6c739ff
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedUPCAReader.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_ONEDUPCAREADER_H_
+#define _BC_ONEDUPCAREADER_H_
+class CBC_BinaryBitmap;
+class CBC_CommonBitArray;
+class CBC_OneDimReader;
+class CBC_OnedEAN13Reader;
+class CBC_OnedUPCAReader;
+class CBC_OnedUPCAReader : public CBC_OneDimReader
+{
+private:
+ CBC_OnedEAN13Reader *m_ean13Reader;
+public:
+ CBC_OnedUPCAReader();
+ virtual ~CBC_OnedUPCAReader();
+ CFX_ByteString DecodeRow(FX_INT32 rowNumber, CBC_CommonBitArray *row, FX_INT32 hints, FX_INT32 &e);
+ CFX_ByteString DecodeRow(FX_INT32 rowNumber, CBC_CommonBitArray *row, CFX_Int32Array *startGuardRange, FX_INT32 hints, FX_INT32 &e);
+ CFX_ByteString Decode(CBC_BinaryBitmap *image, FX_INT32 &e);
+ CFX_ByteString Decode(CBC_BinaryBitmap *image, FX_INT32 hints, FX_INT32 &e);
+ virtual void Init();
+protected:
+ FX_INT32 DecodeMiddle(CBC_CommonBitArray *row, CFX_Int32Array *startRange, CFX_ByteString &resultString, FX_INT32 &e);
+ CFX_ByteString MaybeReturnResult(CFX_ByteString &result, FX_INT32 &e);
+};
+#endif
diff --git a/xfa/src/fxbarcode/oned/BC_OnedUPCAWriter.cpp b/xfa/src/fxbarcode/oned/BC_OnedUPCAWriter.cpp
new file mode 100644
index 0000000000..612c031c02
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedUPCAWriter.cpp
@@ -0,0 +1,285 @@
+// 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 2010 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_OneDimWriter.h"
+#include "BC_OnedEAN13Writer.h"
+#include "BC_OnedUPCAWriter.h"
+CBC_OnedUPCAWriter::CBC_OnedUPCAWriter()
+{
+ m_subWriter = NULL;
+ m_bLeftPadding = TRUE;
+ m_bRightPadding = TRUE;
+}
+void CBC_OnedUPCAWriter::Init()
+{
+ m_subWriter = FX_NEW CBC_OnedEAN13Writer;
+}
+CBC_OnedUPCAWriter::~CBC_OnedUPCAWriter()
+{
+ if(m_subWriter != NULL) {
+ delete m_subWriter;
+ }
+ m_subWriter = NULL;
+}
+FX_BOOL CBC_OnedUPCAWriter::CheckContentValidity(FX_WSTR contents)
+{
+ FX_INT32 i = 0;
+ for (i = 0; i < contents.GetLength(); i++) {
+ if (contents.GetAt(i) >= '0' && contents.GetAt(i) <= '9') {
+ continue;
+ } else {
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+CFX_WideString CBC_OnedUPCAWriter::FilterContents(FX_WSTR contents)
+{
+ CFX_WideString filtercontents;
+ FX_WCHAR ch;
+ for (FX_INT32 i = 0; i < contents.GetLength(); i++) {
+ ch = contents.GetAt(i);
+ if(ch > 175) {
+ i++;
+ continue;
+ }
+ if (ch >= '0' && ch <= '9') {
+ filtercontents += ch;
+ }
+ }
+ return filtercontents;
+}
+FX_INT32 CBC_OnedUPCAWriter::CalcChecksum(const CFX_ByteString &contents)
+{
+ FX_INT32 odd = 0;
+ FX_INT32 even = 0;
+ FX_INT32 j = 1;
+ for(FX_INT32 i = contents.GetLength() - 1; i >= 0; i--) {
+ if(j % 2) {
+ odd += FXSYS_atoi(contents.Mid(i, 1));
+ } else {
+ even += FXSYS_atoi(contents.Mid(i, 1));
+ }
+ j++;
+ }
+ FX_INT32 checksum = (odd * 3 + even) % 10;
+ checksum = (10 - checksum) % 10;
+ return (checksum);
+}
+FX_BYTE *CBC_OnedUPCAWriter::Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 &e)
+{
+ FX_BYTE *ret = Encode(contents, format, outWidth, outHeight, 0, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return ret;
+}
+FX_BYTE *CBC_OnedUPCAWriter::Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 hints, FX_INT32 &e)
+{
+ if (format != BCFORMAT_UPC_A) {
+ e = BCExceptionOnlyEncodeUPC_A;
+ return NULL;
+ }
+ CFX_ByteString toEAN13String = '0' + contents;
+ m_iDataLenth = 13;
+ FX_BYTE *ret = m_subWriter->Encode(toEAN13String, BCFORMAT_EAN_13, outWidth, outHeight, hints, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return ret;
+}
+void CBC_OnedUPCAWriter::ShowChars(FX_WSTR contents, CFX_DIBitmap *pOutBitmap, CFX_RenderDevice* device, const CFX_Matrix* matrix, FX_INT32 barWidth, FX_INT32 multiple, FX_INT32 &e)
+{
+ if (device == NULL && pOutBitmap == NULL) {
+ e = BCExceptionIllegalArgument;
+ return;
+ }
+ FX_INT32 leftPadding = 7 * multiple;
+ FX_INT32 leftPosition = 10 * multiple + leftPadding;
+ CFX_ByteString str = FX_UTF8Encode(contents);
+ FX_INT32 iLen = str.GetLength();
+ FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, iLen);
+ if (!pCharPos) {
+ return;
+ }
+ FXSYS_memset32(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLen);
+ CFX_ByteString tempStr = str.Mid(1, 5);
+ FX_FLOAT strWidth = (FX_FLOAT)35 * multiple;
+ FX_FLOAT blank = 0.0;
+ CFX_FxgeDevice geBitmap;
+ if (pOutBitmap != NULL) {
+ geBitmap.Attach(pOutBitmap);
+ }
+ FX_FLOAT charsWidth = 0;
+ iLen = tempStr.GetLength();
+ FX_INT32 iFontSize = (FX_INT32)fabs(m_fFontSize);
+ FX_INT32 iTextHeight = iFontSize + 1;
+ if (pOutBitmap == NULL) {
+ CFX_Matrix matr(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
+ CFX_FloatRect rect((FX_FLOAT)leftPosition, (FX_FLOAT)(m_Height - iTextHeight), (FX_FLOAT)(leftPosition + strWidth - 0.5), (FX_FLOAT)m_Height);
+ matr.Concat(*matrix);
+ matr.TransformRect(rect);
+ FX_RECT re = rect.GetOutterRect();
+ device->FillRect(&re, m_backgroundColor);
+ CFX_Matrix matr1(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
+ CFX_FloatRect rect1((FX_FLOAT)(leftPosition + 40 * multiple), (FX_FLOAT)(m_Height - iTextHeight), (FX_FLOAT)((leftPosition + 40 * multiple) + strWidth - 0.5), (FX_FLOAT)m_Height);
+ matr1.Concat(*matrix);
+ matr1.TransformRect(rect1);
+ re = rect1.GetOutterRect();
+ device->FillRect(&re, m_backgroundColor);
+ FX_FLOAT strWidth1 = (FX_FLOAT)multiple * 7;
+ CFX_Matrix matr2(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
+ CFX_FloatRect rect2(0.0, (FX_FLOAT)(m_Height - iTextHeight), (FX_FLOAT)strWidth1 - 1, (FX_FLOAT)m_Height);
+ matr2.Concat(*matrix);
+ matr2.TransformRect(rect2);
+ re = rect2.GetOutterRect();
+ device->FillRect(&re, m_backgroundColor);
+ CFX_Matrix matr3(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
+ CFX_FloatRect rect3((FX_FLOAT)(leftPosition + 85 * multiple), (FX_FLOAT)(m_Height - iTextHeight), (FX_FLOAT)((leftPosition + 85 * multiple) + strWidth1 - 0.5), (FX_FLOAT)m_Height);
+ matr3.Concat(*matrix);
+ matr3.TransformRect(rect3);
+ re = rect3.GetOutterRect();
+ device->FillRect(&re, m_backgroundColor);
+ }
+ if (pOutBitmap == NULL) {
+ strWidth = strWidth * m_outputHScale;
+ }
+ CalcTextInfo(tempStr, pCharPos + 1, m_pFont, strWidth, iFontSize, blank);
+ CFX_AffineMatrix affine_matrix(1.0, 0.0, 0.0, -1.0, 0.0, (FX_FLOAT)iFontSize);
+ CFX_FxgeDevice ge;
+ if(pOutBitmap != NULL) {
+ ge.Create((int)strWidth, iTextHeight, FXDIB_Argb);
+ ge.GetBitmap()->Clear(m_backgroundColor);
+ ge.DrawNormalText(iLen,
+ pCharPos + 1,
+ m_pFont,
+ CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize ,
+ (CFX_AffineMatrix *) &affine_matrix,
+ m_fontColor, FXTEXT_CLEARTYPE);
+ geBitmap.SetDIBits(ge.GetBitmap(), leftPosition, m_Height - iTextHeight);
+ } else {
+ CFX_AffineMatrix affine_matrix1(1.0, 0.0, 0.0, -1.0, (FX_FLOAT)leftPosition * m_outputHScale, (FX_FLOAT)(m_Height - iTextHeight + iFontSize));
+ if (matrix != NULL) {
+ affine_matrix1.Concat(*matrix);
+ }
+ device->DrawNormalText(iLen,
+ pCharPos + 1,
+ m_pFont,
+ CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize ,
+ (CFX_AffineMatrix *) &affine_matrix1,
+ m_fontColor, FXTEXT_CLEARTYPE);
+ }
+ tempStr = str.Mid(6, 5);
+ iLen = tempStr.GetLength();
+ charsWidth = 0.0f;
+ CalcTextInfo(tempStr, pCharPos + 6, m_pFont, strWidth, iFontSize, blank);
+ if(pOutBitmap != NULL) {
+ FX_RECT rect2(0, 0, (int)strWidth, iTextHeight);
+ ge.FillRect(&rect2, m_backgroundColor);
+ ge.DrawNormalText(iLen,
+ pCharPos + 6,
+ m_pFont,
+ CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize ,
+ (CFX_AffineMatrix *) &affine_matrix,
+ m_fontColor, FXTEXT_CLEARTYPE);
+ geBitmap.SetDIBits(ge.GetBitmap(), leftPosition + 40 * multiple, m_Height - iTextHeight);
+ } else {
+ CFX_AffineMatrix affine_matrix1(1.0, 0.0, 0.0, -1.0, (FX_FLOAT)(leftPosition + 40 * multiple) * m_outputHScale, (FX_FLOAT)(m_Height - iTextHeight + iFontSize));
+ if (matrix != NULL) {
+ affine_matrix1.Concat(*matrix);
+ }
+ device->DrawNormalText(iLen,
+ pCharPos + 6,
+ m_pFont,
+ CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize ,
+ (CFX_AffineMatrix *) &affine_matrix1,
+ m_fontColor, FXTEXT_CLEARTYPE);
+ }
+ tempStr = str.Mid(0, 1);
+ iLen = tempStr.GetLength();
+ strWidth = (FX_FLOAT)multiple * 7;
+ if (pOutBitmap == NULL) {
+ strWidth = strWidth * m_outputHScale;
+ }
+ CalcTextInfo(tempStr, pCharPos, m_pFont, strWidth, iFontSize, blank);
+ if(pOutBitmap != NULL) {
+ delete ge.GetBitmap();
+ ge.Create((int)strWidth, iTextHeight, FXDIB_Argb);
+ ge.GetBitmap()->Clear(m_backgroundColor);
+ ge.DrawNormalText(iLen,
+ pCharPos,
+ m_pFont,
+ CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize ,
+ (CFX_AffineMatrix *) &affine_matrix,
+ m_fontColor, FXTEXT_CLEARTYPE);
+ geBitmap.SetDIBits(ge.GetBitmap(), 0, m_Height - iTextHeight);
+ } else {
+ CFX_AffineMatrix affine_matrix1(1.0, 0.0, 0.0, -1.0, 0, (FX_FLOAT)(m_Height - iTextHeight + iFontSize));
+ if (matrix != NULL) {
+ affine_matrix1.Concat(*matrix);
+ }
+ device->DrawNormalText(iLen,
+ pCharPos,
+ m_pFont,
+ CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize ,
+ (CFX_AffineMatrix *) &affine_matrix1,
+ m_fontColor, FXTEXT_CLEARTYPE);
+ }
+ tempStr = str.Mid(11, 1);
+ iLen = tempStr.GetLength();
+ CalcTextInfo(tempStr, pCharPos + 11, m_pFont, strWidth, iFontSize, blank);
+ if (pOutBitmap != NULL) {
+ delete ge.GetBitmap();
+ ge.Create((int)strWidth, iTextHeight, FXDIB_Argb);
+ ge.GetBitmap()->Clear(m_backgroundColor);
+ ge.DrawNormalText(iLen,
+ pCharPos + 11,
+ m_pFont,
+ CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize ,
+ (CFX_AffineMatrix *) &affine_matrix,
+ m_fontColor, FXTEXT_CLEARTYPE);
+ geBitmap.SetDIBits(ge.GetBitmap(), leftPosition + 85 * multiple, m_Height - iTextHeight);
+ } else {
+ CFX_AffineMatrix affine_matrix1(1.0, 0.0, 0.0, -1.0, (FX_FLOAT)(leftPosition + 85 * multiple) * m_outputHScale, (FX_FLOAT)(m_Height - iTextHeight + iFontSize));
+ if (matrix != NULL) {
+ affine_matrix1.Concat(*matrix);
+ }
+ device->DrawNormalText(iLen,
+ pCharPos + 11,
+ m_pFont,
+ CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize ,
+ (CFX_AffineMatrix *) &affine_matrix1,
+ m_fontColor, FXTEXT_CLEARTYPE);
+ }
+ FX_Free(pCharPos);
+}
+void CBC_OnedUPCAWriter::RenderResult(FX_WSTR contents, FX_BYTE* code, FX_INT32 codeLength, FX_BOOL isDevice, FX_INT32 &e)
+{
+ CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e);
+}
+
diff --git a/xfa/src/fxbarcode/oned/BC_OnedUPCAWriter.h b/xfa/src/fxbarcode/oned/BC_OnedUPCAWriter.h
new file mode 100644
index 0000000000..4174ceb36e
--- /dev/null
+++ b/xfa/src/fxbarcode/oned/BC_OnedUPCAWriter.h
@@ -0,0 +1,31 @@
+// 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_ONEDUPCAWRITER_H_
+#define _BC_ONEDUPCAWRITER_H_
+class CBC_Writer;
+class CBC_OnedEAN13Writer;
+class CBC_OnedUPCAWriter;
+class CBC_OnedUPCAWriter : public CBC_OneDimWriter
+{
+private:
+ CBC_OnedEAN13Writer *m_subWriter;
+public:
+ CBC_OnedUPCAWriter();
+ virtual ~CBC_OnedUPCAWriter();
+ virtual void Init();
+ 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);
+ void RenderResult(FX_WSTR contents, FX_BYTE* code, FX_INT32 codeLength, FX_BOOL isDevice, FX_INT32 &e);
+ FX_BOOL CheckContentValidity(FX_WSTR contents);
+ CFX_WideString FilterContents(FX_WSTR contents);
+ FX_INT32 CalcChecksum(const CFX_ByteString &contents);
+
+protected:
+
+ void ShowChars(FX_WSTR contents, CFX_DIBitmap *pOutBitmap, CFX_RenderDevice* device, const CFX_Matrix* matrix, FX_INT32 barWidth, FX_INT32 multiple, FX_INT32 &e);
+};
+#endif