diff options
author | Lei Zhang <thestig@chromium.org> | 2017-04-03 16:40:51 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-04 19:04:37 +0000 |
commit | 03d58937248fa244cbf02a3d38d430a513500311 (patch) | |
tree | 9ea96b01b0f2f2464bd9d5c49e76dd8e0466a8b0 /fxbarcode/cbc_qrcode.cpp | |
parent | c3202a95773d7a2c95038ad45c5ba2c9e095e67b (diff) | |
download | pdfium-03d58937248fa244cbf02a3d38d430a513500311.tar.xz |
Clean up QRCoderEncoder and friends.
Remove a bunch of unused code, including gotos.
Fix some potential memory leaks.
Change-Id: Ia2775e2ab176f4741b765e259a24a293a5717394
Reviewed-on: https://pdfium-review.googlesource.com/3560
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxbarcode/cbc_qrcode.cpp')
-rw-r--r-- | fxbarcode/cbc_qrcode.cpp | 39 |
1 files changed, 15 insertions, 24 deletions
diff --git a/fxbarcode/cbc_qrcode.cpp b/fxbarcode/cbc_qrcode.cpp index 15c4057826..0e0191dc3e 100644 --- a/fxbarcode/cbc_qrcode.cpp +++ b/fxbarcode/cbc_qrcode.cpp @@ -21,26 +21,18 @@ #include "fxbarcode/cbc_qrcode.h" +#include <memory> + #include "fxbarcode/qrcode/BC_QRCodeWriter.h" CBC_QRCode::CBC_QRCode() : CBC_CodeBase(new CBC_QRCodeWriter) {} CBC_QRCode::~CBC_QRCode() {} -bool CBC_QRCode::SetVersion(int32_t version) { - if (version < 0 || version > 40) - return false; - return m_pBCWriter && - static_cast<CBC_QRCodeWriter*>(m_pBCWriter.get())->SetVersion(version); -} - bool CBC_QRCode::SetErrorCorrectionLevel(int32_t level) { if (level < 0 || level > 3) return false; - - return m_pBCWriter && - static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) - ->SetErrorCorrectionLevel(level); + return m_pBCWriter && writer()->SetErrorCorrectionLevel(level); } bool CBC_QRCode::Encode(const CFX_WideStringC& contents, @@ -48,34 +40,33 @@ bool CBC_QRCode::Encode(const CFX_WideStringC& contents, int32_t& e) { int32_t outWidth = 0; int32_t outHeight = 0; - CBC_QRCodeWriter* pWriter = static_cast<CBC_QRCodeWriter*>(m_pBCWriter.get()); - uint8_t* data = pWriter->Encode(CFX_WideString(contents), - pWriter->GetErrorCorrectionLevel(), outWidth, - outHeight, e); + CBC_QRCodeWriter* pWriter = writer(); + std::unique_ptr<uint8_t, FxFreeDeleter> data(pWriter->Encode( + CFX_WideString(contents), pWriter->GetErrorCorrectionLevel(), outWidth, + outHeight, e)); if (e != BCExceptionNO) return false; - pWriter->RenderResult(data, outWidth, outHeight, e); - FX_Free(data); - if (e != BCExceptionNO) - return false; - return true; + pWriter->RenderResult(data.get(), outWidth, outHeight, e); + return e == BCExceptionNO; } bool CBC_QRCode::RenderDevice(CFX_RenderDevice* device, const CFX_Matrix* matrix, int32_t& e) { - static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) - ->RenderDeviceResult(device, matrix); + writer()->RenderDeviceResult(device, matrix); return true; } bool CBC_QRCode::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, int32_t& e) { - static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) - ->RenderBitmapResult(pOutBitmap, e); + writer()->RenderBitmapResult(pOutBitmap, e); return e == BCExceptionNO; } BC_TYPE CBC_QRCode::GetType() { return BC_QR_CODE; } + +CBC_QRCodeWriter* CBC_QRCode::writer() { + return static_cast<CBC_QRCodeWriter*>(m_pBCWriter.get()); +} |