summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-06-06 12:57:44 -0700
committerCommit bot <commit-bot@chromium.org>2016-06-06 12:57:44 -0700
commit52d78564a61fad5d435f3c95a3a6c0df142e50cf (patch)
tree209840b7f578c0e35722984b789a2e9e84d5d428 /xfa
parentfe433f15d60f92ccde7a928160c2e7cc77dcb8bf (diff)
downloadpdfium-52d78564a61fad5d435f3c95a3a6c0df142e50cf.tar.xz
Clean up C-Style casts in CBC_CodeBase and subclasses
Make the parent class own the reader/writer via unique_ptrs. De-virtualize some methods with no overrides. Review-Url: https://codereview.chromium.org/2037573005
Diffstat (limited to 'xfa')
-rw-r--r--xfa/fxbarcode/cbc_codabar.cpp42
-rw-r--r--xfa/fxbarcode/cbc_code128.cpp30
-rw-r--r--xfa/fxbarcode/cbc_code39.cpp50
-rw-r--r--xfa/fxbarcode/cbc_codebase.cpp4
-rw-r--r--xfa/fxbarcode/cbc_codebase.h23
-rw-r--r--xfa/fxbarcode/cbc_datamatrix.cpp23
-rw-r--r--xfa/fxbarcode/cbc_ean13.cpp26
-rw-r--r--xfa/fxbarcode/cbc_ean8.cpp26
-rw-r--r--xfa/fxbarcode/cbc_onecode.cpp30
-rw-r--r--xfa/fxbarcode/cbc_onecode.h2
-rw-r--r--xfa/fxbarcode/cbc_pdf417i.cpp27
-rw-r--r--xfa/fxbarcode/cbc_qrcode.cpp41
-rw-r--r--xfa/fxbarcode/cbc_upca.cpp37
13 files changed, 173 insertions, 188 deletions
diff --git a/xfa/fxbarcode/cbc_codabar.cpp b/xfa/fxbarcode/cbc_codabar.cpp
index 23cd2d1e7e..4ed63ba7e2 100644
--- a/xfa/fxbarcode/cbc_codabar.cpp
+++ b/xfa/fxbarcode/cbc_codabar.cpp
@@ -27,35 +27,34 @@
#include "xfa/fxbarcode/oned/BC_OnedCodaBarReader.h"
#include "xfa/fxbarcode/oned/BC_OnedCodaBarWriter.h"
-CBC_Codabar::CBC_Codabar() {
- m_pBCReader = (CBC_Reader*)new (CBC_OnedCodaBarReader);
- m_pBCWriter = (CBC_Writer*)new (CBC_OnedCodaBarWriter);
-}
+CBC_Codabar::CBC_Codabar()
+ : CBC_OneCode(new CBC_OnedCodaBarReader, new CBC_OnedCodaBarWriter) {}
-CBC_Codabar::~CBC_Codabar() {
- delete (m_pBCReader);
- delete (m_pBCWriter);
-}
+CBC_Codabar::~CBC_Codabar() {}
FX_BOOL CBC_Codabar::SetStartChar(FX_CHAR start) {
- if (m_pBCWriter)
- return ((CBC_OnedCodaBarWriter*)m_pBCWriter)->SetStartChar(start);
- return FALSE;
+ if (!m_pBCWriter)
+ return FALSE;
+ return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
+ ->SetStartChar(start);
}
FX_BOOL CBC_Codabar::SetEndChar(FX_CHAR end) {
if (m_pBCWriter)
- return ((CBC_OnedCodaBarWriter*)m_pBCWriter)->SetEndChar(end);
+ return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
+ ->SetEndChar(end);
return FALSE;
}
FX_BOOL CBC_Codabar::SetTextLocation(BC_TEXT_LOC location) {
- return ((CBC_OnedCodaBarWriter*)m_pBCWriter)->SetTextLocation(location);
+ return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
+ ->SetTextLocation(location);
}
FX_BOOL CBC_Codabar::SetWideNarrowRatio(int32_t ratio) {
if (m_pBCWriter)
- return ((CBC_OnedCodaBarWriter*)m_pBCWriter)->SetWideNarrowRatio(ratio);
+ return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
+ ->SetWideNarrowRatio(ratio);
return FALSE;
}
@@ -70,13 +69,14 @@ FX_BOOL CBC_Codabar::Encode(const CFX_WideStringC& contents,
int32_t outWidth = 0;
int32_t outHeight = 0;
CFX_WideString filtercontents =
- ((CBC_OneDimWriter*)m_pBCWriter)->FilterContents(contents);
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
+ ->FilterContents(contents);
CFX_ByteString byteString = filtercontents.UTF8Encode();
m_renderContents = filtercontents;
- uint8_t* data = static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter)
+ uint8_t* data = static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
->Encode(byteString, format, outWidth, outHeight, e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
- ((CBC_OneDimWriter*)m_pBCWriter)
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderResult(filtercontents.AsStringC(), data, outWidth, isDevice, e);
FX_Free(data);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
@@ -87,9 +87,9 @@ FX_BOOL CBC_Codabar::RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) {
CFX_WideString renderCon =
- ((CBC_OnedCodaBarWriter*)m_pBCWriter)
+ static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
->encodedContents(m_renderContents.AsStringC());
- ((CBC_OneDimWriter*)m_pBCWriter)
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderDeviceResult(device, matrix, renderCon.AsStringC(), e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
return TRUE;
@@ -97,9 +97,9 @@ FX_BOOL CBC_Codabar::RenderDevice(CFX_RenderDevice* device,
FX_BOOL CBC_Codabar::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
CFX_WideString renderCon =
- ((CBC_OnedCodaBarWriter*)m_pBCWriter)
+ static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
->encodedContents(m_renderContents.AsStringC());
- ((CBC_OneDimWriter*)m_pBCWriter)
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderBitmapResult(pOutBitmap, renderCon.AsStringC(), e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
return TRUE;
diff --git a/xfa/fxbarcode/cbc_code128.cpp b/xfa/fxbarcode/cbc_code128.cpp
index 85d7afbbe8..c3614bee90 100644
--- a/xfa/fxbarcode/cbc_code128.cpp
+++ b/xfa/fxbarcode/cbc_code128.cpp
@@ -27,19 +27,15 @@
#include "xfa/fxbarcode/oned/BC_OnedCode128Reader.h"
#include "xfa/fxbarcode/oned/BC_OnedCode128Writer.h"
-CBC_Code128::CBC_Code128(BC_TYPE type) {
- m_pBCReader = (CBC_Reader*)new (CBC_OnedCode128Reader);
- m_pBCWriter = (CBC_Writer*)new CBC_OnedCode128Writer(type);
-}
+CBC_Code128::CBC_Code128(BC_TYPE type)
+ : CBC_OneCode(new CBC_OnedCode128Reader, new CBC_OnedCode128Writer(type)) {}
-CBC_Code128::~CBC_Code128() {
- delete (m_pBCReader);
- delete (m_pBCWriter);
-}
+CBC_Code128::~CBC_Code128() {}
FX_BOOL CBC_Code128::SetTextLocation(BC_TEXT_LOC location) {
if (m_pBCWriter)
- return ((CBC_OnedCode128Writer*)m_pBCWriter)->SetTextLocation(location);
+ return static_cast<CBC_OnedCode128Writer*>(m_pBCWriter.get())
+ ->SetTextLocation(location);
return FALSE;
}
@@ -55,17 +51,19 @@ FX_BOOL CBC_Code128::Encode(const CFX_WideStringC& contents,
int32_t outHeight = 0;
CFX_WideString content(contents);
if (contents.GetLength() % 2 &&
- ((CBC_OnedCode128Writer*)m_pBCWriter)->GetType() == BC_CODE128_C) {
+ static_cast<CBC_OnedCode128Writer*>(m_pBCWriter.get())->GetType() ==
+ BC_CODE128_C) {
content += '0';
}
- CFX_WideString encodeContents = ((CBC_OnedCode128Writer*)m_pBCWriter)
- ->FilterContents(content.AsStringC());
+ CFX_WideString encodeContents =
+ static_cast<CBC_OnedCode128Writer*>(m_pBCWriter.get())
+ ->FilterContents(content.AsStringC());
m_renderContents = encodeContents;
CFX_ByteString byteString = encodeContents.UTF8Encode();
- uint8_t* data = static_cast<CBC_OnedCode128Writer*>(m_pBCWriter)
+ uint8_t* data = static_cast<CBC_OnedCode128Writer*>(m_pBCWriter.get())
->Encode(byteString, format, outWidth, outHeight, e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
- ((CBC_OneDimWriter*)m_pBCWriter)
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderResult(encodeContents.AsStringC(), data, outWidth, isDevice, e);
FX_Free(data);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
@@ -75,14 +73,14 @@ FX_BOOL CBC_Code128::Encode(const CFX_WideStringC& contents,
FX_BOOL CBC_Code128::RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) {
- ((CBC_OneDimWriter*)m_pBCWriter)
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderDeviceResult(device, matrix, m_renderContents.AsStringC(), e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
return TRUE;
}
FX_BOOL CBC_Code128::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
- ((CBC_OneDimWriter*)m_pBCWriter)
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
return TRUE;
diff --git a/xfa/fxbarcode/cbc_code39.cpp b/xfa/fxbarcode/cbc_code39.cpp
index 5d00d772e4..03e618e188 100644
--- a/xfa/fxbarcode/cbc_code39.cpp
+++ b/xfa/fxbarcode/cbc_code39.cpp
@@ -27,26 +27,18 @@
#include "xfa/fxbarcode/oned/BC_OnedCode39Reader.h"
#include "xfa/fxbarcode/oned/BC_OnedCode39Writer.h"
-CBC_Code39::CBC_Code39() {
- m_pBCReader = (CBC_Reader*)new (CBC_OnedCode39Reader);
- m_pBCWriter = (CBC_Writer*)new (CBC_OnedCode39Writer);
-}
+CBC_Code39::CBC_Code39()
+ : CBC_OneCode(new CBC_OnedCode39Reader, new CBC_OnedCode39Writer) {}
-CBC_Code39::CBC_Code39(FX_BOOL usingCheckDigit) {
- m_pBCReader = (CBC_Reader*)new CBC_OnedCode39Reader(usingCheckDigit);
- m_pBCWriter = (CBC_Writer*)new CBC_OnedCode39Writer;
-}
+CBC_Code39::CBC_Code39(FX_BOOL usingCheckDigit)
+ : CBC_OneCode(new CBC_OnedCode39Reader(usingCheckDigit),
+ new CBC_OnedCode39Writer) {}
-CBC_Code39::CBC_Code39(FX_BOOL usingCheckDigit, FX_BOOL extendedMode) {
- m_pBCReader =
- (CBC_Reader*)new CBC_OnedCode39Reader(usingCheckDigit, extendedMode);
- m_pBCWriter = (CBC_Writer*)new CBC_OnedCode39Writer(extendedMode);
-}
+CBC_Code39::CBC_Code39(FX_BOOL usingCheckDigit, FX_BOOL extendedMode)
+ : CBC_OneCode(new CBC_OnedCode39Reader(usingCheckDigit, extendedMode),
+ new CBC_OnedCode39Writer(extendedMode)) {}
-CBC_Code39::~CBC_Code39() {
- delete (m_pBCReader);
- delete (m_pBCWriter);
-}
+CBC_Code39::~CBC_Code39() {}
FX_BOOL CBC_Code39::Encode(const CFX_WideStringC& contents,
FX_BOOL isDevice,
@@ -59,15 +51,17 @@ FX_BOOL CBC_Code39::Encode(const CFX_WideStringC& contents,
int32_t outWidth = 0;
int32_t outHeight = 0;
CFX_WideString filtercontents =
- ((CBC_OnedCode39Writer*)m_pBCWriter)->FilterContents(contents);
+ static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get())
+ ->FilterContents(contents);
CFX_WideString renderContents =
- ((CBC_OnedCode39Writer*)m_pBCWriter)->RenderTextContents(contents);
+ static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get())
+ ->RenderTextContents(contents);
m_renderContents = renderContents;
CFX_ByteString byteString = filtercontents.UTF8Encode();
- uint8_t* data = static_cast<CBC_OnedCode39Writer*>(m_pBCWriter)
+ uint8_t* data = static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get())
->Encode(byteString, format, outWidth, outHeight, e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
- ((CBC_OneDimWriter*)m_pBCWriter)
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderResult(renderContents.AsStringC(), data, outWidth, isDevice, e);
FX_Free(data);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
@@ -78,9 +72,9 @@ FX_BOOL CBC_Code39::RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) {
CFX_WideString renderCon =
- ((CBC_OnedCode39Writer*)m_pBCWriter)
+ static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get())
->encodedContents(m_renderContents.AsStringC(), e);
- ((CBC_OneDimWriter*)m_pBCWriter)
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderDeviceResult(device, matrix, renderCon.AsStringC(), e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
return TRUE;
@@ -88,9 +82,9 @@ FX_BOOL CBC_Code39::RenderDevice(CFX_RenderDevice* device,
FX_BOOL CBC_Code39::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
CFX_WideString renderCon =
- ((CBC_OnedCode39Writer*)m_pBCWriter)
+ static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get())
->encodedContents(m_renderContents.AsStringC(), e);
- ((CBC_OneDimWriter*)m_pBCWriter)
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderBitmapResult(pOutBitmap, renderCon.AsStringC(), e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
return TRUE;
@@ -115,12 +109,14 @@ CFX_WideString CBC_Code39::Decode(CFX_DIBitmap* pBitmap, int32_t& e) {
FX_BOOL CBC_Code39::SetTextLocation(BC_TEXT_LOC location) {
if (m_pBCWriter)
- return ((CBC_OnedCode39Writer*)m_pBCWriter)->SetTextLocation(location);
+ return static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get())
+ ->SetTextLocation(location);
return FALSE;
}
FX_BOOL CBC_Code39::SetWideNarrowRatio(int32_t ratio) {
if (m_pBCWriter)
- return ((CBC_OnedCode39Writer*)m_pBCWriter)->SetWideNarrowRatio(ratio);
+ return static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get())
+ ->SetWideNarrowRatio(ratio);
return FALSE;
}
diff --git a/xfa/fxbarcode/cbc_codebase.cpp b/xfa/fxbarcode/cbc_codebase.cpp
index 64a358a038..7065c2eade 100644
--- a/xfa/fxbarcode/cbc_codebase.cpp
+++ b/xfa/fxbarcode/cbc_codebase.cpp
@@ -21,9 +21,11 @@
#include "xfa/fxbarcode/cbc_codebase.h"
+#include "xfa/fxbarcode/BC_Reader.h"
#include "xfa/fxbarcode/BC_Writer.h"
-CBC_CodeBase::CBC_CodeBase() {}
+CBC_CodeBase::CBC_CodeBase(CBC_Reader* pReader, CBC_Writer* pWriter)
+ : m_pBCReader(pReader), m_pBCWriter(pWriter) {}
CBC_CodeBase::~CBC_CodeBase() {}
diff --git a/xfa/fxbarcode/cbc_codebase.h b/xfa/fxbarcode/cbc_codebase.h
index 2124f75d78..1ecfe20b27 100644
--- a/xfa/fxbarcode/cbc_codebase.h
+++ b/xfa/fxbarcode/cbc_codebase.h
@@ -7,6 +7,8 @@
#ifndef XFA_FXBARCODE_CBC_CODEBASE_H_
#define XFA_FXBARCODE_CBC_CODEBASE_H_
+#include <memory>
+
#include "core/fxcrt/include/fx_system.h"
#include "core/fxge/include/fx_dib.h"
#include "xfa/fxbarcode/include/BC_Library.h"
@@ -18,7 +20,7 @@ class CFX_RenderDevice;
class CBC_CodeBase {
public:
- CBC_CodeBase();
+ CBC_CodeBase(CBC_Reader* pReader, CBC_Writer* pWriter);
virtual ~CBC_CodeBase();
virtual BC_TYPE GetType() = 0;
@@ -35,18 +37,17 @@ class CBC_CodeBase {
int32_t& e) = 0;
virtual CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e) = 0;
- virtual FX_BOOL SetCharEncoding(int32_t encoding);
- virtual FX_BOOL SetModuleHeight(int32_t moduleHeight);
- virtual FX_BOOL SetModuleWidth(int32_t moduleWidth);
-
- virtual FX_BOOL SetHeight(int32_t height);
- virtual FX_BOOL SetWidth(int32_t width);
- virtual void SetBackgroundColor(FX_ARGB backgroundColor);
- virtual void SetBarcodeColor(FX_ARGB foregroundColor);
+ FX_BOOL SetCharEncoding(int32_t encoding);
+ FX_BOOL SetModuleHeight(int32_t moduleHeight);
+ FX_BOOL SetModuleWidth(int32_t moduleWidth);
+ FX_BOOL SetHeight(int32_t height);
+ FX_BOOL SetWidth(int32_t width);
+ void SetBackgroundColor(FX_ARGB backgroundColor);
+ void SetBarcodeColor(FX_ARGB foregroundColor);
protected:
- CBC_Writer* m_pBCWriter;
- CBC_Reader* m_pBCReader;
+ std::unique_ptr<CBC_Reader> m_pBCReader;
+ std::unique_ptr<CBC_Writer> m_pBCWriter;
};
#endif // XFA_FXBARCODE_CBC_CODEBASE_H_
diff --git a/xfa/fxbarcode/cbc_datamatrix.cpp b/xfa/fxbarcode/cbc_datamatrix.cpp
index 7430187f5b..08b76830fd 100644
--- a/xfa/fxbarcode/cbc_datamatrix.cpp
+++ b/xfa/fxbarcode/cbc_datamatrix.cpp
@@ -27,16 +27,12 @@
#include "xfa/fxbarcode/datamatrix/BC_DataMatrixReader.h"
#include "xfa/fxbarcode/datamatrix/BC_DataMatrixWriter.h"
-CBC_DataMatrix::CBC_DataMatrix() {
- m_pBCReader = (CBC_Reader*)new (CBC_DataMatrixReader);
- ((CBC_DataMatrixReader*)m_pBCReader)->Init();
- m_pBCWriter = (CBC_Writer*)new (CBC_DataMatrixWriter);
+CBC_DataMatrix::CBC_DataMatrix()
+ : CBC_CodeBase(new CBC_DataMatrixReader, new CBC_DataMatrixWriter) {
+ static_cast<CBC_DataMatrixReader*>(m_pBCReader.get())->Init();
}
-CBC_DataMatrix::~CBC_DataMatrix() {
- delete (m_pBCReader);
- delete (m_pBCWriter);
-}
+CBC_DataMatrix::~CBC_DataMatrix() {}
FX_BOOL CBC_DataMatrix::Encode(const CFX_WideStringC& contents,
FX_BOOL isDevice,
@@ -44,10 +40,11 @@ FX_BOOL CBC_DataMatrix::Encode(const CFX_WideStringC& contents,
int32_t outWidth = 0;
int32_t outHeight = 0;
uint8_t* data =
- ((CBC_DataMatrixWriter*)m_pBCWriter)
+ static_cast<CBC_DataMatrixWriter*>(m_pBCWriter.get())
->Encode(CFX_WideString(contents), outWidth, outHeight, e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
- ((CBC_TwoDimWriter*)m_pBCWriter)->RenderResult(data, outWidth, outHeight, e);
+ static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
+ ->RenderResult(data, outWidth, outHeight, e);
FX_Free(data);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
return TRUE;
@@ -56,12 +53,14 @@ FX_BOOL CBC_DataMatrix::Encode(const CFX_WideStringC& contents,
FX_BOOL CBC_DataMatrix::RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) {
- ((CBC_TwoDimWriter*)m_pBCWriter)->RenderDeviceResult(device, matrix);
+ static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
+ ->RenderDeviceResult(device, matrix);
return TRUE;
}
FX_BOOL CBC_DataMatrix::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
- ((CBC_TwoDimWriter*)m_pBCWriter)->RenderBitmapResult(pOutBitmap, e);
+ static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
+ ->RenderBitmapResult(pOutBitmap, e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
return TRUE;
}
diff --git a/xfa/fxbarcode/cbc_ean13.cpp b/xfa/fxbarcode/cbc_ean13.cpp
index ea67c9f64b..589af5b090 100644
--- a/xfa/fxbarcode/cbc_ean13.cpp
+++ b/xfa/fxbarcode/cbc_ean13.cpp
@@ -27,27 +27,23 @@
#include "xfa/fxbarcode/oned/BC_OnedEAN13Reader.h"
#include "xfa/fxbarcode/oned/BC_OnedEAN13Writer.h"
-CBC_EAN13::CBC_EAN13() {
- m_pBCReader = (CBC_Reader*)new (CBC_OnedEAN13Reader);
- m_pBCWriter = (CBC_Writer*)new (CBC_OnedEAN13Writer);
-}
+CBC_EAN13::CBC_EAN13()
+ : CBC_OneCode(new CBC_OnedEAN13Reader, new CBC_OnedEAN13Writer) {}
-CBC_EAN13::~CBC_EAN13() {
- delete (m_pBCReader);
- delete (m_pBCWriter);
-}
+CBC_EAN13::~CBC_EAN13() {}
CFX_WideString CBC_EAN13::Preprocess(const CFX_WideStringC& contents) {
CFX_WideString encodeContents =
- ((CBC_OnedEAN13Writer*)m_pBCWriter)->FilterContents(contents);
+ static_cast<CBC_OnedEAN13Writer*>(m_pBCWriter.get())
+ ->FilterContents(contents);
int32_t length = encodeContents.GetLength();
if (length <= 12) {
for (int32_t i = 0; i < 12 - length; i++)
encodeContents = FX_WCHAR('0') + encodeContents;
CFX_ByteString byteString = encodeContents.UTF8Encode();
- int32_t checksum =
- ((CBC_OnedEAN13Writer*)m_pBCWriter)->CalcChecksum(byteString);
+ int32_t checksum = static_cast<CBC_OnedEAN13Writer*>(m_pBCWriter.get())
+ ->CalcChecksum(byteString);
byteString += checksum - 0 + '0';
encodeContents = byteString.UTF8Decode();
}
@@ -70,10 +66,10 @@ FX_BOOL CBC_EAN13::Encode(const CFX_WideStringC& contents,
CFX_WideString encodeContents = Preprocess(contents);
CFX_ByteString byteString = encodeContents.UTF8Encode();
m_renderContents = encodeContents;
- uint8_t* data = static_cast<CBC_OnedEAN13Writer*>(m_pBCWriter)
+ uint8_t* data = static_cast<CBC_OnedEAN13Writer*>(m_pBCWriter.get())
->Encode(byteString, format, outWidth, outHeight, e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
- ((CBC_OneDimWriter*)m_pBCWriter)
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderResult(encodeContents.AsStringC(), data, outWidth, isDevice, e);
FX_Free(data);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
@@ -83,14 +79,14 @@ FX_BOOL CBC_EAN13::Encode(const CFX_WideStringC& contents,
FX_BOOL CBC_EAN13::RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) {
- ((CBC_OneDimWriter*)m_pBCWriter)
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderDeviceResult(device, matrix, m_renderContents.AsStringC(), e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
return TRUE;
}
FX_BOOL CBC_EAN13::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
- ((CBC_OneDimWriter*)m_pBCWriter)
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
return TRUE;
diff --git a/xfa/fxbarcode/cbc_ean8.cpp b/xfa/fxbarcode/cbc_ean8.cpp
index 418ef87c1f..3f32d2274c 100644
--- a/xfa/fxbarcode/cbc_ean8.cpp
+++ b/xfa/fxbarcode/cbc_ean8.cpp
@@ -27,27 +27,23 @@
#include "xfa/fxbarcode/oned/BC_OnedEAN8Reader.h"
#include "xfa/fxbarcode/oned/BC_OnedEAN8Writer.h"
-CBC_EAN8::CBC_EAN8() {
- m_pBCReader = (CBC_Reader*)new (CBC_OnedEAN8Reader);
- m_pBCWriter = (CBC_Writer*)new (CBC_OnedEAN8Writer);
-}
+CBC_EAN8::CBC_EAN8()
+ : CBC_OneCode(new CBC_OnedEAN8Reader, new CBC_OnedEAN8Writer) {}
-CBC_EAN8::~CBC_EAN8() {
- delete (m_pBCReader);
- delete (m_pBCWriter);
-}
+CBC_EAN8::~CBC_EAN8() {}
CFX_WideString CBC_EAN8::Preprocess(const CFX_WideStringC& contents) {
CFX_WideString encodeContents =
- ((CBC_OnedEAN8Writer*)m_pBCWriter)->FilterContents(contents);
+ static_cast<CBC_OnedEAN8Writer*>(m_pBCWriter.get())
+ ->FilterContents(contents);
int32_t length = encodeContents.GetLength();
if (length <= 7) {
for (int32_t i = 0; i < 7 - length; i++)
encodeContents = FX_WCHAR('0') + encodeContents;
CFX_ByteString byteString = encodeContents.UTF8Encode();
- int32_t checksum =
- ((CBC_OnedEAN8Writer*)m_pBCWriter)->CalcChecksum(byteString);
+ int32_t checksum = static_cast<CBC_OnedEAN8Writer*>(m_pBCWriter.get())
+ ->CalcChecksum(byteString);
encodeContents += FX_WCHAR(checksum - 0 + '0');
}
if (length > 8)
@@ -69,10 +65,10 @@ FX_BOOL CBC_EAN8::Encode(const CFX_WideStringC& contents,
CFX_WideString encodeContents = Preprocess(contents);
CFX_ByteString byteString = encodeContents.UTF8Encode();
m_renderContents = encodeContents;
- uint8_t* data = static_cast<CBC_OnedEAN8Writer*>(m_pBCWriter)
+ uint8_t* data = static_cast<CBC_OnedEAN8Writer*>(m_pBCWriter.get())
->Encode(byteString, format, outWidth, outHeight, e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
- ((CBC_OneDimWriter*)m_pBCWriter)
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderResult(encodeContents.AsStringC(), data, outWidth, isDevice, e);
FX_Free(data);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
@@ -82,14 +78,14 @@ FX_BOOL CBC_EAN8::Encode(const CFX_WideStringC& contents,
FX_BOOL CBC_EAN8::RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) {
- ((CBC_OneDimWriter*)m_pBCWriter)
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderDeviceResult(device, matrix, m_renderContents.AsStringC(), e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
return TRUE;
}
FX_BOOL CBC_EAN8::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
- ((CBC_OneDimWriter*)m_pBCWriter)
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
return TRUE;
diff --git a/xfa/fxbarcode/cbc_onecode.cpp b/xfa/fxbarcode/cbc_onecode.cpp
index f5e1a3960a..b435a59012 100644
--- a/xfa/fxbarcode/cbc_onecode.cpp
+++ b/xfa/fxbarcode/cbc_onecode.cpp
@@ -23,55 +23,57 @@
#include "xfa/fxbarcode/oned/BC_OneDimWriter.h"
-CBC_OneCode::CBC_OneCode() {}
+CBC_OneCode::CBC_OneCode(CBC_Reader* pReader, CBC_Writer* pWriter)
+ : CBC_CodeBase(pReader, pWriter) {}
CBC_OneCode::~CBC_OneCode() {}
FX_BOOL CBC_OneCode::CheckContentValidity(const CFX_WideStringC& contents) {
- if (m_pBCWriter)
- return ((CBC_OneDimWriter*)m_pBCWriter)->CheckContentValidity(contents);
- return FALSE;
+ return m_pBCWriter &&
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
+ ->CheckContentValidity(contents);
}
CFX_WideString CBC_OneCode::FilterContents(const CFX_WideStringC& contents) {
- CFX_WideString tmp;
if (!m_pBCWriter)
- return tmp;
- return ((CBC_OneDimWriter*)m_pBCWriter)->FilterContents(contents);
+ return CFX_WideString();
+ return static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
+ ->FilterContents(contents);
}
void CBC_OneCode::SetPrintChecksum(FX_BOOL checksum) {
if (m_pBCWriter)
- ((CBC_OneDimWriter*)m_pBCWriter)->SetPrintChecksum(checksum);
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
+ ->SetPrintChecksum(checksum);
}
void CBC_OneCode::SetDataLength(int32_t length) {
if (m_pBCWriter)
- ((CBC_OneDimWriter*)m_pBCWriter)->SetDataLength(length);
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())->SetDataLength(length);
}
void CBC_OneCode::SetCalChecksum(FX_BOOL calc) {
if (m_pBCWriter)
- ((CBC_OneDimWriter*)m_pBCWriter)->SetCalcChecksum(calc);
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())->SetCalcChecksum(calc);
}
FX_BOOL CBC_OneCode::SetFont(CFX_Font* cFont) {
if (m_pBCWriter)
- return ((CBC_OneDimWriter*)m_pBCWriter)->SetFont(cFont);
+ return static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())->SetFont(cFont);
return FALSE;
}
void CBC_OneCode::SetFontSize(FX_FLOAT size) {
if (m_pBCWriter)
- ((CBC_OneDimWriter*)m_pBCWriter)->SetFontSize(size);
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())->SetFontSize(size);
}
void CBC_OneCode::SetFontStyle(int32_t style) {
if (m_pBCWriter)
- ((CBC_OneDimWriter*)m_pBCWriter)->SetFontStyle(style);
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())->SetFontStyle(style);
}
void CBC_OneCode::SetFontColor(FX_ARGB color) {
if (m_pBCWriter)
- ((CBC_OneDimWriter*)m_pBCWriter)->SetFontColor(color);
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())->SetFontColor(color);
}
diff --git a/xfa/fxbarcode/cbc_onecode.h b/xfa/fxbarcode/cbc_onecode.h
index 6e447cc772..a915f78a6d 100644
--- a/xfa/fxbarcode/cbc_onecode.h
+++ b/xfa/fxbarcode/cbc_onecode.h
@@ -17,7 +17,7 @@ class CFX_RenderDevice;
class CBC_OneCode : public CBC_CodeBase {
public:
- CBC_OneCode();
+ CBC_OneCode(CBC_Reader* pReader, CBC_Writer* pWriter);
~CBC_OneCode() override;
virtual FX_BOOL CheckContentValidity(const CFX_WideStringC& contents);
diff --git a/xfa/fxbarcode/cbc_pdf417i.cpp b/xfa/fxbarcode/cbc_pdf417i.cpp
index 228caed47f..514cc01415 100644
--- a/xfa/fxbarcode/cbc_pdf417i.cpp
+++ b/xfa/fxbarcode/cbc_pdf417i.cpp
@@ -27,23 +27,19 @@
#include "xfa/fxbarcode/pdf417/BC_PDF417Reader.h"
#include "xfa/fxbarcode/pdf417/BC_PDF417Writer.h"
-CBC_PDF417I::CBC_PDF417I() {
- m_pBCReader = (CBC_Reader*)new (CBC_PDF417Reader);
- m_pBCWriter = (CBC_Writer*)new (CBC_PDF417Writer);
-}
+CBC_PDF417I::CBC_PDF417I()
+ : CBC_CodeBase(new CBC_PDF417Reader, new CBC_PDF417Writer) {}
-CBC_PDF417I::~CBC_PDF417I() {
- delete (m_pBCReader);
- delete (m_pBCWriter);
-}
+CBC_PDF417I::~CBC_PDF417I() {}
FX_BOOL CBC_PDF417I::SetErrorCorrectionLevel(int32_t level) {
- ((CBC_PDF417Writer*)m_pBCWriter)->SetErrorCorrectionLevel(level);
+ static_cast<CBC_PDF417Writer*>(m_pBCWriter.get())
+ ->SetErrorCorrectionLevel(level);
return TRUE;
}
void CBC_PDF417I::SetTruncated(FX_BOOL truncated) {
- ((CBC_PDF417Writer*)m_pBCWriter)->SetTruncated(truncated);
+ static_cast<CBC_PDF417Writer*>(m_pBCWriter.get())->SetTruncated(truncated);
}
FX_BOOL CBC_PDF417I::Encode(const CFX_WideStringC& contents,
@@ -52,10 +48,11 @@ FX_BOOL CBC_PDF417I::Encode(const CFX_WideStringC& contents,
int32_t outWidth = 0;
int32_t outHeight = 0;
uint8_t* data =
- ((CBC_PDF417Writer*)m_pBCWriter)
+ static_cast<CBC_PDF417Writer*>(m_pBCWriter.get())
->Encode(CFX_WideString(contents), outWidth, outHeight, e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
- ((CBC_TwoDimWriter*)m_pBCWriter)->RenderResult(data, outWidth, outHeight, e);
+ static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
+ ->RenderResult(data, outWidth, outHeight, e);
FX_Free(data);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
return TRUE;
@@ -64,12 +61,14 @@ FX_BOOL CBC_PDF417I::Encode(const CFX_WideStringC& contents,
FX_BOOL CBC_PDF417I::RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) {
- ((CBC_TwoDimWriter*)m_pBCWriter)->RenderDeviceResult(device, matrix);
+ static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
+ ->RenderDeviceResult(device, matrix);
return TRUE;
}
FX_BOOL CBC_PDF417I::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
- ((CBC_TwoDimWriter*)m_pBCWriter)->RenderBitmapResult(pOutBitmap, e);
+ static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
+ ->RenderBitmapResult(pOutBitmap, e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
return TRUE;
}
diff --git a/xfa/fxbarcode/cbc_qrcode.cpp b/xfa/fxbarcode/cbc_qrcode.cpp
index 6f93b4415e..9ea20a6820 100644
--- a/xfa/fxbarcode/cbc_qrcode.cpp
+++ b/xfa/fxbarcode/cbc_qrcode.cpp
@@ -27,31 +27,27 @@
#include "xfa/fxbarcode/qrcode/BC_QRCodeReader.h"
#include "xfa/fxbarcode/qrcode/BC_QRCodeWriter.h"
-CBC_QRCode::CBC_QRCode() {
- m_pBCReader = (CBC_Reader*)new (CBC_QRCodeReader);
- ((CBC_QRCodeReader*)m_pBCReader)->Init();
- m_pBCWriter = (CBC_Writer*)new (CBC_QRCodeWriter);
+CBC_QRCode::CBC_QRCode()
+ : CBC_CodeBase(new CBC_QRCodeReader, new CBC_QRCodeWriter) {
+ static_cast<CBC_QRCodeReader*>(m_pBCReader.get())->Init();
}
-CBC_QRCode::~CBC_QRCode() {
- delete (m_pBCReader);
- delete (m_pBCWriter);
-}
+CBC_QRCode::~CBC_QRCode() {}
FX_BOOL CBC_QRCode::SetVersion(int32_t version) {
if (version < 0 || version > 40)
return FALSE;
- if (!m_pBCWriter)
- return FALSE;
- return ((CBC_QRCodeWriter*)m_pBCWriter)->SetVersion(version);
+ return m_pBCWriter &&
+ static_cast<CBC_QRCodeWriter*>(m_pBCWriter.get())->SetVersion(version);
}
FX_BOOL CBC_QRCode::SetErrorCorrectionLevel(int32_t level) {
if (level < 0 || level > 3)
return FALSE;
- if (!m_pBCWriter)
- return FALSE;
- return ((CBC_TwoDimWriter*)m_pBCWriter)->SetErrorCorrectionLevel(level);
+
+ return m_pBCWriter &&
+ static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
+ ->SetErrorCorrectionLevel(level);
}
FX_BOOL CBC_QRCode::Encode(const CFX_WideStringC& contents,
@@ -59,13 +55,12 @@ FX_BOOL CBC_QRCode::Encode(const CFX_WideStringC& contents,
int32_t& e) {
int32_t outWidth = 0;
int32_t outHeight = 0;
- uint8_t* data =
- ((CBC_QRCodeWriter*)m_pBCWriter)
- ->Encode(CFX_WideString(contents),
- ((CBC_QRCodeWriter*)m_pBCWriter)->GetErrorCorrectionLevel(),
- outWidth, outHeight, e);
+ CBC_QRCodeWriter* pWriter = static_cast<CBC_QRCodeWriter*>(m_pBCWriter.get());
+ uint8_t* data = pWriter->Encode(CFX_WideString(contents),
+ pWriter->GetErrorCorrectionLevel(), outWidth,
+ outHeight, e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
- ((CBC_TwoDimWriter*)m_pBCWriter)->RenderResult(data, outWidth, outHeight, e);
+ pWriter->RenderResult(data, outWidth, outHeight, e);
FX_Free(data);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
return TRUE;
@@ -74,12 +69,14 @@ FX_BOOL CBC_QRCode::Encode(const CFX_WideStringC& contents,
FX_BOOL CBC_QRCode::RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) {
- ((CBC_TwoDimWriter*)m_pBCWriter)->RenderDeviceResult(device, matrix);
+ static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
+ ->RenderDeviceResult(device, matrix);
return TRUE;
}
FX_BOOL CBC_QRCode::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
- ((CBC_TwoDimWriter*)m_pBCWriter)->RenderBitmapResult(pOutBitmap, e);
+ static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
+ ->RenderBitmapResult(pOutBitmap, e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
return TRUE;
}
diff --git a/xfa/fxbarcode/cbc_upca.cpp b/xfa/fxbarcode/cbc_upca.cpp
index 886525ab54..525612257a 100644
--- a/xfa/fxbarcode/cbc_upca.cpp
+++ b/xfa/fxbarcode/cbc_upca.cpp
@@ -27,28 +27,24 @@
#include "xfa/fxbarcode/oned/BC_OnedUPCAReader.h"
#include "xfa/fxbarcode/oned/BC_OnedUPCAWriter.h"
-CBC_UPCA::CBC_UPCA() {
- m_pBCReader = (CBC_Reader*)new (CBC_OnedUPCAReader);
- ((CBC_OnedUPCAReader*)m_pBCReader)->Init();
- m_pBCWriter = (CBC_Writer*)new (CBC_OnedUPCAWriter);
+CBC_UPCA::CBC_UPCA()
+ : CBC_OneCode(new CBC_OnedUPCAReader, new CBC_OnedUPCAWriter) {
+ static_cast<CBC_OnedUPCAReader*>(m_pBCReader.get())->Init();
}
-CBC_UPCA::~CBC_UPCA() {
- delete (m_pBCReader);
- delete (m_pBCWriter);
-}
+CBC_UPCA::~CBC_UPCA() {}
CFX_WideString CBC_UPCA::Preprocess(const CFX_WideStringC& contents) {
- CFX_WideString encodeContents =
- ((CBC_OnedUPCAWriter*)m_pBCWriter)->FilterContents(contents);
+ CBC_OnedUPCAWriter* pWriter =
+ static_cast<CBC_OnedUPCAWriter*>(m_pBCWriter.get());
+ CFX_WideString encodeContents = pWriter->FilterContents(contents);
int32_t length = encodeContents.GetLength();
if (length <= 11) {
for (int32_t i = 0; i < 11 - length; i++)
encodeContents = FX_WCHAR('0') + encodeContents;
CFX_ByteString byteString = encodeContents.UTF8Encode();
- int32_t checksum =
- ((CBC_OnedUPCAWriter*)m_pBCWriter)->CalcChecksum(byteString);
+ int32_t checksum = pWriter->CalcChecksum(byteString);
byteString += checksum - 0 + '0';
encodeContents = byteString.UTF8Decode();
}
@@ -71,12 +67,15 @@ FX_BOOL CBC_UPCA::Encode(const CFX_WideStringC& contents,
CFX_WideString encodeContents = Preprocess(contents);
CFX_ByteString byteString = encodeContents.UTF8Encode();
m_renderContents = encodeContents;
- ((CBC_OnedUPCAWriter*)m_pBCWriter)->Init();
- uint8_t* data = static_cast<CBC_OnedUPCAWriter*>(m_pBCWriter)
- ->Encode(byteString, format, outWidth, outHeight, e);
+
+ CBC_OnedUPCAWriter* pWriter =
+ static_cast<CBC_OnedUPCAWriter*>(m_pBCWriter.get());
+
+ pWriter->Init();
+ uint8_t* data = pWriter->Encode(byteString, format, outWidth, outHeight, e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
- ((CBC_OneDimWriter*)m_pBCWriter)
- ->RenderResult(encodeContents.AsStringC(), data, outWidth, isDevice, e);
+ pWriter->RenderResult(encodeContents.AsStringC(), data, outWidth, isDevice,
+ e);
FX_Free(data);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
return TRUE;
@@ -85,14 +84,14 @@ FX_BOOL CBC_UPCA::Encode(const CFX_WideStringC& contents,
FX_BOOL CBC_UPCA::RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) {
- ((CBC_OneDimWriter*)m_pBCWriter)
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderDeviceResult(device, matrix, m_renderContents.AsStringC(), e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
return TRUE;
}
FX_BOOL CBC_UPCA::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
- ((CBC_OneDimWriter*)m_pBCWriter)
+ static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e);
BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
return TRUE;