Change CBC_TwoDimWriter::RenderResult() to take a vector.
Move vector::empty() check from callers into RenderResult(). Also mark
RenderResult and RenderDeviceResult() non-virtual since they do not have
any overrides.
Change-Id: I047e2c16c6b09d780cd77e111448eb5e208fadaa
Reviewed-on: https://pdfium-review.googlesource.com/c/46522
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fxbarcode/BC_TwoDimWriter.cpp b/fxbarcode/BC_TwoDimWriter.cpp
index 236ddf3..09ae8c7 100644
--- a/fxbarcode/BC_TwoDimWriter.cpp
+++ b/fxbarcode/BC_TwoDimWriter.cpp
@@ -4,12 +4,13 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include "fxbarcode/BC_TwoDimWriter.h"
+
#include <algorithm>
#include "core/fxge/cfx_graphstatedata.h"
#include "core/fxge/cfx_pathdata.h"
#include "core/fxge/cfx_renderdevice.h"
-#include "fxbarcode/BC_TwoDimWriter.h"
#include "fxbarcode/BC_Writer.h"
#include "fxbarcode/common/BC_CommonBitMatrix.h"
#include "third_party/base/numerics/safe_math.h"
@@ -20,9 +21,12 @@
CBC_TwoDimWriter::~CBC_TwoDimWriter() = default;
-bool CBC_TwoDimWriter::RenderResult(uint8_t* code,
+bool CBC_TwoDimWriter::RenderResult(const std::vector<uint8_t>& code,
int32_t codeWidth,
int32_t codeHeight) {
+ if (code.empty())
+ return false;
+
m_inputWidth = codeWidth;
m_inputHeight = codeHeight;
int32_t tempWidth = m_inputWidth + 2;
diff --git a/fxbarcode/BC_TwoDimWriter.h b/fxbarcode/BC_TwoDimWriter.h
index a56c9ed..91f5ac7 100644
--- a/fxbarcode/BC_TwoDimWriter.h
+++ b/fxbarcode/BC_TwoDimWriter.h
@@ -8,6 +8,7 @@
#define FXBARCODE_BC_TWODIMWRITER_H_
#include <memory>
+#include <vector>
#include "core/fxcrt/fx_coordinates.h"
#include "fxbarcode/BC_Writer.h"
@@ -20,11 +21,10 @@
explicit CBC_TwoDimWriter(bool bFixedSize);
~CBC_TwoDimWriter() override;
- virtual bool RenderResult(uint8_t* code,
- int32_t codeWidth,
- int32_t codeHeight);
- virtual void RenderDeviceResult(CFX_RenderDevice* device,
- const CFX_Matrix* matrix);
+ bool RenderResult(const std::vector<uint8_t>& code,
+ int32_t codeWidth,
+ int32_t codeHeight);
+ void RenderDeviceResult(CFX_RenderDevice* device, const CFX_Matrix* matrix);
int32_t error_correction_level() const { return m_iCorrectionLevel; }
diff --git a/fxbarcode/cbc_datamatrix.cpp b/fxbarcode/cbc_datamatrix.cpp
index 6557550..bebff2d 100644
--- a/fxbarcode/cbc_datamatrix.cpp
+++ b/fxbarcode/cbc_datamatrix.cpp
@@ -37,7 +37,7 @@
auto* pWriter = GetDataMatrixWriter();
std::vector<uint8_t> data =
pWriter->Encode(WideString(contents), &width, &height);
- return !data.empty() && pWriter->RenderResult(data.data(), width, height);
+ return pWriter->RenderResult(data, width, height);
}
bool CBC_DataMatrix::RenderDevice(CFX_RenderDevice* device,
diff --git a/fxbarcode/cbc_pdf417i.cpp b/fxbarcode/cbc_pdf417i.cpp
index 72a30d6..321468b 100644
--- a/fxbarcode/cbc_pdf417i.cpp
+++ b/fxbarcode/cbc_pdf417i.cpp
@@ -36,7 +36,7 @@
int32_t height;
auto* pWriter = GetPDF417Writer();
std::vector<uint8_t> data = pWriter->Encode(contents, &width, &height);
- return !data.empty() && pWriter->RenderResult(data.data(), width, height);
+ return pWriter->RenderResult(data, width, height);
}
bool CBC_PDF417I::RenderDevice(CFX_RenderDevice* device,
diff --git a/fxbarcode/cbc_qrcode.cpp b/fxbarcode/cbc_qrcode.cpp
index f038f9e..c89387b 100644
--- a/fxbarcode/cbc_qrcode.cpp
+++ b/fxbarcode/cbc_qrcode.cpp
@@ -37,7 +37,7 @@
CBC_QRCodeWriter* pWriter = GetQRCodeWriter();
std::vector<uint8_t> data = pWriter->Encode(
contents, pWriter->error_correction_level(), &width, &height);
- return !data.empty() && pWriter->RenderResult(data.data(), width, height);
+ return pWriter->RenderResult(data, width, height);
}
bool CBC_QRCode::RenderDevice(CFX_RenderDevice* device,