diff options
author | tsepez <tsepez@chromium.org> | 2016-11-15 11:33:44 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-11-15 11:33:44 -0800 |
commit | 70c4afd5c3c5c44cd24f814423a23a6ef05bba02 (patch) | |
tree | cbe593d0b6c0bfc6fd5038bf60a77a94e49c69c9 /core/fpdfapi/edit | |
parent | f16f6b8b52277348f5d571b7641bb0bbd5239589 (diff) | |
download | pdfium-70c4afd5c3c5c44cd24f814423a23a6ef05bba02.tar.xz |
Make AddIndirectObject() take a unique_ptr.
Add convenience routines to create and add object in
one step.
Review-Url: https://codereview.chromium.org/2489283003
Diffstat (limited to 'core/fpdfapi/edit')
-rw-r--r-- | core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp index c27ca044e6..8e7e7b3504 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp @@ -52,10 +52,9 @@ void CPDF_PageContentGenerator::GenerateContent() { if (pContent) pPageDict->RemoveFor("Contents"); - CPDF_Stream* pStream = new CPDF_Stream; + CPDF_Stream* pStream = m_pDocument->NewIndirect<CPDF_Stream>(); pStream->SetData(buf.GetBuffer(), buf.GetLength()); - pPageDict->SetReferenceFor("Contents", m_pDocument, - m_pDocument->AddIndirectObject(pStream)); + pPageDict->SetReferenceFor("Contents", m_pDocument, pStream); } CFX_ByteString CPDF_PageContentGenerator::RealizeResource( @@ -63,11 +62,10 @@ CFX_ByteString CPDF_PageContentGenerator::RealizeResource( const CFX_ByteString& bsType) { ASSERT(dwResourceObjNum); if (!m_pPage->m_pResources) { - m_pPage->m_pResources = - new CPDF_Dictionary(m_pDocument->GetByteStringPool()); - m_pPage->m_pFormDict->SetReferenceFor( - "Resources", m_pDocument, - m_pDocument->AddIndirectObject(m_pPage->m_pResources)); + m_pPage->m_pResources = m_pDocument->NewIndirect<CPDF_Dictionary>( + m_pDocument->GetByteStringPool()); + m_pPage->m_pFormDict->SetReferenceFor("Resources", m_pDocument, + m_pPage->m_pResources); } CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(bsType); if (!pResList) { @@ -133,11 +131,10 @@ void CPDF_PageContentGenerator::ProcessForm(CFX_ByteTextBuf& buf, pFormDict->SetNameFor("Subtype", "Form"); pFormDict->SetRectFor("BBox", bbox); - CPDF_Stream* pStream = new CPDF_Stream; + CPDF_Stream* pStream = m_pDocument->NewIndirect<CPDF_Stream>(); pStream->InitStream(data, size, pFormDict); - CFX_ByteString name = - RealizeResource(m_pDocument->AddIndirectObject(pStream), "XObject"); + CFX_ByteString name = RealizeResource(pStream->GetObjNum(), "XObject"); buf << "/" << PDF_NameEncode(name) << " Do Q\n"; } @@ -181,8 +178,7 @@ void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) { contentStream.LoadAllData(pStream); ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); } - CPDF_Stream* pStream = new CPDF_Stream; + CPDF_Stream* pStream = m_pDocument->NewIndirect<CPDF_Stream>(); pStream->SetData(buf.GetBuffer(), buf.GetLength()); - m_pPage->m_pFormDict->SetReferenceFor( - "Contents", m_pDocument, m_pDocument->AddIndirectObject(pStream)); + m_pPage->m_pFormDict->SetReferenceFor("Contents", m_pDocument, pStream); } |