| Index: fpdfsdk/fpdf_flatten.cpp
|
| diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp
|
| index abfc69b0926d930204ecd995818d61d885f46d5d..3a1135130ecf8e5b1b0a3b665fef8fa6d7f906b4 100644
|
| --- a/fpdfsdk/fpdf_flatten.cpp
|
| +++ b/fpdfsdk/fpdf_flatten.cpp
|
| @@ -186,12 +186,12 @@ CFX_FloatRect CalculateRect(CPDF_RectArray* pRectArray) {
|
|
|
| uint32_t NewIndirectContentsStream(const CFX_ByteString& key,
|
| CPDF_Document* pDocument) {
|
| - CPDF_Stream* pNewContents = new CPDF_Stream(
|
| + CPDF_Stream* pNewContents = pDocument->AddIndirectStream(
|
| 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,
|
| @@ -211,17 +211,15 @@ void SetPageContents(const CFX_ByteString& key,
|
| }
|
| pPage->ConvertToIndirectObjectFor("Contents", pDocument);
|
| if (!pContentsArray) {
|
| - pContentsArray = new CPDF_Array;
|
| + pContentsArray = pDocument->AddIndirectArray();
|
| CPDF_StreamAcc acc;
|
| acc.LoadAllData(pContentsStream);
|
| CFX_ByteString sStream = "q\n";
|
| - CFX_ByteString sBody =
|
| - CFX_ByteString((const FX_CHAR*)acc.GetData(), acc.GetSize());
|
| + CFX_ByteString sBody = CFX_ByteString(acc.GetData(), acc.GetSize());
|
| 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,
|
| @@ -318,10 +316,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->AddIndirectStream(
|
| 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());
|
| @@ -426,8 +424,10 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) {
|
|
|
| CFX_ByteString sFormName;
|
| sFormName.Format("F%d", i);
|
| +
|
| + // TODO(tsepez): check |pObj| ownership.
|
| pXObject->SetReferenceFor(sFormName, pDocument,
|
| - pDocument->AddIndirectObject(pObj));
|
| + pDocument->AddIndirectObject(UniqueObject(pObj)));
|
|
|
| CPDF_StreamAcc acc;
|
| acc.LoadAllData(pNewXObject);
|
|
|