summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/cpdfsdk_annothandlermgr.cpp8
-rw-r--r--fpdfsdk/cpdfsdk_formfillenvironment.cpp7
-rw-r--r--fpdfsdk/formfiller/cffl_combobox.cpp14
-rw-r--r--fpdfsdk/formfiller/cffl_combobox.h4
-rw-r--r--fpdfsdk/fpdf_dataavail.cpp7
-rw-r--r--fpdfsdk/fpdf_sysfontinfo.cpp4
-rw-r--r--fpdfsdk/fpdf_transformpage.cpp8
-rw-r--r--fpdfsdk/fpdfdoc.cpp3
-rw-r--r--fpdfsdk/fpdfeditpage.cpp23
-rw-r--r--fpdfsdk/fpdfeditpath.cpp13
-rw-r--r--fpdfsdk/fpdfedittext.cpp4
-rw-r--r--fpdfsdk/fpdfformfill.cpp20
12 files changed, 60 insertions, 55 deletions
diff --git a/fpdfsdk/cpdfsdk_annothandlermgr.cpp b/fpdfsdk/cpdfsdk_annothandlermgr.cpp
index 287ee11a4d..7ea301c0e4 100644
--- a/fpdfsdk/cpdfsdk_annothandlermgr.cpp
+++ b/fpdfsdk/cpdfsdk_annothandlermgr.cpp
@@ -17,6 +17,7 @@
#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
#include "fpdfsdk/cpdfsdk_pageview.h"
#include "fpdfsdk/cpdfsdk_widgethandler.h"
+#include "third_party/base/ptr_util.h"
#ifdef PDF_ENABLE_XFA
#include "fpdfsdk/cpdfsdk_xfawidgethandler.h"
@@ -27,10 +28,11 @@
CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(
CPDFSDK_FormFillEnvironment* pFormFillEnv)
- : m_pBAAnnotHandler(new CPDFSDK_BAAnnotHandler()),
- m_pWidgetHandler(new CPDFSDK_WidgetHandler(pFormFillEnv)),
+ : m_pBAAnnotHandler(pdfium::MakeUnique<CPDFSDK_BAAnnotHandler>()),
+ m_pWidgetHandler(pdfium::MakeUnique<CPDFSDK_WidgetHandler>(pFormFillEnv)),
#ifdef PDF_ENABLE_XFA
- m_pXFAWidgetHandler(new CPDFSDK_XFAWidgetHandler(pFormFillEnv)),
+ m_pXFAWidgetHandler(
+ pdfium::MakeUnique<CPDFSDK_XFAWidgetHandler>(pFormFillEnv)),
#endif // PDF_ENABLE_XFA
m_pFormFillEnv(pFormFillEnv) {
m_pWidgetHandler->SetFormFiller(m_pFormFillEnv->GetInteractiveFormFiller());
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
index e1b34ce51a..f17d28b9b6 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -7,6 +7,7 @@
#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
#include <memory>
+#include <utility>
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfdoc/cpdf_docjsactions.h"
@@ -568,8 +569,10 @@ CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView(
if (!renew)
return nullptr;
- CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pUnderlyingPage);
- m_PageMap[pUnderlyingPage].reset(pPageView);
+ auto pNew = pdfium::MakeUnique<CPDFSDK_PageView>(this, pUnderlyingPage);
+ CPDFSDK_PageView* pPageView = pNew.get();
+ m_PageMap[pUnderlyingPage] = std::move(pNew);
+
// Delay to load all the annotations, to avoid endless loop.
pPageView->LoadFXAnnots();
return pPageView;
diff --git a/fpdfsdk/formfiller/cffl_combobox.cpp b/fpdfsdk/formfiller/cffl_combobox.cpp
index ef05a883c9..1f2491fe95 100644
--- a/fpdfsdk/formfiller/cffl_combobox.cpp
+++ b/fpdfsdk/formfiller/cffl_combobox.cpp
@@ -13,10 +13,11 @@
#include "fpdfsdk/formfiller/cffl_interactiveformfiller.h"
#include "fpdfsdk/fsdk_common.h"
#include "fpdfsdk/pdfwindow/PWL_ComboBox.h"
+#include "third_party/base/ptr_util.h"
CFFL_ComboBox::CFFL_ComboBox(CPDFSDK_FormFillEnvironment* pApp,
CPDFSDK_Annot* pAnnot)
- : CFFL_FormFiller(pApp, pAnnot), m_pFontMap(nullptr) {
+ : CFFL_FormFiller(pApp, pAnnot) {
m_State.nIndex = 0;
m_State.nStart = 0;
m_State.nEnd = 0;
@@ -30,22 +31,17 @@ CFFL_ComboBox::~CFFL_ComboBox() {
// The font map should be stored somewhere more appropriate so it will live
// until the PWL_Edit is done with it. pdfium:566
DestroyWindows();
- delete m_pFontMap;
}
PWL_CREATEPARAM CFFL_ComboBox::GetCreateParam() {
PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam();
-
- int nFlags = m_pWidget->GetFieldFlags();
- if (nFlags & FIELDFLAG_EDIT) {
+ if (m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT)
cp.dwFlags |= PCBS_ALLOWCUSTOMTEXT;
- }
if (!m_pFontMap)
- m_pFontMap = new CBA_FontMap(m_pWidget, GetSystemHandler());
- cp.pFontMap = m_pFontMap;
+ m_pFontMap = pdfium::MakeUnique<CBA_FontMap>(m_pWidget, GetSystemHandler());
+ cp.pFontMap = m_pFontMap.get();
cp.pFocusHandler = this;
-
return cp;
}
diff --git a/fpdfsdk/formfiller/cffl_combobox.h b/fpdfsdk/formfiller/cffl_combobox.h
index aab10b90e1..e61e2b73c3 100644
--- a/fpdfsdk/formfiller/cffl_combobox.h
+++ b/fpdfsdk/formfiller/cffl_combobox.h
@@ -7,6 +7,8 @@
#ifndef FPDFSDK_FORMFILLER_CFFL_COMBOBOX_H_
#define FPDFSDK_FORMFILLER_CFFL_COMBOBOX_H_
+#include <memory>
+
#include "core/fxcrt/fx_string.h"
#include "fpdfsdk/formfiller/cffl_formfiller.h"
@@ -56,7 +58,7 @@ class CFFL_ComboBox : public CFFL_FormFiller, public IPWL_FocusHandler {
private:
CFX_WideString GetSelectExportText();
- CBA_FontMap* m_pFontMap;
+ std::unique_ptr<CBA_FontMap> m_pFontMap;
FFL_ComboBoxState m_State;
};
diff --git a/fpdfsdk/fpdf_dataavail.cpp b/fpdfsdk/fpdf_dataavail.cpp
index f2358d2e5c..2511441af5 100644
--- a/fpdfsdk/fpdf_dataavail.cpp
+++ b/fpdfsdk/fpdf_dataavail.cpp
@@ -118,16 +118,17 @@ CFPDF_DataAvail* CFPDFDataAvailFromFPDFAvail(FPDF_AVAIL avail) {
DLLEXPORT FPDF_AVAIL STDCALL FPDFAvail_Create(FX_FILEAVAIL* file_avail,
FPDF_FILEACCESS* file) {
- CFPDF_DataAvail* pAvail = new CFPDF_DataAvail;
+ auto pAvail = pdfium::MakeUnique<CFPDF_DataAvail>();
pAvail->m_FileAvail->Set(file_avail);
pAvail->m_FileRead->Set(file);
pAvail->m_pDataAvail = pdfium::MakeUnique<CPDF_DataAvail>(
pAvail->m_FileAvail.get(), pAvail->m_FileRead, true);
- return pAvail;
+ return pAvail.release(); // Caller takes ownership.
}
DLLEXPORT void STDCALL FPDFAvail_Destroy(FPDF_AVAIL avail) {
- delete (CFPDF_DataAvail*)avail;
+ // Take ownership back from caller and destroy.
+ std::unique_ptr<CFPDF_DataAvail>(static_cast<CFPDF_DataAvail*>(avail));
}
DLLEXPORT int STDCALL FPDFAvail_IsDocAvail(FPDF_AVAIL avail,
diff --git a/fpdfsdk/fpdf_sysfontinfo.cpp b/fpdfsdk/fpdf_sysfontinfo.cpp
index 32e573611b..1b98b94358 100644
--- a/fpdfsdk/fpdf_sysfontinfo.cpp
+++ b/fpdfsdk/fpdf_sysfontinfo.cpp
@@ -15,6 +15,7 @@
#include "core/fxge/ifx_systemfontinfo.h"
#include "fpdfsdk/fsdk_define.h"
#include "fpdfsdk/pdfwindow/PWL_FontMap.h"
+#include "third_party/base/ptr_util.h"
static_assert(FXFONT_ANSI_CHARSET == FX_CHARSET_ANSI, "Charset must match");
static_assert(FXFONT_DEFAULT_CHARSET == FX_CHARSET_Default,
@@ -114,8 +115,7 @@ DLLEXPORT void STDCALL FPDF_SetSystemFontInfo(FPDF_SYSFONTINFO* pFontInfoExt) {
return;
CFX_GEModule::Get()->GetFontMgr()->SetSystemFontInfo(
- std::unique_ptr<IFX_SystemFontInfo>(
- new CFX_ExternalFontInfo(pFontInfoExt)));
+ pdfium::MakeUnique<CFX_ExternalFontInfo>(pFontInfoExt));
}
DLLEXPORT const FPDF_CharsetFontMap* STDCALL FPDF_GetDefaultTTFMap() {
diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp
index 32ba3a7525..cc5239b802 100644
--- a/fpdfsdk/fpdf_transformpage.cpp
+++ b/fpdfsdk/fpdf_transformpage.cpp
@@ -6,6 +6,7 @@
#include "public/fpdf_transformpage.h"
+#include <memory>
#include <vector>
#include "core/fpdfapi/page/cpdf_clippath.h"
@@ -222,13 +223,14 @@ DLLEXPORT FPDF_CLIPPATH STDCALL FPDF_CreateClipPath(float left,
CPDF_Path Path;
Path.AppendRect(left, bottom, right, top);
- CPDF_ClipPath* pNewClipPath = new CPDF_ClipPath();
+ auto pNewClipPath = pdfium::MakeUnique<CPDF_ClipPath>();
pNewClipPath->AppendPath(Path, FXFILL_ALTERNATE, false);
- return pNewClipPath;
+ return pNewClipPath.release(); // Caller takes ownership.
}
DLLEXPORT void STDCALL FPDF_DestroyClipPath(FPDF_CLIPPATH clipPath) {
- delete (CPDF_ClipPath*)clipPath;
+ // Take ownership back from caller and destroy.
+ std::unique_ptr<CPDF_ClipPath>(static_cast<CPDF_ClipPath*>(clipPath));
}
void OutputPath(CFX_ByteTextBuf& buf, CPDF_Path path) {
diff --git a/fpdfsdk/fpdfdoc.cpp b/fpdfsdk/fpdfdoc.cpp
index 0c8e26ceac..70a27a5011 100644
--- a/fpdfsdk/fpdfdoc.cpp
+++ b/fpdfsdk/fpdfdoc.cpp
@@ -230,8 +230,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFDest_GetLocationInPage(FPDF_DEST pDict,
if (!pDict)
return false;
- std::unique_ptr<CPDF_Dest> dest(
- new CPDF_Dest(static_cast<CPDF_Object*>(pDict)));
+ auto dest = pdfium::MakeUnique<CPDF_Dest>(static_cast<CPDF_Object*>(pDict));
// FPDF_BOOL is an int, GetXYZ expects bools.
bool bHasX;
diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp
index 66ff028141..df752d4029 100644
--- a/fpdfsdk/fpdfeditpage.cpp
+++ b/fpdfsdk/fpdfeditpage.cpp
@@ -63,14 +63,13 @@ bool IsPageObject(CPDF_Page* pPage) {
} // namespace
DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() {
- CPDF_Document* pDoc = new CPDF_Document(nullptr);
+ auto pDoc = pdfium::MakeUnique<CPDF_Document>(nullptr);
pDoc->CreateNewDoc();
- time_t currentTime;
+ time_t currentTime;
CFX_ByteString DateStr;
-
if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) {
- if (-1 != time(&currentTime)) {
+ if (time(&currentTime) != -1) {
tm* pTM = localtime(&currentTime);
if (pTM) {
DateStr.Format("D:%04d%02d%02d%02d%02d%02d", pTM->tm_year + 1900,
@@ -80,15 +79,15 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() {
}
}
- CPDF_Dictionary* pInfoDict = nullptr;
- pInfoDict = pDoc->GetInfo();
+ CPDF_Dictionary* pInfoDict = pDoc->GetInfo();
if (pInfoDict) {
if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
pInfoDict->SetNewFor<CPDF_String>("CreationDate", DateStr, false);
pInfoDict->SetNewFor<CPDF_String>("Creator", L"PDFium");
}
- return FPDFDocumentFromCPDFDocument(pDoc);
+ // Caller takes ownership of pDoc.
+ return FPDFDocumentFromCPDFDocument(pDoc.release());
}
DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index) {
@@ -121,19 +120,17 @@ DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document,
auto pXFAPage = pdfium::MakeRetain<CPDFXFA_Page>(
static_cast<CPDFXFA_Context*>(document), page_index);
pXFAPage->LoadPDFPage(pPageDict);
- return pXFAPage.Leak();
+ return pXFAPage.Leak(); // Caller takes ownership.
#else // PDF_ENABLE_XFA
- CPDF_Page* pPage = new CPDF_Page(pDoc, pPageDict, true);
+ auto pPage = pdfium::MakeUnique<CPDF_Page>(pDoc, pPageDict, true);
pPage->ParseContent();
- return pPage;
+ return pPage.release(); // Caller takes ownership.
#endif // PDF_ENABLE_XFA
}
DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) {
CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
- if (!IsPageObject(pPage))
- return -1;
- return pPage->GetPageRotation();
+ return IsPageObject(pPage) ? pPage->GetPageRotation() : -1;
}
DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page,
diff --git a/fpdfsdk/fpdfeditpath.cpp b/fpdfsdk/fpdfeditpath.cpp
index 155dda5c7d..a26ca5186e 100644
--- a/fpdfsdk/fpdfeditpath.cpp
+++ b/fpdfsdk/fpdfeditpath.cpp
@@ -7,22 +7,23 @@
#include "core/fpdfapi/page/cpdf_path.h"
#include "core/fpdfapi/page/cpdf_pathobject.h"
#include "core/fxcrt/fx_system.h"
+#include "third_party/base/ptr_util.h"
DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_CreateNewPath(float x, float y) {
- CPDF_PathObject* pPathObj = new CPDF_PathObject;
+ auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>();
pPathObj->m_Path.AppendPoint(CFX_PointF(x, y), FXPT_TYPE::MoveTo, false);
pPathObj->DefaultStates();
- return pPathObj;
+ return pPathObj.release(); // Caller takes ownership.
}
DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_CreateNewRect(float x,
float y,
float w,
float h) {
- CPDF_PathObject* pPathObj = new CPDF_PathObject;
+ auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>();
pPathObj->m_Path.AppendRect(x, y, x + w, y + h);
pPathObj->DefaultStates();
- return pPathObj;
+ return pPathObj.release(); // Caller takes ownership.
}
DLLEXPORT FPDF_BOOL FPDFPath_SetStrokeColor(FPDF_PAGEOBJECT path,
@@ -33,9 +34,9 @@ DLLEXPORT FPDF_BOOL FPDFPath_SetStrokeColor(FPDF_PAGEOBJECT path,
if (!path || R > 255 || G > 255 || B > 255 || A > 255)
return false;
+ float rgb[3] = {R / 255.f, G / 255.f, B / 255.f};
auto* pPathObj = reinterpret_cast<CPDF_PathObject*>(path);
pPathObj->m_GeneralState.SetStrokeAlpha(A / 255.f);
- float rgb[3] = {R / 255.f, G / 255.f, B / 255.f};
pPathObj->m_ColorState.SetStrokeColor(
CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3);
return true;
@@ -58,9 +59,9 @@ DLLEXPORT FPDF_BOOL FPDFPath_SetFillColor(FPDF_PAGEOBJECT path,
if (!path || R > 255 || G > 255 || B > 255 || A > 255)
return false;
+ float rgb[3] = {R / 255.f, G / 255.f, B / 255.f};
auto* pPathObj = reinterpret_cast<CPDF_PathObject*>(path);
pPathObj->m_GeneralState.SetFillAlpha(A / 255.f);
- float rgb[3] = {R / 255.f, G / 255.f, B / 255.f};
pPathObj->m_ColorState.SetFillColor(
CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3);
return true;
diff --git a/fpdfsdk/fpdfedittext.cpp b/fpdfsdk/fpdfedittext.cpp
index 54388ef701..c2f2df9778 100644
--- a/fpdfsdk/fpdfedittext.cpp
+++ b/fpdfsdk/fpdfedittext.cpp
@@ -388,11 +388,11 @@ DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_NewTextObj(FPDF_DOCUMENT document,
if (!pFont)
return nullptr;
- CPDF_TextObject* pTextObj = new CPDF_TextObject;
+ auto pTextObj = pdfium::MakeUnique<CPDF_TextObject>();
pTextObj->m_TextState.SetFont(pFont);
pTextObj->m_TextState.SetFontSize(font_size);
pTextObj->DefaultStates();
- return pTextObj;
+ return pTextObj.release(); // Caller takes ownership.
}
DLLEXPORT FPDF_BOOL STDCALL FPDFText_SetText(FPDF_PAGEOBJECT text_object,
diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp
index de200cf7bb..a466e73abb 100644
--- a/fpdfsdk/fpdfformfill.cpp
+++ b/fpdfsdk/fpdfformfill.cpp
@@ -263,14 +263,14 @@ FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document,
return pDocument->GetFormFillEnv();
#endif
- CPDFSDK_FormFillEnvironment* pFormFillEnv =
- new CPDFSDK_FormFillEnvironment(pDocument, formInfo);
+ auto pFormFillEnv =
+ pdfium::MakeUnique<CPDFSDK_FormFillEnvironment>(pDocument, formInfo);
#ifdef PDF_ENABLE_XFA
- pDocument->SetFormFillEnv(pFormFillEnv);
+ pDocument->SetFormFillEnv(pFormFillEnv.get());
#endif // PDF_ENABLE_XFA
- return pFormFillEnv;
+ return pFormFillEnv.release(); // Caller takes ownership.
}
DLLEXPORT void STDCALL
@@ -575,18 +575,20 @@ FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document,
if (!hWidget || !document)
return;
- CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document);
+ auto* pContext = static_cast<CPDFXFA_Context*>(document);
if (pContext->GetDocType() != XFA_DocType::Dynamic &&
pContext->GetDocType() != XFA_DocType::Static)
return;
- std::vector<CFX_ByteString>* sSuggestWords = new std::vector<CFX_ByteString>;
CFX_PointF ptPopup;
ptPopup.x = x;
ptPopup.y = y;
- static_cast<CXFA_FFWidget*>(hWidget)
- ->GetSuggestWords(ptPopup, *sSuggestWords);
- *stringHandle = ToFPDFStringHandle(sSuggestWords);
+ auto sSuggestWords = pdfium::MakeUnique<std::vector<CFX_ByteString>>();
+ static_cast<CXFA_FFWidget*>(hWidget)->GetSuggestWords(ptPopup,
+ sSuggestWords.get());
+
+ // Caller takes ownership.
+ *stringHandle = ToFPDFStringHandle(sSuggestWords.release());
}
DLLEXPORT int STDCALL FPDF_StringHandleCounts(FPDF_STRINGHANDLE sHandle) {