diff options
author | tsepez <tsepez@chromium.org> | 2016-11-18 16:22:41 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-11-18 16:22:41 -0800 |
commit | 0e606b5ecd6e45f74391f110cc1fe0cce0e80c64 (patch) | |
tree | 07c55fac710b191cf5d1d6595c63b90ca52e3cbb /fpdfsdk/fpdfppo.cpp | |
parent | 430ab8363e77c48b2c2435af4d289f85e2be1b96 (diff) | |
download | pdfium-0e606b5ecd6e45f74391f110cc1fe0cce0e80c64.tar.xz |
Make CPDF_Dictionary use unique pointers.chromium/2926
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
Diffstat (limited to 'fpdfsdk/fpdfppo.cpp')
-rw-r--r-- | fpdfsdk/fpdfppo.cpp | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/fpdfsdk/fpdfppo.cpp b/fpdfsdk/fpdfppo.cpp index 915de1ad07..4e06856455 100644 --- a/fpdfsdk/fpdfppo.cpp +++ b/fpdfsdk/fpdfppo.cpp @@ -8,6 +8,7 @@ #include <map> #include <memory> +#include <utility> #include <vector> #include "core/fpdfapi/parser/cpdf_array.h" @@ -64,7 +65,7 @@ bool CopyInheritable(CPDF_Dictionary* pCurPageDict, if (!pInheritable) return false; - pCurPageDict->SetFor(key, pInheritable->Clone().release()); + pCurPageDict->SetFor(key, pInheritable->Clone()); return true; } @@ -158,31 +159,30 @@ bool CPDF_PageOrganizer::PDFDocInit() { if (!pDocInfoDict) return false; - CFX_ByteString producerstr; - producerstr.Format("PDFium"); - pDocInfoDict->SetFor("Producer", - new CPDF_String(nullptr, producerstr, false)); + pDocInfoDict->SetNewFor<CPDF_String>("Producer", "PDFium", false); CFX_ByteString cbRootType = pNewRoot->GetStringFor("Type", ""); if (cbRootType.IsEmpty()) - pNewRoot->SetFor("Type", new CPDF_Name(nullptr, "Catalog")); + pNewRoot->SetNewFor<CPDF_Name>("Type", "Catalog"); CPDF_Object* pElement = pNewRoot->GetObjectFor("Pages"); CPDF_Dictionary* pNewPages = pElement ? ToDictionary(pElement->GetDirect()) : nullptr; if (!pNewPages) { pNewPages = m_pDestPDFDoc->NewIndirect<CPDF_Dictionary>(); - pNewRoot->SetReferenceFor("Pages", m_pDestPDFDoc, pNewPages); + pNewRoot->SetNewFor<CPDF_Reference>("Pages", m_pDestPDFDoc, + pNewPages->GetObjNum()); } CFX_ByteString cbPageType = pNewPages->GetStringFor("Type", ""); if (cbPageType.IsEmpty()) - pNewPages->SetFor("Type", new CPDF_Name(nullptr, "Pages")); + pNewPages->SetNewFor<CPDF_Name>("Type", "Pages"); if (!pNewPages->GetArrayFor("Kids")) { - pNewPages->SetIntegerFor("Count", 0); - pNewPages->SetReferenceFor("Kids", m_pDestPDFDoc, - m_pDestPDFDoc->NewIndirect<CPDF_Array>()); + pNewPages->SetNewFor<CPDF_Number>("Count", 0); + pNewPages->SetNewFor<CPDF_Reference>( + "Kids", m_pDestPDFDoc, + m_pDestPDFDoc->NewIndirect<CPDF_Array>()->GetObjNum()); } return true; @@ -202,11 +202,11 @@ bool CPDF_PageOrganizer::ExportPage(const std::vector<uint16_t>& pageNums, // Clone the page dictionary for (const auto& it : *pSrcPageDict) { const CFX_ByteString& cbSrcKeyStr = it.first; - CPDF_Object* pObj = it.second; if (cbSrcKeyStr == "Type" || cbSrcKeyStr == "Parent") continue; - pCurPageDict->SetFor(cbSrcKeyStr, pObj->Clone().release()); + CPDF_Object* pObj = it.second.get(); + pCurPageDict->SetFor(cbSrcKeyStr, pObj->Clone()); } // inheritable item @@ -217,15 +217,14 @@ bool CPDF_PageOrganizer::ExportPage(const std::vector<uint16_t>& pageNums, CPDF_Object* pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox"); if (pInheritable) { - pCurPageDict->SetFor("MediaBox", pInheritable->Clone().release()); + pCurPageDict->SetFor("MediaBox", pInheritable->Clone()); } else { // Make the default size to be letter size (8.5'x11') - CPDF_Array* pArray = new CPDF_Array; + CPDF_Array* pArray = pCurPageDict->SetNewFor<CPDF_Array>("MediaBox"); pArray->AddNew<CPDF_Number>(0); pArray->AddNew<CPDF_Number>(0); pArray->AddNew<CPDF_Number>(612); pArray->AddNew<CPDF_Number>(792); - pCurPageDict->SetFor("MediaBox", pArray); } } @@ -265,7 +264,7 @@ bool CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj, auto it = pDict->begin(); while (it != pDict->end()) { const CFX_ByteString& key = it->first; - CPDF_Object* pNextObj = it->second; + CPDF_Object* pNextObj = it->second.get(); ++it; if (key == "Parent" || key == "Prev" || key == "First") continue; @@ -386,7 +385,6 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_CopyViewerPreferences(FPDF_DOCUMENT dest_doc, if (!pDstDict) return false; - pDstDict->SetFor("ViewerPreferences", - pSrcDict->CloneDirectObject().release()); + pDstDict->SetFor("ViewerPreferences", pSrcDict->CloneDirectObject()); return true; } |