summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorArtem Strygin <art-snake@yandex-team.ru>2017-10-31 00:18:35 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-10-31 00:18:35 +0000
commit8aa3002c673f36909560575514b9a9474e5e66bf (patch)
treecdc15f031a0f3215045af58721d0b3f4b5c0753f /fpdfsdk
parentd6e9cfaab0555c34783dd05261329866b4da1b9f (diff)
downloadpdfium-8aa3002c673f36909560575514b9a9474e5e66bf.tar.xz
Simplify code in fpdf_transformpage.cpp.
Change-Id: I4a33ad52bf5d0710a44f784da9f50123771b8416 Reviewed-on: https://pdfium-review.googlesource.com/17150 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Art Snake <art-snake@yandex-team.ru>
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/fpdf_transformpage.cpp60
1 files 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<CPDF_Dictionary>(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<CPDF_Reference>(0, pDoc, pStream->GetObjNum());
pContentArray->AddNew<CPDF_Reference>(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<CPDF_Reference>(0, pDoc,
- pStream->GetObjNum());
- pContentArray->AddNew<CPDF_Reference>(pDoc, pEndStream->GetObjNum());
- } else if (pDirectObj->IsStream()) {
- pContentArray = pDoc->NewIndirect<CPDF_Array>();
- pContentArray->AddNew<CPDF_Reference>(pDoc, pStream->GetObjNum());
- pContentArray->AddNew<CPDF_Reference>(pDoc, pDirectObj->GetObjNum());
- pContentArray->AddNew<CPDF_Reference>(pDoc, pEndStream->GetObjNum());
- pPageDict->SetNewFor<CPDF_Reference>("Contents", pDoc,
- pContentArray->GetObjNum());
- }
- }
+ } else if (pContentObj->IsStream() && !pContentObj->IsInline()) {
+ CPDF_Array* pContentArray = pDoc->NewIndirect<CPDF_Array>();
+ pContentArray->AddNew<CPDF_Reference>(pDoc, pStream->GetObjNum());
+ pContentArray->AddNew<CPDF_Reference>(pDoc, pContentObj->GetObjNum());
+ pContentArray->AddNew<CPDF_Reference>(pDoc, pEndStream->GetObjNum());
+ pPageDict->SetNewFor<CPDF_Reference>("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<CPDF_Dictionary>(pDoc->GetByteStringPool()));
pStream->SetData(&strClip);
- CPDF_Array* pArray = ToArray(pContentObj);
- if (pArray) {
+ if (CPDF_Array* pArray = ToArray(pContentObj)) {
pArray->InsertNewAt<CPDF_Reference>(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<CPDF_Reference>(0, pDoc, pStream->GetObjNum());
- return;
- }
- if (pDirectObj->IsStream()) {
+ } else if (pContentObj->IsStream() && !pContentObj->IsInline()) {
CPDF_Array* pContentArray = pDoc->NewIndirect<CPDF_Array>();
pContentArray->AddNew<CPDF_Reference>(pDoc, pStream->GetObjNum());
- pContentArray->AddNew<CPDF_Reference>(pDoc, pDirectObj->GetObjNum());
+ pContentArray->AddNew<CPDF_Reference>(pDoc, pContentObj->GetObjNum());
pPageDict->SetNewFor<CPDF_Reference>("Contents", pDoc,
pContentArray->GetObjNum());
}