| OLD | NEW |
| (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 "core/include/fpdfapi/cpdf_array.h" | |
| 8 #include "core/include/fpdfapi/cpdf_document.h" | |
| 9 #include "core/include/fpdfapi/cpdf_string.h" | |
| 10 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_app.h" | |
| 11 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h" | |
| 12 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_page.h" | |
| 13 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_util.h" | |
| 14 #include "fpdfsdk/include/fsdk_define.h" | |
| 15 #include "fpdfsdk/include/fsdk_mgr.h" | |
| 16 #include "fpdfsdk/include/javascript/IJavaScript.h" | |
| 17 #include "public/fpdf_formfill.h" | |
| 18 | |
| 19 #define IDS_XFA_Validate_Input \ | |
| 20 "At least one required field was empty. Please fill in the required " \ | |
| 21 "fields\r\n(highlighted) before continuing." | |
| 22 | |
| 23 // submit | |
| 24 #define FXFA_CONFIG 0x00000001 | |
| 25 #define FXFA_TEMPLATE 0x00000010 | |
| 26 #define FXFA_LOCALESET 0x00000100 | |
| 27 #define FXFA_DATASETS 0x00001000 | |
| 28 #define FXFA_XMPMETA 0x00010000 | |
| 29 #define FXFA_XFDF 0x00100000 | |
| 30 #define FXFA_FORM 0x01000000 | |
| 31 #define FXFA_PDF 0x10000000 | |
| 32 | |
| 33 #ifndef _WIN32 | |
| 34 extern void SetLastError(int err); | |
| 35 | |
| 36 extern int GetLastError(); | |
| 37 #endif | |
| 38 | |
| 39 CPDFXFA_Document::CPDFXFA_Document(CPDF_Document* pPDFDoc, | |
| 40 CPDFXFA_App* pProvider) | |
| 41 : m_iDocType(DOCTYPE_PDF), | |
| 42 m_pPDFDoc(pPDFDoc), | |
| 43 m_pSDKDoc(nullptr), | |
| 44 m_pXFADoc(nullptr), | |
| 45 m_pXFADocView(nullptr), | |
| 46 m_pApp(pProvider), | |
| 47 m_pJSContext(nullptr) { | |
| 48 } | |
| 49 | |
| 50 CPDFXFA_Document::~CPDFXFA_Document() { | |
| 51 if (m_pXFADoc) { | |
| 52 IXFA_App* pApp = m_pApp->GetXFAApp(); | |
| 53 if (pApp) { | |
| 54 IXFA_DocHandler* pDocHandler = pApp->GetDocHandler(); | |
| 55 if (pDocHandler) { | |
| 56 CloseXFADoc(pDocHandler); | |
| 57 } | |
| 58 } | |
| 59 delete m_pXFADoc; | |
| 60 } | |
| 61 if (m_pJSContext && m_pSDKDoc && m_pSDKDoc->GetEnv()) | |
| 62 m_pSDKDoc->GetEnv()->GetJSRuntime()->ReleaseContext(m_pJSContext); | |
| 63 delete m_pSDKDoc; | |
| 64 if (m_pPDFDoc) { | |
| 65 CPDF_Parser* pParser = m_pPDFDoc->GetParser(); | |
| 66 if (pParser) | |
| 67 delete pParser; | |
| 68 else | |
| 69 delete m_pPDFDoc; | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 FX_BOOL CPDFXFA_Document::LoadXFADoc() { | |
| 74 if (!m_pPDFDoc) | |
| 75 return FALSE; | |
| 76 | |
| 77 m_XFAPageList.RemoveAll(); | |
| 78 | |
| 79 IXFA_App* pApp = m_pApp->GetXFAApp(); | |
| 80 if (!pApp) | |
| 81 return FALSE; | |
| 82 | |
| 83 m_pXFADoc = pApp->CreateDoc(this, m_pPDFDoc); | |
| 84 if (!m_pXFADoc) { | |
| 85 SetLastError(FPDF_ERR_XFALOAD); | |
| 86 return FALSE; | |
| 87 } | |
| 88 | |
| 89 IXFA_DocHandler* pDocHandler = pApp->GetDocHandler(); | |
| 90 if (!pDocHandler) { | |
| 91 SetLastError(FPDF_ERR_XFALOAD); | |
| 92 return FALSE; | |
| 93 } | |
| 94 | |
| 95 pDocHandler->StartLoad(m_pXFADoc); | |
| 96 int iStatus = pDocHandler->DoLoad(m_pXFADoc, NULL); | |
| 97 if (iStatus != XFA_PARSESTATUS_Done) { | |
| 98 CloseXFADoc(pDocHandler); | |
| 99 SetLastError(FPDF_ERR_XFALOAD); | |
| 100 return FALSE; | |
| 101 } | |
| 102 pDocHandler->StopLoad(m_pXFADoc); | |
| 103 pDocHandler->SetJSERuntime(m_pXFADoc, m_pApp->GetJSERuntime()); | |
| 104 | |
| 105 if (pDocHandler->GetDocType(m_pXFADoc) == XFA_DOCTYPE_Dynamic) | |
| 106 m_iDocType = DOCTYPE_DYNAMIC_XFA; | |
| 107 else | |
| 108 m_iDocType = DOCTYPE_STATIC_XFA; | |
| 109 | |
| 110 m_pXFADocView = pDocHandler->CreateDocView(m_pXFADoc, XFA_DOCVIEW_View); | |
| 111 if (m_pXFADocView->StartLayout() < 0) { | |
| 112 CloseXFADoc(pDocHandler); | |
| 113 SetLastError(FPDF_ERR_XFALAYOUT); | |
| 114 return FALSE; | |
| 115 } | |
| 116 | |
| 117 m_pXFADocView->DoLayout(NULL); | |
| 118 m_pXFADocView->StopLayout(); | |
| 119 return TRUE; | |
| 120 } | |
| 121 | |
| 122 int CPDFXFA_Document::GetPageCount() { | |
| 123 if (!m_pPDFDoc && !m_pXFADoc) | |
| 124 return 0; | |
| 125 | |
| 126 switch (m_iDocType) { | |
| 127 case DOCTYPE_PDF: | |
| 128 case DOCTYPE_STATIC_XFA: | |
| 129 if (m_pPDFDoc) | |
| 130 return m_pPDFDoc->GetPageCount(); | |
| 131 case DOCTYPE_DYNAMIC_XFA: | |
| 132 if (m_pXFADoc) | |
| 133 return m_pXFADocView->CountPageViews(); | |
| 134 default: | |
| 135 return 0; | |
| 136 } | |
| 137 | |
| 138 return 0; | |
| 139 } | |
| 140 | |
| 141 CPDFXFA_Page* CPDFXFA_Document::GetPage(int page_index) { | |
| 142 if (page_index < 0) | |
| 143 return nullptr; | |
| 144 CPDFXFA_Page* pPage = nullptr; | |
| 145 int nCount = m_XFAPageList.GetSize(); | |
| 146 if (nCount > 0 && page_index < nCount) { | |
| 147 pPage = m_XFAPageList.GetAt(page_index); | |
| 148 if (pPage) | |
| 149 pPage->AddRef(); | |
| 150 } else { | |
| 151 m_XFAPageList.SetSize(GetPageCount()); | |
| 152 } | |
| 153 if (pPage) | |
| 154 return pPage; | |
| 155 pPage = new CPDFXFA_Page(this, page_index); | |
| 156 if (!pPage->LoadPage()) { | |
| 157 delete pPage; | |
| 158 return nullptr; | |
| 159 } | |
| 160 m_XFAPageList.SetAt(page_index, pPage); | |
| 161 return pPage; | |
| 162 } | |
| 163 | |
| 164 CPDFXFA_Page* CPDFXFA_Document::GetPage(IXFA_PageView* pPage) { | |
| 165 if (!pPage) | |
| 166 return NULL; | |
| 167 | |
| 168 if (!m_pXFADoc) | |
| 169 return NULL; | |
| 170 | |
| 171 if (m_iDocType != DOCTYPE_DYNAMIC_XFA) | |
| 172 return NULL; | |
| 173 | |
| 174 int nSize = m_XFAPageList.GetSize(); | |
| 175 for (int i = 0; i < nSize; i++) { | |
| 176 CPDFXFA_Page* pTempPage = m_XFAPageList.GetAt(i); | |
| 177 if (!pTempPage) | |
| 178 continue; | |
| 179 if (pTempPage->GetXFAPageView() && pTempPage->GetXFAPageView() == pPage) | |
| 180 return pTempPage; | |
| 181 } | |
| 182 | |
| 183 return NULL; | |
| 184 } | |
| 185 | |
| 186 void CPDFXFA_Document::RemovePage(CPDFXFA_Page* page) { | |
| 187 m_XFAPageList.SetAt(page->GetPageIndex(), NULL); | |
| 188 } | |
| 189 | |
| 190 CPDFSDK_Document* CPDFXFA_Document::GetSDKDocument( | |
| 191 CPDFDoc_Environment* pFormFillEnv) { | |
| 192 if (!m_pSDKDoc && pFormFillEnv) | |
| 193 m_pSDKDoc = new CPDFSDK_Document(this, pFormFillEnv); | |
| 194 return m_pSDKDoc; | |
| 195 } | |
| 196 | |
| 197 void CPDFXFA_Document::FXRect2PDFRect(const CFX_RectF& fxRectF, | |
| 198 CFX_FloatRect& pdfRect) { | |
| 199 pdfRect.left = fxRectF.left; | |
| 200 pdfRect.top = fxRectF.bottom(); | |
| 201 pdfRect.right = fxRectF.right(); | |
| 202 pdfRect.bottom = fxRectF.top; | |
| 203 } | |
| 204 | |
| 205 void CPDFXFA_Document::SetChangeMark(IXFA_Doc* hDoc) { | |
| 206 if (hDoc == m_pXFADoc && m_pSDKDoc) { | |
| 207 m_pSDKDoc->SetChangeMark(); | |
| 208 } | |
| 209 } | |
| 210 | |
| 211 FX_BOOL CPDFXFA_Document::GetChangeMark(IXFA_Doc* hDoc) { | |
| 212 if (hDoc == m_pXFADoc && m_pSDKDoc) | |
| 213 return m_pSDKDoc->GetChangeMark(); | |
| 214 return FALSE; | |
| 215 } | |
| 216 | |
| 217 void CPDFXFA_Document::InvalidateRect(IXFA_PageView* pPageView, | |
| 218 const CFX_RectF& rt, | |
| 219 FX_DWORD dwFlags /* = 0 */) { | |
| 220 if (!m_pXFADoc || !m_pSDKDoc) | |
| 221 return; | |
| 222 | |
| 223 if (m_iDocType != DOCTYPE_DYNAMIC_XFA) | |
| 224 return; | |
| 225 | |
| 226 CFX_FloatRect rcPage; | |
| 227 FXRect2PDFRect(rt, rcPage); | |
| 228 | |
| 229 CPDFXFA_Page* pPage = GetPage(pPageView); | |
| 230 | |
| 231 if (pPage == NULL) | |
| 232 return; | |
| 233 | |
| 234 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 235 if (!pEnv) | |
| 236 return; | |
| 237 | |
| 238 pEnv->FFI_Invalidate((FPDF_PAGE)pPage, rcPage.left, rcPage.bottom, | |
| 239 rcPage.right, rcPage.top); | |
| 240 } | |
| 241 | |
| 242 void CPDFXFA_Document::InvalidateRect(IXFA_Widget* hWidget, | |
| 243 FX_DWORD dwFlags /* = 0 */) { | |
| 244 if (!hWidget) | |
| 245 return; | |
| 246 | |
| 247 if (!m_pXFADoc || !m_pSDKDoc || !m_pXFADocView) | |
| 248 return; | |
| 249 | |
| 250 if (m_iDocType != DOCTYPE_DYNAMIC_XFA) | |
| 251 return; | |
| 252 | |
| 253 IXFA_WidgetHandler* pWidgetHandler = m_pXFADocView->GetWidgetHandler(); | |
| 254 if (!pWidgetHandler) | |
| 255 return; | |
| 256 | |
| 257 IXFA_PageView* pPageView = pWidgetHandler->GetPageView(hWidget); | |
| 258 if (!pPageView) | |
| 259 return; | |
| 260 | |
| 261 CFX_RectF rect; | |
| 262 pWidgetHandler->GetRect(hWidget, rect); | |
| 263 InvalidateRect(pPageView, rect, dwFlags); | |
| 264 } | |
| 265 | |
| 266 void CPDFXFA_Document::DisplayCaret(IXFA_Widget* hWidget, | |
| 267 FX_BOOL bVisible, | |
| 268 const CFX_RectF* pRtAnchor) { | |
| 269 if (!hWidget || pRtAnchor == NULL) | |
| 270 return; | |
| 271 | |
| 272 if (!m_pXFADoc || !m_pSDKDoc || !m_pXFADocView) | |
| 273 return; | |
| 274 | |
| 275 if (m_iDocType != DOCTYPE_DYNAMIC_XFA) | |
| 276 return; | |
| 277 | |
| 278 IXFA_WidgetHandler* pWidgetHandler = m_pXFADocView->GetWidgetHandler(); | |
| 279 if (!pWidgetHandler) | |
| 280 return; | |
| 281 | |
| 282 IXFA_PageView* pPageView = pWidgetHandler->GetPageView(hWidget); | |
| 283 if (!pPageView) | |
| 284 return; | |
| 285 | |
| 286 CPDFXFA_Page* pPage = GetPage(pPageView); | |
| 287 | |
| 288 if (pPage == NULL) | |
| 289 return; | |
| 290 | |
| 291 CFX_FloatRect rcCaret; | |
| 292 FXRect2PDFRect(*pRtAnchor, rcCaret); | |
| 293 | |
| 294 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 295 if (!pEnv) | |
| 296 return; | |
| 297 | |
| 298 pEnv->FFI_DisplayCaret((FPDF_PAGE)pPage, bVisible, rcCaret.left, rcCaret.top, | |
| 299 rcCaret.right, rcCaret.bottom); | |
| 300 } | |
| 301 | |
| 302 FX_BOOL CPDFXFA_Document::GetPopupPos(IXFA_Widget* hWidget, | |
| 303 FX_FLOAT fMinPopup, | |
| 304 FX_FLOAT fMaxPopup, | |
| 305 const CFX_RectF& rtAnchor, | |
| 306 CFX_RectF& rtPopup) { | |
| 307 if (NULL == hWidget) { | |
| 308 return FALSE; | |
| 309 } | |
| 310 IXFA_PageView* pXFAPageView = | |
| 311 m_pXFADocView->GetWidgetHandler()->GetPageView(hWidget); | |
| 312 if (NULL == pXFAPageView) { | |
| 313 return FALSE; | |
| 314 } | |
| 315 CPDFXFA_Page* pPage = GetPage(pXFAPageView); | |
| 316 if (pPage == NULL) | |
| 317 return FALSE; | |
| 318 | |
| 319 CXFA_WidgetAcc* pWidgetAcc = | |
| 320 m_pXFADocView->GetWidgetHandler()->GetDataAcc(hWidget); | |
| 321 | |
| 322 int nRotate = 0; | |
| 323 #ifdef PDF_ENABLE_XFA | |
| 324 nRotate = pWidgetAcc->GetRotate(); | |
| 325 #endif | |
| 326 | |
| 327 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 328 if (pEnv == NULL) | |
| 329 return FALSE; | |
| 330 FS_RECTF pageViewRect; | |
| 331 pEnv->FFI_GetPageViewRect(pPage, pageViewRect); | |
| 332 | |
| 333 CFX_FloatRect rcAnchor; | |
| 334 | |
| 335 rcAnchor.left = rtAnchor.left; | |
| 336 rcAnchor.top = rtAnchor.bottom(); | |
| 337 rcAnchor.right = rtAnchor.right(); | |
| 338 rcAnchor.bottom = rtAnchor.top; | |
| 339 | |
| 340 int t1, t2, t; | |
| 341 FX_DWORD dwPos; | |
| 342 FX_FLOAT fPoupHeight; | |
| 343 switch (nRotate) { | |
| 344 case 90: { | |
| 345 t1 = (int)(pageViewRect.right - rcAnchor.right); | |
| 346 t2 = (int)(rcAnchor.left - pageViewRect.left); | |
| 347 if (rcAnchor.bottom < pageViewRect.bottom) { | |
| 348 rtPopup.left += rcAnchor.bottom - pageViewRect.bottom; | |
| 349 } | |
| 350 | |
| 351 break; | |
| 352 } | |
| 353 | |
| 354 case 180: { | |
| 355 t2 = (int)(pageViewRect.top - rcAnchor.top); | |
| 356 t1 = (int)(rcAnchor.bottom - pageViewRect.bottom); | |
| 357 if (rcAnchor.left < pageViewRect.left) { | |
| 358 rtPopup.left += rcAnchor.left - pageViewRect.left; | |
| 359 } | |
| 360 break; | |
| 361 } | |
| 362 case 270: { | |
| 363 t1 = (int)(rcAnchor.left - pageViewRect.left); | |
| 364 t2 = (int)(pageViewRect.right - rcAnchor.right); | |
| 365 | |
| 366 if (rcAnchor.top > pageViewRect.top) { | |
| 367 rtPopup.left -= rcAnchor.top - pageViewRect.top; | |
| 368 } | |
| 369 break; | |
| 370 } | |
| 371 case 0: | |
| 372 default: { | |
| 373 t1 = (int)(pageViewRect.top - rcAnchor.top); | |
| 374 t2 = (int)(rcAnchor.bottom - pageViewRect.bottom); | |
| 375 if (rcAnchor.right > pageViewRect.right) { | |
| 376 rtPopup.left -= rcAnchor.right - pageViewRect.right; | |
| 377 } | |
| 378 break; | |
| 379 } | |
| 380 } | |
| 381 | |
| 382 if (t1 <= 0 && t2 <= 0) { | |
| 383 return FALSE; | |
| 384 } | |
| 385 if (t1 <= 0) { | |
| 386 t = t2; | |
| 387 dwPos = 1; | |
| 388 } else if (t2 <= 0) { | |
| 389 t = t1; | |
| 390 dwPos = 0; | |
| 391 } else if (t1 > t2) { | |
| 392 t = t1; | |
| 393 dwPos = 0; | |
| 394 } else { | |
| 395 t = t2; | |
| 396 dwPos = 1; | |
| 397 } | |
| 398 if (t < fMinPopup) { | |
| 399 fPoupHeight = fMinPopup; | |
| 400 } else if (t > fMaxPopup) { | |
| 401 fPoupHeight = fMaxPopup; | |
| 402 } else { | |
| 403 fPoupHeight = (FX_FLOAT)t; | |
| 404 } | |
| 405 | |
| 406 switch (nRotate) { | |
| 407 case 0: | |
| 408 case 180: { | |
| 409 if (dwPos == 0) { | |
| 410 rtPopup.top = rtAnchor.height; | |
| 411 rtPopup.height = fPoupHeight; | |
| 412 } else { | |
| 413 rtPopup.top = -fPoupHeight; | |
| 414 rtPopup.height = fPoupHeight; | |
| 415 } | |
| 416 break; | |
| 417 } | |
| 418 case 90: | |
| 419 case 270: { | |
| 420 if (dwPos == 0) { | |
| 421 rtPopup.top = rtAnchor.width; | |
| 422 rtPopup.height = fPoupHeight; | |
| 423 } else { | |
| 424 rtPopup.top = -fPoupHeight; | |
| 425 rtPopup.height = fPoupHeight; | |
| 426 } | |
| 427 break; | |
| 428 } | |
| 429 default: | |
| 430 break; | |
| 431 } | |
| 432 | |
| 433 return TRUE; | |
| 434 } | |
| 435 | |
| 436 FX_BOOL CPDFXFA_Document::PopupMenu(IXFA_Widget* hWidget, | |
| 437 CFX_PointF ptPopup, | |
| 438 const CFX_RectF* pRectExclude) { | |
| 439 if (NULL == hWidget) { | |
| 440 return FALSE; | |
| 441 } | |
| 442 IXFA_PageView* pXFAPageView = | |
| 443 m_pXFADocView->GetWidgetHandler()->GetPageView(hWidget); | |
| 444 if (pXFAPageView == NULL) | |
| 445 return FALSE; | |
| 446 CPDFXFA_Page* pPage = GetPage(pXFAPageView); | |
| 447 | |
| 448 if (pPage == NULL) | |
| 449 return FALSE; | |
| 450 | |
| 451 int menuFlag = 0; | |
| 452 | |
| 453 IXFA_MenuHandler* pXFAMenuHander = m_pApp->GetXFAApp()->GetMenuHandler(); | |
| 454 if (pXFAMenuHander->CanUndo(hWidget)) | |
| 455 menuFlag |= FXFA_MEMU_UNDO; | |
| 456 if (pXFAMenuHander->CanRedo(hWidget)) | |
| 457 menuFlag |= FXFA_MEMU_REDO; | |
| 458 if (pXFAMenuHander->CanPaste(hWidget)) | |
| 459 menuFlag |= FXFA_MEMU_PASTE; | |
| 460 if (pXFAMenuHander->CanCopy(hWidget)) | |
| 461 menuFlag |= FXFA_MEMU_COPY; | |
| 462 if (pXFAMenuHander->CanCut(hWidget)) | |
| 463 menuFlag |= FXFA_MEMU_CUT; | |
| 464 if (pXFAMenuHander->CanSelectAll(hWidget)) | |
| 465 menuFlag |= FXFA_MEMU_SELECTALL; | |
| 466 | |
| 467 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 468 if (pEnv == NULL) | |
| 469 return FALSE; | |
| 470 | |
| 471 return pEnv->FFI_PopupMenu(pPage, hWidget, menuFlag, ptPopup, NULL); | |
| 472 } | |
| 473 | |
| 474 void CPDFXFA_Document::PageViewEvent(IXFA_PageView* pPageView, | |
| 475 FX_DWORD dwFlags) { | |
| 476 if (!pPageView || (dwFlags != XFA_PAGEVIEWEVENT_PostAdded && | |
| 477 dwFlags != XFA_PAGEVIEWEVENT_PostRemoved)) { | |
| 478 return; | |
| 479 } | |
| 480 CPDFXFA_Page* pPage = nullptr; | |
| 481 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 482 if (dwFlags == XFA_PAGEVIEWEVENT_PostAdded) { | |
| 483 int nPageIndex = pPageView->GetPageViewIndex(); | |
| 484 pPage = GetPage(nPageIndex); | |
| 485 if (pPage) | |
| 486 pPage->SetXFAPageView(pPageView); | |
| 487 pEnv->FFI_PageEvent(nPageIndex, dwFlags); | |
| 488 return; | |
| 489 } | |
| 490 pPage = GetPage(pPageView); | |
| 491 if (!pPage) | |
| 492 return; | |
| 493 pEnv->FFI_PageEvent(pPage->GetPageIndex(), dwFlags); | |
| 494 pPage->Release(); | |
| 495 } | |
| 496 | |
| 497 void CPDFXFA_Document::WidgetEvent(IXFA_Widget* hWidget, | |
| 498 CXFA_WidgetAcc* pWidgetData, | |
| 499 FX_DWORD dwEvent, | |
| 500 void* pParam, | |
| 501 void* pAdditional) { | |
| 502 if (m_iDocType != DOCTYPE_DYNAMIC_XFA || !hWidget) | |
| 503 return; | |
| 504 | |
| 505 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 506 if (!pEnv) | |
| 507 return; | |
| 508 | |
| 509 IXFA_PageView* pPageView = | |
| 510 m_pXFADocView->GetWidgetHandler()->GetPageView(hWidget); | |
| 511 if (pPageView == NULL) | |
| 512 return; | |
| 513 | |
| 514 CPDFXFA_Page* pXFAPage = GetPage(pPageView); | |
| 515 if (pXFAPage == NULL) | |
| 516 return; | |
| 517 | |
| 518 CPDFSDK_PageView* pSdkPageView = m_pSDKDoc->GetPageView(pXFAPage); | |
| 519 if (dwEvent == XFA_WIDGETEVENT_PostAdded) { | |
| 520 pSdkPageView->AddAnnot(hWidget); | |
| 521 | |
| 522 } else if (dwEvent == XFA_WIDGETEVENT_PreRemoved) { | |
| 523 CPDFSDK_Annot* pAnnot = pSdkPageView->GetAnnotByXFAWidget(hWidget); | |
| 524 if (pAnnot) { | |
| 525 pSdkPageView->DeleteAnnot(pAnnot); | |
| 526 } | |
| 527 } | |
| 528 } | |
| 529 | |
| 530 int32_t CPDFXFA_Document::CountPages(IXFA_Doc* hDoc) { | |
| 531 if (hDoc == m_pXFADoc && m_pSDKDoc) { | |
| 532 return GetPageCount(); | |
| 533 } | |
| 534 return 0; | |
| 535 } | |
| 536 int32_t CPDFXFA_Document::GetCurrentPage(IXFA_Doc* hDoc) { | |
| 537 if (hDoc != m_pXFADoc || !m_pSDKDoc) | |
| 538 return -1; | |
| 539 if (m_iDocType != DOCTYPE_DYNAMIC_XFA) | |
| 540 return -1; | |
| 541 | |
| 542 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 543 if (pEnv == NULL) | |
| 544 return -1; | |
| 545 | |
| 546 return pEnv->FFI_GetCurrentPageIndex(this); | |
| 547 } | |
| 548 void CPDFXFA_Document::SetCurrentPage(IXFA_Doc* hDoc, int32_t iCurPage) { | |
| 549 if (hDoc != m_pXFADoc || !m_pSDKDoc || m_iDocType != DOCTYPE_DYNAMIC_XFA || | |
| 550 iCurPage < 0 || iCurPage >= m_pSDKDoc->GetPageCount()) { | |
| 551 return; | |
| 552 } | |
| 553 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 554 if (!pEnv) | |
| 555 return; | |
| 556 pEnv->FFI_SetCurrentPage(this, iCurPage); | |
| 557 } | |
| 558 FX_BOOL CPDFXFA_Document::IsCalculationsEnabled(IXFA_Doc* hDoc) { | |
| 559 if (hDoc != m_pXFADoc || !m_pSDKDoc) | |
| 560 return FALSE; | |
| 561 if (m_pSDKDoc->GetInterForm()) | |
| 562 return m_pSDKDoc->GetInterForm()->IsXfaCalculateEnabled(); | |
| 563 | |
| 564 return FALSE; | |
| 565 } | |
| 566 void CPDFXFA_Document::SetCalculationsEnabled(IXFA_Doc* hDoc, | |
| 567 FX_BOOL bEnabled) { | |
| 568 if (hDoc != m_pXFADoc || !m_pSDKDoc) | |
| 569 return; | |
| 570 if (m_pSDKDoc->GetInterForm()) | |
| 571 m_pSDKDoc->GetInterForm()->XfaEnableCalculate(bEnabled); | |
| 572 } | |
| 573 | |
| 574 void CPDFXFA_Document::GetTitle(IXFA_Doc* hDoc, CFX_WideString& wsTitle) { | |
| 575 if (hDoc != m_pXFADoc) | |
| 576 return; | |
| 577 if (m_pPDFDoc == NULL) | |
| 578 return; | |
| 579 CPDF_Dictionary* pInfoDict = m_pPDFDoc->GetInfo(); | |
| 580 | |
| 581 if (pInfoDict == NULL) | |
| 582 return; | |
| 583 | |
| 584 CFX_ByteString csTitle = pInfoDict->GetStringBy("Title"); | |
| 585 wsTitle = wsTitle.FromLocal(csTitle.GetBuffer(csTitle.GetLength())); | |
| 586 csTitle.ReleaseBuffer(csTitle.GetLength()); | |
| 587 } | |
| 588 void CPDFXFA_Document::SetTitle(IXFA_Doc* hDoc, | |
| 589 const CFX_WideStringC& wsTitle) { | |
| 590 if (hDoc != m_pXFADoc) | |
| 591 return; | |
| 592 if (m_pPDFDoc == NULL) | |
| 593 return; | |
| 594 CPDF_Dictionary* pInfoDict = m_pPDFDoc->GetInfo(); | |
| 595 | |
| 596 if (pInfoDict == NULL) | |
| 597 return; | |
| 598 pInfoDict->SetAt("Title", new CPDF_String(wsTitle)); | |
| 599 } | |
| 600 void CPDFXFA_Document::ExportData(IXFA_Doc* hDoc, | |
| 601 const CFX_WideStringC& wsFilePath, | |
| 602 FX_BOOL bXDP) { | |
| 603 if (hDoc != m_pXFADoc) | |
| 604 return; | |
| 605 if (m_iDocType != DOCTYPE_DYNAMIC_XFA && m_iDocType != DOCTYPE_STATIC_XFA) | |
| 606 return; | |
| 607 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 608 if (pEnv == NULL) | |
| 609 return; | |
| 610 int fileType = bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML; | |
| 611 CFX_ByteString bs = CFX_WideString(wsFilePath).UTF16LE_Encode(); | |
| 612 | |
| 613 if (wsFilePath.IsEmpty()) { | |
| 614 if (!pEnv->GetFormFillInfo() || | |
| 615 pEnv->GetFormFillInfo()->m_pJsPlatform == NULL) | |
| 616 return; | |
| 617 CFX_WideString filepath = pEnv->JS_fieldBrowse(); | |
| 618 bs = filepath.UTF16LE_Encode(); | |
| 619 } | |
| 620 int len = bs.GetLength() / sizeof(unsigned short); | |
| 621 FPDF_FILEHANDLER* pFileHandler = pEnv->FFI_OpenFile( | |
| 622 bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML, | |
| 623 (FPDF_WIDESTRING)bs.GetBuffer(len * sizeof(unsigned short)), "wb"); | |
| 624 bs.ReleaseBuffer(len * sizeof(unsigned short)); | |
| 625 | |
| 626 if (pFileHandler == NULL) | |
| 627 return; | |
| 628 | |
| 629 CFPDF_FileStream fileWrite(pFileHandler); | |
| 630 | |
| 631 IXFA_DocHandler* pXFADocHander = m_pApp->GetXFAApp()->GetDocHandler(); | |
| 632 CFX_ByteString content; | |
| 633 if (fileType == FXFA_SAVEAS_XML) { | |
| 634 content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; | |
| 635 fileWrite.WriteBlock((const FX_CHAR*)content, fileWrite.GetSize(), | |
| 636 content.GetLength()); | |
| 637 CFX_WideStringC data(L"data"); | |
| 638 if (pXFADocHander->SavePackage(m_pXFADocView->GetDoc(), data, &fileWrite)) { | |
| 639 // Ignoring error. | |
| 640 } | |
| 641 } else if (fileType == FXFA_SAVEAS_XDP) { | |
| 642 if (m_pPDFDoc == NULL) | |
| 643 return; | |
| 644 CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot(); | |
| 645 if (pRoot == NULL) | |
| 646 return; | |
| 647 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); | |
| 648 if (NULL == pAcroForm) | |
| 649 return; | |
| 650 CPDF_Object* pXFA = pAcroForm->GetElement("XFA"); | |
| 651 if (pXFA == NULL) | |
| 652 return; | |
| 653 if (!pXFA->IsArray()) | |
| 654 return; | |
| 655 CPDF_Array* pArray = pXFA->GetArray(); | |
| 656 if (NULL == pArray) | |
| 657 return; | |
| 658 int size = pArray->GetCount(); | |
| 659 for (int i = 1; i < size; i += 2) { | |
| 660 CPDF_Object* pPDFObj = pArray->GetElement(i); | |
| 661 CPDF_Object* pPrePDFObj = pArray->GetElement(i - 1); | |
| 662 if (!pPrePDFObj->IsString()) | |
| 663 continue; | |
| 664 if (!pPDFObj->IsReference()) | |
| 665 continue; | |
| 666 CPDF_Object* pDirectObj = pPDFObj->GetDirect(); | |
| 667 if (!pDirectObj->IsStream()) | |
| 668 continue; | |
| 669 if (pPrePDFObj->GetString() == "form") { | |
| 670 CFX_WideStringC form(L"form"); | |
| 671 pXFADocHander->SavePackage(m_pXFADocView->GetDoc(), form, &fileWrite); | |
| 672 } else if (pPrePDFObj->GetString() == "datasets") { | |
| 673 CFX_WideStringC datasets(L"datasets"); | |
| 674 pXFADocHander->SavePackage(m_pXFADocView->GetDoc(), datasets, | |
| 675 &fileWrite); | |
| 676 } else { | |
| 677 if (i == size - 1) { | |
| 678 CFX_WideString wPath = CFX_WideString::FromUTF16LE( | |
| 679 (unsigned short*)(const FX_CHAR*)bs, | |
| 680 bs.GetLength() / sizeof(unsigned short)); | |
| 681 CFX_ByteString bPath = wPath.UTF8Encode(); | |
| 682 CFX_ByteString szFormat = | |
| 683 "\n<pdf href=\"%s\" xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>"; | |
| 684 content.Format(szFormat, (char*)(const FX_CHAR*)bPath); | |
| 685 fileWrite.WriteBlock((const FX_CHAR*)content, fileWrite.GetSize(), | |
| 686 content.GetLength()); | |
| 687 } | |
| 688 | |
| 689 CPDF_Stream* pStream = (CPDF_Stream*)pDirectObj; | |
| 690 CPDF_StreamAcc* pAcc = new CPDF_StreamAcc; | |
| 691 pAcc->LoadAllData(pStream); | |
| 692 fileWrite.WriteBlock(pAcc->GetData(), fileWrite.GetSize(), | |
| 693 pAcc->GetSize()); | |
| 694 delete pAcc; | |
| 695 } | |
| 696 } | |
| 697 } | |
| 698 if (!fileWrite.Flush()) { | |
| 699 // Ignoring flush error. | |
| 700 } | |
| 701 } | |
| 702 void CPDFXFA_Document::ImportData(IXFA_Doc* hDoc, | |
| 703 const CFX_WideStringC& wsFilePath) { | |
| 704 } | |
| 705 | |
| 706 void CPDFXFA_Document::GotoURL(IXFA_Doc* hDoc, | |
| 707 const CFX_WideStringC& bsURL, | |
| 708 FX_BOOL bAppend) { | |
| 709 if (hDoc != m_pXFADoc) | |
| 710 return; | |
| 711 | |
| 712 if (m_iDocType != DOCTYPE_DYNAMIC_XFA) | |
| 713 return; | |
| 714 | |
| 715 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 716 if (pEnv == NULL) | |
| 717 return; | |
| 718 | |
| 719 CFX_WideStringC str(bsURL.GetPtr()); | |
| 720 | |
| 721 pEnv->FFI_GotoURL(this, str, bAppend); | |
| 722 } | |
| 723 | |
| 724 FX_BOOL CPDFXFA_Document::IsValidationsEnabled(IXFA_Doc* hDoc) { | |
| 725 if (hDoc != m_pXFADoc || !m_pSDKDoc) | |
| 726 return FALSE; | |
| 727 if (m_pSDKDoc->GetInterForm()) | |
| 728 return m_pSDKDoc->GetInterForm()->IsXfaValidationsEnabled(); | |
| 729 | |
| 730 return TRUE; | |
| 731 } | |
| 732 void CPDFXFA_Document::SetValidationsEnabled(IXFA_Doc* hDoc, FX_BOOL bEnabled) { | |
| 733 if (hDoc != m_pXFADoc || !m_pSDKDoc) | |
| 734 return; | |
| 735 if (m_pSDKDoc->GetInterForm()) | |
| 736 m_pSDKDoc->GetInterForm()->XfaSetValidationsEnabled(bEnabled); | |
| 737 } | |
| 738 void CPDFXFA_Document::SetFocusWidget(IXFA_Doc* hDoc, IXFA_Widget* hWidget) { | |
| 739 if (hDoc != m_pXFADoc) | |
| 740 return; | |
| 741 | |
| 742 if (NULL == hWidget) { | |
| 743 m_pSDKDoc->SetFocusAnnot(NULL); | |
| 744 return; | |
| 745 } | |
| 746 | |
| 747 int pageViewCount = m_pSDKDoc->GetPageViewCount(); | |
| 748 for (int i = 0; i < pageViewCount; i++) { | |
| 749 CPDFSDK_PageView* pPageView = m_pSDKDoc->GetPageView(i); | |
| 750 if (pPageView == NULL) | |
| 751 continue; | |
| 752 CPDFSDK_Annot* pAnnot = pPageView->GetAnnotByXFAWidget(hWidget); | |
| 753 if (pAnnot) { | |
| 754 m_pSDKDoc->SetFocusAnnot(pAnnot); | |
| 755 break; | |
| 756 } | |
| 757 } | |
| 758 } | |
| 759 void CPDFXFA_Document::Print(IXFA_Doc* hDoc, | |
| 760 int32_t nStartPage, | |
| 761 int32_t nEndPage, | |
| 762 FX_DWORD dwOptions) { | |
| 763 if (hDoc != m_pXFADoc) | |
| 764 return; | |
| 765 | |
| 766 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 767 if (pEnv == NULL) | |
| 768 return; | |
| 769 | |
| 770 if (!pEnv->GetFormFillInfo() || | |
| 771 pEnv->GetFormFillInfo()->m_pJsPlatform == NULL) | |
| 772 return; | |
| 773 if (pEnv->GetFormFillInfo()->m_pJsPlatform->Doc_print == NULL) | |
| 774 return; | |
| 775 pEnv->GetFormFillInfo()->m_pJsPlatform->Doc_print( | |
| 776 pEnv->GetFormFillInfo()->m_pJsPlatform, | |
| 777 dwOptions & XFA_PRINTOPT_ShowDialog, nStartPage, nEndPage, | |
| 778 dwOptions & XFA_PRINTOPT_CanCancel, dwOptions & XFA_PRINTOPT_ShrinkPage, | |
| 779 dwOptions & XFA_PRINTOPT_AsImage, dwOptions & XFA_PRINTOPT_ReverseOrder, | |
| 780 dwOptions & XFA_PRINTOPT_PrintAnnot); | |
| 781 } | |
| 782 | |
| 783 void CPDFXFA_Document::GetURL(IXFA_Doc* hDoc, CFX_WideString& wsDocURL) { | |
| 784 if (hDoc != m_pXFADoc) | |
| 785 return; | |
| 786 | |
| 787 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 788 if (pEnv == NULL) | |
| 789 return; | |
| 790 | |
| 791 pEnv->FFI_GetURL(this, wsDocURL); | |
| 792 } | |
| 793 | |
| 794 FX_ARGB CPDFXFA_Document::GetHighlightColor(IXFA_Doc* hDoc) { | |
| 795 if (hDoc != m_pXFADoc) | |
| 796 return 0; | |
| 797 if (m_pSDKDoc) { | |
| 798 if (CPDFSDK_InterForm* pInterForm = m_pSDKDoc->GetInterForm()) { | |
| 799 FX_COLORREF color = pInterForm->GetHighlightColor(FPDF_FORMFIELD_XFA); | |
| 800 uint8_t alpha = pInterForm->GetHighlightAlpha(); | |
| 801 FX_ARGB argb = ArgbEncode((int)alpha, color); | |
| 802 return argb; | |
| 803 } | |
| 804 } | |
| 805 return 0; | |
| 806 } | |
| 807 | |
| 808 FX_BOOL CPDFXFA_Document::_NotifySubmit(FX_BOOL bPrevOrPost) { | |
| 809 if (bPrevOrPost) | |
| 810 return _OnBeforeNotifySumbit(); | |
| 811 | |
| 812 _OnAfterNotifySumbit(); | |
| 813 return TRUE; | |
| 814 } | |
| 815 | |
| 816 FX_BOOL CPDFXFA_Document::_OnBeforeNotifySumbit() { | |
| 817 #ifdef PDF_ENABLE_XFA | |
| 818 if (m_iDocType != DOCTYPE_DYNAMIC_XFA && m_iDocType != DOCTYPE_STATIC_XFA) | |
| 819 return TRUE; | |
| 820 if (m_pXFADocView == NULL) | |
| 821 return TRUE; | |
| 822 IXFA_WidgetHandler* pWidgetHandler = m_pXFADocView->GetWidgetHandler(); | |
| 823 if (pWidgetHandler == NULL) | |
| 824 return TRUE; | |
| 825 IXFA_WidgetAccIterator* pWidgetAccIterator = | |
| 826 m_pXFADocView->CreateWidgetAccIterator(); | |
| 827 if (pWidgetAccIterator) { | |
| 828 CXFA_EventParam Param; | |
| 829 Param.m_eType = XFA_EVENT_PreSubmit; | |
| 830 CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext(); | |
| 831 while (pWidgetAcc) { | |
| 832 pWidgetHandler->ProcessEvent(pWidgetAcc, &Param); | |
| 833 pWidgetAcc = pWidgetAccIterator->MoveToNext(); | |
| 834 } | |
| 835 pWidgetAccIterator->Release(); | |
| 836 } | |
| 837 pWidgetAccIterator = m_pXFADocView->CreateWidgetAccIterator(); | |
| 838 if (pWidgetAccIterator) { | |
| 839 CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext(); | |
| 840 pWidgetAcc = pWidgetAccIterator->MoveToNext(); | |
| 841 while (pWidgetAcc) { | |
| 842 int fRet = pWidgetAcc->ProcessValidate(-1); | |
| 843 if (fRet == XFA_EVENTERROR_Error) { | |
| 844 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 845 if (pEnv == NULL) | |
| 846 return FALSE; | |
| 847 CFX_WideString ws; | |
| 848 ws.FromLocal(IDS_XFA_Validate_Input); | |
| 849 CFX_ByteString bs = ws.UTF16LE_Encode(); | |
| 850 int len = bs.GetLength() / sizeof(unsigned short); | |
| 851 pEnv->FFI_Alert( | |
| 852 (FPDF_WIDESTRING)bs.GetBuffer(len * sizeof(unsigned short)), | |
| 853 (FPDF_WIDESTRING)L"", 0, 1); | |
| 854 bs.ReleaseBuffer(len * sizeof(unsigned short)); | |
| 855 pWidgetAccIterator->Release(); | |
| 856 return FALSE; | |
| 857 } | |
| 858 pWidgetAcc = pWidgetAccIterator->MoveToNext(); | |
| 859 } | |
| 860 pWidgetAccIterator->Release(); | |
| 861 m_pXFADocView->UpdateDocView(); | |
| 862 } | |
| 863 #endif | |
| 864 return TRUE; | |
| 865 } | |
| 866 void CPDFXFA_Document::_OnAfterNotifySumbit() { | |
| 867 if (m_iDocType != DOCTYPE_DYNAMIC_XFA && m_iDocType != DOCTYPE_STATIC_XFA) | |
| 868 return; | |
| 869 if (m_pXFADocView == NULL) | |
| 870 return; | |
| 871 IXFA_WidgetHandler* pWidgetHandler = m_pXFADocView->GetWidgetHandler(); | |
| 872 if (pWidgetHandler == NULL) | |
| 873 return; | |
| 874 IXFA_WidgetAccIterator* pWidgetAccIterator = | |
| 875 m_pXFADocView->CreateWidgetAccIterator(); | |
| 876 if (pWidgetAccIterator == NULL) | |
| 877 return; | |
| 878 CXFA_EventParam Param; | |
| 879 Param.m_eType = XFA_EVENT_PostSubmit; | |
| 880 | |
| 881 CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext(); | |
| 882 while (pWidgetAcc) { | |
| 883 pWidgetHandler->ProcessEvent(pWidgetAcc, &Param); | |
| 884 pWidgetAcc = pWidgetAccIterator->MoveToNext(); | |
| 885 } | |
| 886 pWidgetAccIterator->Release(); | |
| 887 m_pXFADocView->UpdateDocView(); | |
| 888 } | |
| 889 | |
| 890 FX_BOOL CPDFXFA_Document::SubmitData(IXFA_Doc* hDoc, CXFA_Submit submit) { | |
| 891 if (!_NotifySubmit(TRUE)) | |
| 892 return FALSE; | |
| 893 if (NULL == m_pXFADocView) | |
| 894 return FALSE; | |
| 895 m_pXFADocView->UpdateDocView(); | |
| 896 | |
| 897 FX_BOOL ret = _SubmitData(hDoc, submit); | |
| 898 _NotifySubmit(FALSE); | |
| 899 return ret; | |
| 900 } | |
| 901 | |
| 902 IFX_FileRead* CPDFXFA_Document::OpenLinkedFile(IXFA_Doc* hDoc, | |
| 903 const CFX_WideString& wsLink) { | |
| 904 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 905 if (pEnv == NULL) | |
| 906 return FALSE; | |
| 907 CFX_ByteString bs = wsLink.UTF16LE_Encode(); | |
| 908 int len = bs.GetLength() / sizeof(unsigned short); | |
| 909 FPDF_FILEHANDLER* pFileHandler = pEnv->FFI_OpenFile( | |
| 910 0, (FPDF_WIDESTRING)bs.GetBuffer(len * sizeof(unsigned short)), "rb"); | |
| 911 bs.ReleaseBuffer(len * sizeof(unsigned short)); | |
| 912 | |
| 913 if (pFileHandler == NULL) | |
| 914 return NULL; | |
| 915 return new CFPDF_FileStream(pFileHandler); | |
| 916 } | |
| 917 FX_BOOL CPDFXFA_Document::_ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler, | |
| 918 int fileType, | |
| 919 FPDF_DWORD encodeType, | |
| 920 FPDF_DWORD flag) { | |
| 921 if (NULL == m_pXFADocView) | |
| 922 return FALSE; | |
| 923 IXFA_DocHandler* pDocHandler = m_pApp->GetXFAApp()->GetDocHandler(); | |
| 924 CFX_ByteString content; | |
| 925 | |
| 926 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 927 if (pEnv == NULL) | |
| 928 return FALSE; | |
| 929 | |
| 930 CFPDF_FileStream fileStream(pFileHandler); | |
| 931 | |
| 932 if (fileType == FXFA_SAVEAS_XML) { | |
| 933 CFX_WideString ws; | |
| 934 ws.FromLocal("data"); | |
| 935 CFX_ByteString content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; | |
| 936 fileStream.WriteBlock((const FX_CHAR*)content, 0, content.GetLength()); | |
| 937 pDocHandler->SavePackage(m_pXFADoc, ws, &fileStream); | |
| 938 } else if (fileType == FXFA_SAVEAS_XDP) { | |
| 939 if (flag == 0) | |
| 940 flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS | | |
| 941 FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM; | |
| 942 if (m_pPDFDoc == NULL) { | |
| 943 fileStream.Flush(); | |
| 944 return FALSE; | |
| 945 } | |
| 946 CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot(); | |
| 947 if (pRoot == NULL) { | |
| 948 fileStream.Flush(); | |
| 949 return FALSE; | |
| 950 } | |
| 951 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); | |
| 952 if (NULL == pAcroForm) { | |
| 953 fileStream.Flush(); | |
| 954 return FALSE; | |
| 955 } | |
| 956 CPDF_Object* pXFA = pAcroForm->GetElement("XFA"); | |
| 957 if (pXFA == NULL) { | |
| 958 fileStream.Flush(); | |
| 959 return FALSE; | |
| 960 } | |
| 961 if (!pXFA->IsArray()) { | |
| 962 fileStream.Flush(); | |
| 963 return FALSE; | |
| 964 } | |
| 965 CPDF_Array* pArray = pXFA->GetArray(); | |
| 966 if (NULL == pArray) { | |
| 967 fileStream.Flush(); | |
| 968 return FALSE; | |
| 969 } | |
| 970 int size = pArray->GetCount(); | |
| 971 for (int i = 1; i < size; i += 2) { | |
| 972 CPDF_Object* pPDFObj = pArray->GetElement(i); | |
| 973 CPDF_Object* pPrePDFObj = pArray->GetElement(i - 1); | |
| 974 if (!pPrePDFObj->IsString()) | |
| 975 continue; | |
| 976 if (!pPDFObj->IsReference()) | |
| 977 continue; | |
| 978 CPDF_Object* pDirectObj = pPDFObj->GetDirect(); | |
| 979 if (!pDirectObj->IsStream()) | |
| 980 continue; | |
| 981 if (pPrePDFObj->GetString() == "config" && !(flag & FXFA_CONFIG)) | |
| 982 continue; | |
| 983 if (pPrePDFObj->GetString() == "template" && !(flag & FXFA_TEMPLATE)) | |
| 984 continue; | |
| 985 if (pPrePDFObj->GetString() == "localeSet" && !(flag & FXFA_LOCALESET)) | |
| 986 continue; | |
| 987 if (pPrePDFObj->GetString() == "datasets" && !(flag & FXFA_DATASETS)) | |
| 988 continue; | |
| 989 if (pPrePDFObj->GetString() == "xmpmeta" && !(flag & FXFA_XMPMETA)) | |
| 990 continue; | |
| 991 if (pPrePDFObj->GetString() == "xfdf" && !(flag & FXFA_XFDF)) | |
| 992 continue; | |
| 993 if (pPrePDFObj->GetString() == "form" && !(flag & FXFA_FORM)) | |
| 994 continue; | |
| 995 if (pPrePDFObj->GetString() == "form") { | |
| 996 CFX_WideString ws; | |
| 997 ws.FromLocal("form"); | |
| 998 pDocHandler->SavePackage(m_pXFADoc, ws, &fileStream); | |
| 999 } else if (pPrePDFObj->GetString() == "datasets") { | |
| 1000 CFX_WideString ws; | |
| 1001 ws.FromLocal("datasets"); | |
| 1002 pDocHandler->SavePackage(m_pXFADoc, ws, &fileStream); | |
| 1003 } else { | |
| 1004 // PDF,creator. | |
| 1005 } | |
| 1006 } | |
| 1007 } | |
| 1008 return TRUE; | |
| 1009 } | |
| 1010 | |
| 1011 void CPDFXFA_Document::_ClearChangeMark() { | |
| 1012 if (m_pSDKDoc) | |
| 1013 m_pSDKDoc->ClearChangeMark(); | |
| 1014 } | |
| 1015 | |
| 1016 void CPDFXFA_Document::_ToXFAContentFlags(CFX_WideString csSrcContent, | |
| 1017 FPDF_DWORD& flag) { | |
| 1018 if (csSrcContent.Find(L" config ", 0) != -1) | |
| 1019 flag |= FXFA_CONFIG; | |
| 1020 if (csSrcContent.Find(L" template ", 0) != -1) | |
| 1021 flag |= FXFA_TEMPLATE; | |
| 1022 if (csSrcContent.Find(L" localeSet ", 0) != -1) | |
| 1023 flag |= FXFA_LOCALESET; | |
| 1024 if (csSrcContent.Find(L" datasets ", 0) != -1) | |
| 1025 flag |= FXFA_DATASETS; | |
| 1026 if (csSrcContent.Find(L" xmpmeta ", 0) != -1) | |
| 1027 flag |= FXFA_XMPMETA; | |
| 1028 if (csSrcContent.Find(L" xfdf ", 0) != -1) | |
| 1029 flag |= FXFA_XFDF; | |
| 1030 if (csSrcContent.Find(L" form ", 0) != -1) | |
| 1031 flag |= FXFA_FORM; | |
| 1032 if (flag == 0) | |
| 1033 flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS | | |
| 1034 FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM; | |
| 1035 } | |
| 1036 FX_BOOL CPDFXFA_Document::_MailToInfo(CFX_WideString& csURL, | |
| 1037 CFX_WideString& csToAddress, | |
| 1038 CFX_WideString& csCCAddress, | |
| 1039 CFX_WideString& csBCCAddress, | |
| 1040 CFX_WideString& csSubject, | |
| 1041 CFX_WideString& csMsg) { | |
| 1042 CFX_WideString srcURL = csURL; | |
| 1043 srcURL.TrimLeft(); | |
| 1044 if (0 != srcURL.Left(7).CompareNoCase(L"mailto:")) | |
| 1045 return FALSE; | |
| 1046 int pos = srcURL.Find(L'?', 0); | |
| 1047 CFX_WideString tmp; | |
| 1048 if (pos == -1) { | |
| 1049 pos = srcURL.Find(L'@', 0); | |
| 1050 if (pos == -1) | |
| 1051 return FALSE; | |
| 1052 | |
| 1053 tmp = srcURL.Right(csURL.GetLength() - 7); | |
| 1054 tmp.TrimLeft(); | |
| 1055 tmp.TrimRight(); | |
| 1056 } else { | |
| 1057 tmp = srcURL.Left(pos); | |
| 1058 tmp = tmp.Right(tmp.GetLength() - 7); | |
| 1059 tmp.TrimLeft(); | |
| 1060 tmp.TrimRight(); | |
| 1061 } | |
| 1062 | |
| 1063 csToAddress = tmp; | |
| 1064 | |
| 1065 srcURL = srcURL.Right(srcURL.GetLength() - (pos + 1)); | |
| 1066 while (!srcURL.IsEmpty()) { | |
| 1067 srcURL.TrimLeft(); | |
| 1068 srcURL.TrimRight(); | |
| 1069 pos = srcURL.Find(L'&', 0); | |
| 1070 if (pos == -1) | |
| 1071 tmp = srcURL; | |
| 1072 else | |
| 1073 tmp = srcURL.Left(pos); | |
| 1074 | |
| 1075 tmp.TrimLeft(); | |
| 1076 tmp.TrimRight(); | |
| 1077 if (tmp.GetLength() >= 3 && 0 == tmp.Left(3).CompareNoCase(L"cc=")) { | |
| 1078 tmp = tmp.Right(tmp.GetLength() - 3); | |
| 1079 if (!csCCAddress.IsEmpty()) | |
| 1080 csCCAddress += L';'; | |
| 1081 csCCAddress += tmp; | |
| 1082 | |
| 1083 } else if (tmp.GetLength() >= 4 && | |
| 1084 0 == tmp.Left(4).CompareNoCase(L"bcc=")) { | |
| 1085 tmp = tmp.Right(tmp.GetLength() - 4); | |
| 1086 if (!csBCCAddress.IsEmpty()) | |
| 1087 csBCCAddress += L';'; | |
| 1088 csBCCAddress += tmp; | |
| 1089 } else if (tmp.GetLength() >= 8 && | |
| 1090 0 == tmp.Left(8).CompareNoCase(L"subject=")) { | |
| 1091 tmp = tmp.Right(tmp.GetLength() - 8); | |
| 1092 csSubject += tmp; | |
| 1093 } else if (tmp.GetLength() >= 5 && | |
| 1094 0 == tmp.Left(5).CompareNoCase(L"body=")) { | |
| 1095 tmp = tmp.Right(tmp.GetLength() - 5); | |
| 1096 csMsg += tmp; | |
| 1097 } | |
| 1098 if (pos == -1) | |
| 1099 srcURL = L""; | |
| 1100 else | |
| 1101 srcURL = srcURL.Right(csURL.GetLength() - (pos + 1)); | |
| 1102 } | |
| 1103 csToAddress.Replace(L",", L";"); | |
| 1104 csCCAddress.Replace(L",", L";"); | |
| 1105 csBCCAddress.Replace(L",", L";"); | |
| 1106 return TRUE; | |
| 1107 } | |
| 1108 | |
| 1109 FX_BOOL CPDFXFA_Document::_SubmitData(IXFA_Doc* hDoc, CXFA_Submit submit) { | |
| 1110 #ifdef PDF_ENABLE_XFA | |
| 1111 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 1112 if (!pEnv) | |
| 1113 return FALSE; | |
| 1114 CFX_WideStringC csURLC; | |
| 1115 submit.GetSubmitTarget(csURLC); | |
| 1116 CFX_WideString csURL = csURLC; | |
| 1117 if (csURL.IsEmpty()) { | |
| 1118 CFX_WideString ws; | |
| 1119 ws.FromLocal("Submit cancelled."); | |
| 1120 CFX_ByteString bs = ws.UTF16LE_Encode(); | |
| 1121 int len = bs.GetLength() / sizeof(unsigned short); | |
| 1122 pEnv->FFI_Alert((FPDF_WIDESTRING)bs.GetBuffer(len * sizeof(unsigned short)), | |
| 1123 (FPDF_WIDESTRING)L"", 0, 4); | |
| 1124 bs.ReleaseBuffer(len * sizeof(unsigned short)); | |
| 1125 return FALSE; | |
| 1126 } | |
| 1127 FPDF_BOOL bRet = TRUE; | |
| 1128 FPDF_FILEHANDLER* pFileHandler = nullptr; | |
| 1129 int fileFlag = -1; | |
| 1130 switch (submit.GetSubmitFormat()) { | |
| 1131 case XFA_ATTRIBUTEENUM_Xdp: { | |
| 1132 CFX_WideStringC csContentC; | |
| 1133 submit.GetSubmitXDPContent(csContentC); | |
| 1134 CFX_WideString csContent; | |
| 1135 csContent = csContentC; | |
| 1136 csContent.TrimLeft(); | |
| 1137 csContent.TrimRight(); | |
| 1138 CFX_WideString space; | |
| 1139 space.FromLocal(" "); | |
| 1140 csContent = space + csContent + space; | |
| 1141 FPDF_DWORD flag = 0; | |
| 1142 if (submit.IsSubmitEmbedPDF()) | |
| 1143 flag |= FXFA_PDF; | |
| 1144 _ToXFAContentFlags(csContent, flag); | |
| 1145 pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XDP, nullptr, "wb"); | |
| 1146 fileFlag = FXFA_SAVEAS_XDP; | |
| 1147 _ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XDP, 0, flag); | |
| 1148 break; | |
| 1149 } | |
| 1150 case XFA_ATTRIBUTEENUM_Xml: | |
| 1151 pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XML, nullptr, "wb"); | |
| 1152 fileFlag = FXFA_SAVEAS_XML; | |
| 1153 _ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0); | |
| 1154 break; | |
| 1155 case XFA_ATTRIBUTEENUM_Pdf: | |
| 1156 break; | |
| 1157 case XFA_ATTRIBUTEENUM_Urlencoded: | |
| 1158 pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XML, nullptr, "wb"); | |
| 1159 fileFlag = FXFA_SAVEAS_XML; | |
| 1160 _ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0); | |
| 1161 break; | |
| 1162 default: | |
| 1163 return false; | |
| 1164 } | |
| 1165 if (!pFileHandler) | |
| 1166 return FALSE; | |
| 1167 if (0 == csURL.Left(7).CompareNoCase(L"mailto:")) { | |
| 1168 CFX_WideString csToAddress; | |
| 1169 CFX_WideString csCCAddress; | |
| 1170 CFX_WideString csBCCAddress; | |
| 1171 CFX_WideString csSubject; | |
| 1172 CFX_WideString csMsg; | |
| 1173 bRet = _MailToInfo(csURL, csToAddress, csCCAddress, csBCCAddress, csSubject, | |
| 1174 csMsg); | |
| 1175 if (!bRet) | |
| 1176 return FALSE; | |
| 1177 CFX_ByteString bsTo = CFX_WideString(csToAddress).UTF16LE_Encode(); | |
| 1178 CFX_ByteString bsCC = CFX_WideString(csCCAddress).UTF16LE_Encode(); | |
| 1179 CFX_ByteString bsBcc = CFX_WideString(csBCCAddress).UTF16LE_Encode(); | |
| 1180 CFX_ByteString bsSubject = CFX_WideString(csSubject).UTF16LE_Encode(); | |
| 1181 CFX_ByteString bsMsg = CFX_WideString(csMsg).UTF16LE_Encode(); | |
| 1182 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength()); | |
| 1183 FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength()); | |
| 1184 FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength()); | |
| 1185 FPDF_WIDESTRING pSubject = | |
| 1186 (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength()); | |
| 1187 FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength()); | |
| 1188 pEnv->FFI_EmailTo(pFileHandler, pTo, pSubject, pCC, pBcc, pMsg); | |
| 1189 bsTo.ReleaseBuffer(); | |
| 1190 bsCC.ReleaseBuffer(); | |
| 1191 bsBcc.ReleaseBuffer(); | |
| 1192 bsSubject.ReleaseBuffer(); | |
| 1193 bsMsg.ReleaseBuffer(); | |
| 1194 } else { | |
| 1195 // HTTP or FTP | |
| 1196 CFX_WideString ws; | |
| 1197 CFX_ByteString bs = csURL.UTF16LE_Encode(); | |
| 1198 int len = bs.GetLength() / sizeof(unsigned short); | |
| 1199 pEnv->FFI_UploadTo( | |
| 1200 pFileHandler, fileFlag, | |
| 1201 (FPDF_WIDESTRING)bs.GetBuffer(len * sizeof(unsigned short))); | |
| 1202 bs.ReleaseBuffer(len * sizeof(unsigned short)); | |
| 1203 } | |
| 1204 return bRet; | |
| 1205 #else | |
| 1206 return TRUE; | |
| 1207 #endif | |
| 1208 } | |
| 1209 | |
| 1210 FX_BOOL CPDFXFA_Document::SetGlobalProperty(IXFA_Doc* hDoc, | |
| 1211 const CFX_ByteStringC& szPropName, | |
| 1212 FXJSE_HVALUE hValue) { | |
| 1213 if (hDoc != m_pXFADoc) | |
| 1214 return FALSE; | |
| 1215 | |
| 1216 if (m_pSDKDoc && m_pSDKDoc->GetEnv()->GetJSRuntime()) | |
| 1217 return m_pSDKDoc->GetEnv()->GetJSRuntime()->SetHValueByName(szPropName, | |
| 1218 hValue); | |
| 1219 return FALSE; | |
| 1220 } | |
| 1221 FX_BOOL CPDFXFA_Document::GetPDFScriptObject(IXFA_Doc* hDoc, | |
| 1222 const CFX_ByteStringC& utf8Name, | |
| 1223 FXJSE_HVALUE hValue) { | |
| 1224 if (hDoc != m_pXFADoc) | |
| 1225 return FALSE; | |
| 1226 | |
| 1227 if (!m_pSDKDoc || !m_pSDKDoc->GetEnv()->GetJSRuntime()) | |
| 1228 return FALSE; | |
| 1229 | |
| 1230 if (!m_pJSContext) { | |
| 1231 m_pSDKDoc->GetEnv()->GetJSRuntime()->SetReaderDocument(m_pSDKDoc); | |
| 1232 m_pJSContext = m_pSDKDoc->GetEnv()->GetJSRuntime()->NewContext(); | |
| 1233 } | |
| 1234 | |
| 1235 return _GetHValueByName(utf8Name, hValue, | |
| 1236 m_pSDKDoc->GetEnv()->GetJSRuntime()); | |
| 1237 } | |
| 1238 FX_BOOL CPDFXFA_Document::GetGlobalProperty(IXFA_Doc* hDoc, | |
| 1239 const CFX_ByteStringC& szPropName, | |
| 1240 FXJSE_HVALUE hValue) { | |
| 1241 if (hDoc != m_pXFADoc) | |
| 1242 return FALSE; | |
| 1243 if (!m_pSDKDoc || !m_pSDKDoc->GetEnv()->GetJSRuntime()) | |
| 1244 return FALSE; | |
| 1245 | |
| 1246 if (!m_pJSContext) { | |
| 1247 m_pSDKDoc->GetEnv()->GetJSRuntime()->SetReaderDocument(m_pSDKDoc); | |
| 1248 m_pJSContext = m_pSDKDoc->GetEnv()->GetJSRuntime()->NewContext(); | |
| 1249 } | |
| 1250 | |
| 1251 return _GetHValueByName(szPropName, hValue, | |
| 1252 m_pSDKDoc->GetEnv()->GetJSRuntime()); | |
| 1253 } | |
| 1254 FX_BOOL CPDFXFA_Document::_GetHValueByName(const CFX_ByteStringC& utf8Name, | |
| 1255 FXJSE_HVALUE hValue, | |
| 1256 IJS_Runtime* runTime) { | |
| 1257 return runTime->GetHValueByName(utf8Name, hValue); | |
| 1258 } | |
| OLD | NEW |