diff options
author | weili <weili@chromium.org> | 2016-07-11 14:43:40 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-07-11 14:43:41 -0700 |
commit | 5a6c1398d0e559fb6a048cb0dca46ba9f9309a77 (patch) | |
tree | 40193eaf374d0f9bf2ec2f257871279b0f36efb8 /core | |
parent | ac14258c429141653f73ca5c1b64ad259ac15804 (diff) | |
download | pdfium-5a6c1398d0e559fb6a048cb0dca46ba9f9309a77.tar.xz |
Use smart pointers for class owned member variables
Replace raw member variables to smart pointer type to better
maintain the ownership and to ease the management.
BUG=pdfium:518
Review-Url: https://codereview.chromium.org/2136683002
Diffstat (limited to 'core')
-rw-r--r-- | core/fpdfapi/fpdf_parser/cpdf_parser.cpp | 21 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/include/cpdf_parser.h | 4 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/fpdf_render_image.cpp | 25 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp | 27 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/render_int.h | 8 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_variabletext.cpp | 14 | ||||
-rw-r--r-- | core/fpdfdoc/cpvt_sectioninfo.cpp | 31 | ||||
-rw-r--r-- | core/fpdfdoc/cpvt_sectioninfo.h | 43 | ||||
-rw-r--r-- | core/fpdfdoc/cpvt_wordinfo.cpp | 54 | ||||
-rw-r--r-- | core/fpdfdoc/cpvt_wordinfo.h | 53 | ||||
-rw-r--r-- | core/fpdfdoc/doc_annot.cpp | 10 | ||||
-rw-r--r-- | core/fpdfdoc/include/fpdf_doc.h | 8 |
12 files changed, 161 insertions, 137 deletions
diff --git a/core/fpdfapi/fpdf_parser/cpdf_parser.cpp b/core/fpdfapi/fpdf_parser/cpdf_parser.cpp index 5540877642..e2c88d7e71 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_parser.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_parser.cpp @@ -51,8 +51,7 @@ int32_t GetStreamFirst(CPDF_StreamAcc* pObjStream) { } // namespace CPDF_Parser::CPDF_Parser() - : m_pDocument(nullptr), - m_bOwnFileRead(true), + : m_bOwnFileRead(true), m_FileVersion(0), m_pTrailer(nullptr), m_pEncryptDict(nullptr), @@ -127,8 +126,7 @@ void CPDF_Parser::ShrinkObjectMap(uint32_t objnum) { void CPDF_Parser::CloseParser() { m_bVersionUpdated = false; - delete m_pDocument; - m_pDocument = nullptr; + m_pDocument.reset(); if (m_pTrailer) { m_pTrailer->Release(); @@ -190,7 +188,7 @@ CPDF_Parser::Error CPDF_Parser::StartParse(IFX_FileRead* pFileAccess) { return FORMAT_ERROR; m_pSyntax->RestorePos(m_pSyntax->m_FileLen - m_pSyntax->m_HeaderOffset - 9); - m_pDocument = new CPDF_Document(this); + m_pDocument.reset(new CPDF_Document(this)); FX_BOOL bXRefRebuilt = FALSE; if (m_pSyntax->SearchWord("startxref", TRUE, FALSE, 4096)) { @@ -765,7 +763,7 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() { last_obj = start_pos; FX_FILESIZE obj_end = 0; CPDF_Object* pObject = ParseIndirectObjectAtByStrict( - m_pDocument, obj_pos, objnum, &obj_end); + m_pDocument.get(), obj_pos, objnum, &obj_end); if (CPDF_Stream* pStream = ToStream(pObject)) { if (CPDF_Dictionary* pDict = pStream->GetDict()) { if ((pDict->KeyExist("Type")) && @@ -828,7 +826,8 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() { last_trailer = pos + i - 7; m_pSyntax->RestorePos(pos + i - m_pSyntax->m_HeaderOffset); - CPDF_Object* pObj = m_pSyntax->GetObject(m_pDocument, 0, 0, true); + CPDF_Object* pObj = + m_pSyntax->GetObject(m_pDocument.get(), 0, 0, true); if (pObj) { if (!pObj->IsDictionary() && !pObj->AsStream()) { pObj->Release(); @@ -850,7 +849,7 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() { uint32_t dwObjNum = pElement ? pElement->GetObjNum() : 0; if (dwObjNum) { - m_pTrailer->SetAtReference(key, m_pDocument, + m_pTrailer->SetAtReference(key, m_pDocument.get(), dwObjNum); } else { m_pTrailer->SetAt(key, pElement->Clone()); @@ -974,7 +973,7 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() { } FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) { - CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, *pos, 0); + CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument.get(), *pos, 0); if (!pObject) return FALSE; @@ -1472,7 +1471,7 @@ CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() { return nullptr; std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( - m_pSyntax->GetObject(m_pDocument, 0, 0, true)); + m_pSyntax->GetObject(m_pDocument.get(), 0, 0, true)); if (!ToDictionary(pObj.get())) return nullptr; return pObj.release()->AsDictionary(); @@ -1559,7 +1558,7 @@ CPDF_Parser::Error CPDF_Parser::StartAsyncParse(IFX_FileRead* pFileAccess) { return StartParse(pFileAccess); } - m_pDocument = new CPDF_Document(this); + m_pDocument.reset(new CPDF_Document(this)); FX_FILESIZE dwFirstXRefOffset = m_pSyntax->SavePos(); FX_BOOL bXRefRebuilt = FALSE; diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_parser.h b/core/fpdfapi/fpdf_parser/include/cpdf_parser.h index b468bead9d..1291180197 100644 --- a/core/fpdfapi/fpdf_parser/include/cpdf_parser.h +++ b/core/fpdfapi/fpdf_parser/include/cpdf_parser.h @@ -44,7 +44,7 @@ class CPDF_Parser { CFX_ByteString GetPassword() { return m_Password; } CPDF_Dictionary* GetTrailer() const { return m_pTrailer; } FX_FILESIZE GetLastXRefOffset() const { return m_LastXRefOffset; } - CPDF_Document* GetDocument() const { return m_pDocument; } + CPDF_Document* GetDocument() const { return m_pDocument.get(); } uint32_t GetRootObjNum(); uint32_t GetInfoObjNum(); @@ -118,7 +118,7 @@ class CPDF_Parser { // the objects. bool VerifyCrossRefV4(); - CPDF_Document* m_pDocument; + std::unique_ptr<CPDF_Document> m_pDocument; std::unique_ptr<CPDF_SyntaxParser> m_pSyntax; bool m_bOwnFileRead; int m_FileVersion; diff --git a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp index b9826a9338..0ea4a17684 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp @@ -326,29 +326,26 @@ void CPDF_DIBTransferFunc::TranslateDownSamples(uint8_t* dest_buf, #endif } } + CPDF_ImageRenderer::CPDF_ImageRenderer() { m_pRenderStatus = nullptr; m_pImageObject = nullptr; m_Result = TRUE; m_Status = 0; - m_pTransformer = nullptr; m_DeviceHandle = nullptr; - m_LoadHandle = nullptr; - m_pClone = nullptr; m_bStdCS = FALSE; m_bPatternColor = FALSE; m_BlendType = FXDIB_BLEND_NORMAL; m_pPattern = nullptr; m_pObj2Device = nullptr; } + CPDF_ImageRenderer::~CPDF_ImageRenderer() { - delete m_pTransformer; if (m_DeviceHandle) { m_pRenderStatus->m_pDevice->CancelDIBits(m_DeviceHandle); } - delete m_LoadHandle; - delete m_pClone; } + FX_BOOL CPDF_ImageRenderer::StartLoadDIBSource() { CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect(); FX_RECT image_rect = image_rect_f.GetOutterRect(); @@ -361,7 +358,7 @@ FX_BOOL CPDF_ImageRenderer::StartLoadDIBSource() { dest_height = -dest_height; } if (m_Loader.Start(m_pImageObject, - m_pRenderStatus->m_pContext->GetPageCache(), m_LoadHandle, + m_pRenderStatus->m_pContext->GetPageCache(), &m_LoadHandle, m_bStdCS, m_pRenderStatus->m_GroupFamily, m_pRenderStatus->m_bLoadMask, m_pRenderStatus, dest_width, dest_height)) { @@ -372,6 +369,7 @@ FX_BOOL CPDF_ImageRenderer::StartLoadDIBSource() { } return FALSE; } + FX_BOOL CPDF_ImageRenderer::StartRenderDIBSource() { if (!m_Loader.m_pBitmap) { return FALSE; @@ -416,10 +414,10 @@ FX_BOOL CPDF_ImageRenderer::StartRenderDIBSource() { } m_FillArgb = m_pRenderStatus->GetFillArgb(m_pImageObject); } else if (m_pRenderStatus->m_Options.m_ColorMode == RENDER_COLOR_GRAY) { - m_pClone = m_pDIBSource->Clone(); + m_pClone.reset(m_pDIBSource->Clone()); m_pClone->ConvertColorScale(m_pRenderStatus->m_Options.m_BackColor, m_pRenderStatus->m_Options.m_ForeColor); - m_pDIBSource = m_pClone; + m_pDIBSource = m_pClone.get(); } m_Flags = 0; if (m_pRenderStatus->m_Options.m_Flags & RENDER_FORCE_DOWNSAMPLE) { @@ -488,6 +486,7 @@ FX_BOOL CPDF_ImageRenderer::StartRenderDIBSource() { } return StartDIBSource(); } + FX_BOOL CPDF_ImageRenderer::Start(CPDF_RenderStatus* pStatus, const CPDF_PageObject* pObj, const CFX_Matrix* pObj2Device, @@ -510,6 +509,7 @@ FX_BOOL CPDF_ImageRenderer::Start(CPDF_RenderStatus* pStatus, } return StartRenderDIBSource(); } + FX_BOOL CPDF_ImageRenderer::Start(CPDF_RenderStatus* pStatus, const CFX_DIBSource* pDIBSource, FX_ARGB bitmap_argb, @@ -528,6 +528,7 @@ FX_BOOL CPDF_ImageRenderer::Start(CPDF_RenderStatus* pStatus, m_BlendType = blendType; return StartDIBSource(); } + FX_BOOL CPDF_ImageRenderer::DrawPatternImage(const CFX_Matrix* pObj2Device) { if (m_pRenderStatus->m_bPrint && !(m_pRenderStatus->m_pDevice->GetRenderCaps() & FXRC_BLEND_MODE)) { @@ -773,8 +774,8 @@ FX_BOOL CPDF_ImageRenderer::StartDIBSource() { FX_RECT clip_box = m_pRenderStatus->m_pDevice->GetClipBox(); clip_box.Intersect(image_rect); m_Status = 2; - m_pTransformer = new CFX_ImageTransformer(m_pDIBSource, &m_ImageMatrix, - m_Flags, &clip_box); + m_pTransformer.reset(new CFX_ImageTransformer(m_pDIBSource, &m_ImageMatrix, + m_Flags, &clip_box)); m_pTransformer->Start(); return TRUE; } @@ -896,7 +897,7 @@ FX_BOOL CPDF_ImageRenderer::Continue(IFX_Pause* pPause) { return m_pRenderStatus->m_pDevice->ContinueDIBits(m_DeviceHandle, pPause); if (m_Status == 4) { - if (m_Loader.Continue(m_LoadHandle, pPause)) + if (m_Loader.Continue(m_LoadHandle.get(), pPause)) return TRUE; if (StartRenderDIBSource()) diff --git a/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp index 2b829d0c56..91574345d3 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp @@ -1548,21 +1548,22 @@ FX_BOOL CPDF_ImageLoaderHandle::Continue(IFX_Pause* pPause) { return ret; } -FX_BOOL CPDF_ImageLoader::Start(const CPDF_ImageObject* pImage, - CPDF_PageRenderCache* pCache, - CPDF_ImageLoaderHandle*& LoadHandle, - FX_BOOL bStdCS, - uint32_t GroupFamily, - FX_BOOL bLoadMask, - CPDF_RenderStatus* pRenderStatus, - int32_t nDownsampleWidth, - int32_t nDownsampleHeight) { +FX_BOOL CPDF_ImageLoader::Start( + const CPDF_ImageObject* pImage, + CPDF_PageRenderCache* pCache, + std::unique_ptr<CPDF_ImageLoaderHandle>* pLoadHandle, + FX_BOOL bStdCS, + uint32_t GroupFamily, + FX_BOOL bLoadMask, + CPDF_RenderStatus* pRenderStatus, + int32_t nDownsampleWidth, + int32_t nDownsampleHeight) { m_nDownsampleWidth = nDownsampleWidth; m_nDownsampleHeight = nDownsampleHeight; - LoadHandle = new CPDF_ImageLoaderHandle; - return LoadHandle->Start(this, pImage, pCache, bStdCS, GroupFamily, bLoadMask, - pRenderStatus, m_nDownsampleWidth, - m_nDownsampleHeight); + pLoadHandle->reset(new CPDF_ImageLoaderHandle); + return (*pLoadHandle) + ->Start(this, pImage, pCache, bStdCS, GroupFamily, bLoadMask, + pRenderStatus, m_nDownsampleWidth, m_nDownsampleHeight); } FX_BOOL CPDF_ImageLoader::Continue(CPDF_ImageLoaderHandle* LoadHandle, diff --git a/core/fpdfapi/fpdf_render/render_int.h b/core/fpdfapi/fpdf_render/render_int.h index d86a62ab19..99d1dfc292 100644 --- a/core/fpdfapi/fpdf_render/render_int.h +++ b/core/fpdfapi/fpdf_render/render_int.h @@ -293,7 +293,7 @@ class CPDF_ImageLoader { FX_BOOL Start(const CPDF_ImageObject* pImage, CPDF_PageRenderCache* pCache, - CPDF_ImageLoaderHandle*& LoadHandle, + std::unique_ptr<CPDF_ImageLoaderHandle>* pLoadHandle, FX_BOOL bStdCS = FALSE, uint32_t GroupFamily = 0, FX_BOOL bLoadMask = FALSE, @@ -373,15 +373,15 @@ class CPDF_ImageRenderer { CFX_Matrix m_ImageMatrix; CPDF_ImageLoader m_Loader; const CFX_DIBSource* m_pDIBSource; - CFX_DIBitmap* m_pClone; + std::unique_ptr<CFX_DIBitmap> m_pClone; int m_BitmapAlpha; FX_BOOL m_bPatternColor; CPDF_Pattern* m_pPattern; FX_ARGB m_FillArgb; uint32_t m_Flags; - CFX_ImageTransformer* m_pTransformer; + std::unique_ptr<CFX_ImageTransformer> m_pTransformer; void* m_DeviceHandle; - CPDF_ImageLoaderHandle* m_LoadHandle; + std::unique_ptr<CPDF_ImageLoaderHandle> m_LoadHandle; FX_BOOL m_bStdCS; int m_BlendType; }; diff --git a/core/fpdfdoc/cpdf_variabletext.cpp b/core/fpdfdoc/cpdf_variabletext.cpp index 010d426cf2..1ac36ade86 100644 --- a/core/fpdfdoc/cpdf_variabletext.cpp +++ b/core/fpdfdoc/cpdf_variabletext.cpp @@ -264,9 +264,9 @@ void CPDF_VariableText::Initialize() { if (!m_bInitial) { CPVT_SectionInfo secinfo; if (m_bRichText) { - secinfo.pSecProps = new CPVT_SecProps(0.0f, 0.0f, 0); - secinfo.pWordProps = new CPVT_WordProps( - GetDefaultFontIndex(), kDefaultFontSize, 0, ScriptType::Normal, 0); + secinfo.pSecProps.reset(new CPVT_SecProps(0.0f, 0.0f, 0)); + secinfo.pWordProps.reset(new CPVT_WordProps( + GetDefaultFontIndex(), kDefaultFontSize, 0, ScriptType::Normal, 0)); } CPVT_WordPlace place; place.nSecIndex = 0; @@ -333,9 +333,9 @@ CPVT_WordPlace CPDF_VariableText::InsertSection( CPVT_SectionInfo secinfo; if (m_bRichText) { if (pSecProps) - secinfo.pSecProps = new CPVT_SecProps(*pSecProps); + secinfo.pSecProps.reset(new CPVT_SecProps(*pSecProps)); if (pWordProps) - secinfo.pWordProps = new CPVT_WordProps(*pWordProps); + secinfo.pWordProps.reset(new CPVT_WordProps(*pWordProps)); } AddSection(NewPlace, secinfo); newplace = NewPlace; @@ -426,9 +426,9 @@ void CPDF_VariableText::SetText(const FX_WCHAR* text, CPVT_SectionInfo secinfo; if (m_bRichText) { if (pSecProps) - secinfo.pSecProps = new CPVT_SecProps(*pSecProps); + secinfo.pSecProps.reset(new CPVT_SecProps(*pSecProps)); if (pWordProps) - secinfo.pWordProps = new CPVT_WordProps(*pWordProps); + secinfo.pWordProps.reset(new CPVT_WordProps(*pWordProps)); } if (CSection* pSection = m_SectionArray.GetAt(0)) pSection->m_SecInfo = secinfo; diff --git a/core/fpdfdoc/cpvt_sectioninfo.cpp b/core/fpdfdoc/cpvt_sectioninfo.cpp new file mode 100644 index 0000000000..eb5c1bb809 --- /dev/null +++ b/core/fpdfdoc/cpvt_sectioninfo.cpp @@ -0,0 +1,31 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfdoc/cpvt_sectioninfo.h" + +CPVT_SectionInfo::CPVT_SectionInfo() : rcSection(), nTotalLine(0) {} + +CPVT_SectionInfo::~CPVT_SectionInfo() {} + +CPVT_SectionInfo::CPVT_SectionInfo(const CPVT_SectionInfo& other) { + operator=(other); +} + +void CPVT_SectionInfo::operator=(const CPVT_SectionInfo& other) { + if (this == &other) + return; + + rcSection = other.rcSection; + nTotalLine = other.nTotalLine; + if (other.pSecProps) + pSecProps.reset(new CPVT_SecProps(*other.pSecProps)); + else + pSecProps.reset(); + if (other.pWordProps) + pWordProps.reset(new CPVT_WordProps(*other.pWordProps)); + else + pWordProps.reset(); +} diff --git a/core/fpdfdoc/cpvt_sectioninfo.h b/core/fpdfdoc/cpvt_sectioninfo.h index e466ae5006..9d9b99fc27 100644 --- a/core/fpdfdoc/cpvt_sectioninfo.h +++ b/core/fpdfdoc/cpvt_sectioninfo.h @@ -7,48 +7,23 @@ #ifndef CORE_FPDFDOC_CPVT_SECTIONINFO_H_ #define CORE_FPDFDOC_CPVT_SECTIONINFO_H_ +#include <memory> + #include "core/fpdfdoc/cpvt_floatrect.h" #include "core/fpdfdoc/include/cpvt_secprops.h" #include "core/fpdfdoc/include/cpvt_wordprops.h" struct CPVT_SectionInfo { - CPVT_SectionInfo() - : rcSection(), nTotalLine(0), pSecProps(nullptr), pWordProps(nullptr) {} - - ~CPVT_SectionInfo() { - delete pSecProps; - delete pWordProps; - } - - CPVT_SectionInfo(const CPVT_SectionInfo& other) - : rcSection(), nTotalLine(0), pSecProps(nullptr), pWordProps(nullptr) { - operator=(other); - } - - void operator=(const CPVT_SectionInfo& other) { - if (this == &other) - return; - - rcSection = other.rcSection; - nTotalLine = other.nTotalLine; - if (other.pSecProps) { - if (pSecProps) - *pSecProps = *other.pSecProps; - else - pSecProps = new CPVT_SecProps(*other.pSecProps); - } - if (other.pWordProps) { - if (pWordProps) - *pWordProps = *other.pWordProps; - else - pWordProps = new CPVT_WordProps(*other.pWordProps); - } - } + CPVT_SectionInfo(); + CPVT_SectionInfo(const CPVT_SectionInfo& other); + ~CPVT_SectionInfo(); + + void operator=(const CPVT_SectionInfo& other); CPVT_FloatRect rcSection; int32_t nTotalLine; - CPVT_SecProps* pSecProps; - CPVT_WordProps* pWordProps; + std::unique_ptr<CPVT_SecProps> pSecProps; + std::unique_ptr<CPVT_WordProps> pWordProps; }; #endif // CORE_FPDFDOC_CPVT_SECTIONINFO_H_ diff --git a/core/fpdfdoc/cpvt_wordinfo.cpp b/core/fpdfdoc/cpvt_wordinfo.cpp new file mode 100644 index 0000000000..2303f30032 --- /dev/null +++ b/core/fpdfdoc/cpvt_wordinfo.cpp @@ -0,0 +1,54 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfdoc/cpvt_wordinfo.h" + +CPVT_WordInfo::CPVT_WordInfo() + : Word(0), + nCharset(FXFONT_ANSI_CHARSET), + fWordX(0.0f), + fWordY(0.0f), + fWordTail(0.0f), + nFontIndex(-1) {} + +CPVT_WordInfo::CPVT_WordInfo(uint16_t word, + int32_t charset, + int32_t fontIndex, + CPVT_WordProps* pProps) + : Word(word), + nCharset(charset), + fWordX(0.0f), + fWordY(0.0f), + fWordTail(0.0f), + nFontIndex(fontIndex) {} + +CPVT_WordInfo::CPVT_WordInfo(const CPVT_WordInfo& word) + : Word(0), + nCharset(FXFONT_ANSI_CHARSET), + fWordX(0.0f), + fWordY(0.0f), + fWordTail(0.0f), + nFontIndex(-1) { + operator=(word); +} + +CPVT_WordInfo::~CPVT_WordInfo() {} + +void CPVT_WordInfo::operator=(const CPVT_WordInfo& word) { + if (this == &word) + return; + + Word = word.Word; + nCharset = word.nCharset; + nFontIndex = word.nFontIndex; + fWordX = word.fWordX; + fWordY = word.fWordY; + fWordTail = word.fWordTail; + if (word.pWordProps) + pWordProps.reset(new CPVT_WordProps(*word.pWordProps)); + else + pWordProps.reset(); +} diff --git a/core/fpdfdoc/cpvt_wordinfo.h b/core/fpdfdoc/cpvt_wordinfo.h index 1ab0df21af..c690e2aa7b 100644 --- a/core/fpdfdoc/cpvt_wordinfo.h +++ b/core/fpdfdoc/cpvt_wordinfo.h @@ -7,58 +7,21 @@ #ifndef CORE_FPDFDOC_CPVT_WORDINFO_H_ #define CORE_FPDFDOC_CPVT_WORDINFO_H_ +#include <memory> + #include "core/fpdfdoc/include/cpvt_wordprops.h" #include "core/fxcrt/include/fx_system.h" struct CPVT_WordInfo { - CPVT_WordInfo() - : Word(0), - nCharset(FXFONT_ANSI_CHARSET), - fWordX(0.0f), - fWordY(0.0f), - fWordTail(0.0f), - nFontIndex(-1), - pWordProps(nullptr) {} - + CPVT_WordInfo(); CPVT_WordInfo(uint16_t word, int32_t charset, int32_t fontIndex, - CPVT_WordProps* pProps) - : Word(word), - nCharset(charset), - fWordX(0.0f), - fWordY(0.0f), - fWordTail(0.0f), - nFontIndex(fontIndex), - pWordProps(pProps) {} - - CPVT_WordInfo(const CPVT_WordInfo& word) - : Word(0), - nCharset(FXFONT_ANSI_CHARSET), - fWordX(0.0f), - fWordY(0.0f), - fWordTail(0.0f), - nFontIndex(-1), - pWordProps(nullptr) { - operator=(word); - } - - ~CPVT_WordInfo() { delete pWordProps; } - - void operator=(const CPVT_WordInfo& word) { - if (this == &word) - return; + CPVT_WordProps* pProps); + CPVT_WordInfo(const CPVT_WordInfo& word); + ~CPVT_WordInfo(); - Word = word.Word; - nCharset = word.nCharset; - nFontIndex = word.nFontIndex; - if (word.pWordProps) { - if (pWordProps) - *pWordProps = *word.pWordProps; - else - pWordProps = new CPVT_WordProps(*word.pWordProps); - } - } + void operator=(const CPVT_WordInfo& word); uint16_t Word; int32_t nCharset; @@ -66,7 +29,7 @@ struct CPVT_WordInfo { FX_FLOAT fWordY; FX_FLOAT fWordTail; int32_t nFontIndex; - CPVT_WordProps* pWordProps; + std::unique_ptr<CPVT_WordProps> pWordProps; }; #endif // CORE_FPDFDOC_CPVT_WORDINFO_H_ diff --git a/core/fpdfdoc/doc_annot.cpp b/core/fpdfdoc/doc_annot.cpp index 9b2f9e505f..fe17e9c811 100644 --- a/core/fpdfdoc/doc_annot.cpp +++ b/core/fpdfdoc/doc_annot.cpp @@ -41,7 +41,8 @@ CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) pAnnots->RemoveAt(i + 1); pDict = pAnnots->GetDictAt(i); } - m_AnnotList.push_back(new CPDF_Annot(pDict, this)); + m_AnnotList.push_back( + std::unique_ptr<CPDF_Annot>(new CPDF_Annot(pDict, this))); if (bRegenerateAP && pDict->GetStringBy("Subtype") == "Widget" && CPDF_InterForm::UpdatingAPEnabled()) { FPDF_GenerateAP(m_pDocument, pDict); @@ -49,10 +50,7 @@ CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) } } -CPDF_AnnotList::~CPDF_AnnotList() { - for (CPDF_Annot* annot : m_AnnotList) - delete annot; -} +CPDF_AnnotList::~CPDF_AnnotList() {} void CPDF_AnnotList::DisplayPass(CPDF_Page* pPage, CFX_RenderDevice* pDevice, @@ -62,7 +60,7 @@ void CPDF_AnnotList::DisplayPass(CPDF_Page* pPage, FX_BOOL bWidgetPass, CPDF_RenderOptions* pOptions, FX_RECT* clip_rect) { - for (CPDF_Annot* pAnnot : m_AnnotList) { + for (const auto& pAnnot : m_AnnotList) { bool bWidget = pAnnot->GetSubType() == "Widget"; if ((bWidgetPass && !bWidget) || (!bWidgetPass && bWidget)) continue; diff --git a/core/fpdfdoc/include/fpdf_doc.h b/core/fpdfdoc/include/fpdf_doc.h index afa5a30b18..be52a1b829 100644 --- a/core/fpdfdoc/include/fpdf_doc.h +++ b/core/fpdfdoc/include/fpdf_doc.h @@ -374,8 +374,10 @@ class CPDF_AnnotList { CPDF_RenderOptions* pOptions, FX_RECT* pClipRect); size_t Count() const { return m_AnnotList.size(); } - CPDF_Annot* GetAt(size_t index) const { return m_AnnotList[index]; } - const std::vector<CPDF_Annot*>& All() const { return m_AnnotList; } + CPDF_Annot* GetAt(size_t index) const { return m_AnnotList[index].get(); } + const std::vector<std::unique_ptr<CPDF_Annot>>& All() const { + return m_AnnotList; + } CPDF_Document* GetDocument() const { return m_pDocument; } protected: @@ -389,7 +391,7 @@ class CPDF_AnnotList { FX_RECT* clip_rect); CPDF_Document* const m_pDocument; - std::vector<CPDF_Annot*> m_AnnotList; + std::vector<std::unique_ptr<CPDF_Annot>> m_AnnotList; }; #define COLORTYPE_TRANSPARENT 0 |