summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdf_flatten.cpp
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-11-15 11:33:44 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-15 11:33:44 -0800
commit70c4afd5c3c5c44cd24f814423a23a6ef05bba02 (patch)
treecbe593d0b6c0bfc6fd5038bf60a77a94e49c69c9 /fpdfsdk/fpdf_flatten.cpp
parentf16f6b8b52277348f5d571b7641bb0bbd5239589 (diff)
downloadpdfium-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 'fpdfsdk/fpdf_flatten.cpp')
-rw-r--r--fpdfsdk/fpdf_flatten.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp
index 1b93bb4d88..b11e4a621d 100644
--- a/fpdfsdk/fpdf_flatten.cpp
+++ b/fpdfsdk/fpdf_flatten.cpp
@@ -172,12 +172,12 @@ CFX_FloatRect CalculateRect(std::vector<CFX_FloatRect>* pRectArray) {
uint32_t NewIndirectContentsStream(const CFX_ByteString& key,
CPDF_Document* pDocument) {
- CPDF_Stream* pNewContents = new CPDF_Stream(
+ CPDF_Stream* pNewContents = pDocument->NewIndirect<CPDF_Stream>(
nullptr, 0, new CPDF_Dictionary(pDocument->GetByteStringPool()));
CFX_ByteString sStream;
sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str());
pNewContents->SetData(sStream.raw_str(), sStream.GetLength());
- return pDocument->AddIndirectObject(pNewContents);
+ return pNewContents->GetObjNum();
}
void SetPageContents(const CFX_ByteString& key,
@@ -197,7 +197,7 @@ void SetPageContents(const CFX_ByteString& key,
}
pPage->ConvertToIndirectObjectFor("Contents", pDocument);
if (!pContentsArray) {
- pContentsArray = new CPDF_Array;
+ pContentsArray = pDocument->NewIndirect<CPDF_Array>();
CPDF_StreamAcc acc;
acc.LoadAllData(pContentsStream);
CFX_ByteString sStream = "q\n";
@@ -206,8 +206,7 @@ void SetPageContents(const CFX_ByteString& key,
sStream = sStream + sBody + "\nQ";
pContentsStream->SetData(sStream.raw_str(), sStream.GetLength());
pContentsArray->AddReference(pDocument, pContentsStream->GetObjNum());
- pPage->SetReferenceFor("Contents", pDocument,
- pDocument->AddIndirectObject(pContentsArray));
+ pPage->SetReferenceFor("Contents", pDocument, pContentsArray);
}
if (!key.IsEmpty()) {
pContentsArray->AddReference(pDocument,
@@ -293,10 +292,10 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) {
pPageDict->SetFor("Resources", pRes);
}
- CPDF_Stream* pNewXObject = new CPDF_Stream(
+ CPDF_Stream* pNewXObject = pDocument->NewIndirect<CPDF_Stream>(
nullptr, 0, new CPDF_Dictionary(pDocument->GetByteStringPool()));
- uint32_t dwObjNum = pDocument->AddIndirectObject(pNewXObject);
+ uint32_t dwObjNum = pNewXObject->GetObjNum();
CPDF_Dictionary* pPageXObject = pRes->GetDictFor("XObject");
if (!pPageXObject) {
pPageXObject = new CPDF_Dictionary(pDocument->GetByteStringPool());
@@ -383,7 +382,7 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) {
if (pObj->IsInline()) {
std::unique_ptr<CPDF_Object> pNew = pObj->Clone();
pObj = pNew.get();
- pDocument->AddIndirectObject(pNew.release());
+ pDocument->AddIndirectObject(std::move(pNew));
}
CPDF_Dictionary* pObjDic = pObj->GetDict();