diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-10-15 16:34:32 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-10-15 16:34:32 -0700 |
commit | 943ea142b6a7e6edc91fe3c307013129e6eb0ef3 (patch) | |
tree | 8de4aaa7bb8eb3d463246d2a2f400006e60bae99 | |
parent | b456ba7f62fa416f456ef78750c18fd2bdf837be (diff) | |
download | pdfium-943ea142b6a7e6edc91fe3c307013129e6eb0ef3.tar.xz |
Introduce CPDFPageFromFPFDPage()
Abstracts the way that pages are passed to the embedder
between XFA and master.
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1406543004 .
-rw-r--r-- | fpdfsdk/include/fsdk_define.h | 1 | ||||
-rw-r--r-- | fpdfsdk/src/fpdf_flatten.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/src/fpdf_progressive.cpp | 22 | ||||
-rw-r--r-- | fpdfsdk/src/fpdf_transformpage.cpp | 16 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfdoc.cpp | 16 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfeditimg.cpp | 8 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfeditpage.cpp | 28 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfformfill.cpp | 44 | ||||
-rw-r--r-- | fpdfsdk/src/fpdftext.cpp | 13 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfview.cpp | 36 |
10 files changed, 96 insertions, 90 deletions
diff --git a/fpdfsdk/include/fsdk_define.h b/fpdfsdk/include/fsdk_define.h index 8910628891..dbe08e71f7 100644 --- a/fpdfsdk/include/fsdk_define.h +++ b/fpdfsdk/include/fsdk_define.h @@ -58,6 +58,7 @@ class CPDF_CustomAccess final : public IFX_FileRead { // 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 210df63d3e..b2303f36aa 100644 --- a/fpdfsdk/src/fpdf_flatten.cpp +++ b/fpdfsdk/src/fpdf_flatten.cpp @@ -310,11 +310,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 = (CPDF_Page*)(page); 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 aaa55a18f6..b13eb553cc 100644 --- a/fpdfsdk/src/fpdf_progressive.cpp +++ b/fpdfsdk/src/fpdf_progressive.cpp @@ -18,16 +18,13 @@ 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) + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + if (!pPage) return FPDF_RENDER_FAILED; - if (pause->version != 1) - return FPDF_RENDER_FAILED; - - CPDF_Page* pPage = (CPDF_Page*)page; CRenderContext* pContext = new CRenderContext; pPage->SetPrivateData((void*)1, pContext, DropContext); #ifdef _SKIA_SUPPORT_ @@ -59,16 +56,13 @@ DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start(FPDF_BITMAP bitmap, DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page, IFSDK_PAUSE* pause) { - if (page == NULL) - return FPDF_RENDER_FAILED; - - if (!pause) + if (!pause || pause->version != 1) return FPDF_RENDER_FAILED; - if (pause->version != 1) + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + if (!pPage) return FPDF_RENDER_FAILED; - CPDF_Page* pPage = (CPDF_Page*)page; CRenderContext* pContext = (CRenderContext*)pPage->GetPrivateData((void*)1); if (pContext && pContext->m_pRenderer) { IFSDK_PAUSE_Adapter IPauseAdapter(pause); @@ -80,10 +74,10 @@ DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page, } DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page) { - if (!page) + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + if (!pPage) return; - CPDF_Page* pPage = (CPDF_Page*)page; CRenderContext* pContext = (CRenderContext*)pPage->GetPrivateData((void*)1); if (!pContext) return; diff --git a/fpdfsdk/src/fpdf_transformpage.cpp b/fpdfsdk/src/fpdf_transformpage.cpp index 4a892f1320..cdc646ae7e 100644 --- a/fpdfsdk/src/fpdf_transformpage.cpp +++ b/fpdfsdk/src/fpdf_transformpage.cpp @@ -9,10 +9,6 @@ namespace { -CPDF_Page* GetPageFromFPDFPage(FPDF_PAGE page) { - return static_cast<CPDF_Page*>(page); -} - void SetBoundingBox(CPDF_Page* page, const CFX_ByteStringC& key, float left, @@ -53,7 +49,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; @@ -65,7 +61,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; @@ -77,7 +73,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); } @@ -86,14 +82,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; @@ -266,7 +262,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 05b151e0a7..b770295604 100644 --- a/fpdfsdk/src/fpdfdoc.cpp +++ b/fpdfsdk/src/fpdfdoc.cpp @@ -201,7 +201,10 @@ DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document, DLLEXPORT FPDF_LINK STDCALL FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, double y) { - CPDF_Page* pPage = (CPDF_Page*)page; + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + if (!pPage) + return nullptr; + CPDF_LinkList* pLinkList = GetLinkList(pPage); if (!pLinkList) return nullptr; @@ -212,7 +215,10 @@ FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, double y) { DLLEXPORT int STDCALL FPDFLink_GetLinkZOrderAtPoint(FPDF_PAGE page, double x, double y) { - CPDF_Page* pPage = (CPDF_Page*)page; + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + if (!pPage) + return -1; + CPDF_LinkList* pLinkList = GetLinkList(pPage); if (!pLinkList) return -1; @@ -251,10 +257,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 = (CPDF_Page*)page; - 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 0c8ea1627a..73fc251195 100644 --- a/fpdfsdk/src/fpdfeditimg.cpp +++ b/fpdfsdk/src/fpdfeditimg.cpp @@ -30,7 +30,9 @@ 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 = (CPDF_Page*)pages[index]; + CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]); + if (!pPage) + continue; pImgObj->m_pImage->ResetCache(pPage, NULL); } pImgObj->m_pImage->SetJpegImage(pFile); @@ -69,7 +71,9 @@ 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 = (CPDF_Page*)pages[index]; + CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]); + if (!pPage) + continue; pImgObj->m_pImage->ResetCache(pPage, NULL); } pImgObj->m_pImage->SetImage(pBmp, FALSE); diff --git a/fpdfsdk/src/fpdfeditpage.cpp b/fpdfsdk/src/fpdfeditpage.cpp index 6e1b852a47..f2d13d6ba1 100644 --- a/fpdfsdk/src/fpdfeditpage.cpp +++ b/fpdfsdk/src/fpdfeditpage.cpp @@ -85,7 +85,7 @@ DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, } DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) { - CPDF_Page* pPage = (CPDF_Page*)page; + 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( @@ -129,7 +129,7 @@ DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) { DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, FPDF_PAGEOBJECT page_obj) { - CPDF_Page* pPage = (CPDF_Page*)page; + 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( @@ -171,13 +171,10 @@ DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, default: break; } - - // pPage->ParseContent(); - // pPage->GenerateContent(); } DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) { - CPDF_Page* pPage = (CPDF_Page*)page; + 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( @@ -185,27 +182,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 = (CPDF_Page*)page; + 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 = (CPDF_Page*)page; - - return pPage->BackgroundAlphaNeeded(); + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + return pPage && pPage->BackgroundAlphaNeeded(); } DLLEXPORT FPDF_BOOL STDCALL @@ -247,7 +239,7 @@ FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) { } DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page) { - CPDF_Page* pPage = (CPDF_Page*)page; + 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( @@ -282,9 +274,9 @@ DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, double d, double e, double f) { - if (page == NULL) + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + if (!pPage) return; - CPDF_Page* pPage = (CPDF_Page*)page; CPDF_AnnotList AnnotList(pPage); for (int i = 0; i < AnnotList.Count(); i++) { CPDF_Annot* pAnnot = AnnotList.GetAt(i); @@ -310,7 +302,7 @@ DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, } DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) { - CPDF_Page* pPage = (CPDF_Page*)page; + 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 02f906f513..7c2c350501 100644 --- a/fpdfsdk/src/fpdfformfill.cpp +++ b/fpdfsdk/src/fpdfformfill.cpp @@ -24,11 +24,12 @@ CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) { CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, FPDF_PAGE page) { - if (!page) + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + if (!pPage) return nullptr; CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); - return pSDKDoc ? pSDKDoc->GetPageView((CPDF_Page*)page, TRUE) : nullptr; + return pSDKDoc ? pSDKDoc->GetPageView(pPage, TRUE) : nullptr; } } // namespace @@ -37,10 +38,11 @@ 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 = CPDFPageFromFPDFPage(page); + if (!pPage) return -1; - - CPDF_Page* pPage = (CPDF_Page*)page; CPDF_InterForm interform(pPage->m_pDocument, FALSE); CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint( pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, nullptr); @@ -48,10 +50,7 @@ DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, return -1; CPDF_FormField* pFormField = pFormCtrl->GetField(); - if (!pFormField) - return -1; - - return pFormField->GetFieldType(); + return pFormField ? pFormField->GetFieldType() : -1; } DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, @@ -65,10 +64,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, @@ -192,10 +192,13 @@ DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, int size_y, int rotate, int flags) { - if (!hHandle || !page) + if (!hHandle) + return; + + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + if (!pPage) return; - CPDF_Page* pPage = (CPDF_Page*)page; CPDF_RenderOptions options; if (flags & FPDF_LCD_TEXT) options.m_Flags |= RENDER_CLEARTYPE; @@ -263,14 +266,17 @@ DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page, DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, FPDF_FORMHANDLE hHandle) { - if (!hHandle || !page) + if (!hHandle) return; CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument(); if (!pSDKDoc) return; - CPDF_Page* pPage = (CPDF_Page*)page; + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + if (!pPage) + return; + CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE); if (pPageView) { pPageView->SetValid(FALSE); @@ -316,10 +322,12 @@ DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, FPDF_FORMHANDLE hHandle, int aaType) { - if (!hHandle || !page) + if (!hHandle) return; CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument(); - CPDF_Page* pPage = (CPDF_Page*)page; + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + if (!pPage) + return; CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE); if (pPageView) { CPDFDoc_Environment* pEnv = pSDKDoc->GetEnv(); diff --git a/fpdfsdk/src/fpdftext.cpp b/fpdfsdk/src/fpdftext.cpp index 43edd525e8..800c138f3f 100644 --- a/fpdfsdk/src/fpdftext.cpp +++ b/fpdfsdk/src/fpdftext.cpp @@ -7,18 +7,19 @@ #include "../../core/include/fpdfdoc/fpdf_doc.h" #include "../../core/include/fpdftext/fpdf_text.h" #include "../../public/fpdf_text.h" +#include "../include/fsdk_define.h" #ifdef _WIN32 #include <tchar.h> #endif DLLEXPORT FPDF_TEXTPAGE STDCALL FPDFText_LoadPage(FPDF_PAGE page) { - if (!page) - return NULL; - IPDF_TextPage* textpage = NULL; - CPDF_ViewerPreferences viewRef(((CPDF_Page*)page)->m_pDocument); - textpage = - IPDF_TextPage::CreateTextPage((CPDF_Page*)page, viewRef.IsDirectionR2L()); + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + if (!pPage) + return nullptr; + CPDF_ViewerPreferences viewRef(pPage->m_pDocument); + IPDF_TextPage* textpage = + IPDF_TextPage::CreateTextPage(pPage, viewRef.IsDirectionR2L()); textpage->ParseTextPage(); return textpage; } diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp index 17f52ec263..b2c5618a52 100644 --- a/fpdfsdk/src/fpdfview.cpp +++ b/fpdfsdk/src/fpdfview.cpp @@ -20,6 +20,10 @@ CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { return static_cast<CPDF_Document*>(doc); } +CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { + return static_cast<CPDF_Page*>(page); +} + CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) { if (pFileAccess) m_FileAccess = *pFileAccess; @@ -284,15 +288,13 @@ DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, } DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { - if (!page) - return 0.0; - return ((CPDF_Page*)page)->GetPageWidth(); + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + return pPage ? pPage->GetPageWidth() : 0.0; } DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { - if (!page) - return 0.0; - return ((CPDF_Page*)page)->GetPageHeight(); + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + return pPage ? pPage->GetPageHeight() : 0.0; } void DropContext(void* data) { @@ -312,9 +314,9 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, int size_y, int rotate, int flags) { - if (page == NULL) + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + if (!pPage) return; - CPDF_Page* pPage = (CPDF_Page*)page; CRenderContext* pContext = new CRenderContext; pPage->SetPrivateData((void*)1, pContext, DropContext); @@ -472,10 +474,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 = CPDFPageFromFPDFPage(page); + if (!pPage) return; - CPDF_Page* pPage = (CPDF_Page*)page; - CRenderContext* pContext = new CRenderContext; pPage->SetPrivateData((void*)1, pContext, DropContext); #ifdef _SKIA_SUPPORT_ @@ -570,10 +573,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; + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + if (!pPage) return; - CPDF_Page* pPage = (CPDF_Page*)page; - CPDF_Matrix page2device; pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, rotate); @@ -681,8 +685,8 @@ void FPDF_RenderPage_Retail(CRenderContext* pContext, int flags, FX_BOOL bNeedToRestore, IFSDK_PAUSE_Adapter* pause) { - CPDF_Page* pPage = (CPDF_Page*)page; - if (pPage == NULL) + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + if (!pPage) return; if (!pContext->m_pOptions) |