From 03d58937248fa244cbf02a3d38d430a513500311 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Mon, 3 Apr 2017 16:40:51 -0700 Subject: 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 Reviewed-by: Tom Sepez --- fxbarcode/cbc_qrcode.cpp | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) (limited to 'fxbarcode/cbc_qrcode.cpp') 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 + #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(m_pBCWriter.get())->SetVersion(version); -} - bool CBC_QRCode::SetErrorCorrectionLevel(int32_t level) { if (level < 0 || level > 3) return false; - - return m_pBCWriter && - static_cast(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(m_pBCWriter.get()); - uint8_t* data = pWriter->Encode(CFX_WideString(contents), - pWriter->GetErrorCorrectionLevel(), outWidth, - outHeight, e); + CBC_QRCodeWriter* pWriter = writer(); + std::unique_ptr 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(m_pBCWriter.get()) - ->RenderDeviceResult(device, matrix); + writer()->RenderDeviceResult(device, matrix); return true; } bool CBC_QRCode::RenderBitmap(CFX_RetainPtr& pOutBitmap, int32_t& e) { - static_cast(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(m_pBCWriter.get()); +} -- cgit v1.2.3