summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-10-16 14:00:21 -0700
committerTom Sepez <tsepez@chromium.org>2015-10-16 14:00:21 -0700
commitdb0be96179f0cd5f1787564cbccf86320a4d54ae (patch)
tree447ba797f172bfffa2d21dacc7dbf6fb2900bfd7 /fpdfsdk
parentcebdda5a686251087f14e8df19b7f988dfae46de (diff)
downloadpdfium-db0be96179f0cd5f1787564cbccf86320a4d54ae.tar.xz
Merge to XFA: Introduce CPDFPageFromFPFDPage()
Original Review URL: https://codereview.chromium.org/1406543004 . (cherry picked from commit 943ea142b6a7e6edc91fe3c307013129e6eb0ef3) R=thestig@chromium.org Review URL: https://codereview.chromium.org/1411623002 .
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/include/fsdk_define.h1
-rw-r--r--fpdfsdk/src/fpdf_flatten.cpp5
-rw-r--r--fpdfsdk/src/fpdf_progressive.cpp24
-rw-r--r--fpdfsdk/src/fpdf_transformpage.cpp16
-rw-r--r--fpdfsdk/src/fpdfdoc.cpp12
-rw-r--r--fpdfsdk/src/fpdfeditimg.cpp4
-rw-r--r--fpdfsdk/src/fpdfeditpage.cpp33
-rw-r--r--fpdfsdk/src/fpdfformfill.cpp12
-rw-r--r--fpdfsdk/src/fpdfview.cpp23
9 files changed, 46 insertions, 84 deletions
diff --git a/fpdfsdk/include/fsdk_define.h b/fpdfsdk/include/fsdk_define.h
index c2aa0d9f32..cc8c12d50f 100644
--- a/fpdfsdk/include/fsdk_define.h
+++ b/fpdfsdk/include/fsdk_define.h
@@ -93,6 +93,7 @@ class CFPDF_FileStream : public IFX_FileStream {
// Conversions from FPDF_ types.
CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc);
+CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page);
void DropContext(void* data);
void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable);
diff --git a/fpdfsdk/src/fpdf_flatten.cpp b/fpdfsdk/src/fpdf_flatten.cpp
index 73410b6c39..9d5a0d4067 100644
--- a/fpdfsdk/src/fpdf_flatten.cpp
+++ b/fpdfsdk/src/fpdf_flatten.cpp
@@ -312,14 +312,11 @@ void GetOffset(FX_FLOAT& fa,
}
DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) {
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!page) {
return FLATTEN_FAIL;
}
- CPDF_Page* pPage = ((CPDFXFA_Page*)(page))->GetPDFPage();
- if (!pPage)
- return FLATTEN_FAIL;
-
CPDF_Document* pDocument = pPage->m_pDocument;
CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
diff --git a/fpdfsdk/src/fpdf_progressive.cpp b/fpdfsdk/src/fpdf_progressive.cpp
index f5e11e8c81..4412648c8c 100644
--- a/fpdfsdk/src/fpdf_progressive.cpp
+++ b/fpdfsdk/src/fpdf_progressive.cpp
@@ -20,16 +20,10 @@ DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start(FPDF_BITMAP bitmap,
int rotate,
int flags,
IFSDK_PAUSE* pause) {
- if (bitmap == NULL || page == NULL)
+ if (!bitmap || !pause || pause->version != 1)
return FPDF_RENDER_FAILED;
- if (!pause)
- return FPDF_RENDER_FAILED;
-
- if (pause->version != 1)
- return FPDF_RENDER_FAILED;
-
- CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage)
return FPDF_RENDER_FAILED;
@@ -66,16 +60,10 @@ DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start(FPDF_BITMAP bitmap,
DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,
IFSDK_PAUSE* pause) {
- if (page == NULL)
+ if (!pause || pause->version != 1)
return FPDF_RENDER_FAILED;
- if (!pause)
- return FPDF_RENDER_FAILED;
-
- if (pause->version != 1)
- return FPDF_RENDER_FAILED;
-
- CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage)
return FPDF_RENDER_FAILED;
@@ -93,9 +81,7 @@ DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,
}
DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page) {
- if (!page)
- return;
- CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage)
return;
diff --git a/fpdfsdk/src/fpdf_transformpage.cpp b/fpdfsdk/src/fpdf_transformpage.cpp
index dbf97aa2f0..132f6683d0 100644
--- a/fpdfsdk/src/fpdf_transformpage.cpp
+++ b/fpdfsdk/src/fpdf_transformpage.cpp
@@ -11,10 +11,6 @@
namespace {
-CPDF_Page* GetPageFromFPDFPage(FPDF_PAGE page) {
- return page ? static_cast<CPDFXFA_Page*>(page)->GetPDFPage() : nullptr;
-}
-
void SetBoundingBox(CPDF_Page* page,
const CFX_ByteStringC& key,
float left,
@@ -55,7 +51,7 @@ DLLEXPORT void STDCALL FPDFPage_SetMediaBox(FPDF_PAGE page,
float bottom,
float right,
float top) {
- CPDF_Page* pPage = GetPageFromFPDFPage(page);
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage)
return;
@@ -67,7 +63,7 @@ DLLEXPORT void STDCALL FPDFPage_SetCropBox(FPDF_PAGE page,
float bottom,
float right,
float top) {
- CPDF_Page* pPage = GetPageFromFPDFPage(page);
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage)
return;
@@ -79,7 +75,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetMediaBox(FPDF_PAGE page,
float* bottom,
float* right,
float* top) {
- CPDF_Page* pPage = GetPageFromFPDFPage(page);
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
return pPage && GetBoundingBox(pPage, "MediaBox", left, bottom, right, top);
}
@@ -88,14 +84,14 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetCropBox(FPDF_PAGE page,
float* bottom,
float* right,
float* top) {
- CPDF_Page* pPage = GetPageFromFPDFPage(page);
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
return pPage && GetBoundingBox(pPage, "CropBox", left, bottom, right, top);
}
DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page,
FS_MATRIX* matrix,
FS_RECTF* clipRect) {
- CPDF_Page* pPage = GetPageFromFPDFPage(page);
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage)
return FALSE;
@@ -268,7 +264,7 @@ void OutputPath(CFX_ByteTextBuf& buf, CPDF_Path path) {
DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page,
FPDF_CLIPPATH clipPath) {
- CPDF_Page* pPage = GetPageFromFPDFPage(page);
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage)
return;
diff --git a/fpdfsdk/src/fpdfdoc.cpp b/fpdfsdk/src/fpdfdoc.cpp
index d4b6b08ff3..d1b71ac2bc 100644
--- a/fpdfsdk/src/fpdfdoc.cpp
+++ b/fpdfsdk/src/fpdfdoc.cpp
@@ -203,8 +203,7 @@ DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document,
DLLEXPORT FPDF_LINK STDCALL
FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, double y) {
- CPDFXFA_Page* pXFAPage = (CPDFXFA_Page*)page;
- CPDF_Page* pPage = pXFAPage->GetPDFPage();
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage)
return nullptr;
@@ -218,8 +217,7 @@ FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, double y) {
DLLEXPORT int STDCALL
FPDFLink_GetLinkZOrderAtPoint(FPDF_PAGE page, double x, double y) {
- CPDFXFA_Page* pXFAPage = (CPDFXFA_Page*)page;
- CPDF_Page* pPage = pXFAPage->GetPDFPage();
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage)
return -1;
@@ -261,10 +259,10 @@ DLLEXPORT FPDF_ACTION STDCALL FPDFLink_GetAction(FPDF_LINK pDict) {
DLLEXPORT FPDF_BOOL STDCALL FPDFLink_Enumerate(FPDF_PAGE page,
int* startPos,
FPDF_LINK* linkAnnot) {
- if (!page || !startPos || !linkAnnot)
+ if (!startPos || !linkAnnot)
return FALSE;
- CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
- if (!pPage->m_pFormDict)
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
+ if (!pPage || !pPage->m_pFormDict)
return FALSE;
CPDF_Array* pAnnots = pPage->m_pFormDict->GetArray("Annots");
if (!pAnnots)
diff --git a/fpdfsdk/src/fpdfeditimg.cpp b/fpdfsdk/src/fpdfeditimg.cpp
index 09295aa3c4..cd4618e44d 100644
--- a/fpdfsdk/src/fpdfeditimg.cpp
+++ b/fpdfsdk/src/fpdfeditimg.cpp
@@ -32,7 +32,7 @@ FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages,
CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
pImgObj->m_GeneralState.GetModify();
for (int index = 0; index < nCount; index++) {
- CPDF_Page* pPage = ((CPDFXFA_Page*)pages[index])->GetPDFPage();
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]);
if (!pPage)
continue;
pImgObj->m_pImage->ResetCache(pPage, NULL);
@@ -73,7 +73,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages,
CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
pImgObj->m_GeneralState.GetModify();
for (int index = 0; index < nCount; index++) {
- CPDF_Page* pPage = ((CPDFXFA_Page*)pages[index])->GetPDFPage();
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]);
if (!pPage)
continue;
pImgObj->m_pImage->ResetCache(pPage, NULL);
diff --git a/fpdfsdk/src/fpdfeditpage.cpp b/fpdfsdk/src/fpdfeditpage.cpp
index e7bbf05f4a..0cf7c880af 100644
--- a/fpdfsdk/src/fpdfeditpage.cpp
+++ b/fpdfsdk/src/fpdfeditpage.cpp
@@ -89,7 +89,7 @@ DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document,
}
DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) {
- CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") ||
!pPage->m_pFormDict->GetElement("Type")->GetDirect() ||
pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare(
@@ -133,7 +133,7 @@ DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) {
DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page,
FPDF_PAGEOBJECT page_obj) {
- CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") ||
!pPage->m_pFormDict->GetElement("Type")->GetDirect() ||
pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare(
@@ -175,9 +175,6 @@ DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page,
default:
break;
}
-
- // pPage->ParseContent();
- // pPage->GenerateContent();
}
DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) {
@@ -189,29 +186,22 @@ DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) {
return -1;
}
return pPage->CountObjects();
- // return 0;
}
DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page,
int index) {
- CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") ||
pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare(
"Page")) {
return NULL;
}
return pPage->GetObjectByIndex(index);
- // return NULL;
}
DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page) {
- if (!page)
- return FALSE;
- CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
- if (!pPage)
- return FALSE;
-
- return pPage->BackgroundAlphaNeeded();
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
+ return pPage && pPage->BackgroundAlphaNeeded();
}
DLLEXPORT FPDF_BOOL STDCALL
@@ -253,7 +243,7 @@ FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) {
}
DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page) {
- CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") ||
!pPage->m_pFormDict->GetElement("Type")->GetDirect() ||
pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare(
@@ -288,9 +278,7 @@ DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page,
double d,
double e,
double f) {
- if (page == NULL)
- return;
- CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage)
return;
CPDF_AnnotList AnnotList(pPage);
@@ -318,12 +306,7 @@ DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page,
}
DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) {
- if (page == NULL)
- return;
- CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
- if (!pPage)
- return;
-
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") ||
!pPage->m_pFormDict->GetElement("Type")->GetDirect() ||
pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare(
diff --git a/fpdfsdk/src/fpdfformfill.cpp b/fpdfsdk/src/fpdfformfill.cpp
index e86a47be55..9fe024c50b 100644
--- a/fpdfsdk/src/fpdfformfill.cpp
+++ b/fpdfsdk/src/fpdfformfill.cpp
@@ -42,10 +42,9 @@ DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle,
FPDF_PAGE page,
double page_x,
double page_y) {
- if (!page || !hHandle)
+ if (!hHandle)
return -1;
-
- CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (pPage) {
CPDF_InterForm interform(pPage->m_pDocument, FALSE);
CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint(
@@ -115,10 +114,11 @@ DLLEXPORT int STDCALL FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle,
FPDF_PAGE page,
double page_x,
double page_y) {
- if (!page || !hHandle)
+ if (!hHandle)
+ return -1;
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
+ if (!pPage)
return -1;
-
- CPDF_Page* pPage = (CPDF_Page*)page;
CPDF_InterForm interform(pPage->m_pDocument, FALSE);
int z_order = -1;
(void)interform.GetControlAtPoint(pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y,
diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp
index 5d9bf4b252..6254eb2b67 100644
--- a/fpdfsdk/src/fpdfview.cpp
+++ b/fpdfsdk/src/fpdfview.cpp
@@ -26,6 +26,10 @@ CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) {
return doc ? static_cast<CPDFXFA_Document*>(doc)->GetPDFDoc() : nullptr;
}
+CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) {
+ return page ? static_cast<CPDFXFA_Page*>(page)->GetPDFPage() : nullptr;
+}
+
CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) {
m_pFS = pFS;
m_nCurPos = 0;
@@ -436,13 +440,11 @@ DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) {
if (!page)
return 0.0;
return ((CPDFXFA_Page*)page)->GetPageWidth();
- // return ((CPDF_Page*)page)->GetPageWidth();
}
DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) {
if (!page)
return 0.0;
- // return ((CPDF_Page*)page)->GetPageHeight();
return ((CPDFXFA_Page*)page)->GetPageHeight();
}
@@ -463,9 +465,7 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc,
int size_y,
int rotate,
int flags) {
- if (page == NULL)
- return;
- CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage)
return;
@@ -625,12 +625,11 @@ DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap,
int size_y,
int rotate,
int flags) {
- if (bitmap == NULL || page == NULL)
+ if (!bitmap)
return;
- CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage)
return;
-
CRenderContext* pContext = new CRenderContext;
pPage->SetPrivateData((void*)1, pContext, DropContext);
#ifdef _SKIA_SUPPORT_
@@ -702,9 +701,11 @@ DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page,
double page_y,
int* device_x,
int* device_y) {
- if (page == NULL || device_x == NULL || device_y == NULL)
+ if (!device_x || !device_y)
return;
CPDFXFA_Page* pPage = (CPDFXFA_Page*)page;
+ if (!pPage)
+ return;
pPage->PageToDevice(start_x, start_y, size_x, size_y, rotate, page_x, page_y,
device_x, device_y);
}
@@ -804,8 +805,8 @@ void FPDF_RenderPage_Retail(CRenderContext* pContext,
int flags,
FX_BOOL bNeedToRestore,
IFSDK_PAUSE_Adapter* pause) {
- CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
- if (pPage == NULL)
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
+ if (!pPage)
return;
if (!pContext->m_pOptions)