summaryrefslogtreecommitdiff
path: root/xfa/fxbarcode/oned
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxbarcode/oned')
-rw-r--r--xfa/fxbarcode/oned/BC_OneDReader.cpp181
-rw-r--r--xfa/fxbarcode/oned/BC_OneDReader.h51
-rw-r--r--xfa/fxbarcode/oned/BC_OneDimReader.cpp217
-rw-r--r--xfa/fxbarcode/oned/BC_OneDimReader.h66
-rw-r--r--xfa/fxbarcode/oned/BC_OnedCodaBarReader.cpp213
-rw-r--r--xfa/fxbarcode/oned/BC_OnedCodaBarReader.h39
-rw-r--r--xfa/fxbarcode/oned/BC_OnedCodaBarWriter.cpp30
-rw-r--r--xfa/fxbarcode/oned/BC_OnedCodaBarWriter.h3
-rw-r--r--xfa/fxbarcode/oned/BC_OnedCode128Reader.cpp349
-rw-r--r--xfa/fxbarcode/oned/BC_OnedCode128Reader.h53
-rw-r--r--xfa/fxbarcode/oned/BC_OnedCode128Writer.cpp61
-rw-r--r--xfa/fxbarcode/oned/BC_OnedCode128Writer.h6
-rw-r--r--xfa/fxbarcode/oned/BC_OnedCode39Reader.cpp286
-rw-r--r--xfa/fxbarcode/oned/BC_OnedCode39Reader.h43
-rw-r--r--xfa/fxbarcode/oned/BC_OnedCode39Writer.cpp142
-rw-r--r--xfa/fxbarcode/oned/BC_OnedCode39Writer.h7
-rw-r--r--xfa/fxbarcode/oned/BC_OnedEAN13Reader.cpp96
-rw-r--r--xfa/fxbarcode/oned/BC_OnedEAN13Reader.h38
-rw-r--r--xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp37
-rw-r--r--xfa/fxbarcode/oned/BC_OnedEAN8Reader.cpp82
-rw-r--r--xfa/fxbarcode/oned/BC_OnedEAN8Reader.h26
-rw-r--r--xfa/fxbarcode/oned/BC_OnedEAN8Writer.cpp27
-rw-r--r--xfa/fxbarcode/oned/BC_OnedUPCAReader.cpp95
-rw-r--r--xfa/fxbarcode/oned/BC_OnedUPCAReader.h53
24 files changed, 137 insertions, 2064 deletions
diff --git a/xfa/fxbarcode/oned/BC_OneDReader.cpp b/xfa/fxbarcode/oned/BC_OneDReader.cpp
deleted file mode 100644
index 53ff9a480c..0000000000
--- a/xfa/fxbarcode/oned/BC_OneDReader.cpp
+++ /dev/null
@@ -1,181 +0,0 @@
-// 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 <algorithm>
-#include <memory>
-
-#include "xfa/fxbarcode/BC_BinaryBitmap.h"
-#include "xfa/fxbarcode/BC_Reader.h"
-#include "xfa/fxbarcode/common/BC_CommonBitArray.h"
-#include "xfa/fxbarcode/oned/BC_OneDReader.h"
-#include "xfa/fxbarcode/utils.h"
-
-CBC_OneDReader::CBC_OneDReader() {}
-CBC_OneDReader::~CBC_OneDReader() {}
-CFX_ByteString CBC_OneDReader::Decode(CBC_BinaryBitmap* image, int32_t& e) {
- CFX_ByteString strtemp = Decode(image, 0, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, "");
- return strtemp;
-}
-CFX_ByteString CBC_OneDReader::Decode(CBC_BinaryBitmap* image,
- int32_t hints,
- int32_t& e) {
- CFX_ByteString strtemp = DeDecode(image, hints, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, "");
- return strtemp;
-}
-CFX_ByteString CBC_OneDReader::DecodeRow(int32_t rowNumber,
- CBC_CommonBitArray* row,
- int32_t hints,
- int32_t& e) {
- return "";
-}
-CFX_ByteString CBC_OneDReader::DeDecode(CBC_BinaryBitmap* image,
- int32_t hints,
- int32_t& e) {
- int32_t height = image->GetHeight();
- int32_t middle = height >> 1;
- FX_BOOL tryHarder = FALSE;
- int32_t rowStep = std::max(1, height >> (tryHarder ? 8 : 5));
- int32_t maxLines;
- if (tryHarder) {
- maxLines = height;
- } else {
- maxLines = 15;
- }
- for (int32_t x = 0; x < maxLines; x++) {
- int32_t rowStepsAboveOrBelow = (x + 1) >> 1;
- const bool isAbove = (x & 0x01) == 0;
- int32_t rowNumber =
- middle +
- rowStep * (isAbove ? rowStepsAboveOrBelow : -rowStepsAboveOrBelow);
- if (rowNumber < 0 || rowNumber >= height) {
- break;
- }
- std::unique_ptr<CBC_CommonBitArray> row(
- image->GetBlackRow(rowNumber, nullptr, e));
- if (e != BCExceptionNO) {
- e = BCExceptionNO;
- continue;
- }
- for (int32_t attempt = 0; attempt < 2; attempt++) {
- if (attempt == 1) {
- row->Reverse();
- }
- CFX_ByteString result = DecodeRow(rowNumber, row.get(), hints, e);
- if (e != BCExceptionNO) {
- e = BCExceptionNO;
- continue;
- }
- return result;
- }
- }
- e = BCExceptionNotFound;
- return "";
-}
-void CBC_OneDReader::RecordPattern(CBC_CommonBitArray* row,
- int32_t start,
- CFX_Int32Array* counters,
- int32_t& e) {
- int32_t numCounters = counters->GetSize();
- for (int32_t i = 0; i < numCounters; i++) {
- (*counters)[i] = 0;
- }
- int32_t end = row->GetSize();
- if (start >= end) {
- e = BCExceptionNotFound;
- return;
- }
- FX_BOOL isWhite = !row->Get(start);
- int32_t counterPosition = 0;
- int32_t 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,
- int32_t start,
- CFX_Int32Array* counters,
- int32_t& e) {
- int32_t 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);
-}
-int32_t CBC_OneDReader::PatternMatchVariance(CFX_Int32Array* counters,
- const int32_t* pattern,
- int32_t maxIndividualVariance) {
- int32_t numCounters = counters->GetSize();
- int32_t total = 0;
- int32_t patternLength = 0;
- for (int32_t i = 0; i < numCounters; i++) {
- total += (*counters)[i];
- patternLength += pattern[i];
- }
- if (total < patternLength) {
-#undef max
- return FXSYS_IntMax;
- }
- int32_t unitBarWidth = (total << INTEGER_MATH_SHIFT) / patternLength;
- maxIndividualVariance =
- (maxIndividualVariance * unitBarWidth) >> INTEGER_MATH_SHIFT;
- int32_t totalVariance = 0;
- for (int32_t x = 0; x < numCounters; x++) {
- int32_t counter = (*counters)[x] << INTEGER_MATH_SHIFT;
- int32_t scaledPattern = pattern[x] * unitBarWidth;
- int32_t variance = counter > scaledPattern ? counter - scaledPattern
- : scaledPattern - counter;
- if (variance > maxIndividualVariance) {
-#undef max
- return FXSYS_IntMax;
- }
- totalVariance += variance;
- }
- return totalVariance / total;
-}
diff --git a/xfa/fxbarcode/oned/BC_OneDReader.h b/xfa/fxbarcode/oned/BC_OneDReader.h
deleted file mode 100644
index 77e04777a4..0000000000
--- a/xfa/fxbarcode/oned/BC_OneDReader.h
+++ /dev/null
@@ -1,51 +0,0 @@
-// 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 XFA_FXBARCODE_ONED_BC_ONEDREADER_H_
-#define XFA_FXBARCODE_ONED_BC_ONEDREADER_H_
-
-#include "xfa/fxbarcode/BC_Reader.h"
-
-class CBC_BinaryBitmap;
-class CBC_CommonBitArray;
-
-class CBC_OneDReader : public CBC_Reader {
- public:
- CBC_OneDReader();
- ~CBC_OneDReader() override;
-
- // CBC_Reader
- CFX_ByteString Decode(CBC_BinaryBitmap* image, int32_t& e) override;
- CFX_ByteString Decode(CBC_BinaryBitmap* image,
- int32_t hints,
- int32_t& e) override;
-
- virtual CFX_ByteString DecodeRow(int32_t rowNumber,
- CBC_CommonBitArray* row,
- int32_t hints,
- int32_t& e);
-
- private:
- CFX_ByteString DeDecode(CBC_BinaryBitmap* image, int32_t hints, int32_t& e);
-
- protected:
- static const int32_t INTEGER_MATH_SHIFT = 8;
- static const int32_t PATTERN_MATCH_RESULT_SCALE_FACTOR = 1 << 8;
-
- void RecordPattern(CBC_CommonBitArray* row,
- int32_t start,
- CFX_Int32Array* counters,
- int32_t& e);
- void RecordPatternInReverse(CBC_CommonBitArray* row,
- int32_t start,
- CFX_Int32Array* counters,
- int32_t& e);
- int32_t PatternMatchVariance(CFX_Int32Array* counters,
- const int32_t* pattern,
- int32_t maxIndividualVariance);
-};
-
-#endif // XFA_FXBARCODE_ONED_BC_ONEDREADER_H_
diff --git a/xfa/fxbarcode/oned/BC_OneDimReader.cpp b/xfa/fxbarcode/oned/BC_OneDimReader.cpp
deleted file mode 100644
index e413adb6a4..0000000000
--- a/xfa/fxbarcode/oned/BC_OneDimReader.cpp
+++ /dev/null
@@ -1,217 +0,0 @@
-// 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 "xfa/fxbarcode/oned/BC_OneDimReader.h"
-
-#include <memory>
-
-#include "xfa/fxbarcode/BC_Reader.h"
-#include "xfa/fxbarcode/common/BC_CommonBitArray.h"
-#include "xfa/fxbarcode/oned/BC_OneDReader.h"
-#include "xfa/fxbarcode/utils.h"
-
-const int32_t CBC_OneDimReader::START_END_PATTERN[3] = {1, 1, 1};
-const int32_t CBC_OneDimReader::MIDDLE_PATTERN[5] = {1, 1, 1, 1, 1};
-const int32_t 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 int32_t 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,
- int32_t& e) {
- FX_BOOL foundStart = FALSE;
- CFX_Int32Array* startRange = nullptr;
- CFX_Int32Array startEndPattern;
- startEndPattern.SetSize(3);
- startEndPattern[0] = START_END_PATTERN[0];
- startEndPattern[1] = START_END_PATTERN[1];
- startEndPattern[2] = START_END_PATTERN[2];
- int32_t nextStart = 0;
- while (!foundStart) {
- delete startRange;
- startRange = FindGuardPattern(row, nextStart, FALSE, &startEndPattern, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
- int32_t start = (*startRange)[0];
- nextStart = (*startRange)[1];
- if (start <= 1) {
- break;
- }
- int32_t quietStart = start - (nextStart - start);
- if (quietStart >= 0) {
- FX_BOOL booT = row->IsRange(quietStart, start, FALSE, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
- foundStart = booT;
- }
- }
- return startRange;
-}
-CFX_ByteString CBC_OneDimReader::DecodeRow(int32_t rowNumber,
- CBC_CommonBitArray* row,
- int32_t hints,
- int32_t& e) {
- std::unique_ptr<CFX_Int32Array> result(FindStartGuardPattern(row, e));
- BC_EXCEPTION_CHECK_ReturnValue(e, "");
- CFX_ByteString temp = DecodeRow(rowNumber, row, result.get(), hints, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, "");
- return temp;
-}
-CFX_ByteString CBC_OneDimReader::DecodeRow(int32_t rowNumber,
- CBC_CommonBitArray* row,
- CFX_Int32Array* startGuardRange,
- int32_t hints,
- int32_t& e) {
- CFX_ByteString result;
- 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, int32_t& e) {
- FX_BOOL temp = CheckStandardUPCEANChecksum(s, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
- return temp;
-}
-FX_BOOL CBC_OneDimReader::CheckStandardUPCEANChecksum(CFX_ByteString& s,
- int32_t& e) {
- int32_t length = s.GetLength();
- if (length == 0) {
- return FALSE;
- }
- int32_t sum = 0;
- for (int32_t i = length - 2; i >= 0; i -= 2) {
- int32_t digit = (int32_t)s[i] - (int32_t)'0';
- if (digit < 0 || digit > 9) {
- e = BCExceptionFormatException;
- return FALSE;
- }
- sum += digit;
- }
- sum *= 3;
- for (int32_t j = length - 1; j >= 0; j -= 2) {
- int32_t digit = (int32_t)s[j] - (int32_t)'0';
- if (digit < 0 || digit > 9) {
- e = BCExceptionFormatException;
- return FALSE;
- }
- sum += digit;
- }
- return sum % 10 == 0;
-}
-CFX_Int32Array* CBC_OneDimReader::DecodeEnd(CBC_CommonBitArray* row,
- int32_t endStart,
- int32_t& 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, nullptr);
- return FindGuard;
-}
-CFX_Int32Array* CBC_OneDimReader::FindGuardPattern(CBC_CommonBitArray* row,
- int32_t rowOffset,
- FX_BOOL whiteFirst,
- CFX_Int32Array* pattern,
- int32_t& e) {
- int32_t patternLength = pattern->GetSize();
- CFX_Int32Array counters;
- counters.SetSize(patternLength);
- int32_t width = row->GetSize();
- FX_BOOL isWhite = FALSE;
- while (rowOffset < width) {
- isWhite = !row->Get(rowOffset);
- if (whiteFirst == isWhite) {
- break;
- }
- rowOffset++;
- }
- int32_t counterPosition = 0;
- int32_t patternStart = rowOffset;
- for (int32_t 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 = new CFX_Int32Array();
- result->SetSize(2);
- (*result)[0] = patternStart;
- (*result)[1] = x;
- return result;
- }
- patternStart += counters[0] + counters[1];
- for (int32_t 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, nullptr);
- return nullptr;
-}
-int32_t CBC_OneDimReader::DecodeDigit(CBC_CommonBitArray* row,
- CFX_Int32Array* counters,
- int32_t rowOffset,
- const int32_t* patterns,
- int32_t patternLength,
- int32_t& e) {
- RecordPattern(row, rowOffset, counters, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, 0);
- int32_t bestVariance = MAX_AVG_VARIANCE;
- int32_t bestMatch = -1;
- int32_t max = patternLength;
- for (int32_t i = 0; i < max; i++) {
- int32_t variance = PatternMatchVariance(counters, &patterns[i * 4],
- MAX_INDIVIDUAL_VARIANCE);
- if (variance < bestVariance) {
- bestVariance = variance;
- bestMatch = i;
- }
- }
- if (bestMatch >= 0) {
- return bestMatch;
- }
- e = BCExceptionNotFound;
- return 0;
-}
diff --git a/xfa/fxbarcode/oned/BC_OneDimReader.h b/xfa/fxbarcode/oned/BC_OneDimReader.h
deleted file mode 100644
index bd46a189f4..0000000000
--- a/xfa/fxbarcode/oned/BC_OneDimReader.h
+++ /dev/null
@@ -1,66 +0,0 @@
-// 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 XFA_FXBARCODE_ONED_BC_ONEDIMREADER_H_
-#define XFA_FXBARCODE_ONED_BC_ONEDIMREADER_H_
-
-#include "core/fxcrt/include/fx_basic.h"
-#include "xfa/fxbarcode/oned/BC_OneDReader.h"
-
-class CBC_CommonBitArray;
-
-class CBC_OneDimReader : public CBC_OneDReader {
- private:
- static const int32_t MAX_AVG_VARIANCE = (int32_t)(256 * 0.48f);
- static const int32_t MAX_INDIVIDUAL_VARIANCE = (int32_t)(256 * 0.7f);
-
- FX_BOOL CheckStandardUPCEANChecksum(CFX_ByteString& s, int32_t& e);
-
- public:
- static const int32_t START_END_PATTERN[3];
- static const int32_t MIDDLE_PATTERN[5];
- static const int32_t L_PATTERNS[10][4];
- static const int32_t L_AND_G_PATTERNS[20][4];
-
- CBC_OneDimReader();
- ~CBC_OneDimReader() override;
-
- // CBC_OneDReader
- CFX_ByteString DecodeRow(int32_t rowNumber,
- CBC_CommonBitArray* row,
- int32_t hints,
- int32_t& e) override;
-
- virtual CFX_ByteString DecodeRow(int32_t rowNumber,
- CBC_CommonBitArray* row,
- CFX_Int32Array* startGuardRange,
- int32_t hints,
- int32_t& e);
-
- protected:
- CFX_Int32Array* FindStartGuardPattern(CBC_CommonBitArray* row, int32_t& e);
- virtual FX_BOOL CheckChecksum(CFX_ByteString& s, int32_t& e);
- CFX_Int32Array* FindGuardPattern(CBC_CommonBitArray* row,
- int32_t rowOffset,
- FX_BOOL whiteFirst,
- CFX_Int32Array* pattern,
- int32_t& e);
- int32_t DecodeDigit(CBC_CommonBitArray* row,
- CFX_Int32Array* counters,
- int32_t rowOffset,
- const int32_t* patterns,
- int32_t patternLength,
- int32_t& e);
- virtual int32_t DecodeMiddle(CBC_CommonBitArray* row,
- CFX_Int32Array* startRange,
- CFX_ByteString& resultResult,
- int32_t& e) = 0;
- virtual CFX_Int32Array* DecodeEnd(CBC_CommonBitArray* row,
- int32_t endStart,
- int32_t& e);
-};
-
-#endif // XFA_FXBARCODE_ONED_BC_ONEDIMREADER_H_
diff --git a/xfa/fxbarcode/oned/BC_OnedCodaBarReader.cpp b/xfa/fxbarcode/oned/BC_OnedCodaBarReader.cpp
deleted file mode 100644
index 0fa0e9a29b..0000000000
--- a/xfa/fxbarcode/oned/BC_OnedCodaBarReader.cpp
+++ /dev/null
@@ -1,213 +0,0 @@
-// 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 "xfa/fxbarcode/oned/BC_OnedCodaBarReader.h"
-
-#include <algorithm>
-#include <memory>
-
-#include "core/fxcrt/include/fx_basic.h"
-#include "xfa/fxbarcode/BC_Reader.h"
-#include "xfa/fxbarcode/common/BC_CommonBitArray.h"
-#include "xfa/fxbarcode/oned/BC_OneDReader.h"
-#include "xfa/fxbarcode/oned/BC_OnedCode39Reader.h"
-#include "xfa/fxbarcode/utils.h"
-
-const FX_CHAR* CBC_OnedCodaBarReader::ALPHABET_STRING =
- "0123456789-$:/.+ABCDTN";
-const int32_t 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_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(int32_t rowNumber,
- CBC_CommonBitArray* row,
- int32_t hints,
- int32_t& e) {
- std::unique_ptr<CFX_Int32Array> start(FindAsteriskPattern(row, e));
- BC_EXCEPTION_CHECK_ReturnValue(e, "");
- (*start)[1] = 0;
- int32_t nextStart = (*start)[1];
- int32_t end = row->GetSize();
- while (nextStart < end && !row->Get(nextStart)) {
- nextStart++;
- }
- CFX_ByteString result;
- CFX_Int32Array counters;
- counters.SetSize(7);
- FX_CHAR decodedChar;
- int32_t 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 (int32_t i = 0; i < counters.GetSize(); i++) {
- nextStart += counters[i];
- }
- while (nextStart < end && !row->Get(nextStart)) {
- nextStart++;
- }
- } while (nextStart < end);
- int32_t lastPatternSize = 0;
- for (int32_t j = 0; j < counters.GetSize(); j++) {
- lastPatternSize += counters[j];
- }
- int32_t 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 "";
- }
- int32_t len = result.GetLength();
- CFX_ByteString temp = result;
- for (int32_t 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) {
- int32_t index =
- temp.Find(result.Mid(1, result.GetLength() - 1).AsStringC());
- 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,
- int32_t& e) {
- int32_t width = row->GetSize();
- int32_t rowOffset = 0;
- while (rowOffset < width) {
- if (row->Get(rowOffset)) {
- break;
- }
- rowOffset++;
- }
- int32_t counterPosition = 0;
- CFX_Int32Array counters;
- counters.SetSize(7);
- int32_t patternStart = rowOffset;
- FX_BOOL isWhite = FALSE;
- int32_t patternLength = counters.GetSize();
- for (int32_t 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(std::max(0, patternStart - (i - patternStart) / 2),
- patternStart, FALSE, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
- if (btemp3) {
- CFX_Int32Array* result = new CFX_Int32Array();
- result->SetSize(2);
- (*result)[0] = patternStart;
- (*result)[1] = i;
- return result;
- }
- }
- patternStart += counters[0] + counters[1];
- for (int32_t 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 nullptr;
-}
-FX_BOOL CBC_OnedCodaBarReader::ArrayContains(const FX_CHAR array[],
- FX_CHAR key) {
- for (int32_t i = 0; i < 8; i++) {
- if (array[i] == key) {
- return TRUE;
- }
- }
- return FALSE;
-}
-FX_CHAR CBC_OnedCodaBarReader::ToNarrowWidePattern(CFX_Int32Array* counter) {
- int32_t numCounters = counter->GetSize();
- if (numCounters < 1) {
- return '!';
- }
- int32_t averageCounter = 0;
- int32_t totalCounters = 0;
- for (int32_t i = 0; i < numCounters; i++) {
- totalCounters += (*counter)[i];
- }
- averageCounter = totalCounters / numCounters;
- int32_t pattern = 0;
- int32_t wideCounters = 0;
- for (int32_t j = 0; j < numCounters; j++) {
- if ((*counter)[j] > averageCounter) {
- pattern |= 1 << (numCounters - 1 - j);
- wideCounters++;
- }
- }
- if ((wideCounters == 2) || (wideCounters == 3)) {
- for (int32_t k = 0; k < 22; k++) {
- if (CHARACTER_ENCODINGS[k] == pattern) {
- return (ALPHABET_STRING)[k];
- }
- }
- }
- return '!';
-}
diff --git a/xfa/fxbarcode/oned/BC_OnedCodaBarReader.h b/xfa/fxbarcode/oned/BC_OnedCodaBarReader.h
deleted file mode 100644
index ce902bff5e..0000000000
--- a/xfa/fxbarcode/oned/BC_OnedCodaBarReader.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// 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 XFA_FXBARCODE_ONED_BC_ONEDCODABARREADER_H_
-#define XFA_FXBARCODE_ONED_BC_ONEDCODABARREADER_H_
-
-#include "core/fxcrt/include/fx_basic.h"
-#include "xfa/fxbarcode/oned/BC_OneDReader.h"
-
-class CBC_CommonBitArray;
-class CBC_OneDReader;
-
-class CBC_OnedCodaBarReader : public CBC_OneDReader {
- public:
- CBC_OnedCodaBarReader();
- ~CBC_OnedCodaBarReader() override;
-
- // CBC_OneDReader
- CFX_ByteString DecodeRow(int32_t rowNumber,
- CBC_CommonBitArray* row,
- int32_t hints,
- int32_t& e) override;
-
- CFX_Int32Array* FindAsteriskPattern(CBC_CommonBitArray* row, int32_t& e);
- FX_BOOL ArrayContains(const FX_CHAR array[], FX_CHAR key);
- FX_CHAR ToNarrowWidePattern(CFX_Int32Array* counter);
-
- static const FX_CHAR* ALPHABET_STRING;
- static const int32_t CHARACTER_ENCODINGS[22];
-
- private:
- static const int32_t minCharacterLength = 3;
- static const FX_CHAR STARTEND_ENCODING[8];
-};
-
-#endif // XFA_FXBARCODE_ONED_BC_ONEDCODABARREADER_H_
diff --git a/xfa/fxbarcode/oned/BC_OnedCodaBarWriter.cpp b/xfa/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
index 59f4d5ea4d..e25a6c0a5c 100644
--- a/xfa/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
+++ b/xfa/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
@@ -20,20 +20,27 @@
* limitations under the License.
*/
-#include "xfa/fxbarcode/BC_Reader.h"
#include "xfa/fxbarcode/BC_Writer.h"
#include "xfa/fxbarcode/common/BC_CommonBitArray.h"
#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h"
-#include "xfa/fxbarcode/oned/BC_OneDReader.h"
#include "xfa/fxbarcode/oned/BC_OneDimWriter.h"
-#include "xfa/fxbarcode/oned/BC_OnedCodaBarReader.h"
#include "xfa/fxbarcode/oned/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', '-', '$', '/', ':', '+', '.'};
+namespace {
+
+const FX_CHAR ALPHABET_STRING[] = "0123456789-$:/.+ABCDTN";
+
+const int32_t 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_CHAR START_END_CHARS[] = {'A', 'B', 'C', 'D', 'T', 'N', '*', 'E',
+ 'a', 'b', 'c', 'd', 't', 'n', 'e'};
+const FX_CHAR CONTENT_CHARS[] = {'0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', '-', '$', '/', ':', '+', '.'};
+
+} // namespace
CBC_OnedCodaBarWriter::CBC_OnedCodaBarWriter() {
m_chStart = 'A';
@@ -158,7 +165,6 @@ uint8_t* CBC_OnedCodaBarWriter::Encode(const CFX_ByteString& contents,
uint8_t* CBC_OnedCodaBarWriter::Encode(const CFX_ByteString& contents,
int32_t& outLength,
int32_t& e) {
- CBC_OnedCodaBarReader CodaBarR;
CFX_ByteString data = m_chStart + contents + m_chEnd;
m_iContentLen = data.GetLength();
uint8_t* result = FX_Alloc2D(uint8_t, m_iWideNarrRatio * 7, data.GetLength());
@@ -186,10 +192,10 @@ uint8_t* CBC_OnedCodaBarWriter::Encode(const CFX_ByteString& contents,
break;
}
int32_t code = 0;
- int32_t len = (int32_t)strlen(CodaBarR.ALPHABET_STRING);
+ int32_t len = (int32_t)strlen(ALPHABET_STRING);
for (int32_t i = 0; i < len; i++) {
- if (ch == CodaBarR.ALPHABET_STRING[i]) {
- code = CodaBarR.CHARACTER_ENCODINGS[i];
+ if (ch == ALPHABET_STRING[i]) {
+ code = CHARACTER_ENCODINGS[i];
break;
}
}
diff --git a/xfa/fxbarcode/oned/BC_OnedCodaBarWriter.h b/xfa/fxbarcode/oned/BC_OnedCodaBarWriter.h
index 99c6bfb039..02b6b66bea 100644
--- a/xfa/fxbarcode/oned/BC_OnedCodaBarWriter.h
+++ b/xfa/fxbarcode/oned/BC_OnedCodaBarWriter.h
@@ -44,9 +44,6 @@ class CBC_OnedCodaBarWriter : public CBC_OneDimWriter {
virtual FX_BOOL FindChar(FX_WCHAR ch, FX_BOOL isContent);
private:
- static const FX_CHAR START_END_CHARS[];
- static const FX_CHAR CONTENT_CHARS[];
-
void RenderResult(const CFX_WideStringC& contents,
uint8_t* code,
int32_t codeLength,
diff --git a/xfa/fxbarcode/oned/BC_OnedCode128Reader.cpp b/xfa/fxbarcode/oned/BC_OnedCode128Reader.cpp
deleted file mode 100644
index b868327a37..0000000000
--- a/xfa/fxbarcode/oned/BC_OnedCode128Reader.cpp
+++ /dev/null
@@ -1,349 +0,0 @@
-// 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 <algorithm>
-
-#include "xfa/fxbarcode/BC_Reader.h"
-#include "xfa/fxbarcode/common/BC_CommonBitArray.h"
-#include "xfa/fxbarcode/oned/BC_OneDReader.h"
-#include "xfa/fxbarcode/oned/BC_OnedCode128Reader.h"
-#include "xfa/fxbarcode/utils.h"
-
-const int32_t 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}};
-
-CBC_OnedCode128Reader::CBC_OnedCode128Reader() {}
-CBC_OnedCode128Reader::~CBC_OnedCode128Reader() {}
-CFX_Int32Array* CBC_OnedCode128Reader::FindStartPattern(CBC_CommonBitArray* row,
- int32_t& e) {
- int32_t width = row->GetSize();
- int32_t rowOffset = 0;
- while (rowOffset < width) {
- if (row->Get(rowOffset)) {
- break;
- }
- rowOffset++;
- }
- int32_t counterPosition = 0;
- CFX_Int32Array counters;
- counters.SetSize(6);
- int32_t patternStart = rowOffset;
- FX_BOOL isWhite = FALSE;
- int32_t patternLength = counters.GetSize();
- for (int32_t i = rowOffset; i < width; i++) {
- FX_BOOL pixel = row->Get(i);
- if (pixel ^ isWhite) {
- counters[counterPosition]++;
- } else {
- if (counterPosition == patternLength - 1) {
- int32_t bestVariance = MAX_AVG_VARIANCE;
- int32_t bestMatch = -1;
- for (int32_t startCode = CODE_START_A; startCode <= CODE_START_C;
- startCode++) {
- int32_t 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(std::max(0, patternStart - (i - patternStart) / 2),
- patternStart, FALSE, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
- if (btemp2) {
- CFX_Int32Array* result = new CFX_Int32Array;
- result->SetSize(3);
- (*result)[0] = patternStart;
- (*result)[1] = i;
- (*result)[2] = bestMatch;
- return result;
- }
- }
- patternStart += counters[0] + counters[1];
- for (int32_t 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 nullptr;
-}
-int32_t CBC_OnedCode128Reader::DecodeCode(CBC_CommonBitArray* row,
- CFX_Int32Array* counters,
- int32_t rowOffset,
- int32_t& e) {
- RecordPattern(row, rowOffset, counters, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, 0);
- int32_t bestVariance = MAX_AVG_VARIANCE;
- int32_t bestMatch = -1;
- for (int32_t d = 0; d < 107; d++) {
- int32_t variance = PatternMatchVariance(counters, &CODE_PATTERNS[d][0],
- MAX_INDIVIDUAL_VARIANCE);
- if (variance < bestVariance) {
- bestVariance = variance;
- bestMatch = d;
- }
- }
- if (bestMatch >= 0) {
- return bestMatch;
- }
- e = BCExceptionNotFound;
- return 0;
-}
-CFX_ByteString CBC_OnedCode128Reader::DecodeRow(int32_t rowNumber,
- CBC_CommonBitArray* row,
- int32_t hints,
- int32_t& e) {
- CFX_Int32Array* startPatternInfo = FindStartPattern(row, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, "");
- int32_t startCode = (*startPatternInfo)[2];
- int32_t 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) {
- startPatternInfo->RemoveAll();
- delete startPatternInfo;
- startPatternInfo = nullptr;
- }
- e = BCExceptionFormatException;
- return "";
- }
- FX_BOOL done = FALSE;
- FX_BOOL isNextShifted = FALSE;
- CFX_ByteString result;
- int32_t lastStart = (*startPatternInfo)[0];
- int32_t nextStart = (*startPatternInfo)[1];
- if (startPatternInfo) {
- startPatternInfo->RemoveAll();
- delete startPatternInfo;
- startPatternInfo = nullptr;
- }
- CFX_Int32Array counters;
- counters.SetSize(6);
- int32_t lastCode = 0;
- int32_t code = 0;
- int32_t checksumTotal = startCode;
- int32_t 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 (int32_t 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];
- // TODO(dsinclair): Should this be snprintf?
- sprintf(temp, "%d", code);
- 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;
- }
- }
- int32_t width = row->GetSize();
- while (nextStart < width && row->Get(nextStart)) {
- nextStart++;
- }
- FX_BOOL boolT1 = row->IsRange(
- nextStart, std::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 "";
- }
- int32_t 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/fxbarcode/oned/BC_OnedCode128Reader.h b/xfa/fxbarcode/oned/BC_OnedCode128Reader.h
deleted file mode 100644
index b63b054984..0000000000
--- a/xfa/fxbarcode/oned/BC_OnedCode128Reader.h
+++ /dev/null
@@ -1,53 +0,0 @@
-// 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 XFA_FXBARCODE_ONED_BC_ONEDCODE128READER_H_
-#define XFA_FXBARCODE_ONED_BC_ONEDCODE128READER_H_
-
-#include "xfa/fxbarcode/oned/BC_OneDReader.h"
-
-class CBC_CommonBitArray;
-
-class CBC_OnedCode128Reader : public CBC_OneDReader {
- public:
- CBC_OnedCode128Reader();
- ~CBC_OnedCode128Reader() override;
-
- // CBC_OneDReader
- CFX_ByteString DecodeRow(int32_t rowNumber,
- CBC_CommonBitArray* row,
- int32_t hints,
- int32_t& e) override;
-
- static const int32_t CODE_PATTERNS[107][7];
-
- private:
- static const int32_t MAX_AVG_VARIANCE = (int32_t)(256 * 0.25f);
- static const int32_t MAX_INDIVIDUAL_VARIANCE = (int32_t)(256 * 0.7f);
-
- static const int32_t CODE_SHIFT = 98;
- static const int32_t CODE_CODE_C = 99;
- static const int32_t CODE_CODE_B = 100;
- static const int32_t CODE_CODE_A = 101;
- static const int32_t CODE_FNC_1 = 102;
- static const int32_t CODE_FNC_2 = 97;
- static const int32_t CODE_FNC_3 = 96;
- static const int32_t CODE_FNC_4_A = 101;
- static const int32_t CODE_FNC_4_B = 100;
-
- static const int32_t CODE_START_A = 103;
- static const int32_t CODE_START_B = 104;
- static const int32_t CODE_START_C = 105;
- static const int32_t CODE_STOP = 106;
-
- CFX_Int32Array* FindStartPattern(CBC_CommonBitArray* row, int32_t& e);
- int32_t DecodeCode(CBC_CommonBitArray* row,
- CFX_Int32Array* counters,
- int32_t rowOffset,
- int32_t& e);
-};
-
-#endif // XFA_FXBARCODE_ONED_BC_ONEDCODE128READER_H_
diff --git a/xfa/fxbarcode/oned/BC_OnedCode128Writer.cpp b/xfa/fxbarcode/oned/BC_OnedCode128Writer.cpp
index d5754230b5..109742e85f 100644
--- a/xfa/fxbarcode/oned/BC_OnedCode128Writer.cpp
+++ b/xfa/fxbarcode/oned/BC_OnedCode128Writer.cpp
@@ -20,13 +20,56 @@
* limitations under the License.
*/
-#include "xfa/fxbarcode/BC_Reader.h"
#include "xfa/fxbarcode/BC_Writer.h"
-#include "xfa/fxbarcode/oned/BC_OneDReader.h"
#include "xfa/fxbarcode/oned/BC_OneDimWriter.h"
-#include "xfa/fxbarcode/oned/BC_OnedCode128Reader.h"
#include "xfa/fxbarcode/oned/BC_OnedCode128Writer.h"
+namespace {
+
+const int32_t 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 int32_t CODE_START_B = 104;
+const int32_t CODE_START_C = 105;
+const int32_t CODE_STOP = 106;
+
+} // namespace
+
CBC_OnedCode128Writer::CBC_OnedCode128Writer() {
m_codeFormat = BC_CODE128_B;
}
@@ -153,8 +196,8 @@ uint8_t* CBC_OnedCode128Writer::Encode(const CFX_ByteString& contents,
return nullptr;
}
checkSum %= 103;
- patterns.Add(CBC_OnedCode128Reader::CODE_PATTERNS[checkSum]);
- patterns.Add(CBC_OnedCode128Reader::CODE_PATTERNS[CODE_STOP]);
+ patterns.Add(CODE_PATTERNS[checkSum]);
+ patterns.Add(CODE_PATTERNS[CODE_STOP]);
m_iContentLen = contents.GetLength() + 3;
int32_t codeWidth = 0;
for (int32_t k = 0; k < patterns.GetSize(); k++) {
@@ -183,13 +226,13 @@ int32_t CBC_OnedCode128Writer::Encode128B(
int32_t checkSum = 0;
int32_t checkWeight = 1;
int32_t position = 0;
- patterns->Add(CBC_OnedCode128Reader::CODE_PATTERNS[CODE_START_B]);
+ patterns->Add(CODE_PATTERNS[CODE_START_B]);
checkSum += CODE_START_B * checkWeight;
while (position < contents.GetLength()) {
int32_t patternIndex = 0;
patternIndex = contents[position] - ' ';
position += 1;
- patterns->Add(CBC_OnedCode128Reader::CODE_PATTERNS[patternIndex]);
+ patterns->Add(CODE_PATTERNS[patternIndex]);
checkSum += patternIndex * checkWeight;
if (position != 0) {
checkWeight++;
@@ -204,7 +247,7 @@ int32_t CBC_OnedCode128Writer::Encode128C(
int32_t checkSum = 0;
int32_t checkWeight = 1;
int32_t position = 0;
- patterns->Add(CBC_OnedCode128Reader::CODE_PATTERNS[CODE_START_C]);
+ patterns->Add(CODE_PATTERNS[CODE_START_C]);
checkSum += CODE_START_C * checkWeight;
while (position < contents.GetLength()) {
int32_t patternIndex = 0;
@@ -221,7 +264,7 @@ int32_t CBC_OnedCode128Writer::Encode128C(
position += 2;
}
}
- patterns->Add(CBC_OnedCode128Reader::CODE_PATTERNS[patternIndex]);
+ patterns->Add(CODE_PATTERNS[patternIndex]);
checkSum += patternIndex * checkWeight;
if (position != 0) {
checkWeight++;
diff --git a/xfa/fxbarcode/oned/BC_OnedCode128Writer.h b/xfa/fxbarcode/oned/BC_OnedCode128Writer.h
index 7338b56952..9d2285f0c6 100644
--- a/xfa/fxbarcode/oned/BC_OnedCode128Writer.h
+++ b/xfa/fxbarcode/oned/BC_OnedCode128Writer.h
@@ -41,12 +41,6 @@ class CBC_OnedCode128Writer : public CBC_OneDimWriter {
BC_TYPE GetType();
private:
- static const int32_t CODE_CODE_B = 100;
- static const int32_t CODE_CODE_C = 99;
- static const int32_t CODE_START_B = 104;
- static const int32_t CODE_START_C = 105;
- static const int32_t CODE_STOP = 106;
-
FX_BOOL IsDigits(const CFX_ByteString& contents,
int32_t start,
int32_t length);
diff --git a/xfa/fxbarcode/oned/BC_OnedCode39Reader.cpp b/xfa/fxbarcode/oned/BC_OnedCode39Reader.cpp
deleted file mode 100644
index 331af7e887..0000000000
--- a/xfa/fxbarcode/oned/BC_OnedCode39Reader.cpp
+++ /dev/null
@@ -1,286 +0,0 @@
-// 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 <algorithm>
-
-#include "xfa/fxbarcode/BC_Reader.h"
-#include "xfa/fxbarcode/common/BC_CommonBitArray.h"
-#include "xfa/fxbarcode/oned/BC_OneDReader.h"
-#include "xfa/fxbarcode/oned/BC_OnedCode39Reader.h"
-#include "xfa/fxbarcode/utils.h"
-
-const FX_CHAR* CBC_OnedCode39Reader::ALPHABET_STRING =
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *$/+%";
-const FX_CHAR* CBC_OnedCode39Reader::CHECKSUM_STRING =
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%";
-const int32_t 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};
-
-CBC_OnedCode39Reader::CBC_OnedCode39Reader()
- : m_usingCheckDigit(FALSE), m_extendedMode(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_usingCheckDigit(usingCheckDigit), m_extendedMode(extendedMode) {}
-CBC_OnedCode39Reader::~CBC_OnedCode39Reader() {}
-CFX_ByteString CBC_OnedCode39Reader::DecodeRow(int32_t rowNumber,
- CBC_CommonBitArray* row,
- int32_t hints,
- int32_t& e) {
- CFX_Int32Array* start = FindAsteriskPattern(row, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, "");
- int32_t nextStart = (*start)[1];
- delete start;
- int32_t end = row->GetSize();
- while (nextStart < end && !row->Get(nextStart)) {
- nextStart++;
- }
- CFX_ByteString result;
- CFX_Int32Array counters;
- counters.SetSize(9);
- FX_CHAR decodedChar;
- do {
- RecordPattern(row, nextStart, &counters, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, "");
- int32_t pattern = ToNarrowWidePattern(&counters);
- if (pattern < 0) {
- e = BCExceptionNotFound;
- return "";
- }
- decodedChar = PatternToChar(pattern, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, "");
- result += decodedChar;
- for (int32_t 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);
- int32_t lastPatternSize = 0;
- for (int32_t j = 0; j < counters.GetSize(); j++) {
- lastPatternSize += counters[j];
- }
- if (m_usingCheckDigit) {
- int32_t max = result.GetLength() - 1;
- int32_t total = 0;
- int32_t len = (int32_t)strlen(ALPHABET_STRING);
- for (int32_t k = 0; k < max; k++) {
- for (int32_t 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,
- int32_t& e) {
- int32_t width = row->GetSize();
- int32_t rowOffset = 0;
- while (rowOffset < width) {
- if (row->Get(rowOffset)) {
- break;
- }
- rowOffset++;
- }
- int32_t counterPosition = 0;
- CFX_Int32Array counters;
- counters.SetSize(9);
- int32_t patternStart = rowOffset;
- FX_BOOL isWhite = FALSE;
- int32_t patternLength = counters.GetSize();
- for (int32_t 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(std::max(0, patternStart - (i - patternStart) / 2),
- patternStart, FALSE, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
- if (bT1) {
- CFX_Int32Array* result = new CFX_Int32Array;
- result->SetSize(2);
- (*result)[0] = patternStart;
- (*result)[1] = i;
- return result;
- }
- }
- patternStart += counters[0] + counters[1];
- for (int32_t 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 nullptr;
-}
-int32_t CBC_OnedCode39Reader::ToNarrowWidePattern(CFX_Int32Array* counters) {
- int32_t numCounters = counters->GetSize();
- int32_t maxNarrowCounter = 0;
- int32_t wideCounters;
- do {
-#undef max
- int32_t minCounter = FXSYS_IntMax;
- for (int32_t i = 0; i < numCounters; i++) {
- int32_t counter = (*counters)[i];
- if (counter < minCounter && counter > maxNarrowCounter) {
- minCounter = counter;
- }
- }
- maxNarrowCounter = minCounter;
- wideCounters = 0;
- int32_t totalWideCountersWidth = 0;
- int32_t pattern = 0;
- for (int32_t j = 0; j < numCounters; j++) {
- int32_t counter = (*counters)[j];
- if ((*counters)[j] > maxNarrowCounter) {
- pattern |= 1 << (numCounters - 1 - j);
- wideCounters++;
- totalWideCountersWidth += counter;
- }
- }
- if (wideCounters == 3) {
- for (int32_t k = 0; k < numCounters && wideCounters > 0; k++) {
- int32_t 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(int32_t pattern, int32_t& e) {
- for (int32_t 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,
- int32_t& e) {
- int32_t length = encoded.GetLength();
- CFX_ByteString decoded;
- FX_CHAR c, next;
- for (int32_t 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/fxbarcode/oned/BC_OnedCode39Reader.h b/xfa/fxbarcode/oned/BC_OnedCode39Reader.h
deleted file mode 100644
index 0e1a728a47..0000000000
--- a/xfa/fxbarcode/oned/BC_OnedCode39Reader.h
+++ /dev/null
@@ -1,43 +0,0 @@
-// 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 XFA_FXBARCODE_ONED_BC_ONEDCODE39READER_H_
-#define XFA_FXBARCODE_ONED_BC_ONEDCODE39READER_H_
-
-#include "core/fxcrt/include/fx_system.h"
-#include "xfa/fxbarcode/oned/BC_OneDReader.h"
-
-class CBC_CommonBitArray;
-
-class CBC_OnedCode39Reader : public CBC_OneDReader {
- public:
- static const FX_CHAR* ALPHABET_STRING;
- static const FX_CHAR* CHECKSUM_STRING;
- static const int32_t CHARACTER_ENCODINGS[44];
- static const int32_t ASTERISK_ENCODING = 0x094;
-
- CBC_OnedCode39Reader();
- explicit CBC_OnedCode39Reader(FX_BOOL usingCheckDigit);
- CBC_OnedCode39Reader(FX_BOOL usingCheckDigit, FX_BOOL extendedMode);
- ~CBC_OnedCode39Reader() override;
-
- // CBC_OneDReader
- CFX_ByteString DecodeRow(int32_t rowNumber,
- CBC_CommonBitArray* row,
- int32_t hints,
- int32_t& e) override;
-
- private:
- CFX_Int32Array* FindAsteriskPattern(CBC_CommonBitArray* row, int32_t& e);
- int32_t ToNarrowWidePattern(CFX_Int32Array* counters);
- FX_CHAR PatternToChar(int32_t pattern, int32_t& e);
- CFX_ByteString DecodeExtended(CFX_ByteString& encoded, int32_t& e);
-
- FX_BOOL m_usingCheckDigit;
- FX_BOOL m_extendedMode;
-};
-
-#endif // XFA_FXBARCODE_ONED_BC_ONEDCODE39READER_H_
diff --git a/xfa/fxbarcode/oned/BC_OnedCode39Writer.cpp b/xfa/fxbarcode/oned/BC_OnedCode39Writer.cpp
index 58d9472e25..3edf87ba30 100644
--- a/xfa/fxbarcode/oned/BC_OnedCode39Writer.cpp
+++ b/xfa/fxbarcode/oned/BC_OnedCode39Writer.cpp
@@ -20,28 +20,33 @@
* limitations under the License.
*/
-#include "xfa/fxbarcode/BC_Reader.h"
#include "xfa/fxbarcode/BC_Writer.h"
#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h"
-#include "xfa/fxbarcode/oned/BC_OneDReader.h"
#include "xfa/fxbarcode/oned/BC_OneDimWriter.h"
-#include "xfa/fxbarcode/oned/BC_OnedCode39Reader.h"
#include "xfa/fxbarcode/oned/BC_OnedCode39Writer.h"
+namespace {
+
+const FX_CHAR ALPHABET_STRING[] =
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *$/+%";
+
+const FX_CHAR CHECKSUM_STRING[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%";
+
+const int32_t CHARACTER_ENCODINGS[44] = {
+ 0x034, 0x121, 0x061, 0x160, 0x031, 0x130, 0x070, 0x025, 0x124,
+ 0x064, 0x109, 0x049, 0x148, 0x019, 0x118, 0x058, 0x00D, 0x10C,
+ 0x04C, 0x01C, 0x103, 0x043, 0x142, 0x013, 0x112, 0x052, 0x007,
+ 0x106, 0x046, 0x016, 0x181, 0x0C1, 0x1C0, 0x091, 0x190, 0x0D0,
+ 0x085, 0x184, 0x0C4, 0x094, 0x0A8, 0x0A2, 0x08A, 0x02A};
+
+} // namespace
+
CBC_OnedCode39Writer::CBC_OnedCode39Writer() {
- m_extendedMode = FALSE;
- m_iWideNarrRatio = 3;
-}
-CBC_OnedCode39Writer::CBC_OnedCode39Writer(FX_BOOL extendedMode) {
m_iWideNarrRatio = 3;
- m_extendedMode = extendedMode;
}
CBC_OnedCode39Writer::~CBC_OnedCode39Writer() {}
FX_BOOL CBC_OnedCode39Writer::CheckContentValidity(
const CFX_WideStringC& contents) {
- if (m_extendedMode) {
- return CheckExtendedContentValidity(contents);
- }
for (int32_t i = 0; i < contents.GetLength(); i++) {
FX_WCHAR ch = contents.GetAt(i);
if ((ch >= (FX_WCHAR)'0' && ch <= (FX_WCHAR)'9') ||
@@ -55,21 +60,9 @@ FX_BOOL CBC_OnedCode39Writer::CheckContentValidity(
}
return TRUE;
}
-FX_BOOL CBC_OnedCode39Writer::CheckExtendedContentValidity(
- const CFX_WideStringC& contents) {
- for (int32_t i = 0; i < contents.GetLength(); i++) {
- FX_WCHAR ch = contents.GetAt(i);
- if (ch > 127) {
- return FALSE;
- }
- }
- return TRUE;
-}
+
CFX_WideString CBC_OnedCode39Writer::FilterContents(
const CFX_WideStringC& contents) {
- if (m_extendedMode) {
- return FilterExtendedContents(contents);
- }
CFX_WideString filtercontents;
for (int32_t i = 0; i < contents.GetLength(); i++) {
FX_WCHAR ch = contents.GetAt(i);
@@ -92,68 +85,9 @@ CFX_WideString CBC_OnedCode39Writer::FilterContents(
}
return filtercontents;
}
-CFX_WideString CBC_OnedCode39Writer::FilterExtendedContents(
- const CFX_WideStringC& contents) {
- CFX_WideString filtercontents;
- for (int32_t i = 0; i < contents.GetLength(); i++) {
- FX_WCHAR ch = contents.GetAt(i);
- if (ch == (FX_WCHAR)'*' && (i == 0 || i == contents.GetLength() - 1)) {
- continue;
- }
- if (ch > 175) {
- i++;
- continue;
- }
- if (ch > 127 && ch < 176) {
- continue;
- }
- if (ch == 0) {
- filtercontents += '%';
- filtercontents += 'U';
- } else if (ch >= 1 && ch <= 26) {
- filtercontents += '$';
- filtercontents += (ch + 64);
- } else if (ch >= 27 && ch <= 31) {
- filtercontents += '%';
- filtercontents += (ch + 38);
- } else if (ch >= 33 && ch <= 47 && ch != 45 && ch != 46) {
- filtercontents += '/';
- filtercontents += (ch + 32);
- } else if (ch == 58) {
- filtercontents += '/';
- filtercontents += 'Z';
- } else if (ch >= 59 && ch <= 63) {
- filtercontents += '%';
- filtercontents += ch + 11;
- } else if (ch == 64) {
- filtercontents += '%';
- filtercontents += 'V';
- } else if (ch >= 91 && ch <= 95) {
- filtercontents += '%';
- filtercontents += ch - 16;
- } else if (ch == 96) {
- filtercontents += '%';
- filtercontents += 'W';
- } else if (ch >= 97 && ch <= 122) {
- filtercontents += '+';
- filtercontents += ch - 32;
- } else if (ch >= 123 && ch <= 126) {
- filtercontents += '%';
- filtercontents += ch - 43;
- } else if (ch == 127) {
- filtercontents += '%';
- filtercontents += 'T';
- } else {
- filtercontents += ch;
- }
- }
- return filtercontents;
-}
+
CFX_WideString CBC_OnedCode39Writer::RenderTextContents(
const CFX_WideStringC& contents) {
- if (m_extendedMode) {
- return RenderExtendedTextContents(contents);
- }
CFX_WideString renderContents;
for (int32_t i = 0; i < contents.GetLength(); i++) {
FX_WCHAR ch = contents.GetAt(i);
@@ -175,25 +109,7 @@ CFX_WideString CBC_OnedCode39Writer::RenderTextContents(
}
return renderContents;
}
-CFX_WideString CBC_OnedCode39Writer::RenderExtendedTextContents(
- const CFX_WideStringC& contents) {
- CFX_WideString renderContents;
- for (int32_t i = 0; i < contents.GetLength(); i++) {
- FX_WCHAR ch = contents.GetAt(i);
- if (ch == (FX_WCHAR)'*' && (i == 0 || i == contents.GetLength() - 1)) {
- continue;
- }
- if (ch > 175) {
- i++;
- continue;
- }
- if (ch > 127 && ch < 176) {
- continue;
- }
- renderContents += ch;
- }
- return renderContents;
-}
+
FX_BOOL CBC_OnedCode39Writer::SetTextLocation(BC_TEXT_LOC location) {
if (location < BC_TEXT_LOC_NONE || location > BC_TEXT_LOC_BELOWEMBED) {
return FALSE;
@@ -245,11 +161,11 @@ FX_CHAR CBC_OnedCode39Writer::CalcCheckSum(const CFX_ByteString& contents,
return '*';
}
int32_t checksum = 0;
- int32_t len = (int32_t)strlen(CBC_OnedCode39Reader::ALPHABET_STRING);
+ int32_t len = (int32_t)strlen(ALPHABET_STRING);
for (int32_t i = 0; i < contents.GetLength(); i++) {
int32_t j = 0;
for (; j < len; j++) {
- if (CBC_OnedCode39Reader::ALPHABET_STRING[j] == contents[i]) {
+ if (ALPHABET_STRING[j] == contents[i]) {
if (contents[i] != '*') {
checksum += j;
break;
@@ -264,7 +180,7 @@ FX_CHAR CBC_OnedCode39Writer::CalcCheckSum(const CFX_ByteString& contents,
}
}
checksum = checksum % 43;
- return CBC_OnedCode39Reader::CHECKSUM_STRING[checksum];
+ return CHECKSUM_STRING[checksum];
}
uint8_t* CBC_OnedCode39Writer::Encode(const CFX_ByteString& contents,
int32_t& outlength,
@@ -283,11 +199,11 @@ uint8_t* CBC_OnedCode39Writer::Encode(const CFX_ByteString& contents,
m_iContentLen = encodedContents.GetLength();
int32_t codeWidth = (wideStrideNum * m_iWideNarrRatio + narrStrideNum) * 2 +
1 + m_iContentLen;
- int32_t len = (int32_t)strlen(CBC_OnedCode39Reader::ALPHABET_STRING);
+ int32_t len = (int32_t)strlen(ALPHABET_STRING);
for (int32_t j = 0; j < m_iContentLen; j++) {
for (int32_t i = 0; i < len; i++) {
- if (CBC_OnedCode39Reader::ALPHABET_STRING[i] == encodedContents[j]) {
- ToIntArray(CBC_OnedCode39Reader::CHARACTER_ENCODINGS[i], widths);
+ if (ALPHABET_STRING[i] == encodedContents[j]) {
+ ToIntArray(CHARACTER_ENCODINGS[i], widths);
for (int32_t k = 0; k < 9; k++) {
codeWidth += widths[k];
}
@@ -296,7 +212,7 @@ uint8_t* CBC_OnedCode39Writer::Encode(const CFX_ByteString& contents,
}
outlength = codeWidth;
uint8_t* result = FX_Alloc(uint8_t, codeWidth);
- ToIntArray(CBC_OnedCode39Reader::CHARACTER_ENCODINGS[39], widths);
+ ToIntArray(CHARACTER_ENCODINGS[39], widths);
int32_t pos = AppendPattern(result, 0, widths, 9, 1, e);
if (e != BCExceptionNO) {
FX_Free(result);
@@ -310,8 +226,8 @@ uint8_t* CBC_OnedCode39Writer::Encode(const CFX_ByteString& contents,
}
for (int32_t l = m_iContentLen - 1; l >= 0; l--) {
for (int32_t i = 0; i < len; i++) {
- if (CBC_OnedCode39Reader::ALPHABET_STRING[i] == encodedContents[l]) {
- ToIntArray(CBC_OnedCode39Reader::CHARACTER_ENCODINGS[i], widths);
+ if (ALPHABET_STRING[i] == encodedContents[l]) {
+ ToIntArray(CHARACTER_ENCODINGS[i], widths);
pos += AppendPattern(result, pos, widths, 9, 1, e);
if (e != BCExceptionNO) {
FX_Free(result);
@@ -325,7 +241,7 @@ uint8_t* CBC_OnedCode39Writer::Encode(const CFX_ByteString& contents,
return nullptr;
}
}
- ToIntArray(CBC_OnedCode39Reader::CHARACTER_ENCODINGS[39], widths);
+ ToIntArray(CHARACTER_ENCODINGS[39], widths);
pos += AppendPattern(result, pos, widths, 9, 1, e);
if (e != BCExceptionNO) {
FX_Free(result);
diff --git a/xfa/fxbarcode/oned/BC_OnedCode39Writer.h b/xfa/fxbarcode/oned/BC_OnedCode39Writer.h
index 7dc314f968..3cd1594271 100644
--- a/xfa/fxbarcode/oned/BC_OnedCode39Writer.h
+++ b/xfa/fxbarcode/oned/BC_OnedCode39Writer.h
@@ -13,7 +13,6 @@
class CBC_OnedCode39Writer : public CBC_OneDimWriter {
public:
CBC_OnedCode39Writer();
- explicit CBC_OnedCode39Writer(FX_BOOL extendedMode);
~CBC_OnedCode39Writer() override;
// CBC_OneDimWriter
@@ -42,11 +41,6 @@ class CBC_OnedCode39Writer : public CBC_OneDimWriter {
virtual CFX_WideString encodedContents(const CFX_WideStringC& contents,
int32_t& e);
- virtual FX_BOOL CheckExtendedContentValidity(const CFX_WideStringC& contents);
- virtual CFX_WideString FilterExtendedContents(
- const CFX_WideStringC& contents);
- virtual CFX_WideString RenderExtendedTextContents(
- const CFX_WideStringC& contents);
virtual FX_BOOL SetTextLocation(BC_TEXT_LOC loction);
virtual FX_BOOL SetWideNarrowRatio(int32_t ratio);
@@ -55,7 +49,6 @@ class CBC_OnedCode39Writer : public CBC_OneDimWriter {
FX_CHAR CalcCheckSum(const CFX_ByteString& contents, int32_t& e);
int32_t m_iWideNarrRatio;
- FX_BOOL m_extendedMode;
};
#endif // XFA_FXBARCODE_ONED_BC_ONEDCODE39WRITER_H_
diff --git a/xfa/fxbarcode/oned/BC_OnedEAN13Reader.cpp b/xfa/fxbarcode/oned/BC_OnedEAN13Reader.cpp
deleted file mode 100644
index 83fea7d5f2..0000000000
--- a/xfa/fxbarcode/oned/BC_OnedEAN13Reader.cpp
+++ /dev/null
@@ -1,96 +0,0 @@
-// 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 "xfa/fxbarcode/BC_Reader.h"
-#include "xfa/fxbarcode/common/BC_CommonBitArray.h"
-#include "xfa/fxbarcode/oned/BC_OneDReader.h"
-#include "xfa/fxbarcode/oned/BC_OneDimReader.h"
-#include "xfa/fxbarcode/oned/BC_OnedEAN13Reader.h"
-#include "xfa/fxbarcode/utils.h"
-
-const int32_t 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,
- int32_t lgPatternFound,
- int32_t& e) {
- for (int32_t 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);
-}
-int32_t CBC_OnedEAN13Reader::DecodeMiddle(CBC_CommonBitArray* row,
- CFX_Int32Array* startRange,
- CFX_ByteString& resultString,
- int32_t& e) {
- CFX_Int32Array counters;
- counters.Add(0);
- counters.Add(0);
- counters.Add(0);
- counters.Add(0);
- int32_t end = row->GetSize();
- int32_t rowOffset = (*startRange)[1];
- int32_t lgPatternFound = 0;
- for (int32_t x = 0; x < 6 && rowOffset < end; x++) {
- int32_t 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 (int32_t 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];
- delete middleRange;
- for (int32_t Y = 0; Y < 6 && rowOffset < end; Y++) {
- int32_t 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 (int32_t k = 0; k < counters.GetSize(); k++) {
- rowOffset += counters[k];
- }
- }
- return rowOffset;
-}
diff --git a/xfa/fxbarcode/oned/BC_OnedEAN13Reader.h b/xfa/fxbarcode/oned/BC_OnedEAN13Reader.h
deleted file mode 100644
index ac53fd4f24..0000000000
--- a/xfa/fxbarcode/oned/BC_OnedEAN13Reader.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// 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 XFA_FXBARCODE_ONED_BC_ONEDEAN13READER_H_
-#define XFA_FXBARCODE_ONED_BC_ONEDEAN13READER_H_
-
-#include "core/fxcrt/include/fx_string.h"
-#include "core/fxcrt/include/fx_system.h"
-#include "xfa/fxbarcode/oned/BC_OneDimReader.h"
-
-class CBC_CommonBitArray;
-class CBC_OnedUPCAReader;
-
-class CBC_OnedEAN13Reader : public CBC_OneDimReader {
- public:
- CBC_OnedEAN13Reader();
- ~CBC_OnedEAN13Reader() override;
-
- static const int32_t FIRST_DIGIT_ENCODINGS[10];
-
- protected:
- friend class CBC_OnedUPCAReader;
-
- int32_t DecodeMiddle(CBC_CommonBitArray* row,
- CFX_Int32Array* startRange,
- CFX_ByteString& resultString,
- int32_t& e) override;
-
- private:
- void DetermineFirstDigit(CFX_ByteString& result,
- int32_t lgPatternFound,
- int32_t& e);
-};
-
-#endif // XFA_FXBARCODE_ONED_BC_ONEDEAN13READER_H_
diff --git a/xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp
index e347cb2385..a7393a48f6 100644
--- a/xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp
+++ b/xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp
@@ -20,14 +20,27 @@
* limitations under the License.
*/
-#include "xfa/fxbarcode/BC_Reader.h"
#include "xfa/fxbarcode/BC_Writer.h"
-#include "xfa/fxbarcode/oned/BC_OneDReader.h"
-#include "xfa/fxbarcode/oned/BC_OneDimReader.h"
#include "xfa/fxbarcode/oned/BC_OneDimWriter.h"
-#include "xfa/fxbarcode/oned/BC_OnedEAN13Reader.h"
#include "xfa/fxbarcode/oned/BC_OnedEAN13Writer.h"
+namespace {
+
+const int32_t FIRST_DIGIT_ENCODINGS[10] = {0x00, 0x0B, 0x0D, 0xE, 0x13,
+ 0x19, 0x1C, 0x15, 0x16, 0x1A};
+const int32_t START_END_PATTERN[3] = {1, 1, 1};
+const int32_t MIDDLE_PATTERN[5] = {1, 1, 1, 1, 1};
+const int32_t L_PATTERNS[10][4] = {
+ {3, 2, 1, 1}, {2, 2, 2, 1}, {2, 1, 2, 2}, {1, 4, 1, 1}, {1, 1, 3, 2},
+ {1, 2, 3, 1}, {1, 1, 1, 4}, {1, 3, 1, 2}, {1, 2, 1, 3}, {3, 1, 1, 2}};
+const int32_t L_AND_G_PATTERNS[20][4] = {
+ {3, 2, 1, 1}, {2, 2, 2, 1}, {2, 1, 2, 2}, {1, 4, 1, 1}, {1, 1, 3, 2},
+ {1, 2, 3, 1}, {1, 1, 1, 4}, {1, 3, 1, 2}, {1, 2, 1, 3}, {3, 1, 1, 2},
+ {1, 1, 2, 3}, {1, 2, 2, 2}, {2, 2, 1, 2}, {1, 1, 4, 1}, {2, 3, 1, 1},
+ {1, 3, 2, 1}, {4, 1, 1, 1}, {2, 1, 3, 1}, {3, 1, 2, 1}, {2, 1, 1, 3}};
+
+} // namespace
+
CBC_OnedEAN13Writer::CBC_OnedEAN13Writer() {
m_bLeftPadding = TRUE;
m_codeWidth = 3 + (7 * 6) + 5 + (7 * 6) + 3;
@@ -108,12 +121,11 @@ uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents,
}
m_iDataLenth = 13;
int32_t firstDigit = FXSYS_atoi(contents.Mid(0, 1).c_str());
- int32_t parities = CBC_OnedEAN13Reader::FIRST_DIGIT_ENCODINGS[firstDigit];
+ int32_t parities = FIRST_DIGIT_ENCODINGS[firstDigit];
outLength = m_codeWidth;
uint8_t* result = FX_Alloc(uint8_t, m_codeWidth);
int32_t pos = 0;
- pos +=
- AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e);
+ pos += AppendPattern(result, pos, START_END_PATTERN, 3, 1, e);
if (e != BCExceptionNO) {
FX_Free(result);
return nullptr;
@@ -124,29 +136,26 @@ uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents,
if ((parities >> (6 - i) & 1) == 1) {
digit += 10;
}
- pos += AppendPattern(result, pos, CBC_OneDimReader::L_AND_G_PATTERNS[digit],
- 4, 0, e);
+ pos += AppendPattern(result, pos, L_AND_G_PATTERNS[digit], 4, 0, e);
if (e != BCExceptionNO) {
FX_Free(result);
return nullptr;
}
}
- pos += AppendPattern(result, pos, CBC_OneDimReader::MIDDLE_PATTERN, 5, 0, e);
+ pos += AppendPattern(result, pos, MIDDLE_PATTERN, 5, 0, e);
if (e != BCExceptionNO) {
FX_Free(result);
return nullptr;
}
for (i = 7; i <= 12; i++) {
int32_t digit = FXSYS_atoi(contents.Mid(i, 1).c_str());
- pos += AppendPattern(result, pos, CBC_OneDimReader::L_PATTERNS[digit], 4, 1,
- e);
+ pos += AppendPattern(result, pos, L_PATTERNS[digit], 4, 1, e);
if (e != BCExceptionNO) {
FX_Free(result);
return nullptr;
}
}
- pos +=
- AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e);
+ pos += AppendPattern(result, pos, START_END_PATTERN, 3, 1, e);
if (e != BCExceptionNO) {
FX_Free(result);
return nullptr;
diff --git a/xfa/fxbarcode/oned/BC_OnedEAN8Reader.cpp b/xfa/fxbarcode/oned/BC_OnedEAN8Reader.cpp
deleted file mode 100644
index f3b21fde99..0000000000
--- a/xfa/fxbarcode/oned/BC_OnedEAN8Reader.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-// 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 "xfa/fxbarcode/BC_Reader.h"
-#include "xfa/fxbarcode/common/BC_CommonBitArray.h"
-#include "xfa/fxbarcode/oned/BC_OneDReader.h"
-#include "xfa/fxbarcode/oned/BC_OneDimReader.h"
-#include "xfa/fxbarcode/oned/BC_OnedEAN8Reader.h"
-#include "xfa/fxbarcode/utils.h"
-
-CBC_OnedEAN8Reader::CBC_OnedEAN8Reader() {}
-CBC_OnedEAN8Reader::~CBC_OnedEAN8Reader() {}
-int32_t CBC_OnedEAN8Reader::DecodeMiddle(CBC_CommonBitArray* row,
- CFX_Int32Array* startRange,
- CFX_ByteString& resultResult,
- int32_t& e) {
- CFX_Int32Array counters;
- counters.Add(0);
- counters.Add(0);
- counters.Add(0);
- counters.Add(0);
- int32_t end = row->GetSize();
- int32_t rowOffset = (*startRange)[1];
- int32_t rowOffsetLeft = rowOffset;
- for (int32_t x = 0; x < 4 && rowOffset < end; x++) {
- int32_t 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 (int32_t i = 0; i < counters.GetSize(); i++) {
- rowOffset += counters[i];
- }
- }
- int32_t 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);
- int32_t rowOffsetMid = rowOffset;
- rowOffset = (*middleRange)[1];
- if ((rowOffset - rowOffsetMid) > RowOffsetLen) {
- e = BCExceptionNotFound;
- BC_EXCEPTION_CHECK_ReturnValue(e, 0);
- }
- delete middleRange;
- for (int32_t y = 0; y < 4 && rowOffset < end; y++) {
- int32_t 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 (int32_t i = 0; i < counters.GetSize(); i++) {
- rowOffset += counters[i];
- }
- }
- return rowOffset;
-}
diff --git a/xfa/fxbarcode/oned/BC_OnedEAN8Reader.h b/xfa/fxbarcode/oned/BC_OnedEAN8Reader.h
deleted file mode 100644
index 756565dd8f..0000000000
--- a/xfa/fxbarcode/oned/BC_OnedEAN8Reader.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// 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 XFA_FXBARCODE_ONED_BC_ONEDEAN8READER_H_
-#define XFA_FXBARCODE_ONED_BC_ONEDEAN8READER_H_
-
-#include "xfa/fxbarcode/oned/BC_OneDimReader.h"
-
-class CBC_CommonBitArray;
-
-class CBC_OnedEAN8Reader : public CBC_OneDimReader {
- public:
- CBC_OnedEAN8Reader();
- ~CBC_OnedEAN8Reader() override;
-
- protected:
- int32_t DecodeMiddle(CBC_CommonBitArray*,
- CFX_Int32Array* startRange,
- CFX_ByteString& result,
- int32_t& e) override;
-};
-
-#endif // XFA_FXBARCODE_ONED_BC_ONEDEAN8READER_H_
diff --git a/xfa/fxbarcode/oned/BC_OnedEAN8Writer.cpp b/xfa/fxbarcode/oned/BC_OnedEAN8Writer.cpp
index 063847b260..bea145b8d1 100644
--- a/xfa/fxbarcode/oned/BC_OnedEAN8Writer.cpp
+++ b/xfa/fxbarcode/oned/BC_OnedEAN8Writer.cpp
@@ -20,14 +20,21 @@
* limitations under the License.
*/
-#include "xfa/fxbarcode/BC_Reader.h"
#include "xfa/fxbarcode/BC_Writer.h"
#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h"
-#include "xfa/fxbarcode/oned/BC_OneDReader.h"
-#include "xfa/fxbarcode/oned/BC_OneDimReader.h"
#include "xfa/fxbarcode/oned/BC_OneDimWriter.h"
#include "xfa/fxbarcode/oned/BC_OnedEAN8Writer.h"
+namespace {
+
+const int32_t START_END_PATTERN[3] = {1, 1, 1};
+const int32_t MIDDLE_PATTERN[5] = {1, 1, 1, 1, 1};
+const int32_t L_PATTERNS[10][4] = {
+ {3, 2, 1, 1}, {2, 2, 2, 1}, {2, 1, 2, 2}, {1, 4, 1, 1}, {1, 1, 3, 2},
+ {1, 2, 3, 1}, {1, 1, 1, 4}, {1, 3, 1, 2}, {1, 2, 1, 3}, {3, 1, 1, 2}};
+
+} // namespace
+
CBC_OnedEAN8Writer::CBC_OnedEAN8Writer() {
m_iDataLenth = 8;
m_codeWidth = 3 + (7 * 4) + 5 + (7 * 4) + 3;
@@ -120,8 +127,7 @@ uint8_t* CBC_OnedEAN8Writer::Encode(const CFX_ByteString& contents,
outLength = m_codeWidth;
uint8_t* result = FX_Alloc(uint8_t, m_codeWidth);
int32_t pos = 0;
- pos +=
- AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e);
+ pos += AppendPattern(result, pos, START_END_PATTERN, 3, 1, e);
if (e != BCExceptionNO) {
FX_Free(result);
return nullptr;
@@ -129,29 +135,26 @@ uint8_t* CBC_OnedEAN8Writer::Encode(const CFX_ByteString& contents,
int32_t i = 0;
for (i = 0; i <= 3; i++) {
int32_t digit = FXSYS_atoi(contents.Mid(i, 1).c_str());
- pos += AppendPattern(result, pos, CBC_OneDimReader::L_PATTERNS[digit], 4, 0,
- e);
+ pos += AppendPattern(result, pos, L_PATTERNS[digit], 4, 0, e);
if (e != BCExceptionNO) {
FX_Free(result);
return nullptr;
}
}
- pos += AppendPattern(result, pos, CBC_OneDimReader::MIDDLE_PATTERN, 5, 0, e);
+ pos += AppendPattern(result, pos, MIDDLE_PATTERN, 5, 0, e);
if (e != BCExceptionNO) {
FX_Free(result);
return nullptr;
}
for (i = 4; i <= 7; i++) {
int32_t digit = FXSYS_atoi(contents.Mid(i, 1).c_str());
- pos += AppendPattern(result, pos, CBC_OneDimReader::L_PATTERNS[digit], 4, 1,
- e);
+ pos += AppendPattern(result, pos, L_PATTERNS[digit], 4, 1, e);
if (e != BCExceptionNO) {
FX_Free(result);
return nullptr;
}
}
- pos +=
- AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e);
+ pos += AppendPattern(result, pos, START_END_PATTERN, 3, 1, e);
if (e != BCExceptionNO) {
FX_Free(result);
return nullptr;
diff --git a/xfa/fxbarcode/oned/BC_OnedUPCAReader.cpp b/xfa/fxbarcode/oned/BC_OnedUPCAReader.cpp
deleted file mode 100644
index b8b7c9426a..0000000000
--- a/xfa/fxbarcode/oned/BC_OnedUPCAReader.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-// 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 "core/fxcrt/include/fx_basic.h"
-#include "xfa/fxbarcode/BC_Reader.h"
-#include "xfa/fxbarcode/oned/BC_OneDReader.h"
-#include "xfa/fxbarcode/oned/BC_OneDimReader.h"
-#include "xfa/fxbarcode/oned/BC_OnedEAN13Reader.h"
-#include "xfa/fxbarcode/oned/BC_OnedUPCAReader.h"
-#include "xfa/fxbarcode/utils.h"
-
-CBC_OnedUPCAReader::CBC_OnedUPCAReader() {
- m_ean13Reader = nullptr;
-}
-void CBC_OnedUPCAReader::Init() {
- m_ean13Reader = new CBC_OnedEAN13Reader;
-}
-CBC_OnedUPCAReader::~CBC_OnedUPCAReader() {
- delete m_ean13Reader;
-}
-CFX_ByteString CBC_OnedUPCAReader::DecodeRow(int32_t rowNumber,
- CBC_CommonBitArray* row,
- int32_t hints,
- int32_t& 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(int32_t rowNumber,
- CBC_CommonBitArray* row,
- CFX_Int32Array* startGuardRange,
- int32_t hints,
- int32_t& 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, int32_t& 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,
- int32_t hints,
- int32_t& 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;
-}
-int32_t CBC_OnedUPCAReader::DecodeMiddle(CBC_CommonBitArray* row,
- CFX_Int32Array* startRange,
- CFX_ByteString& resultString,
- int32_t& e) {
- int32_t temp = m_ean13Reader->DecodeMiddle(row, startRange, resultString, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, 0);
- return temp;
-}
-CFX_ByteString CBC_OnedUPCAReader::MaybeReturnResult(CFX_ByteString& result,
- int32_t& e) {
- if (result[0] == '0') {
- result.Delete(0);
- return result;
- }
- e = BCExceptionFormatException;
- return "";
-}
diff --git a/xfa/fxbarcode/oned/BC_OnedUPCAReader.h b/xfa/fxbarcode/oned/BC_OnedUPCAReader.h
deleted file mode 100644
index 28e03fc21f..0000000000
--- a/xfa/fxbarcode/oned/BC_OnedUPCAReader.h
+++ /dev/null
@@ -1,53 +0,0 @@
-// 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 XFA_FXBARCODE_ONED_BC_ONEDUPCAREADER_H_
-#define XFA_FXBARCODE_ONED_BC_ONEDUPCAREADER_H_
-
-#include "core/fxcrt/include/fx_string.h"
-#include "core/fxcrt/include/fx_system.h"
-#include "xfa/fxbarcode/oned/BC_OneDimReader.h"
-
-class CBC_BinaryBitmap;
-class CBC_CommonBitArray;
-class CBC_OnedEAN13Reader;
-
-class CBC_OnedUPCAReader : public CBC_OneDimReader {
- public:
- CBC_OnedUPCAReader();
- ~CBC_OnedUPCAReader() override;
-
- virtual void Init();
-
- // CBC_OneDimReader
- CFX_ByteString DecodeRow(int32_t rowNumber,
- CBC_CommonBitArray* row,
- int32_t hints,
- int32_t& e) override;
- CFX_ByteString DecodeRow(int32_t rowNumber,
- CBC_CommonBitArray* row,
- CFX_Int32Array* startGuardRange,
- int32_t hints,
- int32_t& e) override;
-
- // CBC_OneDReader
- CFX_ByteString Decode(CBC_BinaryBitmap* image, int32_t& e) override;
- CFX_ByteString Decode(CBC_BinaryBitmap* image,
- int32_t hints,
- int32_t& e) override;
-
- protected:
- int32_t DecodeMiddle(CBC_CommonBitArray* row,
- CFX_Int32Array* startRange,
- CFX_ByteString& resultString,
- int32_t& e) override;
- CFX_ByteString MaybeReturnResult(CFX_ByteString& result, int32_t& e);
-
- private:
- CBC_OnedEAN13Reader* m_ean13Reader;
-};
-
-#endif // XFA_FXBARCODE_ONED_BC_ONEDUPCAREADER_H_