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 /core/fpdfapi/edit/fpdf_edit_create.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 'core/fpdfapi/edit/fpdf_edit_create.cpp')
-rw-r--r-- | core/fpdfapi/edit/fpdf_edit_create.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/core/fpdfapi/edit/fpdf_edit_create.cpp b/core/fpdfapi/edit/fpdf_edit_create.cpp index 360472948d..b2e31054c0 100644 --- a/core/fpdfapi/edit/fpdf_edit_create.cpp +++ b/core/fpdfapi/edit/fpdf_edit_create.cpp @@ -13,6 +13,8 @@ #include "core/fpdfapi/parser/cpdf_crypto_handler.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_document.h" +#include "core/fpdfapi/parser/cpdf_name.h" +#include "core/fpdfapi/parser/cpdf_number.h" #include "core/fpdfapi/parser/cpdf_parser.h" #include "core/fpdfapi/parser/cpdf_reference.h" #include "core/fpdfapi/parser/cpdf_security_handler.h" @@ -128,7 +130,7 @@ int32_t PDF_CreatorAppendObject(const CPDF_Object* pObj, const CPDF_Dictionary* p = pObj->AsDictionary(); for (const auto& it : *p) { const CFX_ByteString& key = it.first; - CPDF_Object* pValue = it.second; + CPDF_Object* pValue = it.second.get(); if (pFile->AppendString("/") < 0) { return -1; } @@ -197,7 +199,7 @@ int32_t PDF_CreatorWriteTrailer(CPDF_Document* pDocument, CPDF_Dictionary* p = pParser->GetTrailer(); for (const auto& it : *p) { const CFX_ByteString& key = it.first; - CPDF_Object* pValue = it.second; + CPDF_Object* pValue = it.second.get(); if (key == "Encrypt" || key == "Size" || key == "Filter" || key == "Index" || key == "Length" || key == "Prev" || key == "W" || key == "XRefStm" || key == "Type" || key == "ID") { @@ -440,8 +442,8 @@ CPDF_FlateEncoder::CPDF_FlateEncoder(CPDF_Stream* pStream, bool bFlateEncode) // TODO(thestig): Move to Init() and check return value. ::FlateEncode(m_Acc.GetData(), m_Acc.GetSize(), &m_pData, &m_dwSize); m_pDict = ToDictionary(pStream->GetDict()->Clone().release()); - m_pDict->SetIntegerFor("Length", m_dwSize); - m_pDict->SetNameFor("Filter", "FlateDecode"); + m_pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(m_dwSize)); + m_pDict->SetNewFor<CPDF_Name>("Filter", "FlateDecode"); m_pDict->RemoveFor("DecodeParms"); } @@ -993,7 +995,8 @@ int32_t CPDF_Creator::WriteStream(const CPDF_Object* pStream, if ((uint32_t)encoder.m_pDict->GetIntegerFor("Length") != encryptor.m_dwSize) { encoder.CloneDict(); - encoder.m_pDict->SetIntegerFor("Length", encryptor.m_dwSize); + encoder.m_pDict->SetNewFor<CPDF_Number>( + "Length", static_cast<int>(encryptor.m_dwSize)); } if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { return -1; @@ -1106,7 +1109,8 @@ int32_t CPDF_Creator::WriteDirectObj(uint32_t objnum, if ((uint32_t)encoder.m_pDict->GetIntegerFor("Length") != encryptor.m_dwSize) { encoder.CloneDict(); - encoder.m_pDict->SetIntegerFor("Length", encryptor.m_dwSize); + encoder.m_pDict->SetNewFor<CPDF_Number>( + "Length", static_cast<int>(encryptor.m_dwSize)); } if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { return -1; @@ -1189,7 +1193,7 @@ int32_t CPDF_Creator::WriteDirectObj(uint32_t objnum, for (const auto& it : *p) { bool bSignValue = false; const CFX_ByteString& key = it.first; - CPDF_Object* pValue = it.second; + CPDF_Object* pValue = it.second.get(); if (m_File.AppendString("/") < 0) { return -1; } @@ -1711,7 +1715,7 @@ int32_t CPDF_Creator::WriteDoc_Stage4(IFX_Pause* pPause) { CPDF_Dictionary* p = m_pParser->GetTrailer(); for (const auto& it : *p) { const CFX_ByteString& key = it.first; - CPDF_Object* pValue = it.second; + CPDF_Object* pValue = it.second.get(); // TODO(ochang): Consolidate with similar check in // PDF_CreatorWriteTrailer. if (key == "Encrypt" || key == "Size" || key == "Filter" || |