From 55dd8546ebc365b3778b40ba9d82879f581503e1 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 24 Nov 2015 13:31:52 -0800 Subject: Add "Underlying types" to master. Change some master code to line up better with XFA, so that the XFA changes are additive when possible, rather than replacements. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1468253005 . --- fpdfsdk/include/fsdk_baseannot.h | 2 ++ fpdfsdk/include/fsdk_define.h | 12 +++++++ fpdfsdk/include/fsdk_mgr.h | 29 +++++++++------- fpdfsdk/src/fpdfformfill.cpp | 23 +++++++------ fpdfsdk/src/fpdfview.cpp | 51 ++++++++++++++++++---------- fpdfsdk/src/fsdk_actionhandler.cpp | 4 +-- fpdfsdk/src/fsdk_annothandler.cpp | 34 ++++++++----------- fpdfsdk/src/fsdk_baseannot.cpp | 4 +++ fpdfsdk/src/fsdk_baseform.cpp | 23 ++++--------- fpdfsdk/src/fsdk_mgr.cpp | 68 ++++++++++++++++++------------------- fpdfsdk/src/javascript/Document.cpp | 4 +-- fpdfsdk/src/javascript/Field.cpp | 5 ++- 12 files changed, 141 insertions(+), 118 deletions(-) diff --git a/fpdfsdk/include/fsdk_baseannot.h b/fpdfsdk/include/fsdk_baseannot.h index 2e54096c76..f747f8576b 100644 --- a/fpdfsdk/include/fsdk_baseannot.h +++ b/fpdfsdk/include/fsdk_baseannot.h @@ -15,6 +15,7 @@ #include "core/include/fpdfdoc/fpdf_doc.h" #include "core/include/fxcrt/fx_basic.h" +#include "fpdfsdk/include/fsdk_define.h" #include "fx_systemhandler.h" class CPDFSDK_PageView; @@ -88,6 +89,7 @@ class CPDFSDK_Annot { CPDF_Matrix* pUser2Device, CPDF_RenderOptions* pOptions) {} + UnderlyingPageType* GetUnderlyingPage(); CPDF_Page* GetPDFPage(); void SetPage(CPDFSDK_PageView* pPageView) { m_pPageView = pPageView; } diff --git a/fpdfsdk/include/fsdk_define.h b/fpdfsdk/include/fsdk_define.h index bca7805226..980411c27b 100644 --- a/fpdfsdk/include/fsdk_define.h +++ b/fpdfsdk/include/fsdk_define.h @@ -52,6 +52,18 @@ class CPDF_CustomAccess final : public IFX_FileRead { FPDF_FILEACCESS m_FileAccess; }; +// Object types for public FPDF_ types; these correspond to next layer down +// from fpdfsdk. For master, these are CPDF_ types, but for XFA, these are +// CPDFXFA_ types. +using UnderlyingDocumentType = CPDF_Document; +using UnderlyingPageType = CPDF_Page; + +// Conversions to/from underlying types. +UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc); +FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc); + +UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page); + // Conversions to/from FPDF_ types. CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc); FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc); diff --git a/fpdfsdk/include/fsdk_mgr.h b/fpdfsdk/include/fsdk_mgr.h index b7b349197a..a4385be318 100644 --- a/fpdfsdk/include/fsdk_mgr.h +++ b/fpdfsdk/include/fsdk_mgr.h @@ -33,7 +33,7 @@ class IFX_SystemHandler; class CPDFDoc_Environment final { public: - CPDFDoc_Environment(CPDF_Document* pDoc, FPDF_FORMFILLINFO* pFFinfo); + CPDFDoc_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo); ~CPDFDoc_Environment(); void FFI_Invalidate(FPDF_PAGE page, @@ -203,7 +203,9 @@ class CPDFDoc_Environment final { FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; } void SetSDKDocument(CPDFSDK_Document* pFXDoc) { m_pSDKDoc = pFXDoc; } CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc; } - CPDF_Document* GetPDFDocument() const { return m_pPDFDoc; } + UnderlyingDocumentType* GetUnderlyingDocument() const { + return m_pUnderlyingDoc; + } CFX_ByteString GetAppName() const { return ""; } IFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); } FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; } @@ -219,30 +221,33 @@ class CPDFDoc_Environment final { nonstd::unique_ptr m_pJSRuntime; FPDF_FORMFILLINFO* const m_pInfo; CPDFSDK_Document* m_pSDKDoc; - CPDF_Document* const m_pPDFDoc; + UnderlyingDocumentType* const m_pUnderlyingDoc; nonstd::unique_ptr m_pIFormFiller; nonstd::unique_ptr m_pSysHandler; }; class CPDFSDK_Document { public: - CPDFSDK_Document(CPDF_Document* pDoc, CPDFDoc_Environment* pEnv); + CPDFSDK_Document(UnderlyingDocumentType* pDoc, CPDFDoc_Environment* pEnv); ~CPDFSDK_Document(); CPDFSDK_InterForm* GetInterForm(); // Gets the document object for the next layer down; for master this is // a CPDF_Document, but for XFA it is a CPDFXFA_Document. - CPDF_Document* GetDocument() const { return m_pDoc; } + UnderlyingDocumentType* GetUnderlyingDocument() const { + return GetPDFDocument(); + } // Gets the CPDF_Document, either directly in master, or from the // CPDFXFA_Document for XFA. CPDF_Document* GetPDFDocument() const { return m_pDoc; } - CPDFSDK_PageView* GetPageView(CPDF_Page* pPDFPage, FX_BOOL ReNew = TRUE); + CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPage, + FX_BOOL ReNew = TRUE); CPDFSDK_PageView* GetPageView(int nIndex); CPDFSDK_PageView* GetCurrentView(); - void ReMovePageView(CPDF_Page* pPDFPage); + void RemovePageView(UnderlyingPageType* pPage); void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot); CPDFSDK_Annot* GetFocusAnnot(); @@ -269,15 +274,15 @@ class CPDFSDK_Document { void SetChangeMark() { m_bChangeMask = TRUE; } void ClearChangeMark() { m_bChangeMask = FALSE; } CFX_WideString GetPath(); - CPDF_Page* GetPage(int nIndex); + UnderlyingPageType* GetPage(int nIndex); CPDFDoc_Environment* GetEnv() { return m_pEnv; } void ProcJavascriptFun(); FX_BOOL ProcOpenAction(); CPDF_OCContext* GetOCContext(); private: - std::map m_pageMap; - CPDF_Document* m_pDoc; + std::map m_pageMap; + UnderlyingDocumentType* m_pDoc; nonstd::unique_ptr m_pInterForm; CPDFSDK_Annot* m_pFocusAnnot; CPDFDoc_Environment* m_pEnv; @@ -287,7 +292,7 @@ class CPDFSDK_Document { }; class CPDFSDK_PageView final { public: - CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, CPDF_Page* page); + CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, UnderlyingPageType* page); ~CPDFSDK_PageView(); void PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, @@ -348,7 +353,7 @@ class CPDFSDK_PageView final { CPDFSDK_Widget* pWidget); CPDF_Matrix m_curMatrix; - CPDF_Page* m_page; + UnderlyingPageType* m_page; nonstd::unique_ptr m_pAnnotList; std::vector m_fxAnnotArray; CPDFSDK_Document* m_pSDKDoc; diff --git a/fpdfsdk/src/fpdfformfill.cpp b/fpdfsdk/src/fpdfformfill.cpp index 06ea2ce755..525cb152b1 100644 --- a/fpdfsdk/src/fpdfformfill.cpp +++ b/fpdfsdk/src/fpdfformfill.cpp @@ -25,7 +25,7 @@ CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) { CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, FPDF_PAGE page) { - CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); if (!pPage) return nullptr; @@ -80,12 +80,14 @@ DLLEXPORT int STDCALL FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle, DLLEXPORT FPDF_FORMHANDLE STDCALL FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, FPDF_FORMFILLINFO* formInfo) { - if (!formInfo || formInfo->version != 1) + const int kRequiredVersion = 1; + if (!formInfo || formInfo->version != kRequiredVersion) return nullptr; - CPDF_Document* pDocument = CPDFDocumentFromFPDFDocument(document); + UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document); if (!pDocument) return nullptr; + CPDFDoc_Environment* pEnv = new CPDFDoc_Environment(pDocument, formInfo); pEnv->SetSDKDocument(new CPDFSDK_Document(pDocument, pEnv)); return pEnv; @@ -274,15 +276,15 @@ DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, if (!pSDKDoc) return; - CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); if (!pPage) return; CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE); if (pPageView) { pPageView->SetValid(FALSE); - // ReMovePageView() takes care of the delete for us. - pSDKDoc->ReMovePageView(pPage); + // RemovePageView() takes care of the delete for us. + pSDKDoc->RemovePageView(pPage); } } @@ -304,7 +306,7 @@ DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, if (!pSDKDoc) return; - CPDF_Document* pDoc = pSDKDoc->GetDocument(); + CPDF_Document* pDoc = pSDKDoc->GetPDFDocument(); CPDF_Dictionary* pDic = pDoc->GetRoot(); if (!pDic) return; @@ -326,13 +328,14 @@ DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, if (!hHandle) return; CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument(); - CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage) + UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); + CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); + if (!pPDFPage) return; if (pSDKDoc->GetPageView(pPage, FALSE)) { CPDFDoc_Environment* pEnv = pSDKDoc->GetEnv(); CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); - CPDF_Dictionary* pPageDict = pPage->m_pFormDict; + CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict; CPDF_AAction aa = pPageDict->GetDict(FX_BSTRC("AA")); if (FPDFPAGE_AACTION_OPEN == aaType) { if (aa.ActionExist(CPDF_AAction::OpenPage)) { diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp index 6ffb523468..fcb6731563 100644 --- a/fpdfsdk/src/fpdfview.cpp +++ b/fpdfsdk/src/fpdfview.cpp @@ -17,21 +17,32 @@ #include "third_party/base/nonstd_unique_ptr.h" #include "third_party/base/numerics/safe_conversions_impl.h" +UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc) { + return static_cast(doc); +} + +FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc) { + return static_cast(doc); +} + +UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page) { + return static_cast(page); +} + CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { - return static_cast(doc); + return UnderlyingFromFPDFDocument(doc); } FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { - return static_cast(doc); + return FPDFDocumentFromUnderlying(doc); } CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { - return static_cast(page); + return UnderlyingFromFPDFPage(page); } CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) { - if (pFileAccess) - m_FileAccess = *pFileAccess; + m_FileAccess = *pFileAccess; } FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, @@ -240,7 +251,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, if (!pDoc) return FALSE; - CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); + CPDF_Parser* pParser = pDoc->GetParser(); if (!pParser) return FALSE; @@ -269,17 +280,17 @@ DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) { } DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) { - CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); + UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); return pDoc ? pDoc->GetPageCount() : 0; } DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, int page_index) { - CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); + UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); if (!pDoc) return nullptr; - if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) + if (page_index < 0 || page_index >= pDoc->GetPageCount()) return nullptr; CPDF_Dictionary* pDict = pDoc->GetPage(page_index); @@ -292,12 +303,12 @@ DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, } DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { - CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); return pPage ? pPage->GetPageWidth() : 0.0; } DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { - CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); return pPage ? pPage->GetPageHeight() : 0.0; } @@ -551,7 +562,7 @@ DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, double* page_y) { if (page == NULL || page_x == NULL || page_y == NULL) return; - CPDF_Page* pPage = (CPDF_Page*)page; + UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); CPDF_Matrix page2device; pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, @@ -579,7 +590,7 @@ DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, int* device_y) { if (!device_x || !device_y) return; - CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); if (!pPage) return; CPDF_Matrix page2device; @@ -757,7 +768,7 @@ DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, int page_index, double* width, double* height) { - CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); + UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); if (!pDoc) return FALSE; @@ -851,13 +862,17 @@ DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, long* buflen) { if (!buffer) *buflen = 0; - if (!document || index < 0) - return NULL; - CPDF_Document* pDoc = (CPDF_Document*)document; + + if (index < 0) + return nullptr; + + CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); + if (!pDoc) + return nullptr; CPDF_Dictionary* pRoot = pDoc->GetRoot(); if (!pRoot) - return NULL; + return nullptr; CPDF_Object* pDestObj = NULL; CFX_ByteString bsName; diff --git a/fpdfsdk/src/fsdk_actionhandler.cpp b/fpdfsdk/src/fsdk_actionhandler.cpp index 736b4074f4..0043bc7787 100644 --- a/fpdfsdk/src/fsdk_actionhandler.cpp +++ b/fpdfsdk/src/fsdk_actionhandler.cpp @@ -433,7 +433,7 @@ void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument, const CPDF_Action& action) { ASSERT(action); - CPDF_Document* pPDFDocument = pDocument->GetDocument(); + CPDF_Document* pPDFDocument = pDocument->GetPDFDocument(); ASSERT(pPDFDocument); CPDF_Dest MyDest = action.GetDest(pPDFDocument); @@ -469,7 +469,7 @@ void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument, CPDFDoc_Environment* pApp = pDocument->GetEnv(); ASSERT(pApp != NULL); - CFX_ByteString sURI = action.GetURI(pDocument->GetDocument()); + CFX_ByteString sURI = action.GetURI(pDocument->GetPDFDocument()); pApp->FFI_DoURIAction(sURI.c_str()); } diff --git a/fpdfsdk/src/fsdk_annothandler.cpp b/fpdfsdk/src/fsdk_annothandler.cpp index 9209a46f49..ee06091bff 100644 --- a/fpdfsdk/src/fsdk_annothandler.cpp +++ b/fpdfsdk/src/fsdk_annothandler.cpp @@ -577,28 +577,24 @@ void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) { } void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) { - ASSERT(pAnnot != NULL); - - CFX_ByteString sSubType = pAnnot->GetSubType(); + if (pAnnot->GetSubType() == BFFT_SIGNATURE) + return; - if (sSubType == BFFT_SIGNATURE) { - } else { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - if (!pWidget->IsAppearanceValid()) - pWidget->ResetAppearance(NULL, FALSE); - - int nFieldType = pWidget->GetFieldType(); - if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) { - FX_BOOL bFormated = FALSE; - CFX_WideString sValue = pWidget->OnFormat(bFormated); - if (bFormated && nFieldType == FIELDTYPE_COMBOBOX) { - pWidget->ResetAppearance(sValue.c_str(), FALSE); - } + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + if (!pWidget->IsAppearanceValid()) + pWidget->ResetAppearance(NULL, FALSE); + + int nFieldType = pWidget->GetFieldType(); + if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) { + FX_BOOL bFormated = FALSE; + CFX_WideString sValue = pWidget->OnFormat(bFormated); + if (bFormated && nFieldType == FIELDTYPE_COMBOBOX) { + pWidget->ResetAppearance(sValue.c_str(), FALSE); } - - if (m_pFormFiller) - m_pFormFiller->OnLoad(pAnnot); } + + if (m_pFormFiller) + m_pFormFiller->OnLoad(pAnnot); } FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, diff --git a/fpdfsdk/src/fsdk_baseannot.cpp b/fpdfsdk/src/fsdk_baseannot.cpp index 8cd3df97c0..e124ace2a3 100644 --- a/fpdfsdk/src/fsdk_baseannot.cpp +++ b/fpdfsdk/src/fsdk_baseannot.cpp @@ -976,6 +976,10 @@ void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice, return; } +UnderlyingPageType* CPDFSDK_Annot::GetUnderlyingPage() { + return GetPDFPage(); +} + CPDF_Page* CPDFSDK_Annot::GetPDFPage() { if (m_pPageView) return m_pPageView->GetPDFPage(); diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp index 3a304986d4..98836e9465 100644 --- a/fpdfsdk/src/fsdk_baseform.cpp +++ b/fpdfsdk/src/fsdk_baseform.cpp @@ -76,8 +76,6 @@ int CPDFSDK_Widget::GetFieldType() const { } FX_BOOL CPDFSDK_Widget::IsAppearanceValid() { - ASSERT(m_pPageView != NULL); - return CPDFSDK_BAAnnot::IsAppearanceValid(); } @@ -1435,11 +1433,11 @@ void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) { FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, PDFSDK_FieldAction& data, CPDFSDK_PageView* pPageView) { + CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); + CPDFDoc_Environment* pEnv = pDocument->GetEnv(); CPDF_Action action = GetAAction(type); if (action && action.GetType() != CPDF_Action::Unknown) { - CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); - CPDFDoc_Environment* pEnv = pDocument->GetEnv(); CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); return pActionHandler->DoAction_Field(action, type, pDocument, GetFormField(), data); @@ -1514,9 +1512,7 @@ CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_Document* pDocument) m_pInterForm(NULL), m_bCalculate(TRUE), m_bBusy(FALSE) { - ASSERT(m_pDocument != NULL); - m_pInterForm = new CPDF_InterForm(m_pDocument->GetDocument(), FALSE); - ASSERT(m_pInterForm != NULL); + m_pInterForm = new CPDF_InterForm(m_pDocument->GetPDFDocument(), FALSE); m_pInterForm->SetFormNotify(this); for (int i = 0; i < kNumFieldTypes; ++i) @@ -1558,7 +1554,7 @@ CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const { return pWidget; CPDF_Dictionary* pControlDict = pControl->GetWidget(); - CPDF_Document* pDocument = m_pDocument->GetDocument(); + CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); CPDFSDK_PageView* pPage = nullptr; if (CPDF_Dictionary* pPageDict = pControlDict->GetDict("P")) { @@ -1643,10 +1639,7 @@ FX_BOOL CPDFSDK_InterForm::IsCalculateEnabled() const { #ifdef _WIN32 CPDF_Stream* CPDFSDK_InterForm::LoadImageFromFile(const CFX_WideString& sFile) { - ASSERT(m_pDocument != NULL); - CPDF_Document* pDocument = m_pDocument->GetDocument(); - ASSERT(pDocument != NULL); - + CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); CPDF_Stream* pRetStream = NULL; if (CFX_DIBitmap* pBmp = CFX_WindowsDIB::LoadFromFile(sFile.c_str())) { @@ -1835,8 +1828,6 @@ void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField, } void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) { - ASSERT(pFormField != NULL); - for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); ASSERT(pFormCtrl != NULL); @@ -1844,10 +1835,8 @@ void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) { if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) { CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); CFFL_IFormFiller* pIFormFiller = pEnv->GetIFormFiller(); - - CPDF_Page* pPage = pWidget->GetPDFPage(); + UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage, FALSE); - FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget); pEnv->FFI_Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right, diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp index 09b0e0aa20..480dc4a51f 100644 --- a/fpdfsdk/src/fsdk_mgr.cpp +++ b/fpdfsdk/src/fsdk_mgr.cpp @@ -90,12 +90,9 @@ void CFX_SystemHandler::SetCursor(int32_t nCursorType) { } void CFX_SystemHandler::InvalidateRect(FX_HWND hWnd, FX_RECT rect) { - // g_pFormFillApp->FFI_Invalidate(); CPDFSDK_Annot* pSDKAnnot = (CPDFSDK_Annot*)hWnd; - CPDF_Page* pPage = NULL; - CPDFSDK_PageView* pPageView = NULL; - pPageView = pSDKAnnot->GetPageView(); - pPage = pSDKAnnot->GetPDFPage(); + CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView(); + UnderlyingPageType* pPage = pSDKAnnot->GetUnderlyingPage(); if (!pPage || !pPageView) return; CPDF_Matrix page2device; @@ -119,10 +116,8 @@ void CFX_SystemHandler::OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect) { CPDF_Point righttop = CPDF_Point(rect.right, rect.top); CPDF_Point ptA = pFFL->PWLtoFFL(leftbottom); CPDF_Point ptB = pFFL->PWLtoFFL(righttop); - CPDFSDK_Annot* pAnnot = pFFL->GetSDKAnnot(); - ASSERT(pAnnot); - CPDF_Page* pPage = pAnnot->GetPDFPage(); + UnderlyingPageType* pPage = pAnnot->GetUnderlyingPage(); ASSERT(pPage); m_pEnv->FFI_OutputSelectedRect(pPage, ptA.x, ptB.y, ptB.x, ptA.y); } @@ -205,9 +200,9 @@ FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime() { return m_pEnv->FFI_GetLocalTime(); } -CPDFDoc_Environment::CPDFDoc_Environment(CPDF_Document* pDoc, +CPDFDoc_Environment::CPDFDoc_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo) - : m_pInfo(pFFinfo), m_pSDKDoc(NULL), m_pPDFDoc(pDoc) { + : m_pInfo(pFFinfo), m_pSDKDoc(NULL), m_pUnderlyingDoc(pDoc) { m_pSysHandler.reset(new CFX_SystemHandler(this)); } @@ -382,14 +377,13 @@ CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller() { return m_pIFormFiller.get(); } -CPDFSDK_Document::CPDFSDK_Document(CPDF_Document* pDoc, +CPDFSDK_Document::CPDFSDK_Document(UnderlyingDocumentType* pDoc, CPDFDoc_Environment* pEnv) : m_pDoc(pDoc), m_pFocusAnnot(nullptr), m_pEnv(pEnv), m_bChangeMask(FALSE), - m_bBeingDestroyed(FALSE) { -} + m_bBeingDestroyed(FALSE) {} CPDFSDK_Document::~CPDFSDK_Document() { m_bBeingDestroyed = TRUE; @@ -402,29 +396,32 @@ CPDFSDK_Document::~CPDFSDK_Document() { m_pageMap.clear(); } -CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDF_Page* pPDFPage, - FX_BOOL ReNew) { - auto it = m_pageMap.find(pPDFPage); +CPDFSDK_PageView* CPDFSDK_Document::GetPageView( + UnderlyingPageType* pUnderlyingPage, + FX_BOOL ReNew) { + auto it = m_pageMap.find(pUnderlyingPage); if (it != m_pageMap.end()) return it->second; if (!ReNew) return nullptr; - CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pPDFPage); - m_pageMap[pPDFPage] = pPageView; + CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pUnderlyingPage); + m_pageMap[pUnderlyingPage] = pPageView; // Delay to load all the annotations, to avoid endless loop. pPageView->LoadFXAnnots(); return pPageView; } CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView() { - CPDF_Page* pPage = (CPDF_Page*)m_pEnv->FFI_GetCurrentPage(m_pDoc); + UnderlyingPageType* pPage = + UnderlyingFromFPDFPage(m_pEnv->FFI_GetCurrentPage(m_pDoc)); return pPage ? GetPageView(pPage, TRUE) : nullptr; } CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex) { - CPDF_Page* pTempPage = (CPDF_Page*)m_pEnv->FFI_GetPage(m_pDoc, nIndex); + UnderlyingPageType* pTempPage = + UnderlyingFromFPDFPage(m_pEnv->FFI_GetPage(m_pDoc, nIndex)); if (!pTempPage) return nullptr; @@ -433,7 +430,7 @@ CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex) { } void CPDFSDK_Document::ProcJavascriptFun() { - CPDF_Document* pPDFDoc = GetDocument(); + CPDF_Document* pPDFDoc = GetPDFDocument(); CPDF_DocJSActions docJS(pPDFDoc); int iCount = docJS.CountJSActions(); if (iCount < 1) @@ -451,7 +448,7 @@ FX_BOOL CPDFSDK_Document::ProcOpenAction() { if (!m_pDoc) return FALSE; - CPDF_Dictionary* pRoot = m_pDoc->GetRoot(); + CPDF_Dictionary* pRoot = GetPDFDocument()->GetRoot(); if (!pRoot) return FALSE; @@ -476,12 +473,12 @@ FX_BOOL CPDFSDK_Document::ProcOpenAction() { CPDF_OCContext* CPDFSDK_Document::GetOCContext() { if (!m_pOccontent) - m_pOccontent.reset(new CPDF_OCContext(m_pDoc)); + m_pOccontent.reset(new CPDF_OCContext(GetPDFDocument())); return m_pOccontent.get(); } -void CPDFSDK_Document::ReMovePageView(CPDF_Page* pPDFPage) { - auto it = m_pageMap.find(pPDFPage); +void CPDFSDK_Document::RemovePageView(UnderlyingPageType* pUnderlyingPage) { + auto it = m_pageMap.find(pUnderlyingPage); if (it == m_pageMap.end()) return; @@ -494,11 +491,8 @@ void CPDFSDK_Document::ReMovePageView(CPDF_Page* pPDFPage) { m_pageMap.erase(it); } -CPDF_Page* CPDFSDK_Document::GetPage(int nIndex) { - CPDF_Page* pTempPage = (CPDF_Page*)m_pEnv->FFI_GetPage(m_pDoc, nIndex); - if (!pTempPage) - return NULL; - return pTempPage; +UnderlyingPageType* CPDFSDK_Document::GetPage(int nIndex) { + return UnderlyingFromFPDFPage(m_pEnv->FFI_GetPage(m_pDoc, nIndex)); } CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm() { @@ -532,8 +526,12 @@ FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) { if (!KillFocusAnnot(nFlag)) return FALSE; } + + if (!pAnnot) + return FALSE; + CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); - if (pAnnot && pPageView->IsValid()) { + if (pPageView && pPageView->IsValid()) { CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); if (!m_pFocusAnnot) { if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, nFlag)) @@ -576,8 +574,7 @@ void CPDFSDK_Document::OnCloseDocument() { } FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag) { - FX_DWORD dwPermissions = m_pDoc->GetUserPermissions(); - return dwPermissions & nFlag; + return GetPDFDocument()->GetUserPermissions() & nFlag; } IJS_Runtime* CPDFSDK_Document::GetJsRuntime() { @@ -590,7 +587,8 @@ CFX_WideString CPDFSDK_Document::GetPath() { return m_pEnv->JS_docGetFilePath(); } -CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, CPDF_Page* page) +CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, + UnderlyingPageType* page) : m_page(page), m_pSDKDoc(pSDKDoc), m_CaptureWidget(nullptr), @@ -903,7 +901,7 @@ void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) { int CPDFSDK_PageView::GetPageIndex() { if (m_page) { CPDF_Dictionary* pDic = m_page->m_pFormDict; - CPDF_Document* pDoc = m_pSDKDoc->GetDocument(); + CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); if (pDoc && pDic) { return pDoc->GetPageIndex(pDic->GetObjNum()); } diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp index 9e352a1ab6..1fa88f9b12 100644 --- a/fpdfsdk/src/javascript/Document.cpp +++ b/fpdfsdk/src/javascript/Document.cpp @@ -536,7 +536,7 @@ FX_BOOL Document::removeField(IJS_Context* cc, CFX_RectArray aRefresh; aRefresh.Add(rcAnnot); - CPDF_Page* pPage = pWidget->GetPDFPage(); + UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); ASSERT(pPage); CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage); @@ -1019,7 +1019,7 @@ FX_BOOL Document::subject(IJS_Context* cc, FX_BOOL Document::title(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - if (m_pDocument == NULL || m_pDocument->GetPDFDocument() == NULL) + if (!m_pDocument || !m_pDocument->GetUnderlyingDocument()) return FALSE; CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); diff --git a/fpdfsdk/src/javascript/Field.cpp b/fpdfsdk/src/javascript/Field.cpp index 39d67d00dc..39e15e9868 100644 --- a/fpdfsdk/src/javascript/Field.cpp +++ b/fpdfsdk/src/javascript/Field.cpp @@ -3397,9 +3397,8 @@ FX_BOOL Field::setFocus(IJS_Context* cc, pWidget = pInterForm->GetWidget(pFormField->GetControl(0)); } else { CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); - ASSERT(pEnv); - CPDF_Page* pPage = - (CPDF_Page*)pEnv->FFI_GetCurrentPage(m_pDocument->GetDocument()); + UnderlyingPageType* pPage = UnderlyingFromFPDFPage( + pEnv->FFI_GetCurrentPage(m_pDocument->GetUnderlyingDocument())); if (!pPage) return FALSE; if (CPDFSDK_PageView* pCurPageView = m_pDocument->GetPageView(pPage)) { -- cgit v1.2.3