From 341ec6256457c53d50f2d0a0667e61041d4d89be Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Mon, 30 Oct 2017 20:19:33 +0000 Subject: Combine common code in fpdf_transformpage.cpp. Change-Id: I50311794b6fb4ef3c38420838ec6c3bb157b06a7 Reviewed-on: https://pdfium-review.googlesource.com/17071 Reviewed-by: Henrique Nakashima Commit-Queue: Lei Zhang --- fpdfsdk/fpdf_transformpage.cpp | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp index 94807718e1..7ba3a3f67b 100644 --- a/fpdfsdk/fpdf_transformpage.cpp +++ b/fpdfsdk/fpdf_transformpage.cpp @@ -54,6 +54,16 @@ bool GetBoundingBox(CPDF_Page* page, return true; } +CPDF_Object* GetPageContent(CPDF_Dictionary* pPageDict) { + if (!pPageDict) + return nullptr; + + CPDF_Object* pContentObj = pPageDict->GetObjectFor("Contents"); + if (!pContentObj) + pContentObj = pPageDict->GetArrayFor("Contents"); + return pContentObj; +} + } // namespace FPDF_EXPORT void FPDF_CALLCONV FPDFPage_SetMediaBox(FPDF_PAGE page, @@ -121,11 +131,8 @@ FPDFPage_TransFormWithClip(FPDF_PAGE page, matrix->d, matrix->e, matrix->f); textBuf << bsMatix; - CPDF_Dictionary* pPageDic = pPage->m_pFormDict.Get(); - CPDF_Object* pContentObj = - pPageDic ? pPageDic->GetObjectFor("Contents") : nullptr; - if (!pContentObj) - pContentObj = pPageDic ? pPageDic->GetArrayFor("Contents") : nullptr; + CPDF_Dictionary* pPageDict = pPage->m_pFormDict.Get(); + CPDF_Object* pContentObj = GetPageContent(pPageDict); if (!pContentObj) return false; @@ -163,14 +170,14 @@ FPDFPage_TransFormWithClip(FPDF_PAGE page, pContentArray->AddNew(pDoc, pStream->GetObjNum()); pContentArray->AddNew(pDoc, pDirectObj->GetObjNum()); pContentArray->AddNew(pDoc, pEndStream->GetObjNum()); - pPageDic->SetNewFor("Contents", pDoc, - pContentArray->GetObjNum()); + pPageDict->SetNewFor("Contents", pDoc, + pContentArray->GetObjNum()); } } } // Need to transform the patterns as well. - CPDF_Dictionary* pRes = pPageDic->GetDictFor("Resources"); + CPDF_Dictionary* pRes = pPageDict->GetDictFor("Resources"); if (pRes) { CPDF_Dictionary* pPattenDict = pRes->GetDictFor("Pattern"); if (pPattenDict) { @@ -278,11 +285,8 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFPage_InsertClipPath(FPDF_PAGE page, if (!pPage) return; - CPDF_Dictionary* pPageDic = pPage->m_pFormDict.Get(); - CPDF_Object* pContentObj = - pPageDic ? pPageDic->GetObjectFor("Contents") : nullptr; - if (!pContentObj) - pContentObj = pPageDic ? pPageDic->GetArrayFor("Contents") : nullptr; + CPDF_Dictionary* pPageDict = pPage->m_pFormDict.Get(); + CPDF_Object* pContentObj = GetPageContent(pPageDict); if (!pContentObj) return; @@ -334,7 +338,7 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFPage_InsertClipPath(FPDF_PAGE page, CPDF_Array* pContentArray = pDoc->NewIndirect(); pContentArray->AddNew(pDoc, pStream->GetObjNum()); pContentArray->AddNew(pDoc, pDirectObj->GetObjNum()); - pPageDic->SetNewFor("Contents", pDoc, - pContentArray->GetObjNum()); + pPageDict->SetNewFor("Contents", pDoc, + pContentArray->GetObjNum()); } } -- cgit v1.2.3