summaryrefslogtreecommitdiff
path: root/fxbarcode
diff options
context:
space:
mode:
Diffstat (limited to 'fxbarcode')
-rw-r--r--fxbarcode/oned/BC_OnedCodaBarWriter.cpp38
-rw-r--r--fxbarcode/oned/BC_OnedCode39Writer.cpp42
-rw-r--r--fxbarcode/oned/BC_OnedCode39Writer.h2
3 files changed, 45 insertions, 37 deletions
diff --git a/fxbarcode/oned/BC_OnedCodaBarWriter.cpp b/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
index 3c3ea4afe8..42990f7f3a 100644
--- a/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
+++ b/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
@@ -30,16 +30,21 @@
namespace {
-const char kOnedCodaAlphabet[] = "0123456789-$:/.+ABCDTN";
-
-const int32_t kOnedCodaCharacterEncoding[22] = {
- 0x003, 0x006, 0x009, 0x060, 0x012, 0x042, 0x021, 0x024,
- 0x030, 0x048, 0x00c, 0x018, 0x045, 0x051, 0x054, 0x015,
- 0x01A, 0x029, 0x00B, 0x00E, 0x01A, 0x029};
-
-const char START_END_CHARS[] = {'A', 'B', 'C', 'D', 'T', 'N', '*', 'E',
- 'a', 'b', 'c', 'd', 't', 'n', 'e'};
-const char CONTENT_CHARS[] = {'0', '1', '2', '3', '4', '5', '6', '7',
+const char kOnedCodaAlphabet[] = {'0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', '-', '$', ':', '/', '.', '+',
+ 'A', 'B', 'C', 'D', 'T', 'N'};
+
+const int8_t kOnedCodaCharacterEncoding[] = {
+ 0x03, 0x06, 0x09, 0x60, 0x12, 0x42, 0x21, 0x24, 0x30, 0x48, 0x0c,
+ 0x18, 0x45, 0x51, 0x54, 0x15, 0x1A, 0x29, 0x0B, 0x0E, 0x1A, 0x29};
+static_assert(FX_ArraySize(kOnedCodaCharacterEncoding) == 22, "Wrong size");
+static_assert(FX_ArraySize(kOnedCodaCharacterEncoding) ==
+ FX_ArraySize(kOnedCodaAlphabet),
+ "Wrong size");
+
+const char kStartEndChars[] = {'A', 'B', 'C', 'D', 'T', 'N', '*', 'E',
+ 'a', 'b', 'c', 'd', 't', 'n', 'e'};
+const char kCOntentChars[] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', '-', '$', '/', ':', '+', '.'};
} // namespace
@@ -50,7 +55,7 @@ CBC_OnedCodaBarWriter::CBC_OnedCodaBarWriter()
CBC_OnedCodaBarWriter::~CBC_OnedCodaBarWriter() {}
bool CBC_OnedCodaBarWriter::SetStartChar(char start) {
- if (!pdfium::ContainsValue(START_END_CHARS, start))
+ if (!pdfium::ContainsValue(kStartEndChars, start))
return false;
m_chStart = start;
@@ -58,7 +63,7 @@ bool CBC_OnedCodaBarWriter::SetStartChar(char start) {
}
bool CBC_OnedCodaBarWriter::SetEndChar(char end) {
- if (!pdfium::ContainsValue(START_END_CHARS, end))
+ if (!pdfium::ContainsValue(kStartEndChars, end))
return false;
m_chEnd = end;
@@ -90,8 +95,8 @@ bool CBC_OnedCodaBarWriter::FindChar(wchar_t ch, bool isContent) {
return false;
char narrow_ch = static_cast<char>(ch);
- return pdfium::ContainsValue(CONTENT_CHARS, narrow_ch) ||
- (isContent && pdfium::ContainsValue(START_END_CHARS, narrow_ch));
+ return pdfium::ContainsValue(kCOntentChars, narrow_ch) ||
+ (isContent && pdfium::ContainsValue(kStartEndChars, narrow_ch));
}
bool CBC_OnedCodaBarWriter::CheckContentValidity(
@@ -157,9 +162,8 @@ uint8_t* CBC_OnedCodaBarWriter::EncodeImpl(const ByteString& contents,
default:
break;
}
- int32_t code = 0;
- size_t len = strlen(kOnedCodaAlphabet);
- for (size_t i = 0; i < len; i++) {
+ int8_t code = 0;
+ for (size_t i = 0; i < FX_ArraySize(kOnedCodaAlphabet); i++) {
if (ch == kOnedCodaAlphabet[i]) {
code = kOnedCodaCharacterEncoding[i];
break;
diff --git a/fxbarcode/oned/BC_OnedCode39Writer.cpp b/fxbarcode/oned/BC_OnedCode39Writer.cpp
index f26ebc193c..f04dc195ea 100644
--- a/fxbarcode/oned/BC_OnedCode39Writer.cpp
+++ b/fxbarcode/oned/BC_OnedCode39Writer.cpp
@@ -30,18 +30,25 @@
namespace {
-const char kOnedCode39Alphabet[] =
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *$/+%";
+const char kOnedCode39Alphabet[] = {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
+ 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
+ 'U', 'V', 'W', 'X', 'Y', 'Z', '-', '.', ' ', '*', '$', '/', '+', '%'};
+constexpr size_t kOnedCode39AlphabetLen = FX_ArraySize(kOnedCode39Alphabet);
-const char kOnedCode39Checksum[] =
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%";
+const char kOnedCode39Checksum[] = {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
+ 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
+ 'U', 'V', 'W', 'X', 'Y', 'Z', '-', '.', ' ', '$', '/', '+', '%'};
+static_assert(FX_ArraySize(kOnedCode39Checksum) == 43, "Wrong size");
-const int32_t kOnedCode39CharacterEncoding[44] = {
- 0x034, 0x121, 0x061, 0x160, 0x031, 0x130, 0x070, 0x025, 0x124,
- 0x064, 0x109, 0x049, 0x148, 0x019, 0x118, 0x058, 0x00D, 0x10C,
- 0x04C, 0x01C, 0x103, 0x043, 0x142, 0x013, 0x112, 0x052, 0x007,
- 0x106, 0x046, 0x016, 0x181, 0x0C1, 0x1C0, 0x091, 0x190, 0x0D0,
- 0x085, 0x184, 0x0C4, 0x094, 0x0A8, 0x0A2, 0x08A, 0x02A};
+const int16_t kOnedCode39CharacterEncoding[] = {
+ 0x0034, 0x0121, 0x0061, 0x0160, 0x0031, 0x0130, 0x0070, 0x0025, 0x0124,
+ 0x0064, 0x0109, 0x0049, 0x0148, 0x0019, 0x0118, 0x0058, 0x000D, 0x010C,
+ 0x004C, 0x001C, 0x0103, 0x0043, 0x0142, 0x0013, 0x0112, 0x0052, 0x0007,
+ 0x0106, 0x0046, 0x0016, 0x0181, 0x00C1, 0x01C0, 0x0091, 0x0190, 0x00D0,
+ 0x0085, 0x0184, 0x00C4, 0x0094, 0x00A8, 0x00A2, 0x008A, 0x002A};
+static_assert(FX_ArraySize(kOnedCode39CharacterEncoding) == 44, "Wrong size");
} // namespace
@@ -132,7 +139,7 @@ uint8_t* CBC_OnedCode39Writer::EncodeWithHint(const ByteString& contents,
hints);
}
-void CBC_OnedCode39Writer::ToIntArray(int32_t a, int8_t* toReturn) {
+void CBC_OnedCode39Writer::ToIntArray(int16_t a, int8_t* toReturn) {
for (int32_t i = 0; i < 9; i++) {
toReturn[i] = (a & (1 << i)) == 0 ? 1 : m_iWideNarrRatio;
}
@@ -143,21 +150,19 @@ char CBC_OnedCode39Writer::CalcCheckSum(const ByteString& contents) {
return '*';
int32_t checksum = 0;
- size_t len = strlen(kOnedCode39Alphabet);
for (const auto& c : contents) {
size_t j = 0;
- for (; j < len; j++) {
+ for (; j < kOnedCode39AlphabetLen; j++) {
if (kOnedCode39Alphabet[j] == c) {
if (c != '*')
checksum += j;
break;
}
}
- if (j >= len)
+ if (j >= kOnedCode39AlphabetLen)
return '*';
}
- checksum = checksum % 43;
- return kOnedCode39Checksum[checksum];
+ return kOnedCode39Checksum[checksum % FX_ArraySize(kOnedCode39Checksum)];
}
uint8_t* CBC_OnedCode39Writer::EncodeImpl(const ByteString& contents,
@@ -175,9 +180,8 @@ uint8_t* CBC_OnedCode39Writer::EncodeImpl(const ByteString& contents,
m_iContentLen = encodedContents.GetLength();
int32_t codeWidth = (wideStrideNum * m_iWideNarrRatio + narrStrideNum) * 2 +
1 + m_iContentLen;
- size_t len = strlen(kOnedCode39Alphabet);
for (size_t j = 0; j < m_iContentLen; j++) {
- for (size_t i = 0; i < len; i++) {
+ for (size_t i = 0; i < kOnedCode39AlphabetLen; i++) {
if (kOnedCode39Alphabet[i] != encodedContents[j])
continue;
@@ -200,7 +204,7 @@ uint8_t* CBC_OnedCode39Writer::EncodeImpl(const ByteString& contents,
return nullptr;
for (int32_t l = m_iContentLen - 1; l >= 0; l--) {
- for (size_t i = 0; i < len; i++) {
+ for (size_t i = 0; i < kOnedCode39AlphabetLen; i++) {
if (kOnedCode39Alphabet[i] != encodedContents[l])
continue;
diff --git a/fxbarcode/oned/BC_OnedCode39Writer.h b/fxbarcode/oned/BC_OnedCode39Writer.h
index ffed6d9c07..90611c005d 100644
--- a/fxbarcode/oned/BC_OnedCode39Writer.h
+++ b/fxbarcode/oned/BC_OnedCode39Writer.h
@@ -35,7 +35,7 @@ class CBC_OnedCode39Writer : public CBC_OneDimWriter {
bool encodedContents(const WideStringView& contents, WideString* result);
private:
- void ToIntArray(int32_t a, int8_t* toReturn);
+ void ToIntArray(int16_t a, int8_t* toReturn);
char CalcCheckSum(const ByteString& contents);
int8_t m_iWideNarrRatio;