From 8aa3002c673f36909560575514b9a9474e5e66bf Mon Sep 17 00:00:00 2001 From: Artem Strygin Date: Tue, 31 Oct 2017 00:18:35 +0000 Subject: Simplify code in fpdf_transformpage.cpp. Change-Id: I4a33ad52bf5d0710a44f784da9f50123771b8416 Reviewed-on: https://pdfium-review.googlesource.com/17150 Reviewed-by: Lei Zhang Commit-Queue: Art Snake --- fpdfsdk/fpdf_transformpage.cpp | 60 +++++++++--------------------------------- 1 file changed, 12 insertions(+), 48 deletions(-) diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp index 7ba3a3f67b..e8a2705dd2 100644 --- a/fpdfsdk/fpdf_transformpage.cpp +++ b/fpdfsdk/fpdf_transformpage.cpp @@ -55,13 +55,7 @@ bool GetBoundingBox(CPDF_Page* page, } CPDF_Object* GetPageContent(CPDF_Dictionary* pPageDict) { - if (!pPageDict) - return nullptr; - - CPDF_Object* pContentObj = pPageDict->GetObjectFor("Contents"); - if (!pContentObj) - pContentObj = pPageDict->GetArrayFor("Contents"); - return pContentObj; + return pPageDict ? pPageDict->GetDirectObjectFor("Contents") : nullptr; } } // namespace @@ -150,30 +144,16 @@ FPDFPage_TransFormWithClip(FPDF_PAGE page, pdfium::MakeUnique(pDoc->GetByteStringPool())); pEndStream->SetData((const uint8_t*)" Q", 2); - CPDF_Array* pContentArray = nullptr; - CPDF_Array* pArray = ToArray(pContentObj); - if (pArray) { - pContentArray = pArray; + if (CPDF_Array* pContentArray = ToArray(pContentObj)) { pContentArray->InsertNewAt(0, pDoc, pStream->GetObjNum()); pContentArray->AddNew(pDoc, pEndStream->GetObjNum()); - } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { - CPDF_Object* pDirectObj = pReference->GetDirect(); - if (pDirectObj) { - CPDF_Array* pObjArray = pDirectObj->AsArray(); - if (pObjArray) { - pContentArray = pObjArray; - pContentArray->InsertNewAt(0, pDoc, - pStream->GetObjNum()); - pContentArray->AddNew(pDoc, pEndStream->GetObjNum()); - } else if (pDirectObj->IsStream()) { - pContentArray = pDoc->NewIndirect(); - pContentArray->AddNew(pDoc, pStream->GetObjNum()); - pContentArray->AddNew(pDoc, pDirectObj->GetObjNum()); - pContentArray->AddNew(pDoc, pEndStream->GetObjNum()); - pPageDict->SetNewFor("Contents", pDoc, - pContentArray->GetObjNum()); - } - } + } else if (pContentObj->IsStream() && !pContentObj->IsInline()) { + CPDF_Array* pContentArray = pDoc->NewIndirect(); + pContentArray->AddNew(pDoc, pStream->GetObjNum()); + pContentArray->AddNew(pDoc, pContentObj->GetObjNum()); + pContentArray->AddNew(pDoc, pEndStream->GetObjNum()); + pPageDict->SetNewFor("Contents", pDoc, + pContentArray->GetObjNum()); } // Need to transform the patterns as well. @@ -316,28 +296,12 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFPage_InsertClipPath(FPDF_PAGE page, pdfium::MakeUnique(pDoc->GetByteStringPool())); pStream->SetData(&strClip); - CPDF_Array* pArray = ToArray(pContentObj); - if (pArray) { + if (CPDF_Array* pArray = ToArray(pContentObj)) { pArray->InsertNewAt(0, pDoc, pStream->GetObjNum()); - return; - } - CPDF_Reference* pReference = ToReference(pContentObj); - if (!pReference) - return; - - CPDF_Object* pDirectObj = pReference->GetDirect(); - if (!pDirectObj) - return; - - CPDF_Array* pObjArray = pDirectObj->AsArray(); - if (pObjArray) { - pObjArray->InsertNewAt(0, pDoc, pStream->GetObjNum()); - return; - } - if (pDirectObj->IsStream()) { + } else if (pContentObj->IsStream() && !pContentObj->IsInline()) { CPDF_Array* pContentArray = pDoc->NewIndirect(); pContentArray->AddNew(pDoc, pStream->GetObjNum()); - pContentArray->AddNew(pDoc, pDirectObj->GetObjNum()); + pContentArray->AddNew(pDoc, pContentObj->GetObjNum()); pPageDict->SetNewFor("Contents", pDoc, pContentArray->GetObjNum()); } -- cgit v1.2.3