aboutsummaryrefslogtreecommitdiff
path: root/fxbarcode/pdf417
diff options
context:
space:
mode:
Diffstat (limited to 'fxbarcode/pdf417')
-rw-r--r--fxbarcode/pdf417/BC_PDF417.cpp24
-rw-r--r--fxbarcode/pdf417/BC_PDF417.h4
-rw-r--r--fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp26
-rw-r--r--fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h8
-rw-r--r--fxbarcode/pdf417/BC_PDF417BarcodeRow.cpp22
-rw-r--r--fxbarcode/pdf417/BC_PDF417BarcodeRow.h13
-rw-r--r--fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp12
-rw-r--r--fxbarcode/pdf417/BC_PDF417ErrorCorrection.h8
-rw-r--r--fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp35
-rw-r--r--fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h14
-rw-r--r--fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp16
-rw-r--r--fxbarcode/pdf417/BC_PDF417Writer.cpp26
-rw-r--r--fxbarcode/pdf417/BC_PDF417Writer.h17
-rw-r--r--fxbarcode/pdf417/BC_PDF417Writer_unittest.cpp17
14 files changed, 126 insertions, 116 deletions
diff --git a/fxbarcode/pdf417/BC_PDF417.cpp b/fxbarcode/pdf417/BC_PDF417.cpp
index b9ba3902e..d48b98ae7 100644
--- a/fxbarcode/pdf417/BC_PDF417.cpp
+++ b/fxbarcode/pdf417/BC_PDF417.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -22,15 +22,16 @@
#include "fxbarcode/pdf417/BC_PDF417.h"
+#include <math.h>
+
#include "fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h"
#include "fxbarcode/pdf417/BC_PDF417BarcodeRow.h"
#include "fxbarcode/pdf417/BC_PDF417ErrorCorrection.h"
#include "fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h"
-#include "third_party/base/ptr_util.h"
namespace {
-const uint16_t g_CodewordTable[3][929] = {
+const uint16_t kCodewordTable[3][929] = {
{0xd5c0, 0xeaf0, 0xf57c, 0xd4e0, 0xea78, 0xf53e, 0xa8c0, 0xd470, 0xa860,
0x5040, 0xa830, 0x5020, 0xadc0, 0xd6f0, 0xeb7c, 0xace0, 0xd678, 0xeb3e,
0x58c0, 0xac70, 0x5860, 0x5dc0, 0xaef0, 0xd77c, 0x5ce0, 0xae78, 0xd73e,
@@ -345,7 +346,7 @@ const uint16_t g_CodewordTable[3][929] = {
0x0fb2, 0xc7ea}};
int32_t Get17BitCodeword(int i, int j) {
- return (0x10000 | g_CodewordTable[i][j]);
+ return (0x10000 | kCodewordTable[i][j]);
}
} // namespace
@@ -365,7 +366,7 @@ bool CBC_PDF417::GenerateBarcodeLogic(WideStringView msg,
if (errorCorrectionCodeWords < 0)
return false;
- Optional<WideString> high_level =
+ absl::optional<WideString> high_level =
CBC_PDF417HighLevelEncoder::EncodeHighLevel(msg);
if (!high_level.has_value())
return false;
@@ -390,13 +391,14 @@ bool CBC_PDF417::GenerateBarcodeLogic(WideStringView msg,
sb += (wchar_t)900;
WideString dataCodewords(sb);
- Optional<WideString> ec = CBC_PDF417ErrorCorrection::GenerateErrorCorrection(
- dataCodewords, errorCorrectionLevel);
+ absl::optional<WideString> ec =
+ CBC_PDF417ErrorCorrection::GenerateErrorCorrection(dataCodewords,
+ errorCorrectionLevel);
if (!ec.has_value())
return false;
WideString fullCodewords = dataCodewords + ec.value();
- m_barcodeMatrix = pdfium::MakeUnique<CBC_BarcodeMatrix>(cols, rows);
+ m_barcodeMatrix = std::make_unique<CBC_BarcodeMatrix>(cols, rows);
encodeLowLevel(fullCodewords, cols, rows, errorCorrectionLevel,
m_barcodeMatrix.get());
return true;
@@ -433,19 +435,19 @@ void CBC_PDF417::encodeChar(int32_t pattern,
CBC_BarcodeRow* logic) {
int32_t map = 1 << (len - 1);
bool last = ((pattern & map) != 0);
- int32_t width = 0;
+ size_t width = 0;
for (int32_t i = 0; i < len; i++) {
bool black = ((pattern & map) != 0);
if (last == black) {
width++;
} else {
- logic->addBar(last, width);
+ logic->AddBar(last, width);
last = black;
width = 1;
}
map >>= 1;
}
- logic->addBar(last, width);
+ logic->AddBar(last, width);
}
void CBC_PDF417::encodeLowLevel(WideString fullCodewords,
diff --git a/fxbarcode/pdf417/BC_PDF417.h b/fxbarcode/pdf417/BC_PDF417.h
index b445ede5f..0312deb3f 100644
--- a/fxbarcode/pdf417/BC_PDF417.h
+++ b/fxbarcode/pdf417/BC_PDF417.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,7 +10,7 @@
#include <memory>
#include <vector>
-#include "core/fxcrt/fx_string.h"
+#include "core/fxcrt/widestring.h"
class CBC_BarcodeRow;
class CBC_BarcodeMatrix;
diff --git a/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp b/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp
index 70e7cd959..b6f407d41 100644
--- a/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp
+++ b/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -21,24 +21,26 @@
*/
#include "fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h"
+
+#include <stdint.h>
+
+#include "core/fxcrt/data_vector.h"
+#include "core/fxcrt/span_util.h"
#include "fxbarcode/pdf417/BC_PDF417BarcodeRow.h"
-#include "third_party/base/ptr_util.h"
CBC_BarcodeMatrix::CBC_BarcodeMatrix(size_t width, size_t height)
: m_width((width + 4) * 17 + 1), m_height(height) {
m_matrix.resize(m_height);
for (size_t i = 0; i < m_height; ++i)
- m_matrix[i] = pdfium::MakeUnique<CBC_BarcodeRow>(m_width);
+ m_matrix[i] = std::make_unique<CBC_BarcodeRow>(m_width);
}
-CBC_BarcodeMatrix::~CBC_BarcodeMatrix() {}
+CBC_BarcodeMatrix::~CBC_BarcodeMatrix() = default;
-std::vector<uint8_t> CBC_BarcodeMatrix::toBitArray() {
- std::vector<uint8_t> bitArray(m_width * m_height);
- for (size_t i = 0; i < m_height; ++i) {
- std::vector<uint8_t>& bytearray = m_matrix[i]->getRow();
- for (size_t j = 0; j < m_width; ++j)
- bitArray[i * m_width + j] = bytearray[j];
- }
- return bitArray;
+DataVector<uint8_t> CBC_BarcodeMatrix::toBitArray() {
+ DataVector<uint8_t> bit_array(m_width * m_height);
+ pdfium::span<uint8_t> bit_array_span(bit_array);
+ for (size_t i = 0; i < m_height; ++i)
+ fxcrt::spancpy(bit_array_span.subspan(i * m_width), m_matrix[i]->GetRow());
+ return bit_array;
}
diff --git a/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h b/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h
index d059cee25..2ed8834f6 100644
--- a/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h
+++ b/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,9 +7,13 @@
#ifndef FXBARCODE_PDF417_BC_PDF417BARCODEMATRIX_H_
#define FXBARCODE_PDF417_BC_PDF417BARCODEMATRIX_H_
+#include <stdint.h>
+
#include <memory>
#include <vector>
+#include "core/fxcrt/data_vector.h"
+
class CBC_BarcodeRow;
class CBC_BarcodeMatrix final {
@@ -20,7 +24,7 @@ class CBC_BarcodeMatrix final {
CBC_BarcodeRow* getRow(size_t row) const { return m_matrix[row].get(); }
size_t getWidth() const { return m_width; }
size_t getHeight() const { return m_height; }
- std::vector<uint8_t> toBitArray();
+ DataVector<uint8_t> toBitArray();
private:
std::vector<std::unique_ptr<CBC_BarcodeRow>> m_matrix;
diff --git a/fxbarcode/pdf417/BC_PDF417BarcodeRow.cpp b/fxbarcode/pdf417/BC_PDF417BarcodeRow.cpp
index 65c27de7e..48e4128af 100644
--- a/fxbarcode/pdf417/BC_PDF417BarcodeRow.cpp
+++ b/fxbarcode/pdf417/BC_PDF417BarcodeRow.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -22,18 +22,16 @@
#include "fxbarcode/pdf417/BC_PDF417BarcodeRow.h"
-#include <algorithm>
+#include "core/fxcrt/span_util.h"
+#include "third_party/base/check_op.h"
-CBC_BarcodeRow::CBC_BarcodeRow(size_t width)
- : m_row(width), m_currentLocation(0) {}
+CBC_BarcodeRow::CBC_BarcodeRow(size_t width) : row_(width) {}
-CBC_BarcodeRow::~CBC_BarcodeRow() {}
+CBC_BarcodeRow::~CBC_BarcodeRow() = default;
-void CBC_BarcodeRow::addBar(bool black, int32_t width) {
- std::fill_n(m_row.begin() + m_currentLocation, width, black ? 1 : 0);
- m_currentLocation += width;
-}
-
-std::vector<uint8_t>& CBC_BarcodeRow::getRow() {
- return m_row;
+void CBC_BarcodeRow::AddBar(bool black, size_t width) {
+ pdfium::span<uint8_t> available = row_.writable_span().subspan(offset_);
+ CHECK_LE(width, available.size());
+ fxcrt::spanset(available.first(width), black ? 1 : 0);
+ offset_ += width;
}
diff --git a/fxbarcode/pdf417/BC_PDF417BarcodeRow.h b/fxbarcode/pdf417/BC_PDF417BarcodeRow.h
index 07ebbd770..160275eea 100644
--- a/fxbarcode/pdf417/BC_PDF417BarcodeRow.h
+++ b/fxbarcode/pdf417/BC_PDF417BarcodeRow.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,19 +9,20 @@
#include <stdint.h>
-#include <vector>
+#include "core/fxcrt/fixed_zeroed_data_vector.h"
+#include "third_party/base/span.h"
class CBC_BarcodeRow final {
public:
explicit CBC_BarcodeRow(size_t width);
~CBC_BarcodeRow();
- void addBar(bool black, int32_t width);
- std::vector<uint8_t>& getRow();
+ void AddBar(bool black, size_t width);
+ pdfium::span<const uint8_t> GetRow() const { return row_; }
private:
- std::vector<uint8_t> m_row;
- int32_t m_currentLocation;
+ FixedZeroedDataVector<uint8_t> row_;
+ size_t offset_ = 0;
};
#endif // FXBARCODE_PDF417_BC_PDF417BARCODEROW_H_
diff --git a/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp b/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
index f910d4a13..509f8aa00 100644
--- a/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
+++ b/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -22,9 +22,9 @@
#include "fxbarcode/pdf417/BC_PDF417ErrorCorrection.h"
-#include <vector>
+#include <stdint.h>
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
namespace {
@@ -133,14 +133,14 @@ int32_t CBC_PDF417ErrorCorrection::GetErrorCorrectionCodewordCount(
}
// static
-Optional<WideString> CBC_PDF417ErrorCorrection::GenerateErrorCorrection(
+absl::optional<WideString> CBC_PDF417ErrorCorrection::GenerateErrorCorrection(
const WideString& dataCodewords,
int32_t errorCorrectionLevel) {
int32_t k = GetErrorCorrectionCodewordCount(errorCorrectionLevel);
if (k < 0)
- return {};
+ return absl::nullopt;
- std::vector<wchar_t, FxAllocAllocator<wchar_t>> ech(k);
+ DataVector<wchar_t> ech(k);
size_t sld = dataCodewords.GetLength();
for (size_t i = 0; i < sld; i++) {
int32_t t1 = (dataCodewords[i] + ech[k - 1]) % 929;
diff --git a/fxbarcode/pdf417/BC_PDF417ErrorCorrection.h b/fxbarcode/pdf417/BC_PDF417ErrorCorrection.h
index f5aa89880..ccb2fa061 100644
--- a/fxbarcode/pdf417/BC_PDF417ErrorCorrection.h
+++ b/fxbarcode/pdf417/BC_PDF417ErrorCorrection.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,8 +9,8 @@
#include <stdint.h>
-#include "core/fxcrt/fx_string.h"
-#include "third_party/base/optional.h"
+#include "core/fxcrt/widestring.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
class CBC_PDF417ErrorCorrection {
public:
@@ -18,7 +18,7 @@ class CBC_PDF417ErrorCorrection {
~CBC_PDF417ErrorCorrection() = delete;
static int32_t GetErrorCorrectionCodewordCount(int32_t errorCorrectionLevel);
- static Optional<WideString> GenerateErrorCorrection(
+ static absl::optional<WideString> GenerateErrorCorrection(
const WideString& dataCodewords,
int32_t errorCorrectionLevel);
};
diff --git a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp
index 09cac1b37..7affbc814 100644
--- a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp
+++ b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -23,6 +23,7 @@
#include "fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h"
#include "core/fxcrt/fx_extension.h"
+#include "core/fxcrt/fx_string.h"
#include "third_party/bigint/BigIntegerLibrary.hh"
namespace {
@@ -52,11 +53,11 @@ constexpr int8_t kPunctuation[128] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, 26, 21, 27, 9, -1};
bool IsAlphaUpperOrSpace(wchar_t ch) {
- return ch == ' ' || (ch >= 'A' && ch <= 'Z');
+ return ch == ' ' || FXSYS_IsUpperASCII(ch);
}
bool IsAlphaLowerOrSpace(wchar_t ch) {
- return ch == ' ' || (ch >= 'a' && ch <= 'z');
+ return ch == ' ' || FXSYS_IsLowerASCII(ch);
}
bool IsMixed(wchar_t ch) {
@@ -76,20 +77,19 @@ bool IsText(wchar_t ch) {
} // namespace
// static
-Optional<WideString> CBC_PDF417HighLevelEncoder::EncodeHighLevel(
+absl::optional<WideString> CBC_PDF417HighLevelEncoder::EncodeHighLevel(
WideStringView msg) {
- ByteString bytes = FX_UTF8Encode(msg);
+ const ByteString bytes = FX_UTF8Encode(msg);
size_t len = bytes.GetLength();
WideString result;
result.Reserve(len);
for (size_t i = 0; i < len; i++) {
wchar_t ch = bytes[i] & 0xff;
if (ch == '?' && bytes[i] != '?')
- return {};
+ return absl::nullopt;
result += ch;
}
- std::vector<uint8_t> byteArr(bytes.begin(), bytes.end());
len = result.GetLength();
WideString sb;
sb.Reserve(len);
@@ -115,18 +115,18 @@ Optional<WideString> CBC_PDF417HighLevelEncoder::EncodeHighLevel(
textSubMode = EncodeText(result, p, t, textSubMode, &sb);
p += t;
} else {
- Optional<size_t> b =
- DetermineConsecutiveBinaryCount(result, &byteArr, p);
- if (!b)
- return {};
+ absl::optional<size_t> b =
+ DetermineConsecutiveBinaryCount(result, bytes.raw_span(), p);
+ if (!b.has_value())
+ return absl::nullopt;
size_t b_value = b.value();
if (b_value == 0)
b_value = 1;
if (b_value == 1 && encodingMode == EncodingMode::kText) {
- EncodeBinary(byteArr, p, 1, EncodingMode::kText, &sb);
+ EncodeBinary(bytes.raw_span(), p, 1, EncodingMode::kText, &sb);
} else {
- EncodeBinary(byteArr, p, b_value, encodingMode, &sb);
+ EncodeBinary(bytes.raw_span(), p, b_value, encodingMode, &sb);
encodingMode = EncodingMode::kByte;
textSubMode = SubMode::kAlpha;
}
@@ -352,9 +352,10 @@ size_t CBC_PDF417HighLevelEncoder::DetermineConsecutiveTextCount(
return idx - startpos;
}
-Optional<size_t> CBC_PDF417HighLevelEncoder::DetermineConsecutiveBinaryCount(
+absl::optional<size_t>
+CBC_PDF417HighLevelEncoder::DetermineConsecutiveBinaryCount(
WideString msg,
- std::vector<uint8_t>* bytes,
+ pdfium::span<const uint8_t> bytes,
size_t startpos) {
size_t len = msg.GetLength();
size_t idx = startpos;
@@ -382,8 +383,8 @@ Optional<size_t> CBC_PDF417HighLevelEncoder::DetermineConsecutiveBinaryCount(
if (textCount >= 5)
return idx - startpos;
ch = msg[idx];
- if ((*bytes)[idx] == 63 && ch != '?')
- return {};
+ if (bytes[idx] == 63 && ch != '?')
+ return absl::nullopt;
idx++;
}
return idx - startpos;
diff --git a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h
index df1cd54f6..16b80daa4 100644
--- a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h
+++ b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,11 +7,9 @@
#ifndef FXBARCODE_PDF417_BC_PDF417HIGHLEVELENCODER_H_
#define FXBARCODE_PDF417_BC_PDF417HIGHLEVELENCODER_H_
-#include <vector>
-
-#include "core/fxcrt/fx_string.h"
+#include "core/fxcrt/widestring.h"
#include "fxbarcode/pdf417/BC_PDF417.h"
-#include "third_party/base/optional.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/base/span.h"
class CBC_PDF417HighLevelEncoder {
@@ -19,7 +17,7 @@ class CBC_PDF417HighLevelEncoder {
CBC_PDF417HighLevelEncoder() = delete;
~CBC_PDF417HighLevelEncoder() = delete;
- static Optional<WideString> EncodeHighLevel(WideStringView msg);
+ static absl::optional<WideString> EncodeHighLevel(WideStringView msg);
private:
enum class EncodingMode { kUnknown = 0, kText, kByte, kNumeric };
@@ -42,9 +40,9 @@ class CBC_PDF417HighLevelEncoder {
WideString* sb);
static size_t DetermineConsecutiveDigitCount(WideString msg, size_t startpos);
static size_t DetermineConsecutiveTextCount(WideString msg, size_t startpos);
- static Optional<size_t> DetermineConsecutiveBinaryCount(
+ static absl::optional<size_t> DetermineConsecutiveBinaryCount(
WideString msg,
- std::vector<uint8_t>* bytes,
+ pdfium::span<const uint8_t> bytes,
size_t startpos);
friend class PDF417HighLevelEncoderTest_ConsecutiveBinaryCount_Test;
diff --git a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp
index 4ca5c8ba3..7f665ac3d 100644
--- a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp
+++ b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp
@@ -1,9 +1,11 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h"
+#include <vector>
+
#include "testing/gtest/include/gtest/gtest.h"
TEST(PDF417HighLevelEncoderTest, EncodeHighLevel) {
@@ -37,11 +39,11 @@ TEST(PDF417HighLevelEncoderTest, EncodeHighLevel) {
{L"0000000000000", L"\x0386\x000f\x00d9\x017b\x000b\x0064", 6},
};
- for (size_t i = 0; i < FX_ArraySize(kEncodeHighLevelCases); ++i) {
+ for (size_t i = 0; i < std::size(kEncodeHighLevelCases); ++i) {
const EncodeHighLevelCase& testcase = kEncodeHighLevelCases[i];
WideStringView input(testcase.input);
WideString expected(testcase.expected, testcase.expected_length);
- Optional<WideString> result =
+ absl::optional<WideString> result =
CBC_PDF417HighLevelEncoder::EncodeHighLevel(input);
ASSERT_TRUE(result.has_value());
EXPECT_EQ(expected, result.value()) << " for case number " << i;
@@ -81,7 +83,7 @@ TEST(PDF417HighLevelEncoderTest, EncodeBinary) {
L"\u039c\u00c9\u031f\u012a\u00d2\u02d0", 6},
};
- for (size_t i = 0; i < FX_ArraySize(kEncodeBinaryCases); ++i) {
+ for (size_t i = 0; i < std::size(kEncodeBinaryCases); ++i) {
const EncodeBinaryCase& testcase = kEncodeBinaryCases[i];
std::vector<uint8_t> input_array;
size_t input_length = strlen(testcase.input);
@@ -148,7 +150,7 @@ TEST(PDF417HighLevelEncoderTest, EncodeNumeric) {
18},
};
- for (size_t i = 0; i < FX_ArraySize(kEncodeNumericCases); ++i) {
+ for (size_t i = 0; i < std::size(kEncodeNumericCases); ++i) {
const EncodeNumericCase& testcase = kEncodeNumericCases[i];
WideString input(testcase.input);
WideString expected(testcase.expected, testcase.expected_length);
@@ -193,7 +195,7 @@ TEST(PDF417HighLevelEncoderTest, ConsecutiveDigitCount) {
{L"123FOO45678", 6, 5},
};
- for (size_t i = 0; i < FX_ArraySize(kConsecutiveDigitCases); ++i) {
+ for (size_t i = 0; i < std::size(kConsecutiveDigitCases); ++i) {
const ConsecutiveDigitCase& testcase = kConsecutiveDigitCases[i];
WideString input(testcase.input);
int actual_count =
@@ -253,7 +255,7 @@ TEST(PDF417HighLevelEncoderTest, ConsecutiveTextCount) {
{L"XXX121XXX12345678901234", 0, 9},
};
- for (size_t i = 0; i < FX_ArraySize(kConsecutiveTextCases); ++i) {
+ for (size_t i = 0; i < std::size(kConsecutiveTextCases); ++i) {
const ConsecutiveTextCase& testcase = kConsecutiveTextCases[i];
WideString input(testcase.input);
int actual_count =
diff --git a/fxbarcode/pdf417/BC_PDF417Writer.cpp b/fxbarcode/pdf417/BC_PDF417Writer.cpp
index f9f36246a..a7ed45295 100644
--- a/fxbarcode/pdf417/BC_PDF417Writer.cpp
+++ b/fxbarcode/pdf417/BC_PDF417Writer.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -22,14 +22,17 @@
#include "fxbarcode/pdf417/BC_PDF417Writer.h"
+#include <stdint.h>
+
#include <algorithm>
#include <utility>
+#include "core/fxcrt/data_vector.h"
+#include "core/fxcrt/stl_util.h"
#include "fxbarcode/BC_TwoDimWriter.h"
#include "fxbarcode/common/BC_CommonBitMatrix.h"
#include "fxbarcode/pdf417/BC_PDF417.h"
#include "fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h"
-#include "third_party/base/stl_util.h"
CBC_PDF417Writer::CBC_PDF417Writer() : CBC_TwoDimWriter(false) {}
@@ -43,10 +46,9 @@ bool CBC_PDF417Writer::SetErrorCorrectionLevel(int32_t level) {
return true;
}
-std::vector<uint8_t> CBC_PDF417Writer::Encode(WideStringView contents,
- int32_t* pOutWidth,
- int32_t* pOutHeight) {
- std::vector<uint8_t> results;
+DataVector<uint8_t> CBC_PDF417Writer::Encode(WideStringView contents,
+ int32_t* pOutWidth,
+ int32_t* pOutHeight) {
CBC_PDF417 encoder;
int32_t col = (m_Width / m_ModuleWidth - 69) / 17;
int32_t row = m_Height / (m_ModuleWidth * 20);
@@ -57,10 +59,10 @@ std::vector<uint8_t> CBC_PDF417Writer::Encode(WideStringView contents,
else if (row >= 3 && row <= 90)
encoder.setDimensions(30, 1, row, row);
if (!encoder.GenerateBarcodeLogic(contents, error_correction_level()))
- return results;
+ return DataVector<uint8_t>();
CBC_BarcodeMatrix* barcodeMatrix = encoder.getBarcodeMatrix();
- std::vector<uint8_t> matrixData = barcodeMatrix->toBitArray();
+ DataVector<uint8_t> matrixData = barcodeMatrix->toBitArray();
int32_t matrixWidth = barcodeMatrix->getWidth();
int32_t matrixHeight = barcodeMatrix->getHeight();
@@ -70,15 +72,13 @@ std::vector<uint8_t> CBC_PDF417Writer::Encode(WideStringView contents,
}
*pOutWidth = matrixWidth;
*pOutHeight = matrixHeight;
- results = pdfium::Vector2D<uint8_t>(*pOutWidth, *pOutHeight);
- memcpy(results.data(), matrixData.data(), *pOutWidth * *pOutHeight);
- return results;
+ return matrixData;
}
-void CBC_PDF417Writer::RotateArray(std::vector<uint8_t>* bitarray,
+void CBC_PDF417Writer::RotateArray(DataVector<uint8_t>* bitarray,
int32_t height,
int32_t width) {
- std::vector<uint8_t> temp = *bitarray;
+ DataVector<uint8_t> temp = *bitarray;
for (int32_t ii = 0; ii < height; ii++) {
int32_t inverseii = height - ii - 1;
for (int32_t jj = 0; jj < width; jj++) {
diff --git a/fxbarcode/pdf417/BC_PDF417Writer.h b/fxbarcode/pdf417/BC_PDF417Writer.h
index 10f069aeb..dc1f1f44b 100644
--- a/fxbarcode/pdf417/BC_PDF417Writer.h
+++ b/fxbarcode/pdf417/BC_PDF417Writer.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,10 +7,11 @@
#ifndef FXBARCODE_PDF417_BC_PDF417WRITER_H_
#define FXBARCODE_PDF417_BC_PDF417WRITER_H_
-#include <vector>
+#include <stddef.h>
+#include <stdint.h>
-#include "core/fxcrt/fx_string.h"
-#include "core/fxcrt/fx_system.h"
+#include "core/fxcrt/data_vector.h"
+#include "core/fxcrt/widestring.h"
#include "fxbarcode/BC_TwoDimWriter.h"
class CBC_PDF417Writer final : public CBC_TwoDimWriter {
@@ -18,15 +19,15 @@ class CBC_PDF417Writer final : public CBC_TwoDimWriter {
CBC_PDF417Writer();
~CBC_PDF417Writer() override;
- std::vector<uint8_t> Encode(WideStringView contents,
- int32_t* pOutWidth,
- int32_t* pOutHeight);
+ DataVector<uint8_t> Encode(WideStringView contents,
+ int32_t* pOutWidth,
+ int32_t* pOutHeight);
// CBC_TwoDimWriter
bool SetErrorCorrectionLevel(int32_t level) override;
private:
- void RotateArray(std::vector<uint8_t>* bitarray,
+ void RotateArray(DataVector<uint8_t>* bitarray,
int32_t width,
int32_t height);
};
diff --git a/fxbarcode/pdf417/BC_PDF417Writer_unittest.cpp b/fxbarcode/pdf417/BC_PDF417Writer_unittest.cpp
index 1c09d7875..d67d8b839 100644
--- a/fxbarcode/pdf417/BC_PDF417Writer_unittest.cpp
+++ b/fxbarcode/pdf417/BC_PDF417Writer_unittest.cpp
@@ -1,11 +1,12 @@
-// Copyright 2018 PDFium Authors. All rights reserved.
+// Copyright 2018 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "fxbarcode/pdf417/BC_PDF417Writer.h"
-#include <vector>
+#include <stdint.h>
+#include "core/fxcrt/data_vector.h"
#include "testing/gtest/include/gtest/gtest.h"
class CBC_PDF417WriterTest : public testing::Test {
@@ -413,11 +414,11 @@ TEST_F(CBC_PDF417WriterTest, Encode) {
1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1,
0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1};
- std::vector<uint8_t> data = writer.Encode(L"", &width, &height);
- ASSERT_EQ(FX_ArraySize(kExpectedData), data.size());
+ DataVector<uint8_t> data = writer.Encode(L"", &width, &height);
+ ASSERT_EQ(std::size(kExpectedData), data.size());
ASSERT_EQ(kExpectedWidth, width);
ASSERT_EQ(kExpectedHeight, height);
- for (size_t i = 0; i < FX_ArraySize(kExpectedData); ++i)
+ for (size_t i = 0; i < std::size(kExpectedData); ++i)
EXPECT_EQ(kExpectedData[i], data[i]) << i;
}
{
@@ -810,11 +811,11 @@ TEST_F(CBC_PDF417WriterTest, Encode) {
1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0,
0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1};
- std::vector<uint8_t> data = writer.Encode(L"hello world", &width, &height);
- ASSERT_EQ(FX_ArraySize(kExpectedData), data.size());
+ DataVector<uint8_t> data = writer.Encode(L"hello world", &width, &height);
+ ASSERT_EQ(std::size(kExpectedData), data.size());
ASSERT_EQ(kExpectedWidth, width);
ASSERT_EQ(kExpectedHeight, height);
- for (size_t i = 0; i < FX_ArraySize(kExpectedData); ++i)
+ for (size_t i = 0; i < std::size(kExpectedData); ++i)
EXPECT_EQ(kExpectedData[i], data[i]) << i;
}
}