summaryrefslogtreecommitdiff
path: root/xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.cpp
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2015-08-04 13:00:21 -0700
committerNico Weber <thakis@chromium.org>2015-08-04 13:00:21 -0700
commit9d8ec5a6e37e8d1d4d4edca9040de234e2d4728f (patch)
treec97037f398d714665aefccb6eb54d0969ad7030c /xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.cpp
parent780cee82236d1b3b0f9b01a22424e4b8ec9a6f12 (diff)
downloadpdfium-9d8ec5a6e37e8d1d4d4edca9040de234e2d4728f.tar.xz
XFA: clang-format all pdfium code.
No behavior change. Generated by: find . -name '*.cpp' -o -name '*.h' | \ grep -E -v 'third_party|thirdparties|lpng_v163|tiff_v403' | \ xargs ../../buildtools/mac/clang-format -i Then manually merged https://codereview.chromium.org/1269223002/ See thread "tabs vs spaces" on pdfium@googlegroups.com for discussion. BUG=none
Diffstat (limited to 'xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.cpp')
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.cpp319
1 files changed, 160 insertions, 159 deletions
diff --git a/xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.cpp b/xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.cpp
index 7f7a69c1b7..ed12f676b4 100644
--- a/xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.cpp
+++ b/xfa/src/fxbarcode/oned/BC_OnedCodaBarReader.cpp
@@ -26,181 +26,182 @@
#include "../oned/BC_OneDReader.h"
#include "../oned/BC_OnedCode39Reader.h"
#include "../oned/BC_OnedCodaBarReader.h"
-const FX_CHAR* CBC_OnedCodaBarReader::ALPHABET_STRING = "0123456789-$:/.+ABCDTN";
+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
-};
+ 0x003, 0x006, 0x009, 0x060, 0x012, 0x042, 0x021, 0x024,
+ 0x030, 0x048, 0x00c, 0x018, 0x045, 0x051, 0x054, 0x015,
+ 0x01A, 0x029, 0x00B, 0x00E, 0x01A, 0x029};
const int32_t 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(int32_t rowNumber, CBC_CommonBitArray *row, int32_t hints, int32_t &e)
-{
- CFX_Int32Array *int32Ptr = FindAsteriskPattern(row, e);
+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) {
+ CFX_Int32Array* int32Ptr = FindAsteriskPattern(row, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ CBC_AutoPtr<CFX_Int32Array> start(int32Ptr);
+ (*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, "");
- CBC_AutoPtr<CFX_Int32Array> start(int32Ptr);
- (*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];
+ decodedChar = ToNarrowWidePattern(&counters);
+ if (decodedChar == '!') {
+ e = BCExceptionNotFound;
+ return "";
}
- int32_t whiteSpaceAfterEnd = nextStart - lastStart - lastPatternSize;
- if (nextStart != end && (whiteSpaceAfterEnd / 2 < lastPatternSize)) {
- e = BCExceptionNotFound;
- return "";
+ result += decodedChar;
+ lastStart = nextStart;
+ for (int32_t i = 0; i < counters.GetSize(); i++) {
+ nextStart += counters[i];
}
- if (result.GetLength() < 2) {
- e = BCExceptionNotFound;
- return "";
+ while (nextStart < end && !row->Get(nextStart)) {
+ nextStart++;
}
- FX_CHAR startchar = result[0];
- if (!ArrayContains(STARTEND_ENCODING, startchar)) {
- e = BCExceptionNotFound;
- return "";
+ } 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;
+ }
}
- 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));
+ if (index == len - (result.GetLength() - 1)) {
+ e = BCExceptionNotFound;
+ return "";
}
- if (result.GetLength() < 5) {
- int32_t 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,
+ int32_t& e) {
+ int32_t width = row->GetSize();
+ int32_t rowOffset = 0;
+ while (rowOffset < width) {
+ if (row->Get(rowOffset)) {
+ break;
}
- if (result.GetLength() > minCharacterLength) {
- result = result.Mid(1, result.GetLength() - 2);
+ 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 {
- 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;
+ 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;
+ }
}
- 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(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 (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;
+ 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 NULL;
+ }
+ e = BCExceptionNotFound;
+ return NULL;
}
-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;
- }
+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;
+ }
+ 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++;
- }
+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];
- }
- }
+ }
+ if ((wideCounters == 2) || (wideCounters == 3)) {
+ for (int32_t k = 0; k < 22; k++) {
+ if (CHARACTER_ENCODINGS[k] == pattern) {
+ return (ALPHABET_STRING)[k];
+ }
}
- return '!';
+ }
+ return '!';
}