summaryrefslogtreecommitdiff
path: root/fpdfsdk/src
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-10-21 14:07:23 -0700
committerTom Sepez <tsepez@chromium.org>2015-10-21 14:07:23 -0700
commitbf59a070593d079256161f6ff47148df309668c7 (patch)
tree0c105507a20881f8f025127183510fefb851c3ce /fpdfsdk/src
parent63dfaab17af7121653749bc86d11fc77b5353dca (diff)
downloadpdfium-bf59a070593d079256161f6ff47148df309668c7.tar.xz
XFA: add CPDFDocumentToFPDFDocument()
Abstracts away that master returns CPDF_Documents directly, but XFA wraps them with a CPDFXFA_Document. Tidy dead code along the way. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1415803002 .
Diffstat (limited to 'fpdfsdk/src')
-rw-r--r--fpdfsdk/src/fpdf_dataavail.cpp4
-rw-r--r--fpdfsdk/src/fpdfeditimg.cpp2
-rw-r--r--fpdfsdk/src/fpdfeditpage.cpp5
-rw-r--r--fpdfsdk/src/fpdfview.cpp30
-rw-r--r--fpdfsdk/src/fpdfxfa/fpdfxfa_doc.cpp103
-rw-r--r--fpdfsdk/src/fsdk_baseform.cpp54
-rw-r--r--fpdfsdk/src/javascript/app.cpp7
7 files changed, 46 insertions, 159 deletions
diff --git a/fpdfsdk/src/fpdf_dataavail.cpp b/fpdfsdk/src/fpdf_dataavail.cpp
index f09b173208..0a90f49d8b 100644
--- a/fpdfsdk/src/fpdf_dataavail.cpp
+++ b/fpdfsdk/src/fpdf_dataavail.cpp
@@ -113,9 +113,7 @@ FPDFAvail_GetDocument(FPDF_AVAIL avail, FPDF_BYTESTRING password) {
}
((CFPDF_DataAvail*)avail)->m_pDataAvail->SetDocument(pParser->GetDocument());
CheckUnSupportError(pParser->GetDocument(), FPDF_ERR_SUCCESS);
- CPDF_Document* pPDFDoc = pParser->GetDocument();
- CPDFXFA_App* pApp = CPDFXFA_App::GetInstance();
- return new CPDFXFA_Document(pPDFDoc, pApp);
+ return FPDFDocumentFromCPDFDocument(pParser->GetDocument());
}
DLLEXPORT int STDCALL FPDFAvail_GetFirstPageNum(FPDF_DOCUMENT doc) {
diff --git a/fpdfsdk/src/fpdfeditimg.cpp b/fpdfsdk/src/fpdfeditimg.cpp
index cd4618e44d..73fc251195 100644
--- a/fpdfsdk/src/fpdfeditimg.cpp
+++ b/fpdfsdk/src/fpdfeditimg.cpp
@@ -6,8 +6,6 @@
#include "../../public/fpdf_edit.h"
#include "../include/fsdk_define.h"
-#include "../include/fpdfxfa/fpdfxfa_doc.h"
-#include "../include/fpdfxfa/fpdfxfa_page.h"
DLLEXPORT FPDF_PAGEOBJECT STDCALL
FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document) {
diff --git a/fpdfsdk/src/fpdfeditpage.cpp b/fpdfsdk/src/fpdfeditpage.cpp
index 42ab3eb694..8b4168fbf4 100644
--- a/fpdfsdk/src/fpdfeditpage.cpp
+++ b/fpdfsdk/src/fpdfeditpage.cpp
@@ -43,8 +43,7 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() {
pInfoDict->SetAt("Creator", new CPDF_String(L"PDFium"));
}
- CPDFXFA_App* pApp = CPDFXFA_App::GetInstance();
- return new CPDFXFA_Document(pDoc, pApp);
+ return FPDFDocumentFromCPDFDocument(pDoc);
}
DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index) {
@@ -177,7 +176,7 @@ DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page,
}
DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) {
- CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") ||
!pPage->m_pFormDict->GetElement("Type")->GetDirect() ||
pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare(
diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp
index e58c53646b..bd7741d1e8 100644
--- a/fpdfsdk/src/fpdfview.cpp
+++ b/fpdfsdk/src/fpdfview.cpp
@@ -26,6 +26,10 @@ CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) {
return doc ? static_cast<CPDFXFA_Document*>(doc)->GetPDFDoc() : nullptr;
}
+FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) {
+ return doc ? new CPDFXFA_Document(doc, CPDFXFA_App::GetInstance()) : nullptr;
+}
+
CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) {
return page ? static_cast<CPDFXFA_Page*>(page)->GetPDFPage() : nullptr;
}
@@ -351,12 +355,7 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf,
CPDF_Document* pDoc = NULL;
pDoc = pParser ? pParser->GetDocument() : NULL;
CheckUnSupportError(pDoc, err_code);
- CPDF_Document* pPDFDoc = pParser->GetDocument();
- if (!pPDFDoc)
- return NULL;
-
- CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance();
- return new CPDFXFA_Document(pPDFDoc, pProvider);
+ return FPDFDocumentFromCPDFDocument(pParser->GetDocument());
}
DLLEXPORT FPDF_DOCUMENT STDCALL
@@ -374,12 +373,7 @@ FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess,
CPDF_Document* pDoc = NULL;
pDoc = pParser ? pParser->GetDocument() : NULL;
CheckUnSupportError(pDoc, err_code);
- CPDF_Document* pPDFDoc = pParser->GetDocument();
- if (!pPDFDoc)
- return NULL;
-
- CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance();
- return new CPDFXFA_Document(pPDFDoc, pProvider);
+ return FPDFDocumentFromCPDFDocument(pParser->GetDocument());
}
DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc,
@@ -437,15 +431,13 @@ DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document,
}
DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) {
- if (!page)
- return 0.0;
- return ((CPDFXFA_Page*)page)->GetPageWidth();
+ CPDFXFA_Page* pPage = static_cast<CPDFXFA_Page*>(page);
+ return pPage ? pPage->GetPageWidth() : 0.0;
}
DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) {
- if (!page)
- return 0.0;
- return ((CPDFXFA_Page*)page)->GetPageHeight();
+ CPDFXFA_Page* pPage = static_cast<CPDFXFA_Page*>(page);
+ return pPage ? pPage->GetPageHeight() : 0.0;
}
void DropContext(void* data) {
@@ -1018,8 +1010,8 @@ DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document,
*buflen = 0;
if (!document || index < 0)
return NULL;
- CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
CPDF_Dictionary* pRoot = pDoc->GetRoot();
if (!pRoot)
return NULL;
diff --git a/fpdfsdk/src/fpdfxfa/fpdfxfa_doc.cpp b/fpdfsdk/src/fpdfxfa/fpdfxfa_doc.cpp
index 365d5d786b..3763003dca 100644
--- a/fpdfsdk/src/fpdfxfa/fpdfxfa_doc.cpp
+++ b/fpdfsdk/src/fpdfxfa/fpdfxfa_doc.cpp
@@ -35,14 +35,13 @@ extern int GetLastError();
CPDFXFA_Document::CPDFXFA_Document(CPDF_Document* pPDFDoc,
CPDFXFA_App* pProvider)
- : m_pPDFDoc(pPDFDoc),
+ : m_iDocType(DOCTYPE_PDF),
+ m_pPDFDoc(pPDFDoc),
+ m_pSDKDoc(nullptr),
+ m_pXFADoc(nullptr),
+ m_pXFADocView(nullptr),
m_pApp(pProvider),
- m_pXFADoc(NULL),
- m_pXFADocView(NULL),
- m_iDocType(DOCTYPE_PDF),
- m_pJSContext(NULL),
- m_pSDKDoc(NULL) {
- m_XFAPageList.RemoveAll();
+ m_pJSContext(nullptr) {
}
CPDFXFA_Document::~CPDFXFA_Document() {
@@ -492,24 +491,6 @@ FX_BOOL CPDFXFA_Document::PopupMenu(IXFA_Widget* hWidget,
void CPDFXFA_Document::PageViewEvent(IXFA_PageView* pPageView,
FX_DWORD dwFlags) {
- if (m_iDocType != DOCTYPE_DYNIMIC_XFA)
- return;
-
- CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- if (pEnv == NULL)
- return;
-
- CPDFXFA_Page* pPage = GetPage(pPageView);
- if (pPage == NULL)
- return;
-
- if (dwFlags == FXFA_PAGEVIEWEVENT_POSTADDED) {
- // pEnv->FFI_PageEvent(pPage, FXFA_PAGEVIEWEVENT_POSTADDED);
- } else if (dwFlags == FXFA_PAGEVIEWEVENT_POSTREMOVED) {
- // pEnv->FFI_PageEvent(pPage, FXFA_PAGEVIEWEVENT_POSTREMOVED);
- // RemovePage(pPage);
- // delete pPage;
- }
}
void CPDFXFA_Document::WidgetEvent(IXFA_Widget* hWidget,
@@ -517,60 +498,30 @@ void CPDFXFA_Document::WidgetEvent(IXFA_Widget* hWidget,
FX_DWORD dwEvent,
void* pParam,
void* pAdditional) {
- if (m_iDocType != DOCTYPE_DYNIMIC_XFA || NULL == hWidget)
+ if (m_iDocType != DOCTYPE_DYNIMIC_XFA || !hWidget)
return;
CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
- if (pEnv == NULL)
- return;
-
- if (NULL == hWidget)
+ if (!pEnv)
return;
IXFA_PageView* pPageView =
m_pXFADocView->GetWidgetHandler()->GetPageView(hWidget);
-
if (pPageView == NULL)
return;
+
CPDFXFA_Page* pXFAPage = GetPage(pPageView);
if (pXFAPage == NULL)
return;
CPDFSDK_PageView* pSdkPageView = m_pSDKDoc->GetPageView(pXFAPage);
-
- CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
-
if (dwEvent == XFA_WIDGETEVENT_PostAdded) {
- // CPDFSDK_Annot* pAnnot =
- // pAnnotHandlerMgr->NewAnnot(hWidget,
- // pSdkPageView);
- // pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
-
- // pEnv->FFI_WidgetEvent(hWidget, XFA_WIDGETEVENT_PostAdded);
- // IXFA_PageView* pOldPageView = (IXFA_PageView*)pAdditional;
- // if (pOldPageView)
- // {
- // CPDFXFA_Page* pDestPage =
- // m_pSDKDoc->GetPageView((IXFA_PageView*)pOldPageView);
- // ASSERT(pDestPage);
- // CPDFSDK_Annot* pAnnot =
- // pDestPage->GetAnnotByXFAWidget(hWidget);
- // if (pAnnot)
- // {
- // if (m_pSDKDoc->GetFocusAnnot() == pAnnot)
- // {
- // m_pSDKDoc->SetFocusAnnot(NULL);
- // }
- // pDestPage->DeleteAnnot(pAnnot);
- // }
- // }
pSdkPageView->AddAnnot(hWidget);
} else if (dwEvent == XFA_WIDGETEVENT_PreRemoved) {
CPDFSDK_Annot* pAnnot = pSdkPageView->GetAnnotByXFAWidget(hWidget);
if (pAnnot) {
pSdkPageView->DeleteAnnot(pAnnot);
- // pEnv->FFI_WidgetEvent(hWidget, XFA_WIDGETEVENT_PreRemoved);
}
}
}
@@ -686,32 +637,9 @@ void CPDFXFA_Document::ExportData(IXFA_Doc* hDoc,
content.GetLength());
CFX_WideStringC data(L"data");
if (pXFADocHander->SavePackage(m_pXFADocView->GetDoc(), data, &fileWrite)) {
- NULL;
+ // TODO: Maybe report error.
}
- }
- /*else if (fileType == FXFA_FILE_STATIC_XDP)
- {
- content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
- fileWrite.WriteBlock((const FX_CHAR*)content, fileWrite.GetSize(),
-content.GetLength());
- CFX_WideStringC data(L"data");
- if( pXFADocHander->SavePackage(m_pXFADocView->GetDoc(), data,
-&fileWrite))
- {
- NULL;
- }
- CFX_WideString wPath = pEnv->FFI_GetFilePath(pFileHandler);
-// CFX_WideString wPath;
-// wPath.FromUTF16LE(filePath);
- CFX_ByteString bPath = wPath.UTF8Encode();
- CFX_ByteString szFormat = "\n<pdf href=\"%s\"
-xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>";
- content.Format(szFormat,(char*)(const FX_CHAR*)bPath);
- fileWrite.WriteBlock((const FX_CHAR*)content,fileWrite.GetSize(),
-content.GetLength());
- }
- */
- else if (fileType == FXFA_SAVEAS_XDP) {
+ } else if (fileType == FXFA_SAVEAS_XDP) {
if (m_pPDFDoc == NULL)
return;
CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot();
@@ -729,8 +657,6 @@ content.GetLength());
if (NULL == pArray)
return;
int size = pArray->GetCount();
- int iFormIndex = -1;
- int iDataSetsIndex = -1;
for (int i = 1; i < size; i += 2) {
CPDF_Object* pPDFObj = pArray->GetElement(i);
CPDF_Object* pPrePDFObj = pArray->GetElement(i - 1);
@@ -750,7 +676,6 @@ content.GetLength());
&fileWrite);
} else {
if (i == size - 1) {
- // CFX_WideString wPath = pEnv->FFI_GetFilePath(pFileHandler);
CFX_WideString wPath = CFX_WideString::FromUTF16LE(
(unsigned short*)(const FX_CHAR*)bs,
bs.GetLength() / sizeof(unsigned short));
@@ -771,7 +696,9 @@ content.GetLength());
}
}
}
- FX_BOOL bError = fileWrite.Flush();
+ if (!fileWrite.Flush()) {
+ // TODO: Report error.
+ }
}
void CPDFXFA_Document::ImportData(IXFA_Doc* hDoc,
const CFX_WideStringC& wsFilePath) {
@@ -1051,8 +978,6 @@ FX_BOOL CPDFXFA_Document::_ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler,
return FALSE;
}
int size = pArray->GetCount();
- int iFormIndex = -1;
- int iDataSetsIndex = -1;
for (int i = 1; i < size; i += 2) {
CPDF_Object* pPDFObj = pArray->GetElement(i);
CPDF_Object* pPrePDFObj = pArray->GetElement(i - 1);
diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp
index 68c320b4af..024287d706 100644
--- a/fpdfsdk/src/fsdk_baseform.cpp
+++ b/fpdfsdk/src/fsdk_baseform.cpp
@@ -39,15 +39,9 @@ CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot,
CPDFSDK_Widget::~CPDFSDK_Widget() {}
-IXFA_Widget* CPDFSDK_Widget::GetMixXFAWidget() {
- ASSERT(m_pPageView != NULL);
-
+IXFA_Widget* CPDFSDK_Widget::GetMixXFAWidget() const {
CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
- ASSERT(pSDKDoc != NULL);
-
CPDFXFA_Document* pDoc = pSDKDoc->GetDocument();
- ASSERT(pDoc != NULL);
-
if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
if (!m_hMixXFAWidget) {
if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) {
@@ -90,15 +84,9 @@ IXFA_Widget* CPDFSDK_Widget::GetGroupMixXFAWidget() {
return NULL;
}
-IXFA_WidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() {
- ASSERT(m_pPageView != NULL);
-
+IXFA_WidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const {
CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
- ASSERT(pSDKDoc != NULL);
-
CPDFXFA_Document* pDoc = pSDKDoc->GetDocument();
- ASSERT(pDoc != NULL);
-
if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
if (!m_pWidgetHandler) {
if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) {
@@ -343,16 +331,10 @@ void CPDFSDK_Widget::SynchronizeXFAValue() {
if (!pXFADocView)
return;
- if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
- if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
- CPDF_FormField* pFormField = GetFormField();
- ASSERT(pFormField != NULL);
-
- CPDF_FormControl* pFormCtrl = GetFormControl();
- ASSERT(pFormCtrl != NULL);
-
- CPDFSDK_Widget::SynchronizeXFAValue(pXFADocView, hWidget, pFormField,
- pFormCtrl);
+ if (IXFA_Widget* hWidget = GetMixXFAWidget()) {
+ if (GetXFAWidgetHandler()) {
+ CPDFSDK_Widget::SynchronizeXFAValue(pXFADocView, hWidget, GetFormField(),
+ GetFormControl());
}
}
#endif // PDF_ENABLE_XFA
@@ -372,13 +354,9 @@ void CPDFSDK_Widget::SynchronizeXFAItems() {
if (!pXFADocView)
return;
- if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
- if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
- CPDF_FormField* pFormField = GetFormField();
- ASSERT(pFormField != NULL);
-
- SynchronizeXFAItems(pXFADocView, hWidget, pFormField, NULL);
- }
+ if (IXFA_Widget* hWidget = GetMixXFAWidget()) {
+ if (GetXFAWidgetHandler())
+ SynchronizeXFAItems(pXFADocView, hWidget, GetFormField(), nullptr);
}
#endif // PDF_ENABLE_XFA
}
@@ -622,12 +600,8 @@ int CPDFSDK_Widget::GetRotate() const {
return pCtrl->GetRotation() % 360;
}
-CFX_WideString CPDFSDK_Widget::GetName() {
- ASSERT(m_pInterForm != NULL);
-
+CFX_WideString CPDFSDK_Widget::GetName() const {
CPDF_FormField* pFormField = GetFormField();
- ASSERT(pFormField != NULL);
-
return pFormField->GetFullName();
}
@@ -680,7 +654,7 @@ FX_FLOAT CPDFSDK_Widget::GetFontSize() const {
return fFontSize;
}
-int CPDFSDK_Widget::GetSelectedIndex(int nIndex) {
+int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const {
#ifdef PDF_ENABLE_XFA
if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
@@ -696,7 +670,7 @@ int CPDFSDK_Widget::GetSelectedIndex(int nIndex) {
return pFormField->GetSelectedIndex(nIndex);
}
-CFX_WideString CPDFSDK_Widget::GetValue(FX_BOOL bDisplay) {
+CFX_WideString CPDFSDK_Widget::GetValue(FX_BOOL bDisplay) const {
#ifdef PDF_ENABLE_XFA
if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
@@ -735,7 +709,7 @@ int CPDFSDK_Widget::CountOptions() const {
return pFormField->CountOptions();
}
-FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) {
+FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const {
#ifdef PDF_ENABLE_XFA
if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
@@ -758,7 +732,7 @@ int CPDFSDK_Widget::GetTopVisibleIndex() const {
return pFormField->GetTopVisibleIndex();
}
-FX_BOOL CPDFSDK_Widget::IsChecked() {
+FX_BOOL CPDFSDK_Widget::IsChecked() const {
#ifdef PDF_ENABLE_XFA
if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp
index 80a9b17aa9..379170f292 100644
--- a/fpdfsdk/src/javascript/app.cpp
+++ b/fpdfsdk/src/javascript/app.cpp
@@ -201,11 +201,12 @@ FX_BOOL app::viewerVersion(IJS_Context* cc,
CJS_Context* pContext = (CJS_Context*)cc;
CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
CPDFXFA_Document* pDoc = pCurDoc->GetDocument();
- if (pDoc->GetDocType() == 1 || pDoc->GetDocType() == 2)
+ if (pDoc->GetDocType() == 1 || pDoc->GetDocType() == 2) {
vp << JS_NUM_VIEWERVERSION_XFA;
- else
- vp << JS_NUM_VIEWERVERSION;
+ return TRUE;
+ }
+ vp << JS_NUM_VIEWERVERSION;
return TRUE;
}