Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Side by Side Diff: fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp

Issue 2385423004: Rename fpdfsdk/fpdfxfa files to match contents (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/fpdfxfa/fpdfxfa_doc.h ('k') | fpdfsdk/fpdfxfa/fpdfxfa_page.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "fpdfsdk/fpdfxfa/fpdfxfa_doc.h"
8
9 #include "core/fpdfapi/parser/cpdf_document.h"
10 #include "fpdfsdk/cpdfsdk_document.h"
11 #include "fpdfsdk/cpdfsdk_environment.h"
12 #include "fpdfsdk/cpdfsdk_interform.h"
13 #include "fpdfsdk/cpdfsdk_pageview.h"
14 #include "fpdfsdk/fpdfxfa/fpdfxfa_app.h"
15 #include "fpdfsdk/fpdfxfa/fpdfxfa_page.h"
16 #include "fpdfsdk/fpdfxfa/fpdfxfa_util.h"
17 #include "fpdfsdk/fsdk_define.h"
18 #include "fpdfsdk/javascript/ijs_runtime.h"
19 #include "public/fpdf_formfill.h"
20 #include "xfa/fxfa/cxfa_eventparam.h"
21 #include "xfa/fxfa/xfa_ffapp.h"
22 #include "xfa/fxfa/xfa_ffdoc.h"
23 #include "xfa/fxfa/xfa_ffdocview.h"
24 #include "xfa/fxfa/xfa_ffpageview.h"
25 #include "xfa/fxfa/xfa_ffwidgethandler.h"
26
27 #ifndef _WIN32
28 extern void SetLastError(int err);
29 extern int GetLastError();
30 #endif
31
32 CPDFXFA_Document::CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc,
33 CPDFXFA_App* pProvider)
34 : m_iDocType(DOCTYPE_PDF),
35 m_pPDFDoc(std::move(pPDFDoc)),
36 m_pXFADocView(nullptr),
37 m_pApp(pProvider),
38 m_nLoadStatus(FXFA_LOADSTATUS_PRELOAD),
39 m_nPageCount(0),
40 m_DocEnv(this) {}
41
42 CPDFXFA_Document::~CPDFXFA_Document() {
43 m_nLoadStatus = FXFA_LOADSTATUS_CLOSING;
44
45 if (m_pXFADoc) {
46 CXFA_FFApp* pApp = m_pApp->GetXFAApp();
47 if (pApp) {
48 CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler();
49 if (pDocHandler)
50 CloseXFADoc(pDocHandler);
51 }
52 m_pXFADoc.reset();
53 }
54
55 m_nLoadStatus = FXFA_LOADSTATUS_CLOSED;
56 }
57
58 FX_BOOL CPDFXFA_Document::LoadXFADoc() {
59 m_nLoadStatus = FXFA_LOADSTATUS_LOADING;
60
61 if (!m_pPDFDoc)
62 return FALSE;
63
64 m_XFAPageList.RemoveAll();
65
66 CXFA_FFApp* pApp = m_pApp->GetXFAApp();
67 if (!pApp)
68 return FALSE;
69
70 m_pXFADoc.reset(pApp->CreateDoc(&m_DocEnv, m_pPDFDoc.get()));
71 if (!m_pXFADoc) {
72 SetLastError(FPDF_ERR_XFALOAD);
73 return FALSE;
74 }
75
76 CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler();
77 if (!pDocHandler) {
78 SetLastError(FPDF_ERR_XFALOAD);
79 return FALSE;
80 }
81
82 m_pXFADoc->StartLoad();
83 int iStatus = m_pXFADoc->DoLoad(nullptr);
84 if (iStatus != XFA_PARSESTATUS_Done) {
85 CloseXFADoc(pDocHandler);
86 SetLastError(FPDF_ERR_XFALOAD);
87 return FALSE;
88 }
89 m_pXFADoc->StopLoad();
90 m_pXFADoc->GetXFADoc()->InitScriptContext(m_pApp->GetJSERuntime());
91
92 if (m_pXFADoc->GetDocType() == XFA_DOCTYPE_Dynamic)
93 m_iDocType = DOCTYPE_DYNAMIC_XFA;
94 else
95 m_iDocType = DOCTYPE_STATIC_XFA;
96
97 m_pXFADocView = m_pXFADoc->CreateDocView(XFA_DOCVIEW_View);
98 if (m_pXFADocView->StartLayout() < 0) {
99 CloseXFADoc(pDocHandler);
100 SetLastError(FPDF_ERR_XFALAYOUT);
101 return FALSE;
102 }
103
104 m_pXFADocView->DoLayout(nullptr);
105 m_pXFADocView->StopLayout();
106 m_nLoadStatus = FXFA_LOADSTATUS_LOADED;
107
108 return TRUE;
109 }
110
111 int CPDFXFA_Document::GetPageCount() const {
112 if (!m_pPDFDoc && !m_pXFADoc)
113 return 0;
114
115 switch (m_iDocType) {
116 case DOCTYPE_PDF:
117 case DOCTYPE_STATIC_XFA:
118 if (m_pPDFDoc)
119 return m_pPDFDoc->GetPageCount();
120 case DOCTYPE_DYNAMIC_XFA:
121 if (m_pXFADoc)
122 return m_pXFADocView->CountPageViews();
123 default:
124 return 0;
125 }
126 }
127
128 CPDFXFA_Page* CPDFXFA_Document::GetXFAPage(int page_index) {
129 if (page_index < 0)
130 return nullptr;
131
132 CPDFXFA_Page* pPage = nullptr;
133 int nCount = m_XFAPageList.GetSize();
134 if (nCount > 0 && page_index < nCount) {
135 pPage = m_XFAPageList.GetAt(page_index);
136 if (pPage)
137 pPage->Retain();
138 } else {
139 m_nPageCount = GetPageCount();
140 m_XFAPageList.SetSize(m_nPageCount);
141 }
142 if (pPage)
143 return pPage;
144
145 pPage = new CPDFXFA_Page(this, page_index);
146 if (!pPage->LoadPage()) {
147 pPage->Release();
148 return nullptr;
149 }
150 m_XFAPageList.SetAt(page_index, pPage);
151 return pPage;
152 }
153
154 CPDFXFA_Page* CPDFXFA_Document::GetXFAPage(CXFA_FFPageView* pPage) const {
155 if (!pPage)
156 return nullptr;
157
158 if (!m_pXFADoc)
159 return nullptr;
160
161 if (m_iDocType != DOCTYPE_DYNAMIC_XFA)
162 return nullptr;
163
164 int nSize = m_XFAPageList.GetSize();
165 for (int i = 0; i < nSize; i++) {
166 CPDFXFA_Page* pTempPage = m_XFAPageList.GetAt(i);
167 if (!pTempPage)
168 continue;
169 if (pTempPage->GetXFAPageView() && pTempPage->GetXFAPageView() == pPage)
170 return pTempPage;
171 }
172
173 return nullptr;
174 }
175
176 void CPDFXFA_Document::DeletePage(int page_index) {
177 // Delete from the document first because, if GetPage was never called for
178 // this |page_index| then |m_XFAPageList| may have size < |page_index| even
179 // if it's a valid page in the document.
180 if (m_pPDFDoc)
181 m_pPDFDoc->DeletePage(page_index);
182
183 if (page_index < 0 || page_index >= m_XFAPageList.GetSize())
184 return;
185
186 if (CPDFXFA_Page* pPage = m_XFAPageList.GetAt(page_index))
187 pPage->Release();
188 }
189
190 void CPDFXFA_Document::RemovePage(CPDFXFA_Page* page) {
191 m_XFAPageList.SetAt(page->GetPageIndex(), nullptr);
192 }
193
194 void CPDFXFA_Document::SetSDKDoc(std::unique_ptr<CPDFSDK_Document> pSDKDoc) {
195 m_pSDKDoc.reset(pSDKDoc.release());
196 }
197
198 void CPDFXFA_Document::ClearChangeMark() {
199 if (m_pSDKDoc)
200 m_pSDKDoc->ClearChangeMark();
201 }
OLDNEW
« no previous file with comments | « fpdfsdk/fpdfxfa/fpdfxfa_doc.h ('k') | fpdfsdk/fpdfxfa/fpdfxfa_page.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698