summaryrefslogtreecommitdiff
path: root/xfa/fde
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-05-11 10:26:05 -0700
committerCommit bot <commit-bot@chromium.org>2016-05-11 10:26:05 -0700
commitf74ad998d2e8d2636fb25e94823946a3b151e34e (patch)
tree0b18e0a29fdc4bf1cce66ea437d8a4841b3daf4a /xfa/fde
parent2c3a16a7698ba15476173e849f82c97ea3da9939 (diff)
downloadpdfium-f74ad998d2e8d2636fb25e94823946a3b151e34e.tar.xz
Replace some calls to Release() with direct delete, part 1.
Searching for the anti-pattern: void Release() { delete this; } We must be explicit on the ownership model. Add unique_ptrs as a result. Review-Url: https://codereview.chromium.org/1960673003
Diffstat (limited to 'xfa/fde')
-rw-r--r--xfa/fde/cfde_path.h2
-rw-r--r--xfa/fde/css/fde_cssstyleselector.cpp63
-rw-r--r--xfa/fde/css/fde_cssstyleselector.h4
-rw-r--r--xfa/fde/css/fde_cssstylesheet.cpp21
-rw-r--r--xfa/fde/css/fde_csssyntax.h3
-rw-r--r--xfa/fde/fde_gedevice.h4
-rw-r--r--xfa/fde/fde_iterator.h4
-rw-r--r--xfa/fde/fde_render.cpp20
-rw-r--r--xfa/fde/fde_render.h9
-rw-r--r--xfa/fde/tto/fde_textout.cpp44
-rw-r--r--xfa/fde/tto/fde_textout.h7
11 files changed, 81 insertions, 100 deletions
diff --git a/xfa/fde/cfde_path.h b/xfa/fde/cfde_path.h
index c4b66f063e..c9f213d350 100644
--- a/xfa/fde/cfde_path.h
+++ b/xfa/fde/cfde_path.h
@@ -12,8 +12,6 @@
class CFDE_Path : public CFX_Target {
public:
- void Release() { delete this; }
-
FX_BOOL StartFigure();
FX_BOOL CloseFigure();
diff --git a/xfa/fde/css/fde_cssstyleselector.cpp b/xfa/fde/css/fde_cssstyleselector.cpp
index 27b251a783..05f036b1f3 100644
--- a/xfa/fde/css/fde_cssstyleselector.cpp
+++ b/xfa/fde/css/fde_cssstyleselector.cpp
@@ -7,6 +7,7 @@
#include "xfa/fde/css/fde_cssstyleselector.h"
#include <algorithm>
+#include <memory>
#include "xfa/fde/css/fde_csscache.h"
#include "xfa/fde/css/fde_cssdeclaration.h"
@@ -538,44 +539,42 @@ void CFDE_CSSStyleSelector::AppendInlineStyle(CFDE_CSSDeclaration* pDecl,
const FX_WCHAR* psz,
int32_t iLen) {
ASSERT(pDecl && psz && iLen > 0);
+ std::unique_ptr<CFDE_CSSSyntaxParser> pSyntax(new CFDE_CSSSyntaxParser);
+ if (!pSyntax->Init(psz, iLen, 32, TRUE))
+ return;
- CFDE_CSSSyntaxParser* pSyntax = new CFDE_CSSSyntaxParser;
- if (pSyntax->Init(psz, iLen, 32, TRUE)) {
- int32_t iLen;
- const FX_WCHAR* psz;
- FDE_CSSPROPERTYARGS args;
- args.pStringCache = NULL;
- args.pStaticStore = m_pInlineStyleStore;
- args.pProperty = NULL;
- CFX_WideString wsName;
- for (;;) {
- FDE_CSSSYNTAXSTATUS eStatus = pSyntax->DoSyntaxParse();
- if (eStatus == FDE_CSSSYNTAXSTATUS_PropertyName) {
- psz = pSyntax->GetCurrentString(iLen);
- args.pProperty = FDE_GetCSSPropertyByName(CFX_WideStringC(psz, iLen));
- if (args.pProperty == NULL) {
- wsName = CFX_WideStringC(psz, iLen);
- }
- } else if (eStatus == FDE_CSSSYNTAXSTATUS_PropertyValue) {
- if (args.pProperty != NULL) {
- psz = pSyntax->GetCurrentString(iLen);
- if (iLen > 0) {
- pDecl->AddProperty(&args, psz, iLen);
- }
- } else if (iLen > 0) {
- psz = pSyntax->GetCurrentString(iLen);
- if (iLen > 0) {
- pDecl->AddProperty(&args, wsName.c_str(), wsName.GetLength(), psz,
- iLen);
- }
+ int32_t iLen2;
+ const FX_WCHAR* psz2;
+ FDE_CSSPROPERTYARGS args;
+ args.pStringCache = nullptr;
+ args.pStaticStore = m_pInlineStyleStore;
+ args.pProperty = nullptr;
+ CFX_WideString wsName;
+ while (1) {
+ FDE_CSSSYNTAXSTATUS eStatus = pSyntax->DoSyntaxParse();
+ if (eStatus == FDE_CSSSYNTAXSTATUS_PropertyName) {
+ psz2 = pSyntax->GetCurrentString(iLen2);
+ args.pProperty = FDE_GetCSSPropertyByName(CFX_WideStringC(psz2, iLen2));
+ if (!args.pProperty)
+ wsName = CFX_WideStringC(psz2, iLen2);
+ } else if (eStatus == FDE_CSSSYNTAXSTATUS_PropertyValue) {
+ if (args.pProperty) {
+ psz2 = pSyntax->GetCurrentString(iLen2);
+ if (iLen2 > 0)
+ pDecl->AddProperty(&args, psz2, iLen2);
+ } else if (iLen2 > 0) {
+ psz2 = pSyntax->GetCurrentString(iLen2);
+ if (iLen2 > 0) {
+ pDecl->AddProperty(&args, wsName.c_str(), wsName.GetLength(), psz2,
+ iLen2);
}
- } else {
- break;
}
+ } else {
+ break;
}
}
- pSyntax->Release();
}
+
#define FDE_CSSNONINHERITS (pComputedStyle->m_NonInheritedData)
#define FDE_CSSINHERITS (pComputedStyle->m_InheritedData)
#define FDE_CSSFONTSIZE (FDE_CSSINHERITS.m_fFontSize)
diff --git a/xfa/fde/css/fde_cssstyleselector.h b/xfa/fde/css/fde_cssstyleselector.h
index 790149c596..cb54aaed7f 100644
--- a/xfa/fde/css/fde_cssstyleselector.h
+++ b/xfa/fde/css/fde_cssstyleselector.h
@@ -93,9 +93,7 @@ class CFDE_CSSRuleCollection : public CFX_Target {
class CFDE_CSSStyleSelector : public CFX_Target {
public:
CFDE_CSSStyleSelector();
- ~CFDE_CSSStyleSelector();
-
- void Release() { delete this; }
+ ~CFDE_CSSStyleSelector() override;
void SetFontMgr(IFX_FontMgr* pFontMgr);
void SetDefFontSize(FX_FLOAT fFontSize);
diff --git a/xfa/fde/css/fde_cssstylesheet.cpp b/xfa/fde/css/fde_cssstylesheet.cpp
index af6872bbaa..b07031c354 100644
--- a/xfa/fde/css/fde_cssstylesheet.cpp
+++ b/xfa/fde/css/fde_cssstylesheet.cpp
@@ -6,6 +6,8 @@
#include "xfa/fde/css/fde_cssstylesheet.h"
+#include <memory>
+
#include "xfa/fde/css/fde_cssdatatable.h"
#include "xfa/fde/css/fde_csssyntax.h"
#include "xfa/fgas/crt/fgas_codepage.h"
@@ -120,32 +122,33 @@ int32_t CFDE_CSSStyleSheet::CountRules() const {
IFDE_CSSRule* CFDE_CSSStyleSheet::GetRule(int32_t index) {
return m_RuleArray.GetAt(index);
}
+
FX_BOOL CFDE_CSSStyleSheet::LoadFromStream(const CFX_WideString& szUrl,
IFX_Stream* pStream,
uint16_t wCodePage) {
- CFDE_CSSSyntaxParser* pSyntax = new CFDE_CSSSyntaxParser;
- if (pStream->GetCodePage() != wCodePage) {
+ std::unique_ptr<CFDE_CSSSyntaxParser> pSyntax(new CFDE_CSSSyntaxParser);
+ if (pStream->GetCodePage() != wCodePage)
pStream->SetCodePage(wCodePage);
- }
- FX_BOOL bRet = pSyntax->Init(pStream, 4096) && LoadFromSyntax(pSyntax);
- pSyntax->Release();
+
+ FX_BOOL bRet = pSyntax->Init(pStream, 4096) && LoadFromSyntax(pSyntax.get());
m_wCodePage = wCodePage;
m_szUrl = szUrl;
return bRet;
}
+
FX_BOOL CFDE_CSSStyleSheet::LoadFromBuffer(const CFX_WideString& szUrl,
const FX_WCHAR* pBuffer,
int32_t iBufSize,
uint16_t wCodePage) {
ASSERT(pBuffer && iBufSize > 0);
-
- CFDE_CSSSyntaxParser* pSyntax = new CFDE_CSSSyntaxParser;
- FX_BOOL bRet = pSyntax->Init(pBuffer, iBufSize) && LoadFromSyntax(pSyntax);
- pSyntax->Release();
+ std::unique_ptr<CFDE_CSSSyntaxParser> pSyntax(new CFDE_CSSSyntaxParser);
+ FX_BOOL bRet =
+ pSyntax->Init(pBuffer, iBufSize) && LoadFromSyntax(pSyntax.get());
m_wCodePage = wCodePage;
m_szUrl = szUrl;
return bRet;
}
+
FX_BOOL CFDE_CSSStyleSheet::LoadFromSyntax(CFDE_CSSSyntaxParser* pSyntax) {
Reset();
m_pAllocator = IFX_MemoryAllocator::Create(FX_ALLOCTYPE_Static, 1024, 0);
diff --git a/xfa/fde/css/fde_csssyntax.h b/xfa/fde/css/fde_csssyntax.h
index d14f81ea7a..a4e9249055 100644
--- a/xfa/fde/css/fde_csssyntax.h
+++ b/xfa/fde/css/fde_csssyntax.h
@@ -77,9 +77,8 @@ enum FDE_CSSSYNTAXMODE {
class CFDE_CSSSyntaxParser : public CFX_Target {
public:
CFDE_CSSSyntaxParser();
- ~CFDE_CSSSyntaxParser();
+ ~CFDE_CSSSyntaxParser() override;
- void Release() { delete this; }
FX_BOOL Init(IFX_Stream* pStream,
int32_t iCSSPlaneSize,
int32_t iTextDataSize = 32,
diff --git a/xfa/fde/fde_gedevice.h b/xfa/fde/fde_gedevice.h
index 3d14a0f8af..f69e4d106c 100644
--- a/xfa/fde/fde_gedevice.h
+++ b/xfa/fde/fde_gedevice.h
@@ -21,9 +21,7 @@ class IFX_Font;
class CFDE_RenderDevice : public CFX_Target {
public:
CFDE_RenderDevice(CFX_RenderDevice* pDevice, FX_BOOL bOwnerDevice);
- ~CFDE_RenderDevice();
-
- void Release() { delete this; }
+ ~CFDE_RenderDevice() override;
int32_t GetWidth() const;
int32_t GetHeight() const;
diff --git a/xfa/fde/fde_iterator.h b/xfa/fde/fde_iterator.h
index 4d089254ea..4f3fdf3f29 100644
--- a/xfa/fde/fde_iterator.h
+++ b/xfa/fde/fde_iterator.h
@@ -20,9 +20,7 @@ struct FDE_CANVASITEM {
class CFDE_VisualSetIterator : public CFX_Target {
public:
CFDE_VisualSetIterator();
- ~CFDE_VisualSetIterator();
-
- void Release() { delete this; }
+ ~CFDE_VisualSetIterator() override;
FX_BOOL AttachCanvas(IFDE_CanvasSet* pCanvas);
FX_BOOL FilterObjects(uint32_t dwObjects = 0xFFFFFFFF);
diff --git a/xfa/fde/fde_render.cpp b/xfa/fde/fde_render.cpp
index 7c989a0c6b..074a851e9f 100644
--- a/xfa/fde/fde_render.cpp
+++ b/xfa/fde/fde_render.cpp
@@ -16,11 +16,9 @@
CFDE_RenderContext::CFDE_RenderContext()
: m_eStatus(FDE_RENDERSTATUS_Reset),
m_pRenderDevice(nullptr),
- m_pBrush(nullptr),
m_Transform(),
m_pCharPos(nullptr),
- m_iCharPosCount(0),
- m_pIterator(nullptr) {
+ m_iCharPosCount(0) {
m_Transform.SetIdentity();
}
@@ -42,7 +40,7 @@ FX_BOOL CFDE_RenderContext::StartRender(CFDE_RenderDevice* pRenderDevice,
m_pRenderDevice = pRenderDevice;
m_Transform = tmDoc2Device;
if (!m_pIterator)
- m_pIterator = new CFDE_VisualSetIterator;
+ m_pIterator.reset(new CFDE_VisualSetIterator);
return m_pIterator->AttachCanvas(pCanvasSet) && m_pIterator->FilterObjects();
}
@@ -101,12 +99,8 @@ void CFDE_RenderContext::StopRender() {
m_eStatus = FDE_RENDERSTATUS_Reset;
m_pRenderDevice = nullptr;
m_Transform.SetIdentity();
- if (m_pIterator) {
- m_pIterator->Release();
- m_pIterator = nullptr;
- }
- delete m_pBrush;
- m_pBrush = nullptr;
+ m_pIterator.reset();
+ m_pBrush.reset();
FX_Free(m_pCharPos);
m_pCharPos = nullptr;
m_iCharPosCount = 0;
@@ -126,7 +120,7 @@ void CFDE_RenderContext::RenderText(IFDE_TextSet* pTextSet,
return;
if (!m_pBrush)
- m_pBrush = new CFDE_Brush;
+ m_pBrush.reset(new CFDE_Brush);
if (!m_pCharPos)
m_pCharPos = FX_Alloc(FXTEXT_CHARPOS, iCount);
@@ -142,8 +136,8 @@ void CFDE_RenderContext::RenderText(IFDE_TextSet* pTextSet,
m_pBrush->SetColor(dwColor);
FDE_HDEVICESTATE hState;
FX_BOOL bClip = ApplyClip(pTextSet, hText, hState);
- m_pRenderDevice->DrawString(m_pBrush, pFont, m_pCharPos, iCount, fFontSize,
- &m_Transform);
+ m_pRenderDevice->DrawString(m_pBrush.get(), pFont, m_pCharPos, iCount,
+ fFontSize, &m_Transform);
if (bClip)
RestoreClip(hState);
}
diff --git a/xfa/fde/fde_render.h b/xfa/fde/fde_render.h
index c28b4abd16..1a80bce926 100644
--- a/xfa/fde/fde_render.h
+++ b/xfa/fde/fde_render.h
@@ -7,6 +7,8 @@
#ifndef XFA_FDE_FDE_RENDER_H_
#define XFA_FDE_FDE_RENDER_H_
+#include <memory>
+
#include "core/fxcrt/include/fx_coordinates.h"
#include "xfa/fde/fde_gedevice.h"
#include "xfa/fde/fde_iterator.h"
@@ -24,9 +26,8 @@ enum FDE_RENDERSTATUS {
class CFDE_RenderContext : public CFX_Target {
public:
CFDE_RenderContext();
- ~CFDE_RenderContext();
+ ~CFDE_RenderContext() override;
- void Release() { delete this; }
FX_BOOL StartRender(CFDE_RenderDevice* pRenderDevice,
IFDE_CanvasSet* pCanvasSet,
const CFX_Matrix& tmDoc2Device);
@@ -42,11 +43,11 @@ class CFDE_RenderContext : public CFX_Target {
protected:
FDE_RENDERSTATUS m_eStatus;
CFDE_RenderDevice* m_pRenderDevice;
- CFDE_Brush* m_pBrush;
CFX_Matrix m_Transform;
FXTEXT_CHARPOS* m_pCharPos;
int32_t m_iCharPosCount;
- CFDE_VisualSetIterator* m_pIterator;
+ std::unique_ptr<CFDE_Brush> m_pBrush;
+ std::unique_ptr<CFDE_VisualSetIterator> m_pIterator;
};
#endif // XFA_FDE_FDE_RENDER_H_
diff --git a/xfa/fde/tto/fde_textout.cpp b/xfa/fde/tto/fde_textout.cpp
index fc97d99125..ca108de92c 100644
--- a/xfa/fde/tto/fde_textout.cpp
+++ b/xfa/fde/tto/fde_textout.cpp
@@ -40,8 +40,7 @@ CFDE_TextOut::CFDE_TextOut()
m_iCurPiece(0),
m_iTotalLines(0),
m_pCharPos(NULL),
- m_iCharPosSize(0),
- m_pRenderDevice(NULL) {
+ m_iCharPosSize(0) {
m_pTxtBreak = new CFX_TxtBreak(FX_TXTBREAKPOLICY_None);
m_Matrix.SetIdentity();
m_rtClip.Reset();
@@ -53,9 +52,6 @@ CFDE_TextOut::~CFDE_TextOut() {
}
FX_Free(m_pCharWidths);
FX_Free(m_pEllCharWidths);
- if (m_pRenderDevice) {
- m_pRenderDevice->Release();
- }
FX_Free(m_pCharPos);
m_ttoLines.RemoveAll();
}
@@ -134,21 +130,15 @@ void CFDE_TextOut::SetLineSpace(FX_FLOAT fLineSpace) {
void CFDE_TextOut::SetDIBitmap(CFX_DIBitmap* pDIB) {
ASSERT(pDIB);
- if (m_pRenderDevice)
- m_pRenderDevice->Release();
-
+ m_pRenderDevice.reset();
CFX_FxgeDevice* device = new CFX_FxgeDevice;
device->Attach(pDIB, 0, FALSE);
- m_pRenderDevice = new CFDE_RenderDevice(device, FALSE);
+ m_pRenderDevice.reset(new CFDE_RenderDevice(device, FALSE));
}
void CFDE_TextOut::SetRenderDevice(CFX_RenderDevice* pDevice) {
ASSERT(pDevice);
-
- if (m_pRenderDevice)
- m_pRenderDevice->Release();
-
- m_pRenderDevice = new CFDE_RenderDevice(pDevice, FALSE);
+ m_pRenderDevice.reset(new CFDE_RenderDevice(pDevice, FALSE));
}
void CFDE_TextOut::SetClipRect(const CFX_Rect& rtClip) {
@@ -780,13 +770,13 @@ void CFDE_TextOut::DoAlignment(const CFX_RectF& rect) {
}
}
void CFDE_TextOut::OnDraw(const CFX_RectF& rtClip) {
- if (m_pRenderDevice == NULL) {
+ if (!m_pRenderDevice)
return;
- }
+
int32_t iLines = m_ttoLines.GetSize();
- if (iLines < 1) {
+ if (iLines < 1)
return;
- }
+
CFDE_Brush* pBrush = new CFDE_Brush;
pBrush->SetColor(m_TxtColor);
CFDE_Pen* pPen = NULL;
@@ -846,14 +836,14 @@ void CFDE_TextOut::DrawLine(const FDE_TTOPIECE* pPiece, CFDE_Pen*& pPen) {
FX_BOOL bStrikeOut = !!(m_dwStyles & FDE_TTOSTYLE_Strikeout);
FX_BOOL bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey);
FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout);
- if (!bUnderLine && !bStrikeOut && !bHotKey) {
+ if (!bUnderLine && !bStrikeOut && !bHotKey)
return;
- }
- if (pPen == NULL) {
+
+ if (!pPen) {
pPen = new CFDE_Pen;
pPen->SetColor(m_TxtColor);
}
- CFDE_Path* pPath = new CFDE_Path;
+ std::unique_ptr<CFDE_Path> pPath(new CFDE_Path);
int32_t iLineCount = 0;
CFX_RectF rtText = pPiece->rtPiece;
CFX_PointF pt1, pt2;
@@ -913,19 +903,21 @@ void CFDE_TextOut::DrawLine(const FDE_TTOPIECE* pPiece, CFDE_Pen*& pPen) {
}
}
}
- if (iLineCount > 0) {
- m_pRenderDevice->DrawPath(pPen, 1, pPath, &m_Matrix);
- }
- pPath->Release();
+ if (iLineCount > 0)
+ m_pRenderDevice->DrawPath(pPen, 1, pPath.get(), &m_Matrix);
}
+
CFDE_TTOLine::CFDE_TTOLine()
: m_bNewReload(FALSE), m_pieces(5), m_iPieceCount(0) {}
+
CFDE_TTOLine::CFDE_TTOLine(const CFDE_TTOLine& ttoLine) : m_pieces(5) {
m_bNewReload = ttoLine.m_bNewReload;
m_iPieceCount = ttoLine.m_iPieceCount;
m_pieces.Copy(ttoLine.m_pieces);
}
+
CFDE_TTOLine::~CFDE_TTOLine() {}
+
int32_t CFDE_TTOLine::AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece) {
if (index >= m_iPieceCount) {
index = m_pieces.Add(ttoPiece) + 1;
diff --git a/xfa/fde/tto/fde_textout.h b/xfa/fde/tto/fde_textout.h
index e3e87a780a..91f03e8d9b 100644
--- a/xfa/fde/tto/fde_textout.h
+++ b/xfa/fde/tto/fde_textout.h
@@ -7,6 +7,8 @@
#ifndef XFA_FDE_TTO_FDE_TEXTOUT_H_
#define XFA_FDE_TTO_FDE_TEXTOUT_H_
+#include <memory>
+
#include "core/fxge/include/fx_dib.h"
#include "core/fxge/include/fx_ge.h"
#include "xfa/fde/fde_object.h"
@@ -72,9 +74,8 @@ typedef CFX_ObjectMassArrayTemplate<CFDE_TTOLine> CFDE_TTOLineArray;
class CFDE_TextOut : public CFX_Target {
public:
CFDE_TextOut();
- ~CFDE_TextOut();
+ ~CFDE_TextOut() override;
- void Release() { delete this; }
void SetFont(IFX_Font* pFont);
void SetFontSize(FX_FLOAT fFontSize);
void SetTextColor(FX_ARGB color);
@@ -179,7 +180,7 @@ class CFDE_TextOut : public CFX_Target {
int32_t m_iTotalLines;
FXTEXT_CHARPOS* m_pCharPos;
int32_t m_iCharPosSize;
- CFDE_RenderDevice* m_pRenderDevice;
+ std::unique_ptr<CFDE_RenderDevice> m_pRenderDevice;
CFX_Int32Array m_hotKeys;
CFX_RectFArray m_rectArray;
};