From fb72726e51bfd0c7bfc61c9b354e2b60f46adac5 Mon Sep 17 00:00:00 2001 From: Artem Strygin Date: Mon, 11 Jun 2018 18:19:57 +0000 Subject: Implement CPDF_Object::MakeReference method. Change-Id: I153747ef587a184eaef58ff09dbf8f214c9ddfb3 Reviewed-on: https://pdfium-review.googlesource.com/17230 Reviewed-by: Tom Sepez Commit-Queue: Art Snake --- fpdfsdk/fpdf_flatten.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'fpdfsdk/fpdf_flatten.cpp') diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp index d35cfe370d..4b9e1f8a9d 100644 --- a/fpdfsdk/fpdf_flatten.cpp +++ b/fpdfsdk/fpdf_flatten.cpp @@ -169,15 +169,15 @@ CFX_FloatRect CalculateRect(std::vector* pRectArray) { return rcRet; } -uint32_t NewIndirectContentsStream(const ByteString& key, - CPDF_Document* pDocument) { +CPDF_Object* NewIndirectContentsStream(const ByteString& key, + CPDF_Document* pDocument) { CPDF_Stream* pNewContents = pDocument->NewIndirect( nullptr, 0, pdfium::MakeUnique(pDocument->GetByteStringPool())); ByteString sStream = ByteString::Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); pNewContents->SetData(sStream.raw_str(), sStream.GetLength()); - return pNewContents->GetObjNum(); + return pNewContents; } void SetPageContents(const ByteString& key, @@ -190,9 +190,9 @@ void SetPageContents(const ByteString& key, pContentsArray = pPage->GetArrayFor(pdfium::page_object::kContents); if (!pContentsArray) { if (!key.IsEmpty()) { - pPage->SetNewFor( - pdfium::page_object::kContents, pDocument, - NewIndirectContentsStream(key, pDocument)); + pPage->SetFor(pdfium::page_object::kContents, + NewIndirectContentsStream(key, pDocument) + ->MakeReference(pDocument)); } return; } @@ -207,14 +207,13 @@ void SetPageContents(const ByteString& key, sStream = sStream + sBody + "\nQ"; pContentsStream->SetDataAndRemoveFilter(sStream.raw_str(), sStream.GetLength()); - pContentsArray->AddNew(pDocument, - pContentsStream->GetObjNum()); - pPage->SetNewFor(pdfium::page_object::kContents, pDocument, - pContentsArray->GetObjNum()); + pContentsArray->Add(pContentsStream->MakeReference(pDocument)); + pPage->SetFor(pdfium::page_object::kContents, + pContentsArray->MakeReference(pDocument)); } if (!key.IsEmpty()) { - pContentsArray->AddNew( - pDocument, NewIndirectContentsStream(key, pDocument)); + pContentsArray->Add( + NewIndirectContentsStream(key, pDocument)->MakeReference(pDocument)); } } @@ -290,7 +289,6 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { nullptr, 0, pdfium::MakeUnique(pDocument->GetByteStringPool())); - uint32_t dwObjNum = pNewXObject->GetObjNum(); CPDF_Dictionary* pPageXObject = pRes->GetDictFor("XObject"); if (!pPageXObject) pPageXObject = pRes->SetNewFor("XObject"); @@ -312,7 +310,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { CPDF_Dictionary* pNewXORes = nullptr; if (!key.IsEmpty()) { - pPageXObject->SetNewFor(key, pDocument, dwObjNum); + pPageXObject->SetFor(key, pNewXObject->MakeReference(pDocument)); CPDF_Dictionary* pNewOXbjectDic = pNewXObject->GetDict(); pNewXORes = pNewOXbjectDic->SetNewFor("Resources"); pNewOXbjectDic->SetNewFor("Type", "XObject"); @@ -387,8 +385,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { pXObject = pNewXORes->SetNewFor("XObject"); ByteString sFormName = ByteString::Format("F%d", i); - pXObject->SetNewFor(sFormName, pDocument, - pObj->GetObjNum()); + pXObject->SetFor(sFormName, pObj->MakeReference(pDocument)); auto pAcc = pdfium::MakeRetain(pNewXObject); pAcc->LoadAllDataFiltered(); -- cgit v1.2.3