From 51da093564cdfd32a6ac02ad75e981787a0f1b35 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 25 Nov 2015 16:05:49 -0800 Subject: Inflict PDF_ENABLE_XFA ifdefs on XFA fpdfsdk/ R=thestig@chromium.org Review URL: https://codereview.chromium.org/1477583002 . --- fpdfsdk/include/formfiller/FFL_ComboBox.h | 2 + fpdfsdk/include/formfiller/FFL_FormFiller.h | 2 + fpdfsdk/include/formfiller/FFL_IFormFiller.h | 6 ++ fpdfsdk/include/formfiller/FFL_TextField.h | 2 + fpdfsdk/include/fsdk_annothandler.h | 16 ++++ fpdfsdk/include/fsdk_baseannot.h | 12 +++ fpdfsdk/include/fsdk_baseform.h | 33 ++++++++ fpdfsdk/include/fsdk_define.h | 17 ++++ fpdfsdk/include/fsdk_mgr.h | 38 +++++++++ fpdfsdk/include/javascript/IJavaScript.h | 4 + fpdfsdk/include/jsapi/fxjs_v8.h | 10 +++ fpdfsdk/include/pdfwindow/PWL_Edit.h | 2 + fpdfsdk/src/formfiller/FFL_ComboBox.cpp | 2 + fpdfsdk/src/formfiller/FFL_FormFiller.cpp | 2 + fpdfsdk/src/formfiller/FFL_IFormFiller.cpp | 6 ++ fpdfsdk/src/formfiller/FFL_TextField.cpp | 2 + fpdfsdk/src/fpdf_ext.cpp | 11 +++ fpdfsdk/src/fpdfeditpage.cpp | 8 ++ fpdfsdk/src/fpdfformfill.cpp | 68 +++++++++++++++ fpdfsdk/src/fpdfsave.cpp | 10 +++ fpdfsdk/src/fpdftext.cpp | 6 ++ fpdfsdk/src/fpdfview.cpp | 119 +++++++++++++++++++++++++++ fpdfsdk/src/fpdfview_c_api_test.c | 6 ++ fpdfsdk/src/fsdk_annothandler.cpp | 23 ++++++ fpdfsdk/src/fsdk_baseannot.cpp | 10 +++ fpdfsdk/src/fsdk_baseform.cpp | 50 +++++++++++ fpdfsdk/src/fsdk_mgr.cpp | 91 ++++++++++++++++++++ fpdfsdk/src/javascript/JS_Context.cpp | 2 + fpdfsdk/src/javascript/JS_Runtime.cpp | 31 +++++++ fpdfsdk/src/javascript/JS_Runtime.h | 2 + fpdfsdk/src/javascript/JS_Runtime_Stub.cpp | 2 + fpdfsdk/src/javascript/app.cpp | 4 + fpdfsdk/src/jsapi/fxjs_v8.cpp | 8 ++ fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp | 4 + fpdfsdk/src/pdfwindow/PWL_ComboBox.cpp | 10 +++ 35 files changed, 621 insertions(+) diff --git a/fpdfsdk/include/formfiller/FFL_ComboBox.h b/fpdfsdk/include/formfiller/FFL_ComboBox.h index ce244d80bb..f8f5c3c191 100644 --- a/fpdfsdk/include/formfiller/FFL_ComboBox.h +++ b/fpdfsdk/include/formfiller/FFL_ComboBox.h @@ -55,9 +55,11 @@ class CFFL_ComboBox : public CFFL_FormFiller, // IPWL_Edit_Notify: void OnAddUndo(CPWL_Edit* pEdit) override; +#ifdef PDF_ENABLE_XFA // CFFL_FormFiller: FX_BOOL IsFieldFull(CPDFSDK_PageView* pPageView) override; +#endif private: CFX_WideString GetSelectExportText(); diff --git a/fpdfsdk/include/formfiller/FFL_FormFiller.h b/fpdfsdk/include/formfiller/FFL_FormFiller.h index 5cfa2b6878..83b9902aa5 100644 --- a/fpdfsdk/include/formfiller/FFL_FormFiller.h +++ b/fpdfsdk/include/formfiller/FFL_FormFiller.h @@ -120,8 +120,10 @@ class CFFL_FormFiller : public IPWL_Provider, public CPWL_TimerHandler { virtual FX_BOOL IsDataChanged(CPDFSDK_PageView* pPageView); virtual void SaveData(CPDFSDK_PageView* pPageView); +#ifdef PDF_ENABLE_XFA virtual FX_BOOL IsFieldFull(CPDFSDK_PageView* pPageView); +#endif CPWL_Wnd* GetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bNew); void DestroyPDFWindow(CPDFSDK_PageView* pPageView); void EscapeFiller(CPDFSDK_PageView* pPageView, FX_BOOL bDestroyPDFWindow); diff --git a/fpdfsdk/include/formfiller/FFL_IFormFiller.h b/fpdfsdk/include/formfiller/FFL_IFormFiller.h index 79a8964626..bfdce10f59 100644 --- a/fpdfsdk/include/formfiller/FFL_IFormFiller.h +++ b/fpdfsdk/include/formfiller/FFL_IFormFiller.h @@ -112,6 +112,7 @@ class CFFL_IFormFiller : public IPWL_Filler_Notify { FX_BOOL& bReset, FX_BOOL& bExit, FX_UINT nFlag); +#ifdef PDF_ENABLE_XFA void OnClick(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bReset, @@ -132,6 +133,7 @@ class CFFL_IFormFiller : public IPWL_Filler_Notify { FX_BOOL& bReset, FX_BOOL& bExit, FX_UINT nFlag); +#endif private: using CFFL_Widget2Filler = std::map; @@ -151,17 +153,21 @@ class CFFL_IFormFiller : public IPWL_Filler_Notify { FX_BOOL& bRC, FX_BOOL& bExit, FX_DWORD nFlag) override; +#ifdef PDF_ENABLE_XFA void OnPopupPreOpen(void* pPrivateData, FX_BOOL& bExit, FX_DWORD nFlag) override; void OnPopupPostOpen(void* pPrivateData, FX_BOOL& bExit, FX_DWORD nFlag) override; +#endif void UnRegisterFormFiller(CPDFSDK_Annot* pAnnot); +#ifdef PDF_ENABLE_XFA void SetFocusAnnotTab(CPDFSDK_Annot* pWidget, FX_BOOL bSameField, FX_BOOL bNext); +#endif CPDFDoc_Environment* m_pApp; CFFL_Widget2Filler m_Maps; diff --git a/fpdfsdk/include/formfiller/FFL_TextField.h b/fpdfsdk/include/formfiller/FFL_TextField.h index 49a0f24e16..a6065fe992 100644 --- a/fpdfsdk/include/formfiller/FFL_TextField.h +++ b/fpdfsdk/include/formfiller/FFL_TextField.h @@ -56,9 +56,11 @@ class CFFL_TextField : public CFFL_FormFiller, // IPWL_Edit_Notify: void OnAddUndo(CPWL_Edit* pEdit) override; +#ifdef PDF_ENABLE_XFA // CFFL_FormFiller: FX_BOOL IsFieldFull(CPDFSDK_PageView* pPageView) override; +#endif private: CBA_FontMap* m_pFontMap; FFL_TextFieldState m_State; diff --git a/fpdfsdk/include/fsdk_annothandler.h b/fpdfsdk/include/fsdk_annothandler.h index 19051ee8de..d43bc7b7e9 100644 --- a/fpdfsdk/include/fsdk_annothandler.h +++ b/fpdfsdk/include/fsdk_annothandler.h @@ -12,8 +12,10 @@ #include "core/include/fxcrt/fx_basic.h" +#ifdef PDF_ENABLE_XFA #define FSDK_XFAWIDGET_TYPENAME "XFAWidget" +#endif class CFFL_IFormFiller; class CFX_RenderDevice; class CPDFDoc_Environment; @@ -37,9 +39,11 @@ class IPDFSDK_AnnotHandler { virtual CPDFSDK_Annot* NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage) = 0; +#ifdef PDF_ENABLE_XFA virtual CPDFSDK_Annot* NewAnnot(IXFA_Widget* hWidget, CPDFSDK_PageView* pPage) = 0; +#endif virtual void ReleaseAnnot(CPDFSDK_Annot* pAnnot) = 0; virtual void DeleteAnnot(CPDFSDK_Annot* pAnnot) = 0; @@ -124,8 +128,10 @@ class IPDFSDK_AnnotHandler { virtual FX_BOOL OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) = 0; virtual FX_BOOL OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) = 0; +#ifdef PDF_ENABLE_XFA virtual FX_BOOL OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot, CPDFSDK_Annot* pNewAnnot) = 0; +#endif }; class CPDFSDK_BFAnnotHandler : public IPDFSDK_AnnotHandler { @@ -139,8 +145,10 @@ class CPDFSDK_BFAnnotHandler : public IPDFSDK_AnnotHandler { CFX_ByteString GetName() override { return CFX_ByteString("WidgetHandler"); } FX_BOOL CanAnswer(CPDFSDK_Annot* pAnnot) override; CPDFSDK_Annot* NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage) override; +#ifdef PDF_ENABLE_XFA CPDFSDK_Annot* NewAnnot(IXFA_Widget* hWidget, CPDFSDK_PageView* pPage) override; +#endif void ReleaseAnnot(CPDFSDK_Annot* pAnnot) override; void DeleteAnnot(CPDFSDK_Annot* pAnnot) override {} CPDF_Rect GetViewBBox(CPDFSDK_PageView* pPageView, @@ -213,10 +221,12 @@ class CPDFSDK_BFAnnotHandler : public IPDFSDK_AnnotHandler { void OnSelected(CPDFSDK_Annot* pAnnot) override {} FX_BOOL OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) override; FX_BOOL OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) override; +#ifdef PDF_ENABLE_XFA FX_BOOL OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot, CPDFSDK_Annot* pNewAnnot) override { return TRUE; } +#endif void SetFormFiller(CFFL_IFormFiller* pFiller) { m_pFormFiller = pFiller; } CFFL_IFormFiller* GetFormFiller() { return m_pFormFiller; } @@ -226,6 +236,7 @@ class CPDFSDK_BFAnnotHandler : public IPDFSDK_AnnotHandler { CFFL_IFormFiller* m_pFormFiller; }; +#ifdef PDF_ENABLE_XFA class CPDFSDK_XFAAnnotHandler : public IPDFSDK_AnnotHandler { public: explicit CPDFSDK_XFAAnnotHandler(CPDFDoc_Environment* pApp); @@ -339,6 +350,7 @@ class CPDFSDK_XFAAnnotHandler : public IPDFSDK_AnnotHandler { CPDFDoc_Environment* m_pApp; }; +#endif #define CBA_AnnotHandlerArray CFX_ArrayTemplate class CPDFSDK_AnnotHandlerMgr { public: @@ -352,8 +364,10 @@ class CPDFSDK_AnnotHandlerMgr { virtual CPDFSDK_Annot* NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView); +#ifdef PDF_ENABLE_XFA virtual CPDFSDK_Annot* NewAnnot(IXFA_Widget* pAnnot, CPDFSDK_PageView* pPageView); +#endif virtual void ReleaseAnnot(CPDFSDK_Annot* pAnnot); virtual void Annot_OnCreate(CPDFSDK_Annot* pAnnot); @@ -415,8 +429,10 @@ class CPDFSDK_AnnotHandlerMgr { virtual FX_BOOL Annot_OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag); virtual FX_BOOL Annot_OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag); +#ifdef PDF_ENABLE_XFA virtual FX_BOOL Annot_OnChangeFocus(CPDFSDK_Annot* pSetAnnot, CPDFSDK_Annot* pKillAnnot); +#endif virtual CPDF_Rect Annot_OnGetViewBBox(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot); diff --git a/fpdfsdk/include/fsdk_baseannot.h b/fpdfsdk/include/fsdk_baseannot.h index 441036a657..ce65383e6b 100644 --- a/fpdfsdk/include/fsdk_baseannot.h +++ b/fpdfsdk/include/fsdk_baseannot.h @@ -16,7 +16,11 @@ #include "core/include/fpdfdoc/fpdf_doc.h" #include "core/include/fxcrt/fx_basic.h" #include "fpdfsdk/include/fsdk_define.h" +#ifndef PDF_ENABLE_XFA +#include "fx_systemhandler.h" +#else #include "fpdfsdk/include/fx_systemhandler.h" +#endif class CPDFSDK_PageView; class CPDF_Annot; @@ -72,15 +76,19 @@ class CPDFSDK_Annot { explicit CPDFSDK_Annot(CPDFSDK_PageView* pPageView); virtual ~CPDFSDK_Annot() {} +#ifdef PDF_ENABLE_XFA virtual FX_BOOL IsXFAField() { return FALSE; } +#endif virtual FX_FLOAT GetMinWidth() const; virtual FX_FLOAT GetMinHeight() const; // define layout order to 5. virtual int GetLayoutOrder() const { return 5; } virtual CPDF_Annot* GetPDFAnnot() const { return nullptr; } +#ifdef PDF_ENABLE_XFA virtual IXFA_Widget* GetXFAWidget() const { return nullptr; } +#endif virtual CFX_ByteString GetType() const { return ""; } virtual CFX_ByteString GetSubType() const { return ""; } @@ -94,7 +102,9 @@ class CPDFSDK_Annot { UnderlyingPageType* GetUnderlyingPage(); CPDF_Page* GetPDFPage(); +#ifdef PDF_ENABLE_XFA CPDFXFA_Page* GetPDFXFAPage(); +#endif void SetPage(CPDFSDK_PageView* pPageView) { m_pPageView = pPageView; } CPDFSDK_PageView* GetPageView() const { return m_pPageView; } @@ -118,7 +128,9 @@ class CPDFSDK_BAAnnot : public CPDFSDK_Annot { CPDFSDK_BAAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView); ~CPDFSDK_BAAnnot() override {} +#ifdef PDF_ENABLE_XFA FX_BOOL IsXFAField() override; +#endif CFX_ByteString GetType() const override; CFX_ByteString GetSubType() const override; void SetRect(const CPDF_Rect& rect) override; diff --git a/fpdfsdk/include/fsdk_baseform.h b/fpdfsdk/include/fsdk_baseform.h index e648558a3a..0b6a04eb52 100644 --- a/fpdfsdk/include/fsdk_baseform.h +++ b/fpdfsdk/include/fsdk_baseform.h @@ -31,6 +31,7 @@ class CPDF_Action; class CPDF_FormField; struct CPWL_Color; +#ifdef PDF_ENABLE_XFA typedef enum _PDFSDK_XFAAActionType { PDFSDK_XFA_Click = 0, PDFSDK_XFA_Full, @@ -38,6 +39,7 @@ typedef enum _PDFSDK_XFAAActionType { PDFSDK_XFA_PostOpen } PDFSDK_XFAAActionType; +#endif typedef struct _PDFSDK_FieldAction { _PDFSDK_FieldAction() { bModifier = FALSE; @@ -66,6 +68,7 @@ typedef struct _PDFSDK_FieldAction { class CPDFSDK_Widget : public CPDFSDK_BAAnnot { public: +#ifdef PDF_ENABLE_XFA IXFA_Widget* GetMixXFAWidget() const; IXFA_Widget* GetGroupMixXFAWidget(); IXFA_WidgetHandler* GetXFAWidgetHandler() const; @@ -88,6 +91,7 @@ class CPDFSDK_Widget : public CPDFSDK_BAAnnot { CPDF_FormField* pFormField, CPDF_FormControl* pFormControl); +#endif CPDFSDK_Widget(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView, CPDFSDK_InterForm* pInterForm); @@ -115,7 +119,11 @@ class CPDFSDK_Widget : public CPDFSDK_BAAnnot { FX_FLOAT GetFontSize() const; int GetSelectedIndex(int nIndex) const; +#ifndef PDF_ENABLE_XFA + CFX_WideString GetValue() const; +#else CFX_WideString GetValue(FX_BOOL bDisplay = TRUE) const; +#endif CFX_WideString GetDefaultValue() const; CFX_WideString GetOptionLabel(int nIndex) const; int CountOptions() const; @@ -129,7 +137,9 @@ class CPDFSDK_Widget : public CPDFSDK_BAAnnot { */ int GetAlignment() const; int GetMaxLen() const; +#ifdef PDF_ENABLE_XFA CFX_WideString GetName() const; +#endif CFX_WideString GetAlternateName() const; // Set Properties. @@ -140,7 +150,9 @@ class CPDFSDK_Widget : public CPDFSDK_BAAnnot { void ClearSelection(FX_BOOL bNotify); void SetTopVisibleIndex(int index); +#ifdef PDF_ENABLE_XFA void ResetAppearance(FX_BOOL bValueChanged); +#endif void ResetAppearance(const FX_WCHAR* sValue, FX_BOOL bValueChanged); void ResetFieldAppearance(FX_BOOL bValueChanged); void UpdateField(); @@ -197,15 +209,21 @@ class CPDFSDK_Widget : public CPDFSDK_BAAnnot { FX_BOOL HitTest(FX_FLOAT pageX, FX_FLOAT pageY); +#ifndef PDF_ENABLE_XFA + private: +#endif CPDFSDK_InterForm* m_pInterForm; FX_BOOL m_bAppModified; int32_t m_nAppAge; int32_t m_nValueAge; +#ifdef PDF_ENABLE_XFA mutable IXFA_Widget* m_hMixXFAWidget; mutable IXFA_WidgetHandler* m_pWidgetHandler; +#endif }; +#ifdef PDF_ENABLE_XFA class CPDFSDK_XFAWidget : public CPDFSDK_Annot { public: CPDFSDK_XFAWidget(IXFA_Widget* pAnnot, @@ -230,6 +248,7 @@ class CPDFSDK_XFAWidget : public CPDFSDK_Annot { CFX_MapPtrTemplate #define CPDFSDK_FieldSynchronizeMap CFX_MapPtrTemplate +#endif class CPDFSDK_InterForm : public CPDF_FormNotify { public: explicit CPDFSDK_InterForm(CPDFSDK_Document* pDocument); @@ -250,19 +269,23 @@ class CPDFSDK_InterForm : public CPDF_FormNotify { void AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidget); void RemoveMap(CPDF_FormControl* pControl); +#ifdef PDF_ENABLE_XFA void AddXFAMap(IXFA_Widget* hWidget, CPDFSDK_XFAWidget* pWidget); void RemoveXFAMap(IXFA_Widget* hWidget); CPDFSDK_XFAWidget* GetXFAWidget(IXFA_Widget* hWidget); +#endif void EnableCalculate(FX_BOOL bEnabled); FX_BOOL IsCalculateEnabled() const; +#ifdef PDF_ENABLE_XFA void XfaEnableCalculate(FX_BOOL bEnabled); FX_BOOL IsXfaCalculateEnabled() const; FX_BOOL IsXfaValidationsEnabled(); void XfaSetValidationsEnabled(FX_BOOL bEnabled); +#endif #ifdef _WIN32 CPDF_Stream* LoadImageFromFile(const CFX_WideString& sFile); #endif @@ -300,8 +323,10 @@ class CPDFSDK_InterForm : public CPDF_FormNotify { CFX_ByteTextBuf& textBuf); CFX_WideString GetTemporaryFileName(const CFX_WideString& sFileExt); +#ifdef PDF_ENABLE_XFA void SynchronizeField(CPDF_FormField* pFormField, FX_BOOL bSynchronizeElse); +#endif private: // CPDF_FormNotify int BeforeValueChange(const CPDF_FormField* pField, @@ -328,11 +353,15 @@ class CPDFSDK_InterForm : public CPDF_FormNotify { CPDFSDK_Document* m_pDocument; CPDF_InterForm* m_pInterForm; CPDFSDK_WidgetMap m_Map; +#ifdef PDF_ENABLE_XFA CPDFSDK_XFAWidgetMap m_XFAMap; CPDFSDK_FieldSynchronizeMap m_FieldSynchronizeMap; +#endif FX_BOOL m_bCalculate; +#ifdef PDF_ENABLE_XFA FX_BOOL m_bXfaCalculate; FX_BOOL m_bXfaValidationsEnabled; +#endif FX_BOOL m_bBusy; public: @@ -344,7 +373,11 @@ class CPDFSDK_InterForm : public CPDF_FormNotify { FX_COLORREF GetHighlightColor(int nFieldType); private: +#ifndef PDF_ENABLE_XFA + static const int kNumFieldTypes = 6; +#else static const int kNumFieldTypes = 7; +#endif FX_COLORREF m_aHighlightColor[kNumFieldTypes]; uint8_t m_iHighlightAlpha; FX_BOOL m_bNeedHightlight[kNumFieldTypes]; diff --git a/fpdfsdk/include/fsdk_define.h b/fpdfsdk/include/fsdk_define.h index 89c8f6ca6a..4dfe5c2840 100644 --- a/fpdfsdk/include/fsdk_define.h +++ b/fpdfsdk/include/fsdk_define.h @@ -7,23 +7,31 @@ #ifndef FPDFSDK_INCLUDE_FSDK_DEFINE_H_ #define FPDFSDK_INCLUDE_FSDK_DEFINE_H_ +#ifndef PDF_ENABLE_XFA +#include "core/include/fpdfapi/fpdfapi.h" +#else #include "../../xfa/include/fwl/adapter/fwl_adaptertimermgr.h" #include "../../xfa/include/fxbarcode/BC_BarCode.h" #include "../../xfa/include/fxfa/fxfa.h" #include "../../xfa/include/fxgraphics/fx_graphics.h" #include "../../xfa/include/fxjse/fxjse.h" +#endif #include "core/include/fpdfapi/fpdf_module.h" #include "core/include/fpdfapi/fpdf_pageobj.h" #include "core/include/fpdfapi/fpdf_parser.h" #include "core/include/fpdfapi/fpdf_render.h" #include "core/include/fpdfapi/fpdf_serial.h" +#ifdef PDF_ENABLE_XFA #include "core/include/fpdfapi/fpdfapi.h" +#endif #include "core/include/fpdfdoc/fpdf_doc.h" #include "core/include/fpdfdoc/fpdf_vt.h" #include "core/include/fxge/fx_ge.h" #include "core/include/fxge/fx_ge_win32.h" +#ifdef PDF_ENABLE_XFA #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h" #include "fpdfsdk/include/fpdfxfa/fpdfxfa_page.h" +#endif #include "public/fpdfview.h" #ifdef _WIN32 @@ -55,12 +63,15 @@ class CPDF_CustomAccess final : public IFX_FileRead { void Release() override { delete this; } FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; +#ifdef PDF_ENABLE_XFA virtual CFX_ByteString GetFullPath() { return ""; } virtual FX_BOOL GetByte(FX_DWORD pos, uint8_t& ch); virtual FX_BOOL GetBlock(FX_DWORD pos, uint8_t* pBuf, FX_DWORD size); +#endif private: FPDF_FILEACCESS m_FileAccess; +#ifdef PDF_ENABLE_XFA uint8_t m_Buffer[512]; FX_DWORD m_BufferOffset; }; @@ -87,13 +98,19 @@ class CFPDF_FileStream : public IFX_FileStream { protected: FPDF_FILEHANDLER* m_pFS; FX_FILESIZE m_nCurPos; +#endif }; // 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. +#ifndef PDF_ENABLE_XFA +using UnderlyingDocumentType = CPDF_Document; +using UnderlyingPageType = CPDF_Page; +#else using UnderlyingDocumentType = CPDFXFA_Document; using UnderlyingPageType = CPDFXFA_Page; +#endif // Conversions to/from underlying types. UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc); diff --git a/fpdfsdk/include/fsdk_mgr.h b/fpdfsdk/include/fsdk_mgr.h index 3fc40ba085..4b217f1ad3 100644 --- a/fpdfsdk/include/fsdk_mgr.h +++ b/fpdfsdk/include/fsdk_mgr.h @@ -10,8 +10,10 @@ #include #include "core/include/fpdftext/fpdf_text.h" +#ifdef PDF_ENABLE_XFA #include "fpdfxfa/fpdfxfa_doc.h" #include "fpdfxfa/fpdfxfa_page.h" +#endif #include "fsdk_actionhandler.h" #include "fsdk_annothandler.h" #include "fsdk_baseannot.h" @@ -38,12 +40,14 @@ class CPDFDoc_Environment final { CPDFDoc_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo); ~CPDFDoc_Environment(); +#ifdef PDF_ENABLE_XFA void Release() { if (m_pInfo && m_pInfo->Release) m_pInfo->Release(m_pInfo); delete this; } +#endif void FFI_Invalidate(FPDF_PAGE page, double left, double top, @@ -208,6 +212,7 @@ class CPDFDoc_Environment final { sizeOfArray); } +#ifdef PDF_ENABLE_XFA void FFI_DisplayCaret(FPDF_PAGE page, FPDF_BOOL bVisible, double left, @@ -446,6 +451,7 @@ class CPDFDoc_Environment final { return L""; } +#endif 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; } @@ -482,19 +488,29 @@ class CPDFSDK_Document { // Gets the document object for the next layer down; for master this is // a CPDF_Document, but for XFA it is a CPDFXFA_Document. UnderlyingDocumentType* GetUnderlyingDocument() const { +#ifndef PDF_ENABLE_XFA + return GetPDFDocument(); +#else return GetXFADocument(); +#endif } // Gets the CPDF_Document, either directly in master, or from the // CPDFXFA_Document for XFA. +#ifndef PDF_ENABLE_XFA + CPDF_Document* GetPDFDocument() const { return m_pDoc; } +#else CPDF_Document* GetPDFDocument() const { return m_pDoc ? m_pDoc->GetPDFDoc() : nullptr; } // Gets the XFA document directly (XFA-only). CPDFXFA_Document* GetXFADocument() const { return m_pDoc; } +#endif +#ifdef PDF_ENABLE_XFA int GetPageViewCount() const { return m_pageMap.size(); } +#endif CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPage, FX_BOOL ReNew = TRUE); CPDFSDK_PageView* GetPageView(int nIndex); @@ -548,8 +564,12 @@ class CPDFSDK_PageView final { ~CPDFSDK_PageView(); void PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, +#ifndef PDF_ENABLE_XFA + CPDF_RenderOptions* pOptions); +#else CPDF_RenderOptions* pOptions, const FX_RECT& pClip); +#endif const CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); const CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); @@ -567,20 +587,28 @@ class CPDFSDK_PageView final { CPDFSDK_Annot* AddAnnot(CPDF_Dictionary* pDict); CPDFSDK_Annot* AddAnnot(const FX_CHAR* lpSubType, CPDF_Dictionary* pDict); CPDFSDK_Annot* AddAnnot(CPDF_Annot* pPDFAnnot); +#ifdef PDF_ENABLE_XFA CPDFSDK_Annot* AddAnnot(IXFA_Widget* pPDFAnnot); +#endif FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot); size_t CountAnnots() const; CPDFSDK_Annot* GetAnnot(size_t nIndex); CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary* pDict); +#ifndef PDF_ENABLE_XFA + CPDF_Page* GetPDFPage() { return m_page; } +#else CPDFSDK_Annot* GetAnnotByXFAWidget(IXFA_Widget* hWidget); CPDFXFA_Page* GetPDFXFAPage() { return m_page; } CPDF_Page* GetPDFPage(); +#endif CPDF_Document* GetPDFDocument(); CPDFSDK_Document* GetSDKDocument() { return m_pSDKDoc; } FX_BOOL OnLButtonDown(const CPDF_Point& point, FX_UINT nFlag); FX_BOOL OnLButtonUp(const CPDF_Point& point, FX_UINT nFlag); +#ifdef PDF_ENABLE_XFA FX_BOOL OnRButtonDown(const CPDF_Point& point, FX_UINT nFlag); FX_BOOL OnRButtonUp(const CPDF_Point& point, FX_UINT nFlag); +#endif FX_BOOL OnChar(int nChar, FX_UINT nFlag); FX_BOOL OnKeyDown(int nKeyCode, int nFlag); FX_BOOL OnKeyUp(int nKeyCode, int nFlag); @@ -604,6 +632,9 @@ class CPDFSDK_PageView final { FX_BOOL IsValid() { return m_bValid; } void SetLock(FX_BOOL bLocked) { m_bLocked = bLocked; } FX_BOOL IsLocked() { return m_bLocked; } +#ifndef PDF_ENABLE_XFA + void TakeOverPage() { m_bTakeOverPage = TRUE; } +#endif private: void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice, @@ -614,12 +645,19 @@ class CPDFSDK_PageView final { nonstd::unique_ptr m_pAnnotList; std::vector m_fxAnnotArray; CPDFSDK_Document* m_pSDKDoc; +#ifndef PDF_ENABLE_XFA + CPDFSDK_Widget* m_CaptureWidget; +#else CPDFSDK_Annot* m_CaptureWidget; +#endif FX_BOOL m_bEnterWidget; FX_BOOL m_bExitWidget; FX_BOOL m_bOnWidget; FX_BOOL m_bValid; FX_BOOL m_bLocked; +#ifndef PDF_ENABLE_XFA + FX_BOOL m_bTakeOverPage; +#endif }; template diff --git a/fpdfsdk/include/javascript/IJavaScript.h b/fpdfsdk/include/javascript/IJavaScript.h index f654696fc8..7eab25fe88 100644 --- a/fpdfsdk/include/javascript/IJavaScript.h +++ b/fpdfsdk/include/javascript/IJavaScript.h @@ -7,7 +7,9 @@ #ifndef FPDFSDK_INCLUDE_JAVASCRIPT_IJAVASCRIPT_H_ #define FPDFSDK_INCLUDE_JAVASCRIPT_IJAVASCRIPT_H_ +#ifdef PDF_ENABLE_XFA #include "../../../xfa/include/fxjse/fxjse.h" +#endif #include "core/include/fxcrt/fx_string.h" #include "core/include/fxcrt/fx_system.h" @@ -149,11 +151,13 @@ class IJS_Runtime { const wchar_t* script, CFX_WideString* info) = 0; +#ifdef PDF_ENABLE_XFA virtual FX_BOOL GetHValueByName(const CFX_ByteStringC& utf8Name, FXJSE_HVALUE hValue) = 0; virtual FX_BOOL SetHValueByName(const CFX_ByteStringC& utf8Name, FXJSE_HVALUE hValue) = 0; +#endif protected: IJS_Runtime() {} }; diff --git a/fpdfsdk/include/jsapi/fxjs_v8.h b/fpdfsdk/include/jsapi/fxjs_v8.h index 97f96f6c5f..992721e90a 100644 --- a/fpdfsdk/include/jsapi/fxjs_v8.h +++ b/fpdfsdk/include/jsapi/fxjs_v8.h @@ -27,10 +27,12 @@ class CFXJS_ObjDefinition; class IJS_Context; // A description of the event that caused JS execution. class IJS_Runtime; // A native runtime, typically owns the v8::Context. +#ifdef PDF_ENABLE_XFA // FXJS_V8 places no interpreation on this calass; it merely passes it // along to XFA. class CFXJSE_RuntimeData; +#endif enum FXJSOBJTYPE { FXJSOBJTYPE_DYNAMIC = 0, // Created by native method and returned to JS. FXJSOBJTYPE_STATIC, // Created by init and hung off of global object. @@ -49,10 +51,16 @@ class FXJS_PerIsolateData { static FXJS_PerIsolateData* Get(v8::Isolate* pIsolate); std::vector m_ObjectDefnArray; +#ifdef PDF_ENABLE_XFA CFXJSE_RuntimeData* m_pFXJSERuntimeData; +#endif protected: +#ifndef PDF_ENABLE_XFA + FXJS_PerIsolateData() {} +#else FXJS_PerIsolateData() : m_pFXJSERuntimeData(nullptr) {} +#endif }; extern const wchar_t kFXJSValueNameString[]; @@ -137,11 +145,13 @@ void FXJS_ReleaseRuntime(v8::Isolate* pIsolate, std::vector*>* pStaticObjects); IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate); +#ifdef PDF_ENABLE_XFA // Called as part of FXJS_InitializeRuntime, exposed so PDF can make its // own contexts compatible with XFA or vice versa. void FXJS_SetRuntimeForV8Context(v8::Local v8Context, IJS_Runtime* pIRuntime); +#endif // Called after FXJS_InitializeRuntime call made. int FXJS_Execute(v8::Isolate* pIsolate, IJS_Context* pJSContext, diff --git a/fpdfsdk/include/pdfwindow/PWL_Edit.h b/fpdfsdk/include/pdfwindow/PWL_Edit.h index 1a8db7860c..edb605c07e 100644 --- a/fpdfsdk/include/pdfwindow/PWL_Edit.h +++ b/fpdfsdk/include/pdfwindow/PWL_Edit.h @@ -33,6 +33,7 @@ class IPWL_Filler_Notify { FX_BOOL& bRC, FX_BOOL& bExit, FX_DWORD nFlag) = 0; +#ifdef PDF_ENABLE_XFA virtual void OnPopupPreOpen(void* pPrivateData, FX_BOOL& bExit, @@ -40,6 +41,7 @@ class IPWL_Filler_Notify { virtual void OnPopupPostOpen(void* pPrivateData, FX_BOOL& bExit, FX_DWORD nFlag) = 0; +#endif }; class CPWL_Edit : public CPWL_EditCtrl, public IFX_Edit_OprNotify { diff --git a/fpdfsdk/src/formfiller/FFL_ComboBox.cpp b/fpdfsdk/src/formfiller/FFL_ComboBox.cpp index 348d5d14d2..a348d054a1 100644 --- a/fpdfsdk/src/formfiller/FFL_ComboBox.cpp +++ b/fpdfsdk/src/formfiller/FFL_ComboBox.cpp @@ -256,6 +256,7 @@ CPWL_Wnd* CFFL_ComboBox::ResetPDFWindow(CPDFSDK_PageView* pPageView, return pRet; } +#ifdef PDF_ENABLE_XFA FX_BOOL CFFL_ComboBox::IsFieldFull(CPDFSDK_PageView* pPageView) { if (CPWL_ComboBox* pComboBox = static_cast(GetPDFWindow(pPageView, FALSE))) { @@ -265,6 +266,7 @@ FX_BOOL CFFL_ComboBox::IsFieldFull(CPDFSDK_PageView* pPageView) { return FALSE; } +#endif void CFFL_ComboBox::OnSetFocus(CPWL_Wnd* pWnd) { ASSERT(m_pApp != NULL); diff --git a/fpdfsdk/src/formfiller/FFL_FormFiller.cpp b/fpdfsdk/src/formfiller/FFL_FormFiller.cpp index 9817f05db3..867bda09cc 100644 --- a/fpdfsdk/src/formfiller/FFL_FormFiller.cpp +++ b/fpdfsdk/src/formfiller/FFL_FormFiller.cpp @@ -562,10 +562,12 @@ FX_BOOL CFFL_FormFiller::IsDataChanged(CPDFSDK_PageView* pPageView) { void CFFL_FormFiller::SaveData(CPDFSDK_PageView* pPageView) {} +#ifdef PDF_ENABLE_XFA FX_BOOL CFFL_FormFiller::IsFieldFull(CPDFSDK_PageView* pPageView) { return FALSE; } +#endif void CFFL_FormFiller::SetChangeMark() { m_pApp->FFI_OnChange(); } diff --git a/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp b/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp index a12d84e88a..3257faae68 100644 --- a/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp +++ b/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp @@ -277,10 +277,12 @@ FX_BOOL CFFL_IFormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView, OnButtonUp(pWidget, pPageView, bReset, bExit, nFlags); if (bExit) return TRUE; +#ifdef PDF_ENABLE_XFA OnClick(pWidget, pPageView, bReset, bExit, nFlags); if (bExit) return TRUE; +#endif } return bRet; } @@ -796,6 +798,7 @@ void CFFL_IFormFiller::OnFormat(CPDFSDK_Widget* pWidget, } } +#ifdef PDF_ENABLE_XFA void CFFL_IFormFiller::OnClick(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bReset, @@ -978,6 +981,7 @@ void CFFL_IFormFiller::OnPostOpen(CPDFSDK_Widget* pWidget, } } +#endif FX_BOOL CFFL_IFormFiller::IsValidAnnot(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot) { if (pPageView) @@ -1002,6 +1006,7 @@ void CFFL_IFormFiller::OnBeforeKeyStroke(void* pPrivateData, CFFL_FormFiller* pFormFiller = GetFormFiller(pData->pWidget, FALSE); ASSERT(pFormFiller != NULL); +#ifdef PDF_ENABLE_XFA if (pFormFiller->IsFieldFull(pData->pPageView)) { FX_BOOL bFullExit = FALSE; FX_BOOL bFullReset = FALSE; @@ -1013,6 +1018,7 @@ void CFFL_IFormFiller::OnBeforeKeyStroke(void* pPrivateData, } } +#endif if (!m_bNotifying) { if (pData->pWidget->GetAAction(CPDF_AAction::KeyStroke)) { m_bNotifying = TRUE; diff --git a/fpdfsdk/src/formfiller/FFL_TextField.cpp b/fpdfsdk/src/formfiller/FFL_TextField.cpp index 3c0cdeb1f2..2962451101 100644 --- a/fpdfsdk/src/formfiller/FFL_TextField.cpp +++ b/fpdfsdk/src/formfiller/FFL_TextField.cpp @@ -268,6 +268,7 @@ CPWL_Wnd* CFFL_TextField::ResetPDFWindow(CPDFSDK_PageView* pPageView, return pRet; } +#ifdef PDF_ENABLE_XFA FX_BOOL CFFL_TextField::IsFieldFull(CPDFSDK_PageView* pPageView) { if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { return pWnd->IsTextFull(); @@ -276,6 +277,7 @@ FX_BOOL CFFL_TextField::IsFieldFull(CPDFSDK_PageView* pPageView) { return FALSE; } +#endif void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd) { ASSERT(m_pApp != NULL); diff --git a/fpdfsdk/src/fpdf_ext.cpp b/fpdfsdk/src/fpdf_ext.cpp index db84f97c6d..910c2c7717 100644 --- a/fpdfsdk/src/fpdf_ext.cpp +++ b/fpdfsdk/src/fpdf_ext.cpp @@ -6,7 +6,9 @@ #include "public/fpdf_ext.h" +#ifdef PDF_ENABLE_XFA #include "../include/fpdfxfa/fpdfxfa_doc.h" +#endif #include "core/include/fxcrt/fx_xml.h" #include "fpdfsdk/include/fsdk_define.h" @@ -175,6 +177,15 @@ void CheckUnSupportError(CPDF_Document* pDoc, FX_DWORD err_code) { const CXML_Element* pElement = metaData.GetRoot(); if (pElement) CheckSharedForm(pElement, "workflowType"); +#ifndef PDF_ENABLE_XFA + + // XFA Forms + CPDF_InterForm* pInterForm = new CPDF_InterForm(pDoc, FALSE); + if (pInterForm->HasXFAForm()) { + FPDF_UnSupportError(FPDF_UNSP_DOC_XFAFORM); + } + delete pInterForm; +#endif } DLLEXPORT int FPDFDoc_GetPageMode(FPDF_DOCUMENT document) { diff --git a/fpdfsdk/src/fpdfeditpage.cpp b/fpdfsdk/src/fpdfeditpage.cpp index 7c757cb3b6..75ed27ced9 100644 --- a/fpdfsdk/src/fpdfeditpage.cpp +++ b/fpdfsdk/src/fpdfeditpage.cpp @@ -6,9 +6,11 @@ #include "public/fpdf_edit.h" +#ifdef PDF_ENABLE_XFA #include "../include/fpdfxfa/fpdfxfa_app.h" #include "../include/fpdfxfa/fpdfxfa_doc.h" #include "../include/fpdfxfa/fpdfxfa_page.h" +#endif #include "fpdfsdk/include/fsdk_define.h" #include "public/fpdf_formfill.h" @@ -81,9 +83,15 @@ DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, pPageDict->SetAt("Rotate", new CPDF_Number(0)); pPageDict->SetAt("Resources", new CPDF_Dictionary); +#ifndef PDF_ENABLE_XFA + CPDF_Page* pPage = new CPDF_Page; + pPage->Load(pDoc, pPageDict); + pPage->ParseContent(); +#else CPDFXFA_Page* pPage = new CPDFXFA_Page((CPDFXFA_Document*)document, page_index); pPage->LoadPDFPage(pPageDict); +#endif return pPage; } diff --git a/fpdfsdk/src/fpdfformfill.cpp b/fpdfsdk/src/fpdfformfill.cpp index 0798c4e190..95defc5da4 100644 --- a/fpdfsdk/src/fpdfformfill.cpp +++ b/fpdfsdk/src/fpdfformfill.cpp @@ -6,9 +6,11 @@ #include "public/fpdf_formfill.h" +#ifdef PDF_ENABLE_XFA #include "../include/fpdfxfa/fpdfxfa_app.h" #include "../include/fpdfxfa/fpdfxfa_doc.h" #include "../include/fpdfxfa/fpdfxfa_page.h" +#endif #include "fpdfsdk/include/fsdk_define.h" #include "fpdfsdk/include/fsdk_mgr.h" #include "public/fpdfview.h" @@ -45,6 +47,15 @@ DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, if (!hHandle) return -1; CPDF_Page* pPage = CPDFPageFromFPDFPage(page); +#ifndef PDF_ENABLE_XFA + if (!pPage) + return -1; + CPDF_InterForm interform(pPage->m_pDocument, FALSE); + CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint( + pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, nullptr); + if (!pFormCtrl) + return -1; +#else if (pPage) { CPDF_InterForm interform(pPage->m_pDocument, FALSE); CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint( @@ -99,8 +110,14 @@ DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, pWidgetIterator->Release(); } +#endif +#ifndef PDF_ENABLE_XFA + CPDF_FormField* pFormField = pFormCtrl->GetField(); + return pFormField ? pFormField->GetFieldType() : -1; +#else return -1; +#endif } DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, @@ -129,7 +146,11 @@ DLLEXPORT int STDCALL FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle, DLLEXPORT FPDF_FORMHANDLE STDCALL FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, FPDF_FORMFILLINFO* formInfo) { +#ifndef PDF_ENABLE_XFA + const int kRequiredVersion = 1; +#else const int kRequiredVersion = 2; +#endif if (!formInfo || formInfo->version != kRequiredVersion) return nullptr; @@ -138,10 +159,14 @@ FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, return nullptr; CPDFDoc_Environment* pEnv = new CPDFDoc_Environment(pDocument, formInfo); +#ifndef PDF_ENABLE_XFA + pEnv->SetSDKDocument(new CPDFSDK_Document(pDocument, pEnv)); +#else pEnv->SetSDKDocument(pDocument->GetSDKDocument(pEnv)); CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); pApp->AddFormFillEnv(pEnv); +#endif return pEnv; } @@ -149,9 +174,19 @@ DLLEXPORT void STDCALL FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { if (!hHandle) return; +#ifndef PDF_ENABLE_XFA + + CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; + if (CPDFSDK_Document* pSDKDoc = pEnv->GetSDKDocument()) { + pEnv->SetSDKDocument(NULL); + delete pSDKDoc; + } + delete pEnv; +#else CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); pApp->RemoveFormFillEnv((CPDFDoc_Environment*)hHandle); delete (CPDFDoc_Environment*)hHandle; +#endif } DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, @@ -193,6 +228,7 @@ DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle, return pPageView->OnLButtonUp(pt, modifier); } +#ifdef PDF_ENABLE_XFA DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int modifier, @@ -219,6 +255,7 @@ DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonUp(FPDF_FORMHANDLE hHandle, return pPageView->OnRButtonUp(pt, modifier); } +#endif DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int nKeyCode, @@ -276,18 +313,40 @@ DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, if (!pPage) return; +#ifndef PDF_ENABLE_XFA + CPDF_RenderOptions options; + if (flags & FPDF_LCD_TEXT) + options.m_Flags |= RENDER_CLEARTYPE; + else + options.m_Flags &= ~RENDER_CLEARTYPE; +#else CPDFXFA_Document* pDocument = pPage->GetDocument(); if (!pDocument) return; +#endif +#ifndef PDF_ENABLE_XFA + // Grayscale output + if (flags & FPDF_GRAYSCALE) { + options.m_ColorMode = RENDER_COLOR_GRAY; + options.m_ForeColor = 0; + options.m_BackColor = 0xffffff; + } +#else CPDF_Document* pPDFDoc = pDocument->GetPDFDoc(); if (!pPDFDoc) return; +#endif +#ifndef PDF_ENABLE_XFA + options.m_AddFlags = flags >> 8; + options.m_pOCContext = new CPDF_OCContext(pPage->m_pDocument); +#else CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; CPDFSDK_Document* pFXDoc = pEnv->GetSDKDocument(); if (!pFXDoc) return; +#endif CFX_AffineMatrix matrix; pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate); @@ -303,13 +362,19 @@ DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, #else nonstd::unique_ptr pDevice(new CFX_FxgeDevice); #endif +#ifdef PDF_ENABLE_XFA if (!pDevice) return; +#endif pDevice->Attach((CFX_DIBitmap*)bitmap); pDevice->SaveState(); pDevice->SetClip_Rect(&clip); +#ifndef PDF_ENABLE_XFA + if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage)) + pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options); +#else CPDF_RenderOptions options; if (flags & FPDF_LCD_TEXT) options.m_Flags |= RENDER_CLEARTYPE; @@ -327,9 +392,11 @@ DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, if (CPDFSDK_PageView* pPageView = pFXDoc->GetPageView(pPage)) pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip); +#endif pDevice->RestoreState(); delete options.m_pOCContext; +#ifdef PDF_ENABLE_XFA options.m_pOCContext = NULL; } DLLEXPORT void STDCALL FPDF_Widget_Undo(FPDF_DOCUMENT document, @@ -580,6 +647,7 @@ FPDF_StringHandleAddString(FPDF_STRINGHANDLE stringHandle, stringArr->Add(bsStr); return TRUE; +#endif } DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle, diff --git a/fpdfsdk/src/fpdfsave.cpp b/fpdfsdk/src/fpdfsave.cpp index f643f704d7..a3a91c7187 100644 --- a/fpdfsdk/src/fpdfsave.cpp +++ b/fpdfsdk/src/fpdfsave.cpp @@ -6,12 +6,16 @@ #include "public/fpdf_save.h" +#ifdef PDF_ENABLE_XFA #include "../include/fpdfxfa/fpdfxfa_app.h" #include "../include/fpdfxfa/fpdfxfa_doc.h" #include "../include/fpdfxfa/fpdfxfa_util.h" +#endif #include "fpdfsdk/include/fsdk_define.h" #include "public/fpdf_edit.h" +#ifdef PDF_ENABLE_XFA #include "public/fpdf_formfill.h" +#endif #if _FX_OS_ == _FX_ANDROID_ #include "time.h" @@ -56,6 +60,7 @@ void CFX_IFileWrite::Release() { delete this; } +#ifdef PDF_ENABLE_XFA #define XFA_DATASETS 0 #define XFA_FORMS 1 @@ -279,6 +284,7 @@ FX_BOOL _SendPreSaveToXFADoc(CPDFXFA_Document* pDocument, return _SaveXFADocumentData(pDocument, fileList); } +#endif FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document, FPDF_FILEWRITE* pFileWrite, FPDF_DWORD flags, @@ -288,10 +294,12 @@ FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document, if (!pPDFDoc) return 0; +#ifdef PDF_ENABLE_XFA CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document; CFX_PtrArray fileList; _SendPreSaveToXFADoc(pDoc, fileList); +#endif if (flags < FPDF_INCREMENTAL || flags > FPDF_REMOVE_SECURITY) { flags = 0; } @@ -309,12 +317,14 @@ FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document, pStreamWrite = new CFX_IFileWrite; pStreamWrite->Init(pFileWrite); bRet = FileMaker.Create(pStreamWrite, flags); +#ifdef PDF_ENABLE_XFA _SendPostSaveToXFADoc(pDoc); for (int i = 0; i < fileList.GetSize(); i++) { IFX_FileStream* pFile = (IFX_FileStream*)fileList.GetAt(i); pFile->Release(); } fileList.RemoveAll(); +#endif pStreamWrite->Release(); return bRet; } diff --git a/fpdfsdk/src/fpdftext.cpp b/fpdfsdk/src/fpdftext.cpp index ac4e01e2bc..741bbe718d 100644 --- a/fpdfsdk/src/fpdftext.cpp +++ b/fpdfsdk/src/fpdftext.cpp @@ -6,8 +6,10 @@ #include "public/fpdf_text.h" +#ifdef PDF_ENABLE_XFA #include "../include/fpdfxfa/fpdfxfa_doc.h" #include "../include/fpdfxfa/fpdfxfa_page.h" +#endif #include "core/include/fpdfdoc/fpdf_doc.h" #include "core/include/fpdftext/fpdf_text.h" #include "fpdfsdk/include/fsdk_define.h" @@ -20,9 +22,13 @@ DLLEXPORT FPDF_TEXTPAGE STDCALL FPDFText_LoadPage(FPDF_PAGE page) { CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); if (!pPDFPage) return nullptr; +#ifndef PDF_ENABLE_XFA + CPDF_ViewerPreferences viewRef(pPDFPage->m_pDocument); +#else CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; CPDFXFA_Document* pDoc = pPage->GetDocument(); CPDF_ViewerPreferences viewRef(pDoc->GetPDFDoc()); +#endif IPDF_TextPage* textpage = IPDF_TextPage::CreateTextPage(pPDFPage, viewRef.IsDirectionR2L()); textpage->ParseTextPage(); diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp index 2066631e3c..d47e2b02da 100644 --- a/fpdfsdk/src/fpdfview.cpp +++ b/fpdfsdk/src/fpdfview.cpp @@ -6,11 +6,13 @@ #include "public/fpdfview.h" +#ifdef PDF_ENABLE_XFA #include "../include/fpdfxfa/fpdfxfa_app.h" #include "../include/fpdfxfa/fpdfxfa_doc.h" #include "../include/fpdfxfa/fpdfxfa_page.h" #include "../include/fpdfxfa/fpdfxfa_util.h" #include "core/include/fpdfapi/fpdf_module.h" +#endif #include "core/include/fxcodec/fx_codec.h" #include "core/include/fxcrt/fx_safe_types.h" #include "fpdfsdk/include/fsdk_define.h" @@ -18,7 +20,9 @@ #include "fpdfsdk/include/fsdk_rendercontext.h" #include "fpdfsdk/include/javascript/IJavaScript.h" #include "public/fpdf_ext.h" +#ifdef PDF_ENABLE_XFA #include "public/fpdf_formfill.h" +#endif #include "public/fpdf_progressive.h" #include "third_party/base/nonstd_unique_ptr.h" #include "third_party/base/numerics/safe_conversions_impl.h" @@ -36,16 +40,27 @@ UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page) { } CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { +#ifndef PDF_ENABLE_XFA + return UnderlyingFromFPDFDocument(doc); +#else return doc ? UnderlyingFromFPDFDocument(doc)->GetPDFDoc() : nullptr; +#endif } FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { +#ifndef PDF_ENABLE_XFA + return FPDFDocumentFromUnderlying(doc); +#else return doc ? FPDFDocumentFromUnderlying( new CPDFXFA_Document(doc, CPDFXFA_App::GetInstance())) : nullptr; +#endif } CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { +#ifndef PDF_ENABLE_XFA + return UnderlyingFromFPDFPage(page); +#else return page ? UnderlyingFromFPDFPage(page)->GetPDFPage() : nullptr; } @@ -126,10 +141,12 @@ FX_BOOL CFPDF_FileStream::Flush() { return TRUE; return m_pFS->Flush(m_pFS->clientData) == 0; +#endif } CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) { m_FileAccess = *pFileAccess; +#ifdef PDF_ENABLE_XFA m_BufferOffset = (FX_DWORD)-1; } @@ -157,6 +174,7 @@ FX_BOOL CPDF_CustomAccess::GetBlock(FX_DWORD pos, if (pos + size > m_FileAccess.m_FileLen) return FALSE; return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, pos, pBuf, size); +#endif } FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, @@ -218,13 +236,22 @@ DLLEXPORT void STDCALL FPDF_InitLibraryWithConfig( pModuleMgr->SetCodecModule(g_pCodecModule); pModuleMgr->InitPageModule(); pModuleMgr->InitRenderModule(); +#ifndef PDF_ENABLE_XFA + pModuleMgr->LoadEmbeddedGB1CMaps(); + pModuleMgr->LoadEmbeddedJapan1CMaps(); + pModuleMgr->LoadEmbeddedCNS1CMaps(); + pModuleMgr->LoadEmbeddedKorea1CMaps(); +#else CPDFXFA_App::GetInstance()->Initialize(); +#endif if (cfg && cfg->version >= 2) IJS_Runtime::Initialize(cfg->m_v8EmbedderSlot, cfg->m_pIsolate); } DLLEXPORT void STDCALL FPDF_DestroyLibrary() { +#ifdef PDF_ENABLE_XFA CPDFXFA_App::ReleaseInstance(); +#endif CPDF_ModuleMgr::Destroy(); CFX_GEModule::Destroy(); @@ -285,6 +312,9 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path, ProcessParseError(err_code); return NULL; } +#ifndef PDF_ENABLE_XFA + return pParser->GetDocument(); +#else CPDF_Document* pPDFDoc = pParser->GetDocument(); if (!pPDFDoc) return NULL; @@ -327,6 +357,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document, DLLEXPORT FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document) { return document && (static_cast(document))->LoadXFADoc(); +#endif } class CMemFile final : public IFX_FileRead { @@ -415,7 +446,11 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); if (!pDoc) +#ifndef PDF_ENABLE_XFA + return 0; +#else return (FX_DWORD)-1; +#endif CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); return pDict ? pDict->GetInteger("P") : (FX_DWORD)-1; @@ -444,7 +479,17 @@ DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, if (page_index < 0 || page_index >= pDoc->GetPageCount()) return nullptr; +#ifndef PDF_ENABLE_XFA + CPDF_Dictionary* pDict = pDoc->GetPage(page_index); + if (pDict == NULL) + return NULL; + CPDF_Page* pPage = new CPDF_Page; + pPage->Load(pDoc, pDict); + pPage->ParseContent(); + return pPage; +#else return pDoc->GetPage(page_index); +#endif } DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { @@ -669,13 +714,36 @@ DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) { if (!page) return; +#ifndef PDF_ENABLE_XFA + CPDFSDK_PageView* pPageView = + (CPDFSDK_PageView*)(((CPDF_Page*)page))->GetPrivateData((void*)page); + if (pPageView && pPageView->IsLocked()) { + pPageView->TakeOverPage(); + return; + } + delete (CPDF_Page*)page; +#else CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; pPage->Release(); +#endif } DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) { +#ifndef PDF_ENABLE_XFA + CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); + if (!pDoc) + return; + + CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); + if (!pParser) { + delete pDoc; + return; + } + delete pParser; +#else delete CPDFDocumentFromFPDFDocument(document); +#endif } DLLEXPORT unsigned long STDCALL FPDF_GetLastError() { @@ -695,8 +763,24 @@ DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, if (page == NULL || page_x == NULL || page_y == NULL) return; UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); +#ifndef PDF_ENABLE_XFA + + CPDF_Matrix page2device; + pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, + rotate); + CPDF_Matrix device2page; + device2page.SetReverse(page2device); + + FX_FLOAT page_x_f, page_y_f; + device2page.Transform((FX_FLOAT)(device_x), (FX_FLOAT)(device_y), page_x_f, + page_y_f); + + *page_x = (page_x_f); + *page_y = (page_y_f); +#else pPage->DeviceToPage(start_x, start_y, size_x, size_y, rotate, device_x, device_y, page_x, page_y); +#endif } DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, @@ -714,8 +798,21 @@ DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); if (!pPage) return; +#ifndef PDF_ENABLE_XFA + CPDF_Matrix page2device; + pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, + rotate); + + FX_FLOAT device_x_f, device_y_f; + page2device.Transform(((FX_FLOAT)page_x), ((FX_FLOAT)page_y), device_x_f, + device_y_f); + + *device_x = FXSYS_round(device_x_f); + *device_y = FXSYS_round(device_y_f); +#else pPage->PageToDevice(start_x, start_y, size_x, size_y, rotate, page_x, page_y, device_x, device_y); +#endif } DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, @@ -830,6 +927,14 @@ void FPDF_RenderPage_Retail(CRenderContext* pContext, pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE; if (flags & FPDF_RENDER_FORCEHALFTONE) pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE; +#ifndef PDF_ENABLE_XFA + if (flags & FPDF_RENDER_NO_SMOOTHTEXT) + pContext->m_pOptions->m_Flags |= RENDER_NOTEXTSMOOTH; + if (flags & FPDF_RENDER_NO_SMOOTHIMAGE) + pContext->m_pOptions->m_Flags |= RENDER_NOIMAGESMOOTH; + if (flags & FPDF_RENDER_NO_SMOOTHPATH) + pContext->m_pOptions->m_Flags |= RENDER_NOPATHSMOOTH; +#endif // Grayscale output if (flags & FPDF_GRAYSCALE) { pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY; @@ -879,16 +984,28 @@ DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, if (!pDoc) return FALSE; +#ifndef PDF_ENABLE_XFA + CPDF_Dictionary* pDict = pDoc->GetPage(page_index); + if (!pDict) +#else int count = pDoc->GetPageCount(); if (page_index < 0 || page_index >= count) return FALSE; CPDFXFA_Page* pPage = pDoc->GetPage(page_index); if (!pPage) +#endif return FALSE; +#ifndef PDF_ENABLE_XFA + CPDF_Page page; + page.Load(pDoc, pDict); + *width = page.GetPageWidth(); + *height = page.GetPageHeight(); +#else *width = pPage->GetPageWidth(); *height = pPage->GetPageHeight(); +#endif return TRUE; } @@ -965,6 +1082,7 @@ DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document, return name_tree.LookupNamedDest(pDoc, name); } +#ifdef PDF_ENABLE_XFA FPDF_RESULT FPDF_BStr_Init(FPDF_BSTR* str) { if (!str) return -1; @@ -1017,6 +1135,7 @@ FPDF_RESULT FPDF_BStr_Clear(FPDF_BSTR* str) { return 0; } +#endif DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, int index, void* buffer, diff --git a/fpdfsdk/src/fpdfview_c_api_test.c b/fpdfsdk/src/fpdfview_c_api_test.c index 344b029eba..fdf83bec6d 100644 --- a/fpdfsdk/src/fpdfview_c_api_test.c +++ b/fpdfsdk/src/fpdfview_c_api_test.c @@ -104,8 +104,10 @@ int CheckPDFiumCApi() { CHK(FORM_OnMouseMove); CHK(FORM_OnLButtonDown); CHK(FORM_OnLButtonUp); +#ifdef PDF_ENABLE_XFA CHK(FORM_OnRButtonDown); CHK(FORM_OnRButtonUp); +#endif CHK(FORM_OnKeyDown); CHK(FORM_OnKeyUp); CHK(FORM_OnChar); @@ -117,6 +119,7 @@ int CheckPDFiumCApi() { CHK(FPDF_SetFormFieldHighlightAlpha); CHK(FPDF_RemoveFormFieldHighlight); CHK(FPDF_FFLDraw); +#ifdef PDF_ENABLE_XFA CHK(FPDF_HasXFAField); CHK(FPDF_LoadXFA); CHK(FPDF_Widget_Undo); @@ -131,6 +134,7 @@ int CheckPDFiumCApi() { CHK(FPDF_StringHandleGetStringByIndex); CHK(FPDF_StringHandleRelease); CHK(FPDF_StringHandleAddString); +#endif // fpdf_ppo.h CHK(FPDF_ImportPages); @@ -227,9 +231,11 @@ int CheckPDFiumCApi() { CHK(FPDF_CountNamedDests); CHK(FPDF_GetNamedDestByName); CHK(FPDF_GetNamedDest); +#ifdef PDF_ENABLE_XFA CHK(FPDF_BStr_Init); CHK(FPDF_BStr_Set); CHK(FPDF_BStr_Clear); +#endif return 1; } diff --git a/fpdfsdk/src/fsdk_annothandler.cpp b/fpdfsdk/src/fsdk_annothandler.cpp index 5edd88a8e2..aa383844b4 100644 --- a/fpdfsdk/src/fsdk_annothandler.cpp +++ b/fpdfsdk/src/fsdk_annothandler.cpp @@ -6,8 +6,10 @@ #include +#ifdef PDF_ENABLE_XFA #include "../include/fpdfxfa/fpdfxfa_doc.h" #include "../include/fpdfxfa/fpdfxfa_util.h" +#endif #include "fpdfsdk/include/formfiller/FFL_FormFiller.h" #include "fpdfsdk/include/fsdk_annothandler.h" #include "fpdfsdk/include/fsdk_define.h" @@ -19,10 +21,12 @@ CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) { CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp); pHandler->SetFormFiller(m_pApp->GetIFormFiller()); RegisterAnnotHandler(pHandler); +#ifdef PDF_ENABLE_XFA CPDFSDK_XFAAnnotHandler* pXFAAnnotHandler = new CPDFSDK_XFAAnnotHandler(m_pApp); RegisterAnnotHandler(pXFAAnnotHandler); +#endif } CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() { @@ -66,6 +70,7 @@ CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot, return new CPDFSDK_BAAnnot(pAnnot, pPageView); } +#ifdef PDF_ENABLE_XFA CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(IXFA_Widget* pAnnot, CPDFSDK_PageView* pPageView) { ASSERT(pAnnot != NULL); @@ -79,6 +84,7 @@ CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(IXFA_Widget* pAnnot, return NULL; } +#endif void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { ASSERT(pAnnot != NULL); @@ -121,8 +127,10 @@ IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); if (pPDFAnnot) return GetAnnotHandler(pPDFAnnot->GetSubType()); +#ifdef PDF_ENABLE_XFA if (pAnnot->GetXFAWidget()) return GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME); +#endif return nullptr; } @@ -142,8 +150,10 @@ void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { pAnnotHandler->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); } else { +#ifdef PDF_ENABLE_XFA if (pAnnot->IsXFAField()) return; +#endif static_cast(pAnnot) ->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); } @@ -315,6 +325,7 @@ FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(CPDFSDK_Annot* pAnnot, return FALSE; } +#ifdef PDF_ENABLE_XFA FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus( CPDFSDK_Annot* pSetAnnot, CPDFSDK_Annot* pKillAnnot) { @@ -330,6 +341,7 @@ FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus( return TRUE; } +#endif CPDF_Rect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox( CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot) { @@ -353,6 +365,10 @@ FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot, FX_BOOL bNext) { +#ifndef PDF_ENABLE_XFA + CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), "Widget", ""); + return bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot); +#else CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView(); CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage(); if (pPage == NULL) @@ -381,6 +397,7 @@ CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot, pWidgetIterator->Release(); return pPageView->GetAnnotByXFAWidget(hNextFocus); +#endif } FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { @@ -424,11 +441,13 @@ CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CPDF_Annot* pAnnot, return pWidget; } +#ifdef PDF_ENABLE_XFA CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(IXFA_Widget* hWidget, CPDFSDK_PageView* pPage) { return NULL; } +#endif void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { ASSERT(pAnnot != NULL); @@ -662,6 +681,7 @@ void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) { } } +#ifdef PDF_ENABLE_XFA CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); @@ -670,6 +690,7 @@ void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) { pWidget->ResetAppearance(FALSE); } +#endif if (m_pFormFiller) m_pFormFiller->OnLoad(pAnnot); } @@ -725,6 +746,7 @@ FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, return rect.Contains(point.x, point.y); } +#ifdef PDF_ENABLE_XFA #define FWL_WGTHITTEST_Unknown 0 #define FWL_WGTHITTEST_Client 1 // arrow #define FWL_WGTHITTEST_Titlebar 11 // caption @@ -1143,6 +1165,7 @@ FX_DWORD CPDFSDK_XFAAnnotHandler::GetFWLFlags(FX_DWORD dwFlag) { return dwFWLFlag; } +#endif CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView, bool bReverse) : m_bReverse(bReverse), m_pos(0) { diff --git a/fpdfsdk/src/fsdk_baseannot.cpp b/fpdfsdk/src/fsdk_baseannot.cpp index cecf5f79b3..2453ec5596 100644 --- a/fpdfsdk/src/fsdk_baseannot.cpp +++ b/fpdfsdk/src/fsdk_baseannot.cpp @@ -5,7 +5,9 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include "core/include/fxcrt/fx_ext.h" +#ifdef PDF_ENABLE_XFA #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h" +#endif #include "fpdfsdk/include/fsdk_baseannot.h" #include "fpdfsdk/include/fsdk_define.h" #include "fpdfsdk/include/fsdk_mgr.h" @@ -967,10 +969,12 @@ CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) { return CPDF_Action(); } +#ifdef PDF_ENABLE_XFA FX_BOOL CPDFSDK_BAAnnot::IsXFAField() { return FALSE; } +#endif void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, CPDF_RenderOptions* pOptions) { @@ -982,7 +986,11 @@ void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice, } UnderlyingPageType* CPDFSDK_Annot::GetUnderlyingPage() { +#ifndef PDF_ENABLE_XFA + return GetPDFPage(); +#else return GetPDFXFAPage(); +#endif } CPDF_Page* CPDFSDK_Annot::GetPDFPage() { @@ -990,9 +998,11 @@ CPDF_Page* CPDFSDK_Annot::GetPDFPage() { return m_pPageView->GetPDFPage(); return NULL; } +#ifdef PDF_ENABLE_XFA CPDFXFA_Page* CPDFSDK_Annot::GetPDFXFAPage() { if (m_pPageView) return m_pPageView->GetPDFXFAPage(); return NULL; } +#endif diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp index af6a8e549a..c09182e9d7 100644 --- a/fpdfsdk/src/fsdk_baseform.cpp +++ b/fpdfsdk/src/fsdk_baseform.cpp @@ -4,8 +4,10 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com +#ifdef PDF_ENABLE_XFA #include "../include/fpdfxfa/fpdfxfa_doc.h" #include "../include/fpdfxfa/fpdfxfa_util.h" +#endif #include "fpdfsdk/include/formfiller/FFL_FormFiller.h" #include "fpdfsdk/include/fsdk_actionhandler.h" #include "fpdfsdk/include/fsdk_baseannot.h" @@ -26,14 +28,19 @@ CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot, : CPDFSDK_BAAnnot(pAnnot, pPageView), m_pInterForm(pInterForm), m_nAppAge(0), +#ifndef PDF_ENABLE_XFA + m_nValueAge(0) { +#else m_nValueAge(0), m_hMixXFAWidget(NULL), m_pWidgetHandler(NULL) { +#endif ASSERT(m_pInterForm != NULL); } CPDFSDK_Widget::~CPDFSDK_Widget() {} +#ifdef PDF_ENABLE_XFA IXFA_Widget* CPDFSDK_Widget::GetMixXFAWidget() const { CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); @@ -456,6 +463,7 @@ void CPDFSDK_Widget::SynchronizeXFAItems(IXFA_DocView* pXFADocView, #endif // PDF_ENABLE_XFA } +#endif FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid( CPDF_Annot::AppearanceMode mode) { CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP"); @@ -502,12 +510,14 @@ int CPDFSDK_Widget::GetFieldType() const { } FX_BOOL CPDFSDK_Widget::IsAppearanceValid() { +#ifdef PDF_ENABLE_XFA CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); int nDocType = pDoc->GetDocType(); if (nDocType != DOCTYPE_PDF && nDocType != DOCTYPE_STATIC_XFA) return TRUE; +#endif return CPDFSDK_BAAnnot::IsAppearanceValid(); } @@ -550,11 +560,13 @@ int CPDFSDK_Widget::GetRotate() const { return pCtrl->GetRotation() % 360; } +#ifdef PDF_ENABLE_XFA CFX_WideString CPDFSDK_Widget::GetName() const { CPDF_FormField* pFormField = GetFormField(); return pFormField->GetFullName(); } +#endif FX_BOOL CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const { CPDF_FormControl* pFormCtrl = GetFormControl(); ASSERT(pFormCtrl != NULL); @@ -605,6 +617,7 @@ FX_FLOAT CPDFSDK_Widget::GetFontSize() const { } int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const { +#ifdef PDF_ENABLE_XFA #ifdef PDF_ENABLE_XFA if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) { if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) { @@ -616,10 +629,14 @@ int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const { } #endif // PDF_ENABLE_XFA +#endif CPDF_FormField* pFormField = GetFormField(); return pFormField->GetSelectedIndex(nIndex); } +#ifndef PDF_ENABLE_XFA +CFX_WideString CPDFSDK_Widget::GetValue() const { +#else CFX_WideString CPDFSDK_Widget::GetValue(FX_BOOL bDisplay) const { #ifdef PDF_ENABLE_XFA if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) { @@ -634,6 +651,7 @@ CFX_WideString CPDFSDK_Widget::GetValue(FX_BOOL bDisplay) const { } #endif // PDF_ENABLE_XFA +#endif CPDF_FormField* pFormField = GetFormField(); return pFormField->GetValue(); } @@ -660,6 +678,7 @@ int CPDFSDK_Widget::CountOptions() const { } FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const { +#ifdef PDF_ENABLE_XFA #ifdef PDF_ENABLE_XFA if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) { if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) { @@ -673,6 +692,7 @@ FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const { } #endif // PDF_ENABLE_XFA +#endif CPDF_FormField* pFormField = GetFormField(); return pFormField->IsItemSelected(nIndex); } @@ -683,6 +703,7 @@ int CPDFSDK_Widget::GetTopVisibleIndex() const { } FX_BOOL CPDFSDK_Widget::IsChecked() const { +#ifdef PDF_ENABLE_XFA #ifdef PDF_ENABLE_XFA if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) { if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) { @@ -694,6 +715,7 @@ FX_BOOL CPDFSDK_Widget::IsChecked() const { } #endif // PDF_ENABLE_XFA +#endif CPDF_FormControl* pFormCtrl = GetFormControl(); return pFormCtrl->IsChecked(); } @@ -721,10 +743,12 @@ void CPDFSDK_Widget::SetCheck(FX_BOOL bChecked, FX_BOOL bNotify) { pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked, bNotify); +#ifdef PDF_ENABLE_XFA if (!IsWidgetAppearanceValid(CPDF_Annot::Normal)) ResetAppearance(TRUE); if (!bNotify) Synchronize(TRUE); +#endif } void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify) { @@ -732,9 +756,11 @@ void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify) { ASSERT(pFormField != NULL); pFormField->SetValue(sValue, bNotify); +#ifdef PDF_ENABLE_XFA if (!bNotify) Synchronize(TRUE); +#endif } void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue) {} @@ -745,9 +771,11 @@ void CPDFSDK_Widget::SetOptionSelection(int index, ASSERT(pFormField != NULL); pFormField->SetItemSelection(index, bSelected, bNotify); +#ifdef PDF_ENABLE_XFA if (!bNotify) Synchronize(TRUE); +#endif } void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify) { @@ -755,9 +783,11 @@ void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify) { ASSERT(pFormField != NULL); pFormField->ClearSelection(bNotify); +#ifdef PDF_ENABLE_XFA if (!bNotify) Synchronize(TRUE); +#endif } void CPDFSDK_Widget::SetTopVisibleIndex(int index) {} @@ -774,6 +804,7 @@ FX_BOOL CPDFSDK_Widget::IsAppModified() const { return m_bAppModified; } +#ifdef PDF_ENABLE_XFA void CPDFSDK_Widget::ResetAppearance(FX_BOOL bValueChanged) { switch (GetFieldType()) { case FIELDTYPE_TEXTFIELD: @@ -791,6 +822,7 @@ void CPDFSDK_Widget::ResetAppearance(FX_BOOL bValueChanged) { } } +#endif void CPDFSDK_Widget::ResetAppearance(const FX_WCHAR* sValue, FX_BOOL bValueChanged) { SetAppModified(); @@ -1642,12 +1674,14 @@ void CPDFSDK_Widget::ResetAppearance_TextField(const FX_WCHAR* sValue) { FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1; FX_FLOAT fFontSize = GetFontSize(); +#ifdef PDF_ENABLE_XFA CFX_WideString sValueTmp; if (!sValue && (NULL != this->GetMixXFAWidget())) { sValueTmp = GetValue(TRUE); sValue = sValueTmp; } +#endif if (nMaxLen > 0) { if (bCharArray) { pEdit->SetCharArray(nMaxLen); @@ -1956,6 +1990,7 @@ FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, CPDFSDK_PageView* pPageView) { CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); CPDFDoc_Environment* pEnv = pDocument->GetEnv(); +#ifdef PDF_ENABLE_XFA CPDFXFA_Document* pDoc = pDocument->GetXFADocument(); if (IXFA_Widget* hWidget = GetMixXFAWidget()) { @@ -1995,6 +2030,7 @@ FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, } } +#endif CPDF_Action action = GetAAction(type); if (action && action.GetType() != CPDF_Action::Unknown) { @@ -2067,6 +2103,7 @@ FX_BOOL CPDFSDK_Widget::HitTest(FX_FLOAT pageX, FX_FLOAT pageY) { return FALSE; } +#ifdef PDF_ENABLE_XFA CPDFSDK_XFAWidget::CPDFSDK_XFAWidget(IXFA_Widget* pAnnot, CPDFSDK_PageView* pPageView, CPDFSDK_InterForm* pInterForm) @@ -2095,12 +2132,15 @@ CFX_FloatRect CPDFSDK_XFAWidget::GetRect() const { rcBBox.top + rcBBox.height); } +#endif CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_Document* pDocument) : m_pDocument(pDocument), m_pInterForm(NULL), m_bCalculate(TRUE), +#ifdef PDF_ENABLE_XFA m_bXfaCalculate(TRUE), m_bXfaValidationsEnabled(TRUE), +#endif m_bBusy(FALSE) { m_pInterForm = new CPDF_InterForm(m_pDocument->GetPDFDocument(), FALSE); m_pInterForm->SetFormNotify(this); @@ -2114,7 +2154,9 @@ CPDFSDK_InterForm::~CPDFSDK_InterForm() { delete m_pInterForm; m_pInterForm = nullptr; m_Map.clear(); +#ifdef PDF_ENABLE_XFA m_XFAMap.RemoveAll(); +#endif } FX_BOOL CPDFSDK_InterForm::HighlightWidgets() { @@ -2220,6 +2262,7 @@ void CPDFSDK_InterForm::RemoveMap(CPDF_FormControl* pControl) { m_Map.erase(pControl); } +#ifdef PDF_ENABLE_XFA void CPDFSDK_InterForm::AddXFAMap(IXFA_Widget* hWidget, CPDFSDK_XFAWidget* pWidget) { m_XFAMap.SetAt(hWidget, pWidget); @@ -2236,6 +2279,7 @@ CPDFSDK_XFAWidget* CPDFSDK_InterForm::GetXFAWidget(IXFA_Widget* hWidget) { return pWidget; } +#endif void CPDFSDK_InterForm::EnableCalculate(FX_BOOL bEnabled) { m_bCalculate = bEnabled; } @@ -2244,6 +2288,7 @@ FX_BOOL CPDFSDK_InterForm::IsCalculateEnabled() const { return m_bCalculate; } +#ifdef PDF_ENABLE_XFA void CPDFSDK_InterForm::XfaEnableCalculate(FX_BOOL bEnabled) { m_bXfaCalculate = bEnabled; } @@ -2258,6 +2303,7 @@ void CPDFSDK_InterForm::XfaSetValidationsEnabled(FX_BOOL bEnabled) { m_bXfaValidationsEnabled = bEnabled; } +#endif #ifdef _WIN32 CPDF_Stream* CPDFSDK_InterForm::LoadImageFromFile(const CFX_WideString& sFile) { CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); @@ -2660,6 +2706,7 @@ FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf( return pFDF ? pFDF->WriteBuf(textBuf) : FALSE; } +#ifdef PDF_ENABLE_XFA void CPDFSDK_InterForm::SynchronizeField(CPDF_FormField* pFormField, FX_BOOL bSynchronizeElse) { ASSERT(pFormField != NULL); @@ -2679,6 +2726,7 @@ void CPDFSDK_InterForm::SynchronizeField(CPDF_FormField* pFormField, } } +#endif CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName( const CFX_WideString& sFileExt) { CFX_WideString sFileName; @@ -2795,8 +2843,10 @@ int CPDFSDK_InterForm::BeforeValueChange(const CPDF_FormField* pField, int CPDFSDK_InterForm::AfterValueChange(const CPDF_FormField* pField) { CPDF_FormField* pFormField = (CPDF_FormField*)pField; +#ifdef PDF_ENABLE_XFA SynchronizeField(pFormField, FALSE); +#endif int nType = pFormField->GetFieldType(); if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) { OnCalculate(pFormField); diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp index ed2ac1a971..2e03989d6c 100644 --- a/fpdfsdk/src/fsdk_mgr.cpp +++ b/fpdfsdk/src/fsdk_mgr.cpp @@ -14,11 +14,13 @@ #include "public/fpdf_ext.h" #include "third_party/base/nonstd_unique_ptr.h" +#ifdef PDF_ENABLE_XFA #include "../include/fpdfxfa/fpdfxfa_app.h" #include "../include/fpdfxfa/fpdfxfa_doc.h" #include "../include/fpdfxfa/fpdfxfa_page.h" #include "../include/fpdfxfa/fpdfxfa_util.h" +#endif #if _FX_OS_ == _FX_ANDROID_ #include "time.h" #else @@ -212,9 +214,11 @@ CPDFDoc_Environment::CPDFDoc_Environment(UnderlyingDocumentType* pDoc, } CPDFDoc_Environment::~CPDFDoc_Environment() { +#ifdef PDF_ENABLE_XFA CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); if (pProvider->m_pEnvList.GetSize() == 0) pProvider->SetJavaScriptInitialized(FALSE); +#endif } int CPDFDoc_Environment::JS_appAlert(const FX_WCHAR* Msg, @@ -538,14 +542,18 @@ FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) { if (!pAnnot) return FALSE; +#ifdef PDF_ENABLE_XFA CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot; +#endif CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); if (pPageView && pPageView->IsValid()) { CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); if (!m_pFocusAnnot) { +#ifdef PDF_ENABLE_XFA if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, pLastFocusAnnot)) return FALSE; +#endif if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, nFlag)) return FALSE; if (!m_pFocusAnnot) { @@ -562,10 +570,12 @@ FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag) { CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot; m_pFocusAnnot = nullptr; +#ifdef PDF_ENABLE_XFA if (!pAnnotHandler->Annot_OnChangeFocus(nullptr, pFocusAnnot)) return FALSE; +#endif if (pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag)) { if (pFocusAnnot->GetType() == FX_BSTRC("Widget")) { CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot; @@ -612,13 +622,25 @@ CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, m_bExitWidget(FALSE), m_bOnWidget(FALSE), m_bValid(FALSE), +#ifndef PDF_ENABLE_XFA + m_bLocked(FALSE), + m_bTakeOverPage(FALSE) { +#else m_bLocked(FALSE) { +#endif CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); if (pInterForm) { CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); +#ifndef PDF_ENABLE_XFA + pPDFInterForm->FixPageFields(page); +#else if (page->GetPDFPage()) pPDFInterForm->FixPageFields(page->GetPDFPage()); +#endif } +#ifndef PDF_ENABLE_XFA + m_page->SetPrivateData((void*)m_page, (void*)this, nullptr); +#endif } CPDFSDK_PageView::~CPDFSDK_PageView() { @@ -629,14 +651,26 @@ CPDFSDK_PageView::~CPDFSDK_PageView() { m_fxAnnotArray.clear(); m_pAnnotList.reset(); +#ifndef PDF_ENABLE_XFA + + m_page->RemovePrivateData((void*)m_page); + if (m_bTakeOverPage) { + delete m_page; + } +#endif } void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, +#ifndef PDF_ENABLE_XFA + CPDF_RenderOptions* pOptions) { +#else CPDF_RenderOptions* pOptions, const FX_RECT& pClip) { +#endif m_curMatrix = *pUser2Device; CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); +#ifdef PDF_ENABLE_XFA CPDFXFA_Page* pPage = GetPDFXFAPage(); if (pPage == NULL) return; @@ -666,6 +700,7 @@ void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, #endif // PDF_ENABLE_XFA // for pdf/static xfa. +#endif CPDFSDK_AnnotIterator annotIterator(this, true); while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); @@ -717,9 +752,13 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); CPDFSDK_AnnotIterator annotIterator(this, false); while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { +#ifndef PDF_ENABLE_XFA + if (pSDKAnnot->GetType() == "Widget") { +#else bool bHitTest = pSDKAnnot->GetType() == "Widget"; bHitTest = bHitTest || pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME; if (bHitTest) { +#endif pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); CPDF_Point point(pageX, pageY); if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point)) @@ -760,6 +799,7 @@ CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot* pPDFAnnot) { return pSDKAnnot; } +#ifdef PDF_ENABLE_XFA CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(IXFA_Widget* pPDFAnnot) { if (!pPDFAnnot) return nullptr; @@ -778,6 +818,7 @@ CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(IXFA_Widget* pPDFAnnot) { return pSDKAnnot; } +#endif CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary* pDict) { return pDict ? AddAnnot(pDict->GetString("Subtype"), pDict) : nullptr; } @@ -788,6 +829,9 @@ CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType, } FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { +#ifndef PDF_ENABLE_XFA + return FALSE; +#else if (!pAnnot) return FALSE; CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); @@ -802,10 +846,14 @@ FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { m_CaptureWidget = nullptr; return TRUE; +#endif } CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { if (m_page) { +#ifndef PDF_ENABLE_XFA + return m_page->m_pDocument; +#else return m_page->GetDocument()->GetPDFDoc(); } return NULL; @@ -814,6 +862,7 @@ CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { CPDF_Page* CPDFSDK_PageView::GetPDFPage() { if (m_page) { return m_page->GetPDFPage(); +#endif } return NULL; } @@ -833,6 +882,7 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary* pDict) { } return nullptr; } +#ifdef PDF_ENABLE_XFA CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(IXFA_Widget* hWidget) { if (!hWidget) return nullptr; @@ -843,6 +893,7 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(IXFA_Widget* hWidget) { } return nullptr; } +#endif FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point& point, FX_UINT nFlag) { @@ -862,6 +913,7 @@ FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point& point, return bRet; } +#ifdef PDF_ENABLE_XFA FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CPDF_Point& point, FX_UINT nFlag) { CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); @@ -900,6 +952,7 @@ FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CPDF_Point& point, FX_UINT nFlag) { return TRUE; } +#endif FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point& point, FX_UINT nFlag) { CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); ASSERT(pEnv); @@ -985,9 +1038,24 @@ FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag) { void CPDFSDK_PageView::LoadFXAnnots() { CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); +#ifdef PDF_ENABLE_XFA CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); +#endif +#ifndef PDF_ENABLE_XFA + FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); + // Disable the default AP construction. + CPDF_InterForm::EnableUpdateAP(FALSE); + m_pAnnotList.reset(new CPDF_AnnotList(m_page)); + CPDF_InterForm::EnableUpdateAP(enableAPUpdate); + const size_t nCount = m_pAnnotList->Count(); +#endif SetLock(TRUE); +#ifndef PDF_ENABLE_XFA + for (size_t i = 0; i < nCount; ++i) { + CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); + CPDF_Document* pDoc = GetPDFDocument(); +#else m_page->AddRef(); if (m_pSDKDoc->GetXFADocument()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { IXFA_PageView* pageView = NULL; @@ -1012,12 +1080,24 @@ void CPDFSDK_PageView::LoadFXAnnots() { m_fxAnnotArray.push_back(pAnnot); pAnnotHandlerMgr->Annot_OnLoad(pAnnot); } +#endif +#ifndef PDF_ENABLE_XFA + CheckUnSupportAnnot(pDoc, pPDFAnnot); +#else pWidgetHander->Release(); } else { CPDF_Page* pPage = m_page->GetPDFPage(); ASSERT(pPage != NULL); +#endif +#ifndef PDF_ENABLE_XFA + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); + if (!pAnnot) + continue; + m_fxAnnotArray.push_back(pAnnot); +#else FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); // Disable the default AP construction. CPDF_InterForm::EnableUpdateAP(FALSE); @@ -1033,11 +1113,18 @@ void CPDFSDK_PageView::LoadFXAnnots() { if (!pAnnot) continue; m_fxAnnotArray.push_back(pAnnot); +#endif +#ifndef PDF_ENABLE_XFA + pAnnotHandlerMgr->Annot_OnLoad(pAnnot); +#else pAnnotHandlerMgr->Annot_OnLoad(pAnnot); } +#endif } +#ifdef PDF_ENABLE_XFA m_page->Release(); +#endif SetLock(FALSE); } @@ -1058,7 +1145,11 @@ void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) { int CPDFSDK_PageView::GetPageIndex() { if (m_page) { +#ifndef PDF_ENABLE_XFA + CPDF_Dictionary* pDic = m_page->m_pFormDict; +#else CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict; +#endif CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); if (pDoc && pDic) { return pDoc->GetPageIndex(pDic->GetObjNum()); diff --git a/fpdfsdk/src/javascript/JS_Context.cpp b/fpdfsdk/src/javascript/JS_Context.cpp index 76988d5ef6..e59b1a77ed 100644 --- a/fpdfsdk/src/javascript/JS_Context.cpp +++ b/fpdfsdk/src/javascript/JS_Context.cpp @@ -35,7 +35,9 @@ CPDFDoc_Environment* CJS_Context::GetReaderApp() { FX_BOOL CJS_Context::RunScript(const CFX_WideString& script, CFX_WideString* info) { v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate()); +#ifdef PDF_ENABLE_XFA v8::Locker locker(m_pRuntime->GetIsolate()); +#endif v8::HandleScope handle_scope(m_pRuntime->GetIsolate()); v8::Local context = m_pRuntime->NewJSContext(); v8::Context::Scope context_scope(context); diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp index b195b42957..2d0d7f6e76 100644 --- a/fpdfsdk/src/javascript/JS_Runtime.cpp +++ b/fpdfsdk/src/javascript/JS_Runtime.cpp @@ -6,8 +6,10 @@ #include "JS_Runtime.h" +#ifdef PDF_ENABLE_XFA #include "../../../xfa/src/fxjse/src/value.h" #include "../../include/fpdfxfa/fpdfxfa_app.h" +#endif #include "Consts.h" #include "Document.h" #include "Field.h" @@ -51,6 +53,15 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) m_bBlocking(FALSE), m_isolate(NULL), m_isolateManaged(false) { +#ifndef PDF_ENABLE_XFA + IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform; + if (pPlatform->version <= 2) { + unsigned int embedderDataSlot = 0; + v8::Isolate* pExternalIsolate = nullptr; + if (pPlatform->version == 2) { + pExternalIsolate = reinterpret_cast(pPlatform->m_isolate); + embedderDataSlot = pPlatform->m_v8EmbedderSlot; +#else if (CPDFXFA_App::GetInstance()->GetJSERuntime()) { // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate. m_isolate = (v8::Isolate*)CPDFXFA_App::GetInstance()->GetJSERuntime(); @@ -64,7 +75,11 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) embedderDataSlot = pPlatform->m_v8EmbedderSlot; } FXJS_Initialize(embedderDataSlot, pExternalIsolate); +#endif } +#ifndef PDF_ENABLE_XFA + FXJS_Initialize(embedderDataSlot, pExternalIsolate); +#else m_isolateManaged = FXJS_GetIsolate(&m_isolate); } @@ -77,13 +92,20 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects); ReleaseContext(pContext); return; +#endif } +#ifndef PDF_ENABLE_XFA + m_isolateManaged = FXJS_GetIsolate(&m_isolate); +#else +#endif if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0) DefineJSObjects(); +#ifdef PDF_ENABLE_XFA CPDFXFA_App::GetInstance()->SetJavaScriptInitialized(TRUE); +#endif CJS_Context* pContext = (CJS_Context*)NewContext(); FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects); ReleaseContext(pContext); @@ -97,6 +119,9 @@ CJS_Runtime::~CJS_Runtime() { delete m_ContextArray.GetAt(i); m_ContextArray.RemoveAll(); +#ifndef PDF_ENABLE_XFA + FXJS_ReleaseRuntime(GetIsolate(), &m_context, &m_StaticObjects); +#endif m_pApp = NULL; m_pDocument = NULL; @@ -108,7 +133,9 @@ CJS_Runtime::~CJS_Runtime() { void CJS_Runtime::DefineJSObjects() { v8::Isolate::Scope isolate_scope(GetIsolate()); +#ifdef PDF_ENABLE_XFA v8::Locker locker(GetIsolate()); +#endif v8::HandleScope handle_scope(GetIsolate()); v8::Local context = v8::Context::New(GetIsolate()); v8::Context::Scope context_scope(context); @@ -181,7 +208,9 @@ IJS_Context* CJS_Runtime::GetCurrentContext() { void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) { if (m_pDocument != pReaderDoc) { v8::Isolate::Scope isolate_scope(m_isolate); +#ifdef PDF_ENABLE_XFA v8::Locker locker(m_isolate); +#endif v8::HandleScope handle_scope(m_isolate); v8::Local context = v8::Local::New(m_isolate, m_context); @@ -227,6 +256,7 @@ v8::Local CJS_Runtime::NewJSContext() { return v8::Local::New(m_isolate, m_context); } +#ifdef PDF_ENABLE_XFA CFX_WideString ChangeObjName(const CFX_WideString& str) { CFX_WideString sRet = str; sRet.Replace(L"_", L"."); @@ -293,6 +323,7 @@ FX_BOOL CJS_Runtime::SetHValueByName(const CFX_ByteStringC& utf8Name, return TRUE; } +#endif void CJS_Runtime::AddObserver(Observer* observer) { ASSERT(m_observers.find(observer) == m_observers.end()); m_observers.insert(observer); diff --git a/fpdfsdk/src/javascript/JS_Runtime.h b/fpdfsdk/src/javascript/JS_Runtime.h index 2353517016..6de2b705a5 100644 --- a/fpdfsdk/src/javascript/JS_Runtime.h +++ b/fpdfsdk/src/javascript/JS_Runtime.h @@ -58,12 +58,14 @@ class CJS_Runtime : public IJS_Runtime { v8::Isolate* GetIsolate() const { return m_isolate; } v8::Local NewJSContext(); +#ifdef PDF_ENABLE_XFA // IJS_Runtime: FX_BOOL GetHValueByName(const CFX_ByteStringC& utf8Name, FXJSE_HVALUE hValue) override; FX_BOOL SetHValueByName(const CFX_ByteStringC& utf8Name, FXJSE_HVALUE hValue) override; +#endif void AddObserver(Observer* observer); void RemoveObserver(Observer* observer); diff --git a/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp b/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp index 90d19d9451..b538066190 100644 --- a/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp +++ b/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp @@ -136,6 +136,7 @@ class CJS_RuntimeStub final : public IJS_Runtime { } CPDFSDK_Document* GetReaderDocument() override { return m_pDoc; } +#ifdef PDF_ENABLE_XFA virtual FX_BOOL GetHValueByName(const CFX_ByteStringC&, FXJSE_HVALUE) override { return FALSE; @@ -146,6 +147,7 @@ class CJS_RuntimeStub final : public IJS_Runtime { return FALSE; } +#endif int Execute(IJS_Context* cc, const wchar_t* script, CFX_WideString* info) override { diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp index 09b14440fb..d18e0322ab 100644 --- a/fpdfsdk/src/javascript/app.cpp +++ b/fpdfsdk/src/javascript/app.cpp @@ -47,7 +47,9 @@ CJS_Timer* TimerObj::GetTimer() const { #define JS_STR_PLATFORM L"WIN" #define JS_STR_LANGUANGE L"ENU" #define JS_NUM_VIEWERVERSION 8 +#ifdef PDF_ENABLE_XFA #define JS_NUM_VIEWERVERSION_XFA 11 +#endif #define JS_NUM_FORMSVERSION 7 BEGIN_JS_STATIC_CONST(CJS_App) @@ -198,6 +200,7 @@ FX_BOOL app::viewerVersion(IJS_Context* cc, if (!vp.IsGetting()) return FALSE; +#ifdef PDF_ENABLE_XFA CJS_Context* pContext = (CJS_Context*)cc; CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); CPDFXFA_Document* pDoc = pCurDoc->GetXFADocument(); @@ -206,6 +209,7 @@ FX_BOOL app::viewerVersion(IJS_Context* cc, return TRUE; } +#endif vp << JS_NUM_VIEWERVERSION; return TRUE; } diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp index 9a3a268652..d7d2ef54af 100644 --- a/fpdfsdk/src/jsapi/fxjs_v8.cpp +++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp @@ -281,7 +281,9 @@ void FXJS_InitializeRuntime( ++g_isolate_ref_count; v8::Isolate::Scope isolate_scope(pIsolate); +#ifdef PDF_ENABLE_XFA v8::Locker locker(pIsolate); +#endif v8::HandleScope handle_scope(pIsolate); v8::Local v8Context = v8::Context::New(pIsolate, NULL, GetGlobalObjectTemplate(pIsolate)); @@ -325,7 +327,9 @@ void FXJS_ReleaseRuntime(v8::Isolate* pIsolate, v8::Global* pV8PersistentContext, std::vector*>* pStaticObjects) { v8::Isolate::Scope isolate_scope(pIsolate); +#ifdef PDF_ENABLE_XFA v8::Locker locker(pIsolate); +#endif v8::HandleScope handle_scope(pIsolate); v8::Local context = v8::Local::New(pIsolate, *pV8PersistentContext); @@ -335,9 +339,11 @@ void FXJS_ReleaseRuntime(v8::Isolate* pIsolate, if (!pData) return; +#ifdef PDF_ENABLE_XFA // XFA, if present, should have already cleaned itself up. FXSYS_assert(!pData->m_pFXJSERuntimeData); +#endif int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); for (int i = 0; i < maxID; ++i) { CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i); @@ -374,11 +380,13 @@ IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate) { context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex)); } +#ifdef PDF_ENABLE_XFA void FXJS_SetRuntimeForV8Context(v8::Local v8Context, IJS_Runtime* pIRuntime) { v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime); } +#endif int FXJS_Execute(v8::Isolate* pIsolate, IJS_Context* pJSContext, const wchar_t* script, diff --git a/fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp b/fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp index 8e685c9bd4..e7f50e1b94 100644 --- a/fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp +++ b/fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp @@ -30,7 +30,9 @@ class FXJSV8Embeddertest : public EmbedderTest { EmbedderTest::SetUp(); v8::Isolate::Scope isolate_scope(m_pIsolate); +#ifdef PDF_ENABLE_XFA v8::Locker locker(m_pIsolate); +#endif v8::HandleScope handle_scope(m_pIsolate); FXJS_PerIsolateData::SetUp(m_pIsolate); FXJS_InitializeRuntime(m_pIsolate, nullptr, &m_pPersistentContext, @@ -58,7 +60,9 @@ class FXJSV8Embeddertest : public EmbedderTest { TEST_F(FXJSV8Embeddertest, Getters) { v8::Isolate::Scope isolate_scope(isolate()); +#ifdef PDF_ENABLE_XFA v8::Locker locker(isolate()); +#endif v8::HandleScope handle_scope(isolate()); v8::Context::Scope context_scope(GetV8Context()); diff --git a/fpdfsdk/src/pdfwindow/PWL_ComboBox.cpp b/fpdfsdk/src/pdfwindow/PWL_ComboBox.cpp index 943d6acb26..9c9c623e28 100644 --- a/fpdfsdk/src/pdfwindow/PWL_ComboBox.cpp +++ b/fpdfsdk/src/pdfwindow/PWL_ComboBox.cpp @@ -471,11 +471,13 @@ void CPWL_ComboBox::SetPopup(FX_BOOL bPopup) { if (bPopup) { if (m_pFillerNotify) { +#ifdef PDF_ENABLE_XFA FX_BOOL bExit = FALSE; m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, 0); if (bExit) return; +#endif int32_t nWhere = 0; FX_FLOAT fPopupRet = 0.0f; FX_FLOAT fPopupMin = 0.0f; @@ -503,11 +505,13 @@ void CPWL_ComboBox::SetPopup(FX_BOOL bPopup) { m_nPopupWhere = nWhere; Move(rcWindow, TRUE, TRUE); +#ifdef PDF_ENABLE_XFA bExit = FALSE; m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, 0); if (bExit) return; +#endif } } } else { @@ -528,6 +532,7 @@ FX_BOOL CPWL_ComboBox::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag) { case FWL_VKEY_Up: if (m_pList->GetCurSel() > 0) { FX_BOOL bExit = FALSE; +#ifdef PDF_ENABLE_XFA if (m_pFillerNotify) { m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag); @@ -538,6 +543,7 @@ FX_BOOL CPWL_ComboBox::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag) { if (bExit) return FALSE; } +#endif if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) { if (bExit) return FALSE; @@ -548,6 +554,7 @@ FX_BOOL CPWL_ComboBox::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag) { case FWL_VKEY_Down: if (m_pList->GetCurSel() < m_pList->GetCount() - 1) { FX_BOOL bExit = FALSE; +#ifdef PDF_ENABLE_XFA if (m_pFillerNotify) { m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag); @@ -558,6 +565,7 @@ FX_BOOL CPWL_ComboBox::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag) { if (bExit) return FALSE; } +#endif if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) { if (bExit) return FALSE; @@ -585,6 +593,7 @@ FX_BOOL CPWL_ComboBox::OnChar(FX_WORD nChar, FX_DWORD nFlag) { return m_pEdit->OnChar(nChar, nFlag); FX_BOOL bExit = FALSE; +#ifdef PDF_ENABLE_XFA if (m_pFillerNotify) { m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag); if (bExit) @@ -594,6 +603,7 @@ FX_BOOL CPWL_ComboBox::OnChar(FX_WORD nChar, FX_DWORD nFlag) { if (bExit) return FALSE; } +#endif return m_pList->OnCharWithExit(nChar, bExit, nFlag) ? bExit : FALSE; } -- cgit v1.2.3