From 4d29e78fc80285d222f2bad916354e3db970d0cc Mon Sep 17 00:00:00 2001 From: dsinclair Date: Tue, 4 Oct 2016 14:02:47 -0700 Subject: Rename fpdfsdk/fpdfxfa files to match contents Each of these files contains a single class, rename the file to match the internal class name. Review-Url: https://codereview.chromium.org/2385423004 --- fpdfsdk/fpdfxfa/cpdfxfa_app.cpp | 341 ++++++++++++++++++++++++++++ fpdfsdk/fpdfxfa/cpdfxfa_app.h | 79 +++++++ fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp | 4 +- fpdfsdk/fpdfxfa/cpdfxfa_document.cpp | 201 ++++++++++++++++ fpdfsdk/fpdfxfa/cpdfxfa_document.h | 95 ++++++++ fpdfsdk/fpdfxfa/cpdfxfa_page.cpp | 224 ++++++++++++++++++ fpdfsdk/fpdfxfa/cpdfxfa_page.h | 85 +++++++ fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.cpp | 59 +++++ fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h | 48 ++++ fpdfsdk/fpdfxfa/fpdfxfa_app.cpp | 341 ---------------------------- fpdfsdk/fpdfxfa/fpdfxfa_app.h | 79 ------- fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp | 201 ---------------- fpdfsdk/fpdfxfa/fpdfxfa_doc.h | 95 -------- fpdfsdk/fpdfxfa/fpdfxfa_page.cpp | 224 ------------------ fpdfsdk/fpdfxfa/fpdfxfa_page.h | 85 ------- fpdfsdk/fpdfxfa/fpdfxfa_util.cpp | 59 ----- fpdfsdk/fpdfxfa/fpdfxfa_util.h | 48 ---- 17 files changed, 1134 insertions(+), 1134 deletions(-) create mode 100644 fpdfsdk/fpdfxfa/cpdfxfa_app.cpp create mode 100644 fpdfsdk/fpdfxfa/cpdfxfa_app.h create mode 100644 fpdfsdk/fpdfxfa/cpdfxfa_document.cpp create mode 100644 fpdfsdk/fpdfxfa/cpdfxfa_document.h create mode 100644 fpdfsdk/fpdfxfa/cpdfxfa_page.cpp create mode 100644 fpdfsdk/fpdfxfa/cpdfxfa_page.h create mode 100644 fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.cpp create mode 100644 fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h delete mode 100644 fpdfsdk/fpdfxfa/fpdfxfa_app.cpp delete mode 100644 fpdfsdk/fpdfxfa/fpdfxfa_app.h delete mode 100644 fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp delete mode 100644 fpdfsdk/fpdfxfa/fpdfxfa_doc.h delete mode 100644 fpdfsdk/fpdfxfa/fpdfxfa_page.cpp delete mode 100644 fpdfsdk/fpdfxfa/fpdfxfa_page.h delete mode 100644 fpdfsdk/fpdfxfa/fpdfxfa_util.cpp delete mode 100644 fpdfsdk/fpdfxfa/fpdfxfa_util.h (limited to 'fpdfsdk/fpdfxfa') diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp new file mode 100644 index 0000000000..14450a10ab --- /dev/null +++ b/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp @@ -0,0 +1,341 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "fpdfsdk/fpdfxfa/cpdfxfa_app.h" + +#include + +#include "fpdfsdk/cpdfsdk_environment.h" +#include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" +#include "fpdfsdk/fsdk_define.h" +#include "third_party/base/ptr_util.h" +#include "xfa/fxbarcode/BC_Library.h" +#include "xfa/fxfa/xfa_ffapp.h" +#include "xfa/fxfa/xfa_fontmgr.h" + +namespace { + +CPDFXFA_App* g_pApp = nullptr; + +} // namespace + +CPDFXFA_App* CPDFXFA_App::GetInstance() { + if (!g_pApp) { + g_pApp = new CPDFXFA_App(); + } + return g_pApp; +} + +void CPDFXFA_App::ReleaseInstance() { + delete g_pApp; + g_pApp = nullptr; +} + +CPDFXFA_App::CPDFXFA_App() + : m_bJavaScriptInitialized(FALSE), + m_pIsolate(nullptr), + m_csAppType(JS_STR_VIEWERTYPE_STANDARD) { + m_pEnvList.RemoveAll(); +} + +CPDFXFA_App::~CPDFXFA_App() { + FXJSE_Runtime_Release(m_pIsolate); + m_pIsolate = nullptr; + + FXJSE_Finalize(); + BC_Library_Destory(); +} + +FX_BOOL CPDFXFA_App::Initialize(v8::Isolate* pIsolate) { + BC_Library_Init(); + FXJSE_Initialize(); + + m_pIsolate = pIsolate ? pIsolate : FXJSE_Runtime_Create_Own(); + if (!m_pIsolate) + return FALSE; + + m_pXFAApp = pdfium::MakeUnique(this); + m_pXFAApp->SetDefaultFontMgr( + std::unique_ptr(new CXFA_DefFontMgr)); + + return TRUE; +} + +FX_BOOL CPDFXFA_App::AddFormFillEnv(CPDFSDK_Environment* pEnv) { + if (!pEnv) + return FALSE; + + m_pEnvList.Add(pEnv); + return TRUE; +} + +FX_BOOL CPDFXFA_App::RemoveFormFillEnv(CPDFSDK_Environment* pEnv) { + if (!pEnv) + return FALSE; + + int nFind = m_pEnvList.Find(pEnv); + if (nFind != -1) { + m_pEnvList.RemoveAt(nFind); + return TRUE; + } + + return FALSE; +} + +void CPDFXFA_App::GetAppType(CFX_WideString& wsAppType) { + wsAppType = m_csAppType; +} + +void CPDFXFA_App::GetAppName(CFX_WideString& wsName) { + CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); + if (pEnv) { + wsName = pEnv->FFI_GetAppName(); + } +} + +void CPDFXFA_App::SetAppType(const CFX_WideStringC& wsAppType) { + m_csAppType = wsAppType; +} + +void CPDFXFA_App::GetLanguage(CFX_WideString& wsLanguage) { + CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); + if (pEnv) + wsLanguage = pEnv->GetLanguage(); +} + +void CPDFXFA_App::GetPlatform(CFX_WideString& wsPlatform) { + CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); + if (pEnv) { + wsPlatform = pEnv->GetPlatform(); + } +} + +void CPDFXFA_App::GetVariation(CFX_WideString& wsVariation) { + wsVariation = JS_STR_VIEWERVARIATION; +} + +void CPDFXFA_App::GetVersion(CFX_WideString& wsVersion) { + wsVersion = JS_STR_VIEWERVERSION_XFA; +} + +void CPDFXFA_App::Beep(uint32_t dwType) { + CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); + if (pEnv) { + pEnv->JS_appBeep(dwType); + } +} + +int32_t CPDFXFA_App::MsgBox(const CFX_WideString& wsMessage, + const CFX_WideString& wsTitle, + uint32_t dwIconType, + uint32_t dwButtonType) { + CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); + if (!pEnv) + return -1; + + uint32_t iconType = 0; + int iButtonType = 0; + switch (dwIconType) { + case XFA_MBICON_Error: + iconType |= 0; + break; + case XFA_MBICON_Warning: + iconType |= 1; + break; + case XFA_MBICON_Question: + iconType |= 2; + break; + case XFA_MBICON_Status: + iconType |= 3; + break; + } + switch (dwButtonType) { + case XFA_MB_OK: + iButtonType |= 0; + break; + case XFA_MB_OKCancel: + iButtonType |= 1; + break; + case XFA_MB_YesNo: + iButtonType |= 2; + break; + case XFA_MB_YesNoCancel: + iButtonType |= 3; + break; + } + int32_t iRet = pEnv->JS_appAlert(wsMessage.c_str(), wsTitle.c_str(), + iButtonType, iconType); + switch (iRet) { + case 1: + return XFA_IDOK; + case 2: + return XFA_IDCancel; + case 3: + return XFA_IDNo; + case 4: + return XFA_IDYes; + } + return XFA_IDYes; +} + +CFX_WideString CPDFXFA_App::Response(const CFX_WideString& wsQuestion, + const CFX_WideString& wsTitle, + const CFX_WideString& wsDefaultAnswer, + FX_BOOL bMark) { + CFX_WideString wsAnswer; + CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); + if (pEnv) { + int nLength = 2048; + char* pBuff = new char[nLength]; + nLength = pEnv->JS_appResponse(wsQuestion.c_str(), wsTitle.c_str(), + wsDefaultAnswer.c_str(), nullptr, bMark, + pBuff, nLength); + if (nLength > 0) { + nLength = nLength > 2046 ? 2046 : nLength; + pBuff[nLength] = 0; + pBuff[nLength + 1] = 0; + wsAnswer = CFX_WideString::FromUTF16LE( + reinterpret_cast(pBuff), + nLength / sizeof(unsigned short)); + } + delete[] pBuff; + } + return wsAnswer; +} + +IFX_FileRead* CPDFXFA_App::DownloadURL(const CFX_WideString& wsURL) { + CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); + return pEnv ? pEnv->DownloadFromURL(wsURL.c_str()) : nullptr; +} + +FX_BOOL CPDFXFA_App::PostRequestURL(const CFX_WideString& wsURL, + const CFX_WideString& wsData, + const CFX_WideString& wsContentType, + const CFX_WideString& wsEncode, + const CFX_WideString& wsHeader, + CFX_WideString& wsResponse) { + CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); + if (!pEnv) + return FALSE; + + wsResponse = + pEnv->PostRequestURL(wsURL.c_str(), wsData.c_str(), wsContentType.c_str(), + wsEncode.c_str(), wsHeader.c_str()); + return TRUE; +} + +FX_BOOL CPDFXFA_App::PutRequestURL(const CFX_WideString& wsURL, + const CFX_WideString& wsData, + const CFX_WideString& wsEncode) { + CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); + return pEnv && + pEnv->PutRequestURL(wsURL.c_str(), wsData.c_str(), wsEncode.c_str()); +} + +void CPDFXFA_App::LoadString(int32_t iStringID, CFX_WideString& wsString) { + switch (iStringID) { + case XFA_IDS_ValidateFailed: + wsString = L"%s validation failed"; + return; + case XFA_IDS_CalcOverride: + wsString = L"Calculate Override"; + return; + case XFA_IDS_ModifyField: + wsString = L"Are you sure you want to modify this field?"; + return; + case XFA_IDS_NotModifyField: + wsString = L"You are not allowed to modify this field."; + return; + case XFA_IDS_AppName: + wsString = L"pdfium"; + return; + case XFA_IDS_Unable_TO_SET: + wsString = L"Unable to set "; + return; + case XFA_IDS_INVAlID_PROP_SET: + wsString = L"Invalid property set operation."; + return; + case XFA_IDS_NOT_DEFAUL_VALUE: + wsString = L" doesn't have a default property."; + return; + case XFA_IDS_UNABLE_SET_LANGUAGE: + wsString = L"Unable to set language value."; + return; + case XFA_IDS_UNABLE_SET_NUMPAGES: + wsString = L"Unable to set numPages value."; + return; + case XFA_IDS_UNABLE_SET_PLATFORM: + wsString = L"Unable to set platform value."; + return; + case XFA_IDS_UNABLE_SET_VARIATION: + wsString = L"Unable to set variation value."; + return; + case XFA_IDS_UNABLE_SET_VERSION: + wsString = L"Unable to set version value."; + return; + case XFA_IDS_UNABLE_SET_READY: + wsString = L"Unable to set ready value."; + return; + case XFA_IDS_COMPILER_ERROR: + wsString = L"Compiler error."; + return; + case XFA_IDS_DIVIDE_ZERO: + wsString = L"Divide by zero."; + return; + case XFA_IDS_ACCESS_PROPERTY_IN_NOT_OBJECT: + wsString = + L"An attempt was made to reference property '%s' of a non-object in " + L"SOM expression %s."; + return; + case XFA_IDS_INDEX_OUT_OF_BOUNDS: + wsString = L"Index value is out of bounds."; + return; + case XFA_IDS_INCORRECT_NUMBER_OF_METHOD: + wsString = L"Incorrect number of parameters calling method '%s'."; + return; + case XFA_IDS_ARGUMENT_MISMATCH: + wsString = L"Argument mismatch in property or function argument."; + return; + case XFA_IDS_NOT_HAVE_PROPERTY: + wsString = L"'%s' doesn't have property '%s'."; + return; + case XFA_IDS_VIOLATE_BOUNDARY: + wsString = + L"The element [%s] has violated its allowable number of occurrences."; + return; + case XFA_IDS_SERVER_DENY: + wsString = L"Server does not permit."; + return; + case XFA_IDS_ValidateLimit: + wsString = + L"Message limit exceeded. Remaining %d validation errors not " + L"reported."; + return; + case XFA_IDS_ValidateNullWarning: + wsString = + L"%s cannot be blank. To ignore validations for %s, click Ignore."; + return; + case XFA_IDS_ValidateNullError: + wsString = L"%s cannot be blank."; + return; + case XFA_IDS_ValidateWarning: + wsString = + L"The value you entered for %s is invalid. To ignore validations for " + L"%s, click Ignore."; + return; + case XFA_IDS_ValidateError: + wsString = L"The value you entered for %s is invalid."; + return; + } +} + +IFWL_AdapterTimerMgr* CPDFXFA_App::GetTimerMgr() { + CXFA_FWLAdapterTimerMgr* pAdapter = nullptr; + CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); + if (pEnv) + pAdapter = new CXFA_FWLAdapterTimerMgr(pEnv); + return pAdapter; +} diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_app.h b/fpdfsdk/fpdfxfa/cpdfxfa_app.h new file mode 100644 index 0000000000..3830dc4d4c --- /dev/null +++ b/fpdfsdk/fpdfxfa/cpdfxfa_app.h @@ -0,0 +1,79 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef FPDFSDK_FPDFXFA_CPDFXFA_APP_H_ +#define FPDFSDK_FPDFXFA_CPDFXFA_APP_H_ + +#include "xfa/fxfa/fxfa.h" + +class CPDFSDK_Environment; +class IFXJS_Runtime; + +class CPDFXFA_App : public IXFA_AppProvider { + public: + static CPDFXFA_App* GetInstance(); + static void ReleaseInstance(); + + CPDFXFA_App(); + ~CPDFXFA_App() override; + + FX_BOOL Initialize(v8::Isolate* pIsolate); + CXFA_FFApp* GetXFAApp() { return m_pXFAApp.get(); } + + FX_BOOL AddFormFillEnv(CPDFSDK_Environment* pEnv); + FX_BOOL RemoveFormFillEnv(CPDFSDK_Environment* pEnv); + + FX_BOOL IsJavaScriptInitialized() const { return m_bJavaScriptInitialized; } + void SetJavaScriptInitialized(FX_BOOL bInitialized) { + m_bJavaScriptInitialized = bInitialized; + } + + v8::Isolate* GetJSERuntime() const { return m_pIsolate; } + + // IFXA_AppProvider: + void GetAppType(CFX_WideString& wsAppType) override; + void SetAppType(const CFX_WideStringC& wsAppType) override; + + void GetLanguage(CFX_WideString& wsLanguage) override; + void GetPlatform(CFX_WideString& wsPlatform) override; + void GetVariation(CFX_WideString& wsVariation) override; + void GetVersion(CFX_WideString& wsVersion) override; + void GetAppName(CFX_WideString& wsName) override; + + void Beep(uint32_t dwType) override; + int32_t MsgBox(const CFX_WideString& wsMessage, + const CFX_WideString& wsTitle, + uint32_t dwIconType, + uint32_t dwButtonType) override; + CFX_WideString Response(const CFX_WideString& wsQuestion, + const CFX_WideString& wsTitle, + const CFX_WideString& wsDefaultAnswer, + FX_BOOL bMark) override; + + IFX_FileRead* DownloadURL(const CFX_WideString& wsURL) override; + FX_BOOL PostRequestURL(const CFX_WideString& wsURL, + const CFX_WideString& wsData, + const CFX_WideString& wsContentType, + const CFX_WideString& wsEncode, + const CFX_WideString& wsHeader, + CFX_WideString& wsResponse) override; + FX_BOOL PutRequestURL(const CFX_WideString& wsURL, + const CFX_WideString& wsData, + const CFX_WideString& wsEncode) override; + + void LoadString(int32_t iStringID, CFX_WideString& wsString) override; + IFWL_AdapterTimerMgr* GetTimerMgr() override; + + CFX_ArrayTemplate m_pEnvList; + + protected: + FX_BOOL m_bJavaScriptInitialized; + std::unique_ptr m_pXFAApp; + v8::Isolate* m_pIsolate; + CFX_WideString m_csAppType; +}; + +#endif // FPDFSDK_FPDFXFA_CPDFXFA_APP_H_ diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp index 3910a701ce..1b27e16551 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp @@ -13,8 +13,8 @@ #include "fpdfsdk/cpdfsdk_environment.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" -#include "fpdfsdk/fpdfxfa/fpdfxfa_doc.h" -#include "fpdfsdk/fpdfxfa/fpdfxfa_page.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" #include "fpdfsdk/javascript/ijs_runtime.h" #include "xfa/fxfa/xfa_ffdocview.h" #include "xfa/fxfa/xfa_ffwidget.h" diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_document.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_document.cpp new file mode 100644 index 0000000000..e49cfde8c4 --- /dev/null +++ b/fpdfsdk/fpdfxfa/cpdfxfa_document.cpp @@ -0,0 +1,201 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" + +#include "core/fpdfapi/parser/cpdf_document.h" +#include "fpdfsdk/cpdfsdk_document.h" +#include "fpdfsdk/cpdfsdk_environment.h" +#include "fpdfsdk/cpdfsdk_interform.h" +#include "fpdfsdk/cpdfsdk_pageview.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_app.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" +#include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" +#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/javascript/ijs_runtime.h" +#include "public/fpdf_formfill.h" +#include "xfa/fxfa/cxfa_eventparam.h" +#include "xfa/fxfa/xfa_ffapp.h" +#include "xfa/fxfa/xfa_ffdoc.h" +#include "xfa/fxfa/xfa_ffdocview.h" +#include "xfa/fxfa/xfa_ffpageview.h" +#include "xfa/fxfa/xfa_ffwidgethandler.h" + +#ifndef _WIN32 +extern void SetLastError(int err); +extern int GetLastError(); +#endif + +CPDFXFA_Document::CPDFXFA_Document(std::unique_ptr pPDFDoc, + CPDFXFA_App* pProvider) + : m_iDocType(DOCTYPE_PDF), + m_pPDFDoc(std::move(pPDFDoc)), + m_pXFADocView(nullptr), + m_pApp(pProvider), + m_nLoadStatus(FXFA_LOADSTATUS_PRELOAD), + m_nPageCount(0), + m_DocEnv(this) {} + +CPDFXFA_Document::~CPDFXFA_Document() { + m_nLoadStatus = FXFA_LOADSTATUS_CLOSING; + + if (m_pXFADoc) { + CXFA_FFApp* pApp = m_pApp->GetXFAApp(); + if (pApp) { + CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler(); + if (pDocHandler) + CloseXFADoc(pDocHandler); + } + m_pXFADoc.reset(); + } + + m_nLoadStatus = FXFA_LOADSTATUS_CLOSED; +} + +FX_BOOL CPDFXFA_Document::LoadXFADoc() { + m_nLoadStatus = FXFA_LOADSTATUS_LOADING; + + if (!m_pPDFDoc) + return FALSE; + + m_XFAPageList.RemoveAll(); + + CXFA_FFApp* pApp = m_pApp->GetXFAApp(); + if (!pApp) + return FALSE; + + m_pXFADoc.reset(pApp->CreateDoc(&m_DocEnv, m_pPDFDoc.get())); + if (!m_pXFADoc) { + SetLastError(FPDF_ERR_XFALOAD); + return FALSE; + } + + CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler(); + if (!pDocHandler) { + SetLastError(FPDF_ERR_XFALOAD); + return FALSE; + } + + m_pXFADoc->StartLoad(); + int iStatus = m_pXFADoc->DoLoad(nullptr); + if (iStatus != XFA_PARSESTATUS_Done) { + CloseXFADoc(pDocHandler); + SetLastError(FPDF_ERR_XFALOAD); + return FALSE; + } + m_pXFADoc->StopLoad(); + m_pXFADoc->GetXFADoc()->InitScriptContext(m_pApp->GetJSERuntime()); + + if (m_pXFADoc->GetDocType() == XFA_DOCTYPE_Dynamic) + m_iDocType = DOCTYPE_DYNAMIC_XFA; + else + m_iDocType = DOCTYPE_STATIC_XFA; + + m_pXFADocView = m_pXFADoc->CreateDocView(XFA_DOCVIEW_View); + if (m_pXFADocView->StartLayout() < 0) { + CloseXFADoc(pDocHandler); + SetLastError(FPDF_ERR_XFALAYOUT); + return FALSE; + } + + m_pXFADocView->DoLayout(nullptr); + m_pXFADocView->StopLayout(); + m_nLoadStatus = FXFA_LOADSTATUS_LOADED; + + return TRUE; +} + +int CPDFXFA_Document::GetPageCount() const { + if (!m_pPDFDoc && !m_pXFADoc) + return 0; + + switch (m_iDocType) { + case DOCTYPE_PDF: + case DOCTYPE_STATIC_XFA: + if (m_pPDFDoc) + return m_pPDFDoc->GetPageCount(); + case DOCTYPE_DYNAMIC_XFA: + if (m_pXFADoc) + return m_pXFADocView->CountPageViews(); + default: + return 0; + } +} + +CPDFXFA_Page* CPDFXFA_Document::GetXFAPage(int page_index) { + if (page_index < 0) + return nullptr; + + CPDFXFA_Page* pPage = nullptr; + int nCount = m_XFAPageList.GetSize(); + if (nCount > 0 && page_index < nCount) { + pPage = m_XFAPageList.GetAt(page_index); + if (pPage) + pPage->Retain(); + } else { + m_nPageCount = GetPageCount(); + m_XFAPageList.SetSize(m_nPageCount); + } + if (pPage) + return pPage; + + pPage = new CPDFXFA_Page(this, page_index); + if (!pPage->LoadPage()) { + pPage->Release(); + return nullptr; + } + m_XFAPageList.SetAt(page_index, pPage); + return pPage; +} + +CPDFXFA_Page* CPDFXFA_Document::GetXFAPage(CXFA_FFPageView* pPage) const { + if (!pPage) + return nullptr; + + if (!m_pXFADoc) + return nullptr; + + if (m_iDocType != DOCTYPE_DYNAMIC_XFA) + return nullptr; + + int nSize = m_XFAPageList.GetSize(); + for (int i = 0; i < nSize; i++) { + CPDFXFA_Page* pTempPage = m_XFAPageList.GetAt(i); + if (!pTempPage) + continue; + if (pTempPage->GetXFAPageView() && pTempPage->GetXFAPageView() == pPage) + return pTempPage; + } + + return nullptr; +} + +void CPDFXFA_Document::DeletePage(int page_index) { + // Delete from the document first because, if GetPage was never called for + // this |page_index| then |m_XFAPageList| may have size < |page_index| even + // if it's a valid page in the document. + if (m_pPDFDoc) + m_pPDFDoc->DeletePage(page_index); + + if (page_index < 0 || page_index >= m_XFAPageList.GetSize()) + return; + + if (CPDFXFA_Page* pPage = m_XFAPageList.GetAt(page_index)) + pPage->Release(); +} + +void CPDFXFA_Document::RemovePage(CPDFXFA_Page* page) { + m_XFAPageList.SetAt(page->GetPageIndex(), nullptr); +} + +void CPDFXFA_Document::SetSDKDoc(std::unique_ptr pSDKDoc) { + m_pSDKDoc.reset(pSDKDoc.release()); +} + +void CPDFXFA_Document::ClearChangeMark() { + if (m_pSDKDoc) + m_pSDKDoc->ClearChangeMark(); +} diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_document.h b/fpdfsdk/fpdfxfa/cpdfxfa_document.h new file mode 100644 index 0000000000..f67a880a36 --- /dev/null +++ b/fpdfsdk/fpdfxfa/cpdfxfa_document.h @@ -0,0 +1,95 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef FPDFSDK_FPDFXFA_CPDFXFA_DOCUMENT_H_ +#define FPDFSDK_FPDFXFA_CPDFXFA_DOCUMENT_H_ + +#include + +#include "fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h" +#include "xfa/fxfa/xfa_ffdoc.h" + +class CPDFSDK_Document; +class CPDFSDK_Environment; +class CPDFXFA_App; +class CPDFXFA_Page; +class CXFA_FFDocHandler; +class IJS_Runtime; +class IJS_Context; + +enum LoadStatus { + FXFA_LOADSTATUS_PRELOAD = 0, + FXFA_LOADSTATUS_LOADING, + FXFA_LOADSTATUS_LOADED, + FXFA_LOADSTATUS_CLOSING, + FXFA_LOADSTATUS_CLOSED +}; + +class CPDFXFA_Document { + public: + CPDFXFA_Document(std::unique_ptr pPDFDoc, + CPDFXFA_App* pProvider); + ~CPDFXFA_Document(); + + FX_BOOL LoadXFADoc(); + CPDF_Document* GetPDFDoc() { return m_pPDFDoc.get(); } + CXFA_FFDoc* GetXFADoc() { return m_pXFADoc.get(); } + CXFA_FFDocView* GetXFADocView() { return m_pXFADocView; } + int GetDocType() const { return m_iDocType; } + + CPDFSDK_Document* GetSDKDoc() const { return m_pSDKDoc.get(); } + void SetSDKDoc(std::unique_ptr pSDKDoc); + + void DeletePage(int page_index); + int GetPageCount() const; + + CPDFXFA_Page* GetXFAPage(int page_index); + CPDFXFA_Page* GetXFAPage(CXFA_FFPageView* pPage) const; + + void RemovePage(CPDFXFA_Page* page); + + void ClearChangeMark(); + + protected: + friend class CPDFXFA_DocEnvironment; + + int GetOriginalPageCount() const { return m_nPageCount; } + void SetOriginalPageCount(int count) { + m_nPageCount = count; + m_XFAPageList.SetSize(count); + } + + LoadStatus GetLoadStatus() const { return m_nLoadStatus; } + + CFX_ArrayTemplate* GetXFAPageList() { return &m_XFAPageList; } + + private: + void CloseXFADoc(CXFA_FFDocHandler* pDoc) { + if (pDoc) { + m_pXFADoc->CloseDoc(); + m_pXFADoc.reset(); + m_pXFADocView = nullptr; + } + } + + int m_iDocType; + + std::unique_ptr m_pPDFDoc; + // |m_pSDKDoc| must be destroyed before |m_pPDFDoc| since it needs to access + // it to kill focused annotations. + std::unique_ptr m_pSDKDoc; + std::unique_ptr m_pXFADoc; + CXFA_FFDocView* m_pXFADocView; // not owned. + CPDFXFA_App* const m_pApp; + CFX_ArrayTemplate m_XFAPageList; + LoadStatus m_nLoadStatus; + int m_nPageCount; + + // Must be destroy before |m_pSDKDoc|. + CPDFXFA_DocEnvironment m_DocEnv; +}; + +#endif // FPDFSDK_FPDFXFA_CPDFXFA_DOCUMENT_H_ diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp new file mode 100644 index 0000000000..00cff3e28a --- /dev/null +++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp @@ -0,0 +1,224 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" + +#include "core/fpdfapi/page/cpdf_page.h" +#include "core/fpdfapi/parser/cpdf_document.h" +#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" +#include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" +#include "fpdfsdk/fsdk_define.h" +#include "public/fpdf_formfill.h" +#include "third_party/base/ptr_util.h" +#include "xfa/fxfa/xfa_ffdocview.h" +#include "xfa/fxfa/xfa_ffpageview.h" + +CPDFXFA_Page::CPDFXFA_Page(CPDFXFA_Document* pDoc, int page_index) + : m_pXFAPageView(nullptr), + m_pDocument(pDoc), + m_iPageIndex(page_index), + m_iRef(1) {} + +CPDFXFA_Page::~CPDFXFA_Page() { + if (m_pDocument) + m_pDocument->RemovePage(this); +} + +FX_BOOL CPDFXFA_Page::LoadPDFPage() { + if (!m_pDocument) + return FALSE; + + CPDF_Document* pPDFDoc = m_pDocument->GetPDFDoc(); + if (!pPDFDoc) + return FALSE; + + CPDF_Dictionary* pDict = pPDFDoc->GetPage(m_iPageIndex); + if (!pDict) + return FALSE; + + if (!m_pPDFPage || m_pPDFPage->m_pFormDict != pDict) { + m_pPDFPage = pdfium::MakeUnique(pPDFDoc, pDict, true); + m_pPDFPage->ParseContent(); + } + return TRUE; +} + +FX_BOOL CPDFXFA_Page::LoadXFAPageView() { + if (!m_pDocument) + return FALSE; + + CXFA_FFDoc* pXFADoc = m_pDocument->GetXFADoc(); + if (!pXFADoc) + return FALSE; + + CXFA_FFDocView* pXFADocView = m_pDocument->GetXFADocView(); + if (!pXFADocView) + return FALSE; + + CXFA_FFPageView* pPageView = pXFADocView->GetPageView(m_iPageIndex); + if (!pPageView) + return FALSE; + + m_pXFAPageView = pPageView; + return TRUE; +} + +FX_BOOL CPDFXFA_Page::LoadPage() { + if (!m_pDocument || m_iPageIndex < 0) + return FALSE; + + int iDocType = m_pDocument->GetDocType(); + switch (iDocType) { + case DOCTYPE_PDF: + case DOCTYPE_STATIC_XFA: { + return LoadPDFPage(); + } + case DOCTYPE_DYNAMIC_XFA: { + return LoadXFAPageView(); + } + default: + return FALSE; + } +} + +FX_BOOL CPDFXFA_Page::LoadPDFPage(CPDF_Dictionary* pageDict) { + if (!m_pDocument || m_iPageIndex < 0 || !pageDict) + return FALSE; + + m_pPDFPage = + pdfium::MakeUnique(m_pDocument->GetPDFDoc(), pageDict, true); + m_pPDFPage->ParseContent(); + return TRUE; +} + +FX_FLOAT CPDFXFA_Page::GetPageWidth() const { + if (!m_pPDFPage && !m_pXFAPageView) + return 0.0f; + + int nDocType = m_pDocument->GetDocType(); + switch (nDocType) { + case DOCTYPE_DYNAMIC_XFA: { + if (m_pXFAPageView) { + CFX_RectF rect; + m_pXFAPageView->GetPageViewRect(rect); + return rect.width; + } + } break; + case DOCTYPE_STATIC_XFA: + case DOCTYPE_PDF: { + if (m_pPDFPage) + return m_pPDFPage->GetPageWidth(); + } break; + default: + return 0.0f; + } + + return 0.0f; +} + +FX_FLOAT CPDFXFA_Page::GetPageHeight() const { + if (!m_pPDFPage && !m_pXFAPageView) + return 0.0f; + + int nDocType = m_pDocument->GetDocType(); + switch (nDocType) { + case DOCTYPE_PDF: + case DOCTYPE_STATIC_XFA: { + if (m_pPDFPage) + return m_pPDFPage->GetPageHeight(); + } break; + case DOCTYPE_DYNAMIC_XFA: { + if (m_pXFAPageView) { + CFX_RectF rect; + m_pXFAPageView->GetPageViewRect(rect); + return rect.height; + } + } break; + default: + return 0.0f; + } + + return 0.0f; +} + +void CPDFXFA_Page::DeviceToPage(int start_x, + int start_y, + int size_x, + int size_y, + int rotate, + int device_x, + int device_y, + double* page_x, + double* page_y) { + if (!m_pPDFPage && !m_pXFAPageView) + return; + + CFX_Matrix page2device; + CFX_Matrix device2page; + FX_FLOAT page_x_f, page_y_f; + + GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, rotate); + + device2page.SetReverse(page2device); + 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); +} + +void CPDFXFA_Page::PageToDevice(int start_x, + int start_y, + int size_x, + int size_y, + int rotate, + double page_x, + double page_y, + int* device_x, + int* device_y) { + if (!m_pPDFPage && !m_pXFAPageView) + return; + + CFX_Matrix page2device; + FX_FLOAT device_x_f, device_y_f; + + GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, rotate); + + 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); +} + +void CPDFXFA_Page::GetDisplayMatrix(CFX_Matrix& matrix, + int xPos, + int yPos, + int xSize, + int ySize, + int iRotate) const { + if (!m_pPDFPage && !m_pXFAPageView) + return; + + int nDocType = m_pDocument->GetDocType(); + switch (nDocType) { + case DOCTYPE_DYNAMIC_XFA: { + if (m_pXFAPageView) { + CFX_Rect rect; + rect.Set(xPos, yPos, xSize, ySize); + m_pXFAPageView->GetDisplayMatrix(matrix, rect, iRotate); + } + } break; + case DOCTYPE_PDF: + case DOCTYPE_STATIC_XFA: { + if (m_pPDFPage) { + m_pPDFPage->GetDisplayMatrix(matrix, xPos, yPos, xSize, ySize, iRotate); + } + } break; + default: + return; + } +} diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.h b/fpdfsdk/fpdfxfa/cpdfxfa_page.h new file mode 100644 index 0000000000..80a183f807 --- /dev/null +++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.h @@ -0,0 +1,85 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef FPDFSDK_FPDFXFA_CPDFXFA_PAGE_H_ +#define FPDFSDK_FPDFXFA_CPDFXFA_PAGE_H_ + +#include + +#include "core/fxcrt/fx_system.h" + +class CFX_Matrix; +class CPDFXFA_Document; +class CPDF_Dictionary; +class CPDF_Page; +class CXFA_FFPageView; + +class CPDFXFA_Page { + public: + CPDFXFA_Page(CPDFXFA_Document* pDoc, int page_index); + + void Retain() { m_iRef++; } + void Release() { + if (--m_iRef <= 0) + delete this; + } + + FX_BOOL LoadPage(); + FX_BOOL LoadPDFPage(CPDF_Dictionary* pageDict); + CPDFXFA_Document* GetDocument() const { return m_pDocument; } + int GetPageIndex() const { return m_iPageIndex; } + CPDF_Page* GetPDFPage() const { return m_pPDFPage.get(); } + CXFA_FFPageView* GetXFAPageView() const { return m_pXFAPageView; } + + void SetXFAPageView(CXFA_FFPageView* pPageView) { + m_pXFAPageView = pPageView; + } + + FX_FLOAT GetPageWidth() const; + FX_FLOAT GetPageHeight() const; + + void DeviceToPage(int start_x, + int start_y, + int size_x, + int size_y, + int rotate, + int device_x, + int device_y, + double* page_x, + double* page_y); + void PageToDevice(int start_x, + int start_y, + int size_x, + int size_y, + int rotate, + double page_x, + double page_y, + int* device_x, + int* device_y); + + void GetDisplayMatrix(CFX_Matrix& matrix, + int xPos, + int yPos, + int xSize, + int ySize, + int iRotate) const; + + protected: + // Refcounted class. + ~CPDFXFA_Page(); + + FX_BOOL LoadPDFPage(); + FX_BOOL LoadXFAPageView(); + + private: + std::unique_ptr m_pPDFPage; + CXFA_FFPageView* m_pXFAPageView; + CPDFXFA_Document* const m_pDocument; + const int m_iPageIndex; + int m_iRef; +}; + +#endif // FPDFSDK_FPDFXFA_CPDFXFA_PAGE_H_ diff --git a/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.cpp b/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.cpp new file mode 100644 index 0000000000..b835fd4467 --- /dev/null +++ b/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.cpp @@ -0,0 +1,59 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" + +#include + +#include "fpdfsdk/cpdfsdk_environment.h" +#include "fpdfsdk/fsdk_define.h" + +std::vector* CXFA_FWLAdapterTimerMgr::s_TimerArray = nullptr; + +FWL_Error CXFA_FWLAdapterTimerMgr::Start(IFWL_Timer* pTimer, + uint32_t dwElapse, + bool bImmediately, + IFWL_TimerInfo** pTimerInfo) { + if (!m_pEnv) + return FWL_Error::Indefinite; + + int32_t id_event = m_pEnv->SetTimer(dwElapse, TimerProc); + if (!s_TimerArray) + s_TimerArray = new std::vector; + + s_TimerArray->push_back(new CFWL_TimerInfo(id_event, pTimer)); + *pTimerInfo = s_TimerArray->back(); + return FWL_Error::Succeeded; +} + +FWL_Error CXFA_FWLAdapterTimerMgr::Stop(IFWL_TimerInfo* pTimerInfo) { + if (!pTimerInfo || !m_pEnv) + return FWL_Error::Indefinite; + + CFWL_TimerInfo* pInfo = static_cast(pTimerInfo); + m_pEnv->KillTimer(pInfo->idEvent); + if (s_TimerArray) { + auto it = std::find(s_TimerArray->begin(), s_TimerArray->end(), pInfo); + if (it != s_TimerArray->end()) { + s_TimerArray->erase(it); + delete pInfo; + } + } + return FWL_Error::Succeeded; +} + +// static +void CXFA_FWLAdapterTimerMgr::TimerProc(int32_t idEvent) { + if (!s_TimerArray) + return; + + for (CFWL_TimerInfo* pInfo : *s_TimerArray) { + if (pInfo->idEvent == idEvent) { + pInfo->pTimer->Run(pInfo); + break; + } + } +} diff --git a/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h b/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h new file mode 100644 index 0000000000..958171d4ca --- /dev/null +++ b/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h @@ -0,0 +1,48 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef FPDFSDK_FPDFXFA_CXFA_FWLADAPTERTIMERMGR_H_ +#define FPDFSDK_FPDFXFA_CXFA_FWLADAPTERTIMERMGR_H_ + +#include + +#include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" +#include "xfa/fwl/core/ifwl_adaptertimermgr.h" + +#define JS_STR_VIEWERTYPE_STANDARD L"Exchange" +#define JS_STR_LANGUANGE L"ENU" +#define JS_STR_VIEWERVARIATION L"Full" +#define JS_STR_VIEWERVERSION_XFA L"11" + +struct CFWL_TimerInfo; + +class CXFA_FWLAdapterTimerMgr : public IFWL_AdapterTimerMgr { + public: + CXFA_FWLAdapterTimerMgr(CPDFSDK_Environment* pEnv) : m_pEnv(pEnv) {} + + FWL_Error Start(IFWL_Timer* pTimer, + uint32_t dwElapse, + bool bImmediately, + IFWL_TimerInfo** pTimerInfo) override; + FWL_Error Stop(IFWL_TimerInfo* pTimerInfo) override; + + protected: + static void TimerProc(int32_t idEvent); + + static std::vector* s_TimerArray; + CPDFSDK_Environment* const m_pEnv; +}; + +struct CFWL_TimerInfo : public IFWL_TimerInfo { + CFWL_TimerInfo() : pTimer(nullptr) {} + CFWL_TimerInfo(int32_t event, IFWL_Timer* timer) + : idEvent(event), pTimer(timer) {} + + int32_t idEvent; + IFWL_Timer* pTimer; +}; + +#endif // FPDFSDK_FPDFXFA_CXFA_FWLADAPTERTIMERMGR_H_ diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp deleted file mode 100644 index 4edfcf0676..0000000000 --- a/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp +++ /dev/null @@ -1,341 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "fpdfsdk/fpdfxfa/fpdfxfa_app.h" - -#include - -#include "fpdfsdk/cpdfsdk_environment.h" -#include "fpdfsdk/fpdfxfa/fpdfxfa_util.h" -#include "fpdfsdk/fsdk_define.h" -#include "third_party/base/ptr_util.h" -#include "xfa/fxbarcode/BC_Library.h" -#include "xfa/fxfa/xfa_ffapp.h" -#include "xfa/fxfa/xfa_fontmgr.h" - -namespace { - -CPDFXFA_App* g_pApp = nullptr; - -} // namespace - -CPDFXFA_App* CPDFXFA_App::GetInstance() { - if (!g_pApp) { - g_pApp = new CPDFXFA_App(); - } - return g_pApp; -} - -void CPDFXFA_App::ReleaseInstance() { - delete g_pApp; - g_pApp = nullptr; -} - -CPDFXFA_App::CPDFXFA_App() - : m_bJavaScriptInitialized(FALSE), - m_pIsolate(nullptr), - m_csAppType(JS_STR_VIEWERTYPE_STANDARD) { - m_pEnvList.RemoveAll(); -} - -CPDFXFA_App::~CPDFXFA_App() { - FXJSE_Runtime_Release(m_pIsolate); - m_pIsolate = nullptr; - - FXJSE_Finalize(); - BC_Library_Destory(); -} - -FX_BOOL CPDFXFA_App::Initialize(v8::Isolate* pIsolate) { - BC_Library_Init(); - FXJSE_Initialize(); - - m_pIsolate = pIsolate ? pIsolate : FXJSE_Runtime_Create_Own(); - if (!m_pIsolate) - return FALSE; - - m_pXFAApp = pdfium::MakeUnique(this); - m_pXFAApp->SetDefaultFontMgr( - std::unique_ptr(new CXFA_DefFontMgr)); - - return TRUE; -} - -FX_BOOL CPDFXFA_App::AddFormFillEnv(CPDFSDK_Environment* pEnv) { - if (!pEnv) - return FALSE; - - m_pEnvList.Add(pEnv); - return TRUE; -} - -FX_BOOL CPDFXFA_App::RemoveFormFillEnv(CPDFSDK_Environment* pEnv) { - if (!pEnv) - return FALSE; - - int nFind = m_pEnvList.Find(pEnv); - if (nFind != -1) { - m_pEnvList.RemoveAt(nFind); - return TRUE; - } - - return FALSE; -} - -void CPDFXFA_App::GetAppType(CFX_WideString& wsAppType) { - wsAppType = m_csAppType; -} - -void CPDFXFA_App::GetAppName(CFX_WideString& wsName) { - CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); - if (pEnv) { - wsName = pEnv->FFI_GetAppName(); - } -} - -void CPDFXFA_App::SetAppType(const CFX_WideStringC& wsAppType) { - m_csAppType = wsAppType; -} - -void CPDFXFA_App::GetLanguage(CFX_WideString& wsLanguage) { - CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); - if (pEnv) - wsLanguage = pEnv->GetLanguage(); -} - -void CPDFXFA_App::GetPlatform(CFX_WideString& wsPlatform) { - CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); - if (pEnv) { - wsPlatform = pEnv->GetPlatform(); - } -} - -void CPDFXFA_App::GetVariation(CFX_WideString& wsVariation) { - wsVariation = JS_STR_VIEWERVARIATION; -} - -void CPDFXFA_App::GetVersion(CFX_WideString& wsVersion) { - wsVersion = JS_STR_VIEWERVERSION_XFA; -} - -void CPDFXFA_App::Beep(uint32_t dwType) { - CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); - if (pEnv) { - pEnv->JS_appBeep(dwType); - } -} - -int32_t CPDFXFA_App::MsgBox(const CFX_WideString& wsMessage, - const CFX_WideString& wsTitle, - uint32_t dwIconType, - uint32_t dwButtonType) { - CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); - if (!pEnv) - return -1; - - uint32_t iconType = 0; - int iButtonType = 0; - switch (dwIconType) { - case XFA_MBICON_Error: - iconType |= 0; - break; - case XFA_MBICON_Warning: - iconType |= 1; - break; - case XFA_MBICON_Question: - iconType |= 2; - break; - case XFA_MBICON_Status: - iconType |= 3; - break; - } - switch (dwButtonType) { - case XFA_MB_OK: - iButtonType |= 0; - break; - case XFA_MB_OKCancel: - iButtonType |= 1; - break; - case XFA_MB_YesNo: - iButtonType |= 2; - break; - case XFA_MB_YesNoCancel: - iButtonType |= 3; - break; - } - int32_t iRet = pEnv->JS_appAlert(wsMessage.c_str(), wsTitle.c_str(), - iButtonType, iconType); - switch (iRet) { - case 1: - return XFA_IDOK; - case 2: - return XFA_IDCancel; - case 3: - return XFA_IDNo; - case 4: - return XFA_IDYes; - } - return XFA_IDYes; -} - -CFX_WideString CPDFXFA_App::Response(const CFX_WideString& wsQuestion, - const CFX_WideString& wsTitle, - const CFX_WideString& wsDefaultAnswer, - FX_BOOL bMark) { - CFX_WideString wsAnswer; - CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); - if (pEnv) { - int nLength = 2048; - char* pBuff = new char[nLength]; - nLength = pEnv->JS_appResponse(wsQuestion.c_str(), wsTitle.c_str(), - wsDefaultAnswer.c_str(), nullptr, bMark, - pBuff, nLength); - if (nLength > 0) { - nLength = nLength > 2046 ? 2046 : nLength; - pBuff[nLength] = 0; - pBuff[nLength + 1] = 0; - wsAnswer = CFX_WideString::FromUTF16LE( - reinterpret_cast(pBuff), - nLength / sizeof(unsigned short)); - } - delete[] pBuff; - } - return wsAnswer; -} - -IFX_FileRead* CPDFXFA_App::DownloadURL(const CFX_WideString& wsURL) { - CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); - return pEnv ? pEnv->DownloadFromURL(wsURL.c_str()) : nullptr; -} - -FX_BOOL CPDFXFA_App::PostRequestURL(const CFX_WideString& wsURL, - const CFX_WideString& wsData, - const CFX_WideString& wsContentType, - const CFX_WideString& wsEncode, - const CFX_WideString& wsHeader, - CFX_WideString& wsResponse) { - CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); - if (!pEnv) - return FALSE; - - wsResponse = - pEnv->PostRequestURL(wsURL.c_str(), wsData.c_str(), wsContentType.c_str(), - wsEncode.c_str(), wsHeader.c_str()); - return TRUE; -} - -FX_BOOL CPDFXFA_App::PutRequestURL(const CFX_WideString& wsURL, - const CFX_WideString& wsData, - const CFX_WideString& wsEncode) { - CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); - return pEnv && - pEnv->PutRequestURL(wsURL.c_str(), wsData.c_str(), wsEncode.c_str()); -} - -void CPDFXFA_App::LoadString(int32_t iStringID, CFX_WideString& wsString) { - switch (iStringID) { - case XFA_IDS_ValidateFailed: - wsString = L"%s validation failed"; - return; - case XFA_IDS_CalcOverride: - wsString = L"Calculate Override"; - return; - case XFA_IDS_ModifyField: - wsString = L"Are you sure you want to modify this field?"; - return; - case XFA_IDS_NotModifyField: - wsString = L"You are not allowed to modify this field."; - return; - case XFA_IDS_AppName: - wsString = L"pdfium"; - return; - case XFA_IDS_Unable_TO_SET: - wsString = L"Unable to set "; - return; - case XFA_IDS_INVAlID_PROP_SET: - wsString = L"Invalid property set operation."; - return; - case XFA_IDS_NOT_DEFAUL_VALUE: - wsString = L" doesn't have a default property."; - return; - case XFA_IDS_UNABLE_SET_LANGUAGE: - wsString = L"Unable to set language value."; - return; - case XFA_IDS_UNABLE_SET_NUMPAGES: - wsString = L"Unable to set numPages value."; - return; - case XFA_IDS_UNABLE_SET_PLATFORM: - wsString = L"Unable to set platform value."; - return; - case XFA_IDS_UNABLE_SET_VARIATION: - wsString = L"Unable to set variation value."; - return; - case XFA_IDS_UNABLE_SET_VERSION: - wsString = L"Unable to set version value."; - return; - case XFA_IDS_UNABLE_SET_READY: - wsString = L"Unable to set ready value."; - return; - case XFA_IDS_COMPILER_ERROR: - wsString = L"Compiler error."; - return; - case XFA_IDS_DIVIDE_ZERO: - wsString = L"Divide by zero."; - return; - case XFA_IDS_ACCESS_PROPERTY_IN_NOT_OBJECT: - wsString = - L"An attempt was made to reference property '%s' of a non-object in " - L"SOM expression %s."; - return; - case XFA_IDS_INDEX_OUT_OF_BOUNDS: - wsString = L"Index value is out of bounds."; - return; - case XFA_IDS_INCORRECT_NUMBER_OF_METHOD: - wsString = L"Incorrect number of parameters calling method '%s'."; - return; - case XFA_IDS_ARGUMENT_MISMATCH: - wsString = L"Argument mismatch in property or function argument."; - return; - case XFA_IDS_NOT_HAVE_PROPERTY: - wsString = L"'%s' doesn't have property '%s'."; - return; - case XFA_IDS_VIOLATE_BOUNDARY: - wsString = - L"The element [%s] has violated its allowable number of occurrences."; - return; - case XFA_IDS_SERVER_DENY: - wsString = L"Server does not permit."; - return; - case XFA_IDS_ValidateLimit: - wsString = - L"Message limit exceeded. Remaining %d validation errors not " - L"reported."; - return; - case XFA_IDS_ValidateNullWarning: - wsString = - L"%s cannot be blank. To ignore validations for %s, click Ignore."; - return; - case XFA_IDS_ValidateNullError: - wsString = L"%s cannot be blank."; - return; - case XFA_IDS_ValidateWarning: - wsString = - L"The value you entered for %s is invalid. To ignore validations for " - L"%s, click Ignore."; - return; - case XFA_IDS_ValidateError: - wsString = L"The value you entered for %s is invalid."; - return; - } -} - -IFWL_AdapterTimerMgr* CPDFXFA_App::GetTimerMgr() { - CXFA_FWLAdapterTimerMgr* pAdapter = nullptr; - CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); - if (pEnv) - pAdapter = new CXFA_FWLAdapterTimerMgr(pEnv); - return pAdapter; -} diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_app.h b/fpdfsdk/fpdfxfa/fpdfxfa_app.h deleted file mode 100644 index 59cb220cee..0000000000 --- a/fpdfsdk/fpdfxfa/fpdfxfa_app.h +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef FPDFSDK_FPDFXFA_FPDFXFA_APP_H_ -#define FPDFSDK_FPDFXFA_FPDFXFA_APP_H_ - -#include "xfa/fxfa/fxfa.h" - -class CPDFSDK_Environment; -class IFXJS_Runtime; - -class CPDFXFA_App : public IXFA_AppProvider { - public: - static CPDFXFA_App* GetInstance(); - static void ReleaseInstance(); - - CPDFXFA_App(); - ~CPDFXFA_App() override; - - FX_BOOL Initialize(v8::Isolate* pIsolate); - CXFA_FFApp* GetXFAApp() { return m_pXFAApp.get(); } - - FX_BOOL AddFormFillEnv(CPDFSDK_Environment* pEnv); - FX_BOOL RemoveFormFillEnv(CPDFSDK_Environment* pEnv); - - FX_BOOL IsJavaScriptInitialized() const { return m_bJavaScriptInitialized; } - void SetJavaScriptInitialized(FX_BOOL bInitialized) { - m_bJavaScriptInitialized = bInitialized; - } - - v8::Isolate* GetJSERuntime() const { return m_pIsolate; } - - // IFXA_AppProvider: - void GetAppType(CFX_WideString& wsAppType) override; - void SetAppType(const CFX_WideStringC& wsAppType) override; - - void GetLanguage(CFX_WideString& wsLanguage) override; - void GetPlatform(CFX_WideString& wsPlatform) override; - void GetVariation(CFX_WideString& wsVariation) override; - void GetVersion(CFX_WideString& wsVersion) override; - void GetAppName(CFX_WideString& wsName) override; - - void Beep(uint32_t dwType) override; - int32_t MsgBox(const CFX_WideString& wsMessage, - const CFX_WideString& wsTitle, - uint32_t dwIconType, - uint32_t dwButtonType) override; - CFX_WideString Response(const CFX_WideString& wsQuestion, - const CFX_WideString& wsTitle, - const CFX_WideString& wsDefaultAnswer, - FX_BOOL bMark) override; - - IFX_FileRead* DownloadURL(const CFX_WideString& wsURL) override; - FX_BOOL PostRequestURL(const CFX_WideString& wsURL, - const CFX_WideString& wsData, - const CFX_WideString& wsContentType, - const CFX_WideString& wsEncode, - const CFX_WideString& wsHeader, - CFX_WideString& wsResponse) override; - FX_BOOL PutRequestURL(const CFX_WideString& wsURL, - const CFX_WideString& wsData, - const CFX_WideString& wsEncode) override; - - void LoadString(int32_t iStringID, CFX_WideString& wsString) override; - IFWL_AdapterTimerMgr* GetTimerMgr() override; - - CFX_ArrayTemplate m_pEnvList; - - protected: - FX_BOOL m_bJavaScriptInitialized; - std::unique_ptr m_pXFAApp; - v8::Isolate* m_pIsolate; - CFX_WideString m_csAppType; -}; - -#endif // FPDFSDK_FPDFXFA_FPDFXFA_APP_H_ diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp deleted file mode 100644 index a49a2708ef..0000000000 --- a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "fpdfsdk/fpdfxfa/fpdfxfa_doc.h" - -#include "core/fpdfapi/parser/cpdf_document.h" -#include "fpdfsdk/cpdfsdk_document.h" -#include "fpdfsdk/cpdfsdk_environment.h" -#include "fpdfsdk/cpdfsdk_interform.h" -#include "fpdfsdk/cpdfsdk_pageview.h" -#include "fpdfsdk/fpdfxfa/fpdfxfa_app.h" -#include "fpdfsdk/fpdfxfa/fpdfxfa_page.h" -#include "fpdfsdk/fpdfxfa/fpdfxfa_util.h" -#include "fpdfsdk/fsdk_define.h" -#include "fpdfsdk/javascript/ijs_runtime.h" -#include "public/fpdf_formfill.h" -#include "xfa/fxfa/cxfa_eventparam.h" -#include "xfa/fxfa/xfa_ffapp.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffdocview.h" -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidgethandler.h" - -#ifndef _WIN32 -extern void SetLastError(int err); -extern int GetLastError(); -#endif - -CPDFXFA_Document::CPDFXFA_Document(std::unique_ptr pPDFDoc, - CPDFXFA_App* pProvider) - : m_iDocType(DOCTYPE_PDF), - m_pPDFDoc(std::move(pPDFDoc)), - m_pXFADocView(nullptr), - m_pApp(pProvider), - m_nLoadStatus(FXFA_LOADSTATUS_PRELOAD), - m_nPageCount(0), - m_DocEnv(this) {} - -CPDFXFA_Document::~CPDFXFA_Document() { - m_nLoadStatus = FXFA_LOADSTATUS_CLOSING; - - if (m_pXFADoc) { - CXFA_FFApp* pApp = m_pApp->GetXFAApp(); - if (pApp) { - CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler(); - if (pDocHandler) - CloseXFADoc(pDocHandler); - } - m_pXFADoc.reset(); - } - - m_nLoadStatus = FXFA_LOADSTATUS_CLOSED; -} - -FX_BOOL CPDFXFA_Document::LoadXFADoc() { - m_nLoadStatus = FXFA_LOADSTATUS_LOADING; - - if (!m_pPDFDoc) - return FALSE; - - m_XFAPageList.RemoveAll(); - - CXFA_FFApp* pApp = m_pApp->GetXFAApp(); - if (!pApp) - return FALSE; - - m_pXFADoc.reset(pApp->CreateDoc(&m_DocEnv, m_pPDFDoc.get())); - if (!m_pXFADoc) { - SetLastError(FPDF_ERR_XFALOAD); - return FALSE; - } - - CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler(); - if (!pDocHandler) { - SetLastError(FPDF_ERR_XFALOAD); - return FALSE; - } - - m_pXFADoc->StartLoad(); - int iStatus = m_pXFADoc->DoLoad(nullptr); - if (iStatus != XFA_PARSESTATUS_Done) { - CloseXFADoc(pDocHandler); - SetLastError(FPDF_ERR_XFALOAD); - return FALSE; - } - m_pXFADoc->StopLoad(); - m_pXFADoc->GetXFADoc()->InitScriptContext(m_pApp->GetJSERuntime()); - - if (m_pXFADoc->GetDocType() == XFA_DOCTYPE_Dynamic) - m_iDocType = DOCTYPE_DYNAMIC_XFA; - else - m_iDocType = DOCTYPE_STATIC_XFA; - - m_pXFADocView = m_pXFADoc->CreateDocView(XFA_DOCVIEW_View); - if (m_pXFADocView->StartLayout() < 0) { - CloseXFADoc(pDocHandler); - SetLastError(FPDF_ERR_XFALAYOUT); - return FALSE; - } - - m_pXFADocView->DoLayout(nullptr); - m_pXFADocView->StopLayout(); - m_nLoadStatus = FXFA_LOADSTATUS_LOADED; - - return TRUE; -} - -int CPDFXFA_Document::GetPageCount() const { - if (!m_pPDFDoc && !m_pXFADoc) - return 0; - - switch (m_iDocType) { - case DOCTYPE_PDF: - case DOCTYPE_STATIC_XFA: - if (m_pPDFDoc) - return m_pPDFDoc->GetPageCount(); - case DOCTYPE_DYNAMIC_XFA: - if (m_pXFADoc) - return m_pXFADocView->CountPageViews(); - default: - return 0; - } -} - -CPDFXFA_Page* CPDFXFA_Document::GetXFAPage(int page_index) { - if (page_index < 0) - return nullptr; - - CPDFXFA_Page* pPage = nullptr; - int nCount = m_XFAPageList.GetSize(); - if (nCount > 0 && page_index < nCount) { - pPage = m_XFAPageList.GetAt(page_index); - if (pPage) - pPage->Retain(); - } else { - m_nPageCount = GetPageCount(); - m_XFAPageList.SetSize(m_nPageCount); - } - if (pPage) - return pPage; - - pPage = new CPDFXFA_Page(this, page_index); - if (!pPage->LoadPage()) { - pPage->Release(); - return nullptr; - } - m_XFAPageList.SetAt(page_index, pPage); - return pPage; -} - -CPDFXFA_Page* CPDFXFA_Document::GetXFAPage(CXFA_FFPageView* pPage) const { - if (!pPage) - return nullptr; - - if (!m_pXFADoc) - return nullptr; - - if (m_iDocType != DOCTYPE_DYNAMIC_XFA) - return nullptr; - - int nSize = m_XFAPageList.GetSize(); - for (int i = 0; i < nSize; i++) { - CPDFXFA_Page* pTempPage = m_XFAPageList.GetAt(i); - if (!pTempPage) - continue; - if (pTempPage->GetXFAPageView() && pTempPage->GetXFAPageView() == pPage) - return pTempPage; - } - - return nullptr; -} - -void CPDFXFA_Document::DeletePage(int page_index) { - // Delete from the document first because, if GetPage was never called for - // this |page_index| then |m_XFAPageList| may have size < |page_index| even - // if it's a valid page in the document. - if (m_pPDFDoc) - m_pPDFDoc->DeletePage(page_index); - - if (page_index < 0 || page_index >= m_XFAPageList.GetSize()) - return; - - if (CPDFXFA_Page* pPage = m_XFAPageList.GetAt(page_index)) - pPage->Release(); -} - -void CPDFXFA_Document::RemovePage(CPDFXFA_Page* page) { - m_XFAPageList.SetAt(page->GetPageIndex(), nullptr); -} - -void CPDFXFA_Document::SetSDKDoc(std::unique_ptr pSDKDoc) { - m_pSDKDoc.reset(pSDKDoc.release()); -} - -void CPDFXFA_Document::ClearChangeMark() { - if (m_pSDKDoc) - m_pSDKDoc->ClearChangeMark(); -} diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_doc.h b/fpdfsdk/fpdfxfa/fpdfxfa_doc.h deleted file mode 100644 index e3bafd7203..0000000000 --- a/fpdfsdk/fpdfxfa/fpdfxfa_doc.h +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef FPDFSDK_FPDFXFA_FPDFXFA_DOC_H_ -#define FPDFSDK_FPDFXFA_FPDFXFA_DOC_H_ - -#include - -#include "fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h" -#include "xfa/fxfa/xfa_ffdoc.h" - -class CPDFSDK_Document; -class CPDFSDK_Environment; -class CPDFXFA_App; -class CPDFXFA_Page; -class CXFA_FFDocHandler; -class IJS_Runtime; -class IJS_Context; - -enum LoadStatus { - FXFA_LOADSTATUS_PRELOAD = 0, - FXFA_LOADSTATUS_LOADING, - FXFA_LOADSTATUS_LOADED, - FXFA_LOADSTATUS_CLOSING, - FXFA_LOADSTATUS_CLOSED -}; - -class CPDFXFA_Document { - public: - CPDFXFA_Document(std::unique_ptr pPDFDoc, - CPDFXFA_App* pProvider); - ~CPDFXFA_Document(); - - FX_BOOL LoadXFADoc(); - CPDF_Document* GetPDFDoc() { return m_pPDFDoc.get(); } - CXFA_FFDoc* GetXFADoc() { return m_pXFADoc.get(); } - CXFA_FFDocView* GetXFADocView() { return m_pXFADocView; } - int GetDocType() const { return m_iDocType; } - - CPDFSDK_Document* GetSDKDoc() const { return m_pSDKDoc.get(); } - void SetSDKDoc(std::unique_ptr pSDKDoc); - - void DeletePage(int page_index); - int GetPageCount() const; - - CPDFXFA_Page* GetXFAPage(int page_index); - CPDFXFA_Page* GetXFAPage(CXFA_FFPageView* pPage) const; - - void RemovePage(CPDFXFA_Page* page); - - void ClearChangeMark(); - - protected: - friend class CPDFXFA_DocEnvironment; - - int GetOriginalPageCount() const { return m_nPageCount; } - void SetOriginalPageCount(int count) { - m_nPageCount = count; - m_XFAPageList.SetSize(count); - } - - LoadStatus GetLoadStatus() const { return m_nLoadStatus; } - - CFX_ArrayTemplate* GetXFAPageList() { return &m_XFAPageList; } - - private: - void CloseXFADoc(CXFA_FFDocHandler* pDoc) { - if (pDoc) { - m_pXFADoc->CloseDoc(); - m_pXFADoc.reset(); - m_pXFADocView = nullptr; - } - } - - int m_iDocType; - - std::unique_ptr m_pPDFDoc; - // |m_pSDKDoc| must be destroyed before |m_pPDFDoc| since it needs to access - // it to kill focused annotations. - std::unique_ptr m_pSDKDoc; - std::unique_ptr m_pXFADoc; - CXFA_FFDocView* m_pXFADocView; // not owned. - CPDFXFA_App* const m_pApp; - CFX_ArrayTemplate m_XFAPageList; - LoadStatus m_nLoadStatus; - int m_nPageCount; - - // Must be destroy before |m_pSDKDoc|. - CPDFXFA_DocEnvironment m_DocEnv; -}; - -#endif // FPDFSDK_FPDFXFA_FPDFXFA_DOC_H_ diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp deleted file mode 100644 index c8a2a6c206..0000000000 --- a/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp +++ /dev/null @@ -1,224 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "fpdfsdk/fpdfxfa/fpdfxfa_page.h" - -#include "core/fpdfapi/page/cpdf_page.h" -#include "core/fpdfapi/parser/cpdf_document.h" -#include "fpdfsdk/fpdfxfa/fpdfxfa_doc.h" -#include "fpdfsdk/fpdfxfa/fpdfxfa_util.h" -#include "fpdfsdk/fsdk_define.h" -#include "public/fpdf_formfill.h" -#include "third_party/base/ptr_util.h" -#include "xfa/fxfa/xfa_ffdocview.h" -#include "xfa/fxfa/xfa_ffpageview.h" - -CPDFXFA_Page::CPDFXFA_Page(CPDFXFA_Document* pDoc, int page_index) - : m_pXFAPageView(nullptr), - m_pDocument(pDoc), - m_iPageIndex(page_index), - m_iRef(1) {} - -CPDFXFA_Page::~CPDFXFA_Page() { - if (m_pDocument) - m_pDocument->RemovePage(this); -} - -FX_BOOL CPDFXFA_Page::LoadPDFPage() { - if (!m_pDocument) - return FALSE; - - CPDF_Document* pPDFDoc = m_pDocument->GetPDFDoc(); - if (!pPDFDoc) - return FALSE; - - CPDF_Dictionary* pDict = pPDFDoc->GetPage(m_iPageIndex); - if (!pDict) - return FALSE; - - if (!m_pPDFPage || m_pPDFPage->m_pFormDict != pDict) { - m_pPDFPage = pdfium::MakeUnique(pPDFDoc, pDict, true); - m_pPDFPage->ParseContent(); - } - return TRUE; -} - -FX_BOOL CPDFXFA_Page::LoadXFAPageView() { - if (!m_pDocument) - return FALSE; - - CXFA_FFDoc* pXFADoc = m_pDocument->GetXFADoc(); - if (!pXFADoc) - return FALSE; - - CXFA_FFDocView* pXFADocView = m_pDocument->GetXFADocView(); - if (!pXFADocView) - return FALSE; - - CXFA_FFPageView* pPageView = pXFADocView->GetPageView(m_iPageIndex); - if (!pPageView) - return FALSE; - - m_pXFAPageView = pPageView; - return TRUE; -} - -FX_BOOL CPDFXFA_Page::LoadPage() { - if (!m_pDocument || m_iPageIndex < 0) - return FALSE; - - int iDocType = m_pDocument->GetDocType(); - switch (iDocType) { - case DOCTYPE_PDF: - case DOCTYPE_STATIC_XFA: { - return LoadPDFPage(); - } - case DOCTYPE_DYNAMIC_XFA: { - return LoadXFAPageView(); - } - default: - return FALSE; - } -} - -FX_BOOL CPDFXFA_Page::LoadPDFPage(CPDF_Dictionary* pageDict) { - if (!m_pDocument || m_iPageIndex < 0 || !pageDict) - return FALSE; - - m_pPDFPage = - pdfium::MakeUnique(m_pDocument->GetPDFDoc(), pageDict, true); - m_pPDFPage->ParseContent(); - return TRUE; -} - -FX_FLOAT CPDFXFA_Page::GetPageWidth() const { - if (!m_pPDFPage && !m_pXFAPageView) - return 0.0f; - - int nDocType = m_pDocument->GetDocType(); - switch (nDocType) { - case DOCTYPE_DYNAMIC_XFA: { - if (m_pXFAPageView) { - CFX_RectF rect; - m_pXFAPageView->GetPageViewRect(rect); - return rect.width; - } - } break; - case DOCTYPE_STATIC_XFA: - case DOCTYPE_PDF: { - if (m_pPDFPage) - return m_pPDFPage->GetPageWidth(); - } break; - default: - return 0.0f; - } - - return 0.0f; -} - -FX_FLOAT CPDFXFA_Page::GetPageHeight() const { - if (!m_pPDFPage && !m_pXFAPageView) - return 0.0f; - - int nDocType = m_pDocument->GetDocType(); - switch (nDocType) { - case DOCTYPE_PDF: - case DOCTYPE_STATIC_XFA: { - if (m_pPDFPage) - return m_pPDFPage->GetPageHeight(); - } break; - case DOCTYPE_DYNAMIC_XFA: { - if (m_pXFAPageView) { - CFX_RectF rect; - m_pXFAPageView->GetPageViewRect(rect); - return rect.height; - } - } break; - default: - return 0.0f; - } - - return 0.0f; -} - -void CPDFXFA_Page::DeviceToPage(int start_x, - int start_y, - int size_x, - int size_y, - int rotate, - int device_x, - int device_y, - double* page_x, - double* page_y) { - if (!m_pPDFPage && !m_pXFAPageView) - return; - - CFX_Matrix page2device; - CFX_Matrix device2page; - FX_FLOAT page_x_f, page_y_f; - - GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, rotate); - - device2page.SetReverse(page2device); - 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); -} - -void CPDFXFA_Page::PageToDevice(int start_x, - int start_y, - int size_x, - int size_y, - int rotate, - double page_x, - double page_y, - int* device_x, - int* device_y) { - if (!m_pPDFPage && !m_pXFAPageView) - return; - - CFX_Matrix page2device; - FX_FLOAT device_x_f, device_y_f; - - GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, rotate); - - 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); -} - -void CPDFXFA_Page::GetDisplayMatrix(CFX_Matrix& matrix, - int xPos, - int yPos, - int xSize, - int ySize, - int iRotate) const { - if (!m_pPDFPage && !m_pXFAPageView) - return; - - int nDocType = m_pDocument->GetDocType(); - switch (nDocType) { - case DOCTYPE_DYNAMIC_XFA: { - if (m_pXFAPageView) { - CFX_Rect rect; - rect.Set(xPos, yPos, xSize, ySize); - m_pXFAPageView->GetDisplayMatrix(matrix, rect, iRotate); - } - } break; - case DOCTYPE_PDF: - case DOCTYPE_STATIC_XFA: { - if (m_pPDFPage) { - m_pPDFPage->GetDisplayMatrix(matrix, xPos, yPos, xSize, ySize, iRotate); - } - } break; - default: - return; - } -} diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_page.h b/fpdfsdk/fpdfxfa/fpdfxfa_page.h deleted file mode 100644 index cc622b7a40..0000000000 --- a/fpdfsdk/fpdfxfa/fpdfxfa_page.h +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef FPDFSDK_FPDFXFA_FPDFXFA_PAGE_H_ -#define FPDFSDK_FPDFXFA_FPDFXFA_PAGE_H_ - -#include - -#include "core/fxcrt/fx_system.h" - -class CFX_Matrix; -class CPDFXFA_Document; -class CPDF_Dictionary; -class CPDF_Page; -class CXFA_FFPageView; - -class CPDFXFA_Page { - public: - CPDFXFA_Page(CPDFXFA_Document* pDoc, int page_index); - - void Retain() { m_iRef++; } - void Release() { - if (--m_iRef <= 0) - delete this; - } - - FX_BOOL LoadPage(); - FX_BOOL LoadPDFPage(CPDF_Dictionary* pageDict); - CPDFXFA_Document* GetDocument() const { return m_pDocument; } - int GetPageIndex() const { return m_iPageIndex; } - CPDF_Page* GetPDFPage() const { return m_pPDFPage.get(); } - CXFA_FFPageView* GetXFAPageView() const { return m_pXFAPageView; } - - void SetXFAPageView(CXFA_FFPageView* pPageView) { - m_pXFAPageView = pPageView; - } - - FX_FLOAT GetPageWidth() const; - FX_FLOAT GetPageHeight() const; - - void DeviceToPage(int start_x, - int start_y, - int size_x, - int size_y, - int rotate, - int device_x, - int device_y, - double* page_x, - double* page_y); - void PageToDevice(int start_x, - int start_y, - int size_x, - int size_y, - int rotate, - double page_x, - double page_y, - int* device_x, - int* device_y); - - void GetDisplayMatrix(CFX_Matrix& matrix, - int xPos, - int yPos, - int xSize, - int ySize, - int iRotate) const; - - protected: - // Refcounted class. - ~CPDFXFA_Page(); - - FX_BOOL LoadPDFPage(); - FX_BOOL LoadXFAPageView(); - - private: - std::unique_ptr m_pPDFPage; - CXFA_FFPageView* m_pXFAPageView; - CPDFXFA_Document* const m_pDocument; - const int m_iPageIndex; - int m_iRef; -}; - -#endif // FPDFSDK_FPDFXFA_FPDFXFA_PAGE_H_ diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_util.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_util.cpp deleted file mode 100644 index b4e44c834e..0000000000 --- a/fpdfsdk/fpdfxfa/fpdfxfa_util.cpp +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "fpdfsdk/fpdfxfa/fpdfxfa_util.h" - -#include - -#include "fpdfsdk/cpdfsdk_environment.h" -#include "fpdfsdk/fsdk_define.h" - -std::vector* CXFA_FWLAdapterTimerMgr::s_TimerArray = nullptr; - -FWL_Error CXFA_FWLAdapterTimerMgr::Start(IFWL_Timer* pTimer, - uint32_t dwElapse, - bool bImmediately, - IFWL_TimerInfo** pTimerInfo) { - if (!m_pEnv) - return FWL_Error::Indefinite; - - int32_t id_event = m_pEnv->SetTimer(dwElapse, TimerProc); - if (!s_TimerArray) - s_TimerArray = new std::vector; - - s_TimerArray->push_back(new CFWL_TimerInfo(id_event, pTimer)); - *pTimerInfo = s_TimerArray->back(); - return FWL_Error::Succeeded; -} - -FWL_Error CXFA_FWLAdapterTimerMgr::Stop(IFWL_TimerInfo* pTimerInfo) { - if (!pTimerInfo || !m_pEnv) - return FWL_Error::Indefinite; - - CFWL_TimerInfo* pInfo = static_cast(pTimerInfo); - m_pEnv->KillTimer(pInfo->idEvent); - if (s_TimerArray) { - auto it = std::find(s_TimerArray->begin(), s_TimerArray->end(), pInfo); - if (it != s_TimerArray->end()) { - s_TimerArray->erase(it); - delete pInfo; - } - } - return FWL_Error::Succeeded; -} - -// static -void CXFA_FWLAdapterTimerMgr::TimerProc(int32_t idEvent) { - if (!s_TimerArray) - return; - - for (CFWL_TimerInfo* pInfo : *s_TimerArray) { - if (pInfo->idEvent == idEvent) { - pInfo->pTimer->Run(pInfo); - break; - } - } -} diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_util.h b/fpdfsdk/fpdfxfa/fpdfxfa_util.h deleted file mode 100644 index a6b08a0d33..0000000000 --- a/fpdfsdk/fpdfxfa/fpdfxfa_util.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef FPDFSDK_FPDFXFA_FPDFXFA_UTIL_H_ -#define FPDFSDK_FPDFXFA_FPDFXFA_UTIL_H_ - -#include - -#include "fpdfsdk/fpdfxfa/fpdfxfa_doc.h" -#include "xfa/fwl/core/ifwl_adaptertimermgr.h" - -#define JS_STR_VIEWERTYPE_STANDARD L"Exchange" -#define JS_STR_LANGUANGE L"ENU" -#define JS_STR_VIEWERVARIATION L"Full" -#define JS_STR_VIEWERVERSION_XFA L"11" - -struct CFWL_TimerInfo; - -class CXFA_FWLAdapterTimerMgr : public IFWL_AdapterTimerMgr { - public: - CXFA_FWLAdapterTimerMgr(CPDFSDK_Environment* pEnv) : m_pEnv(pEnv) {} - - FWL_Error Start(IFWL_Timer* pTimer, - uint32_t dwElapse, - bool bImmediately, - IFWL_TimerInfo** pTimerInfo) override; - FWL_Error Stop(IFWL_TimerInfo* pTimerInfo) override; - - protected: - static void TimerProc(int32_t idEvent); - - static std::vector* s_TimerArray; - CPDFSDK_Environment* const m_pEnv; -}; - -struct CFWL_TimerInfo : public IFWL_TimerInfo { - CFWL_TimerInfo() : pTimer(nullptr) {} - CFWL_TimerInfo(int32_t event, IFWL_Timer* timer) - : idEvent(event), pTimer(timer) {} - - int32_t idEvent; - IFWL_Timer* pTimer; -}; - -#endif // FPDFSDK_FPDFXFA_FPDFXFA_UTIL_H_ -- cgit v1.2.3