From 0e606b5ecd6e45f74391f110cc1fe0cce0e80c64 Mon Sep 17 00:00:00 2001 From: tsepez Date: Fri, 18 Nov 2016 16:22:41 -0800 Subject: Make CPDF_Dictionary use unique pointers. Some changes were required to match underlying ctors as invoked by the templated methods. Many release() calls go away, a few WrapUniques() are introduced to avoid going deeper into other code. Review-Url: https://codereview.chromium.org/2510223002 --- fpdfsdk/fpdfeditpage.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'fpdfsdk/fpdfeditpage.cpp') diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp index 847adac7ec..c864b82145 100644 --- a/fpdfsdk/fpdfeditpage.cpp +++ b/fpdfsdk/fpdfeditpage.cpp @@ -83,11 +83,9 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() { CPDF_Dictionary* pInfoDict = nullptr; pInfoDict = pDoc->GetInfo(); if (pInfoDict) { - if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) { - pInfoDict->SetFor("CreationDate", - new CPDF_String(nullptr, DateStr, false)); - } - pInfoDict->SetFor("Creator", new CPDF_String(L"PDFium")); + if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) + pInfoDict->SetNewFor("CreationDate", DateStr, false); + pInfoDict->SetNewFor("Creator", L"PDFium"); } return FPDFDocumentFromCPDFDocument(pDoc); @@ -111,15 +109,13 @@ DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, if (!pPageDict) return nullptr; - CPDF_Array* pMediaBoxArray = new CPDF_Array; + CPDF_Array* pMediaBoxArray = pPageDict->SetNewFor("MediaBox"); pMediaBoxArray->AddNew(0); pMediaBoxArray->AddNew(0); pMediaBoxArray->AddNew(static_cast(width)); pMediaBoxArray->AddNew(static_cast(height)); - pPageDict->SetFor("MediaBox", pMediaBoxArray); - pPageDict->SetFor("Rotate", new CPDF_Number(0)); - pPageDict->SetFor("Resources", - new CPDF_Dictionary(pDoc->GetByteStringPool())); + pPageDict->SetNewFor("Rotate", 0); + pPageDict->SetNewFor("Resources"); #ifdef PDF_ENABLE_XFA CPDFXFA_Page* pPage = @@ -296,10 +292,9 @@ DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, rect.Transform(&matrix); CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayFor("Rect"); - if (!pRectArray) { - pRectArray = new CPDF_Array; - pAnnot->GetAnnotDict()->SetFor("Rect", pRectArray); - } + if (!pRectArray) + pRectArray = pAnnot->GetAnnotDict()->SetNewFor("Rect"); + pRectArray->SetNewAt(0, rect.left); pRectArray->SetNewAt(1, rect.bottom); pRectArray->SetNewAt(2, rect.right); @@ -316,5 +311,5 @@ DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) { CPDF_Dictionary* pDict = pPage->m_pFormDict; rotate %= 4; - pDict->SetFor("Rotate", new CPDF_Number(rotate * 90)); + pDict->SetNewFor("Rotate", rotate * 90); } -- cgit v1.2.3