| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" | 7 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | |
| 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" | |
| 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" | |
| 13 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_app.h" | 10 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_app.h" |
| 14 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h" | 11 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h" |
| 15 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_util.h" | 12 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_util.h" |
| 16 #include "fpdfsdk/include/cpdfdoc_environment.h" | 13 #include "fpdfsdk/include/cpdfdoc_environment.h" |
| 17 #include "fpdfsdk/include/cpdfsdk_document.h" | 14 #include "fpdfsdk/include/cpdfsdk_document.h" |
| 18 #include "fpdfsdk/include/cpdfsdk_interform.h" | 15 #include "fpdfsdk/include/cpdfsdk_interform.h" |
| 19 #include "fpdfsdk/include/cpdfsdk_pageview.h" | 16 #include "fpdfsdk/include/cpdfsdk_pageview.h" |
| 20 #include "fpdfsdk/include/fsdk_define.h" | 17 #include "fpdfsdk/include/fsdk_define.h" |
| 21 #include "fpdfsdk/javascript/ijs_runtime.h" | 18 #include "fpdfsdk/javascript/ijs_runtime.h" |
| 22 #include "public/fpdf_formfill.h" | 19 #include "public/fpdf_formfill.h" |
| 23 #include "xfa/fxfa/include/cxfa_eventparam.h" | 20 #include "xfa/fxfa/include/cxfa_eventparam.h" |
| 24 #include "xfa/fxfa/include/xfa_ffapp.h" | 21 #include "xfa/fxfa/include/xfa_ffapp.h" |
| 25 #include "xfa/fxfa/include/xfa_ffdoc.h" | 22 #include "xfa/fxfa/include/xfa_ffdoc.h" |
| 26 #include "xfa/fxfa/include/xfa_ffdocview.h" | 23 #include "xfa/fxfa/include/xfa_ffdocview.h" |
| 27 #include "xfa/fxfa/include/xfa_ffpageview.h" | 24 #include "xfa/fxfa/include/xfa_ffpageview.h" |
| 28 #include "xfa/fxfa/include/xfa_ffwidget.h" | |
| 29 #include "xfa/fxfa/include/xfa_ffwidgethandler.h" | 25 #include "xfa/fxfa/include/xfa_ffwidgethandler.h" |
| 30 | 26 |
| 31 #define IDS_XFA_Validate_Input \ | |
| 32 "At least one required field was empty. Please fill in the required " \ | |
| 33 "fields\r\n(highlighted) before continuing." | |
| 34 | |
| 35 // submit | |
| 36 #define FXFA_CONFIG 0x00000001 | |
| 37 #define FXFA_TEMPLATE 0x00000010 | |
| 38 #define FXFA_LOCALESET 0x00000100 | |
| 39 #define FXFA_DATASETS 0x00001000 | |
| 40 #define FXFA_XMPMETA 0x00010000 | |
| 41 #define FXFA_XFDF 0x00100000 | |
| 42 #define FXFA_FORM 0x01000000 | |
| 43 #define FXFA_PDF 0x10000000 | |
| 44 #define FXFA_XFA_ALL 0x01111111 | |
| 45 | |
| 46 #ifndef _WIN32 | 27 #ifndef _WIN32 |
| 47 extern void SetLastError(int err); | 28 extern void SetLastError(int err); |
| 48 extern int GetLastError(); | 29 extern int GetLastError(); |
| 49 #endif | 30 #endif |
| 50 | 31 |
| 51 CPDFXFA_Document::CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc, | 32 CPDFXFA_Document::CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc, |
| 52 CPDFXFA_App* pProvider) | 33 CPDFXFA_App* pProvider) |
| 53 : m_iDocType(DOCTYPE_PDF), | 34 : m_iDocType(DOCTYPE_PDF), |
| 54 m_pPDFDoc(std::move(pPDFDoc)), | 35 m_pPDFDoc(std::move(pPDFDoc)), |
| 55 m_pXFADocView(nullptr), | 36 m_pXFADocView(nullptr), |
| 56 m_pApp(pProvider), | 37 m_pApp(pProvider), |
| 57 m_pJSContext(nullptr), | |
| 58 m_nLoadStatus(FXFA_LOADSTATUS_PRELOAD), | 38 m_nLoadStatus(FXFA_LOADSTATUS_PRELOAD), |
| 59 m_nPageCount(0) {} | 39 m_nPageCount(0), |
| 40 m_DocEnv(this) {} |
| 60 | 41 |
| 61 CPDFXFA_Document::~CPDFXFA_Document() { | 42 CPDFXFA_Document::~CPDFXFA_Document() { |
| 62 m_nLoadStatus = FXFA_LOADSTATUS_CLOSING; | 43 m_nLoadStatus = FXFA_LOADSTATUS_CLOSING; |
| 63 | 44 |
| 64 if (m_pXFADoc) { | 45 if (m_pXFADoc) { |
| 65 CXFA_FFApp* pApp = m_pApp->GetXFAApp(); | 46 CXFA_FFApp* pApp = m_pApp->GetXFAApp(); |
| 66 if (pApp) { | 47 if (pApp) { |
| 67 CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler(); | 48 CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler(); |
| 68 if (pDocHandler) | 49 if (pDocHandler) |
| 69 CloseXFADoc(pDocHandler); | 50 CloseXFADoc(pDocHandler); |
| 70 } | 51 } |
| 71 m_pXFADoc.reset(); | 52 m_pXFADoc.reset(); |
| 72 } | 53 } |
| 73 if (m_pJSContext && m_pSDKDoc && m_pSDKDoc->GetEnv()) | |
| 74 m_pSDKDoc->GetEnv()->GetJSRuntime()->ReleaseContext(m_pJSContext); | |
| 75 | 54 |
| 76 m_nLoadStatus = FXFA_LOADSTATUS_CLOSED; | 55 m_nLoadStatus = FXFA_LOADSTATUS_CLOSED; |
| 77 } | 56 } |
| 78 | 57 |
| 79 FX_BOOL CPDFXFA_Document::LoadXFADoc() { | 58 FX_BOOL CPDFXFA_Document::LoadXFADoc() { |
| 80 m_nLoadStatus = FXFA_LOADSTATUS_LOADING; | 59 m_nLoadStatus = FXFA_LOADSTATUS_LOADING; |
| 81 | 60 |
| 82 if (!m_pPDFDoc) | 61 if (!m_pPDFDoc) |
| 83 return FALSE; | 62 return FALSE; |
| 84 | 63 |
| 85 m_XFAPageList.RemoveAll(); | 64 m_XFAPageList.RemoveAll(); |
| 86 | 65 |
| 87 CXFA_FFApp* pApp = m_pApp->GetXFAApp(); | 66 CXFA_FFApp* pApp = m_pApp->GetXFAApp(); |
| 88 if (!pApp) | 67 if (!pApp) |
| 89 return FALSE; | 68 return FALSE; |
| 90 | 69 |
| 91 m_pXFADoc.reset(pApp->CreateDoc(this, m_pPDFDoc.get())); | 70 m_pXFADoc.reset(pApp->CreateDoc(&m_DocEnv, m_pPDFDoc.get())); |
| 92 if (!m_pXFADoc) { | 71 if (!m_pXFADoc) { |
| 93 SetLastError(FPDF_ERR_XFALOAD); | 72 SetLastError(FPDF_ERR_XFALOAD); |
| 94 return FALSE; | 73 return FALSE; |
| 95 } | 74 } |
| 96 | 75 |
| 97 CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler(); | 76 CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler(); |
| 98 if (!pDocHandler) { | 77 if (!pDocHandler) { |
| 99 SetLastError(FPDF_ERR_XFALOAD); | 78 SetLastError(FPDF_ERR_XFALOAD); |
| 100 return FALSE; | 79 return FALSE; |
| 101 } | 80 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 m_XFAPageList.SetAt(page->GetPageIndex(), nullptr); | 191 m_XFAPageList.SetAt(page->GetPageIndex(), nullptr); |
| 213 } | 192 } |
| 214 | 193 |
| 215 CPDFSDK_Document* CPDFXFA_Document::GetSDKDocument( | 194 CPDFSDK_Document* CPDFXFA_Document::GetSDKDocument( |
| 216 CPDFDoc_Environment* pFormFillEnv) { | 195 CPDFDoc_Environment* pFormFillEnv) { |
| 217 if (!m_pSDKDoc && pFormFillEnv) | 196 if (!m_pSDKDoc && pFormFillEnv) |
| 218 m_pSDKDoc.reset(new CPDFSDK_Document(this, pFormFillEnv)); | 197 m_pSDKDoc.reset(new CPDFSDK_Document(this, pFormFillEnv)); |
| 219 return m_pSDKDoc.get(); | 198 return m_pSDKDoc.get(); |
| 220 } | 199 } |
| 221 | 200 |
| 222 void CPDFXFA_Document::SetChangeMark(CXFA_FFDoc* hDoc) { | |
| 223 if (hDoc == m_pXFADoc.get() && m_pSDKDoc) | |
| 224 m_pSDKDoc->SetChangeMark(); | |
| 225 } | |
| 226 | |
| 227 void CPDFXFA_Document::InvalidateRect(CXFA_FFPageView* pPageView, | |
| 228 const CFX_RectF& rt, | |
| 229 uint32_t dwFlags /* = 0 */) { | |
| 230 if (!m_pXFADoc || !m_pSDKDoc) | |
| 231 return; | |
| 232 | |
| 233 if (m_iDocType != DOCTYPE_DYNAMIC_XFA) | |
| 234 return; | |
| 235 | |
| 236 CPDFXFA_Page* pPage = GetPage(pPageView); | |
| 237 if (!pPage) | |
| 238 return; | |
| 239 | |
| 240 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 241 if (!pEnv) | |
| 242 return; | |
| 243 | |
| 244 CFX_FloatRect rcPage = CFX_FloatRect::FromCFXRectF(rt); | |
| 245 pEnv->FFI_Invalidate((FPDF_PAGE)pPage, rcPage.left, rcPage.bottom, | |
| 246 rcPage.right, rcPage.top); | |
| 247 } | |
| 248 | |
| 249 void CPDFXFA_Document::DisplayCaret(CXFA_FFWidget* hWidget, | |
| 250 FX_BOOL bVisible, | |
| 251 const CFX_RectF* pRtAnchor) { | |
| 252 if (!hWidget || !pRtAnchor || !m_pXFADoc || !m_pSDKDoc || !m_pXFADocView) | |
| 253 return; | |
| 254 | |
| 255 if (m_iDocType != DOCTYPE_DYNAMIC_XFA) | |
| 256 return; | |
| 257 | |
| 258 CXFA_FFWidgetHandler* pWidgetHandler = m_pXFADocView->GetWidgetHandler(); | |
| 259 if (!pWidgetHandler) | |
| 260 return; | |
| 261 | |
| 262 CXFA_FFPageView* pPageView = hWidget->GetPageView(); | |
| 263 if (!pPageView) | |
| 264 return; | |
| 265 | |
| 266 CPDFXFA_Page* pPage = GetPage(pPageView); | |
| 267 if (!pPage) | |
| 268 return; | |
| 269 | |
| 270 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 271 if (!pEnv) | |
| 272 return; | |
| 273 | |
| 274 CFX_FloatRect rcCaret = CFX_FloatRect::FromCFXRectF(*pRtAnchor); | |
| 275 pEnv->FFI_DisplayCaret((FPDF_PAGE)pPage, bVisible, rcCaret.left, rcCaret.top, | |
| 276 rcCaret.right, rcCaret.bottom); | |
| 277 } | |
| 278 | |
| 279 FX_BOOL CPDFXFA_Document::GetPopupPos(CXFA_FFWidget* hWidget, | |
| 280 FX_FLOAT fMinPopup, | |
| 281 FX_FLOAT fMaxPopup, | |
| 282 const CFX_RectF& rtAnchor, | |
| 283 CFX_RectF& rtPopup) { | |
| 284 if (!hWidget) | |
| 285 return FALSE; | |
| 286 | |
| 287 CXFA_FFPageView* pXFAPageView = hWidget->GetPageView(); | |
| 288 if (!pXFAPageView) | |
| 289 return FALSE; | |
| 290 | |
| 291 CPDFXFA_Page* pPage = GetPage(pXFAPageView); | |
| 292 if (!pPage) | |
| 293 return FALSE; | |
| 294 | |
| 295 CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc(); | |
| 296 int nRotate = pWidgetAcc->GetRotate(); | |
| 297 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 298 if (!pEnv) | |
| 299 return FALSE; | |
| 300 | |
| 301 FS_RECTF pageViewRect = {0.0f, 0.0f, 0.0f, 0.0f}; | |
| 302 pEnv->FFI_GetPageViewRect(pPage, pageViewRect); | |
| 303 | |
| 304 int t1; | |
| 305 int t2; | |
| 306 CFX_FloatRect rcAnchor = CFX_FloatRect::FromCFXRectF(rtAnchor); | |
| 307 switch (nRotate) { | |
| 308 case 90: { | |
| 309 t1 = (int)(pageViewRect.right - rcAnchor.right); | |
| 310 t2 = (int)(rcAnchor.left - pageViewRect.left); | |
| 311 if (rcAnchor.bottom < pageViewRect.bottom) | |
| 312 rtPopup.left += rcAnchor.bottom - pageViewRect.bottom; | |
| 313 break; | |
| 314 } | |
| 315 case 180: { | |
| 316 t2 = (int)(pageViewRect.top - rcAnchor.top); | |
| 317 t1 = (int)(rcAnchor.bottom - pageViewRect.bottom); | |
| 318 if (rcAnchor.left < pageViewRect.left) | |
| 319 rtPopup.left += rcAnchor.left - pageViewRect.left; | |
| 320 break; | |
| 321 } | |
| 322 case 270: { | |
| 323 t1 = (int)(rcAnchor.left - pageViewRect.left); | |
| 324 t2 = (int)(pageViewRect.right - rcAnchor.right); | |
| 325 if (rcAnchor.top > pageViewRect.top) | |
| 326 rtPopup.left -= rcAnchor.top - pageViewRect.top; | |
| 327 break; | |
| 328 } | |
| 329 case 0: | |
| 330 default: { | |
| 331 t1 = (int)(pageViewRect.top - rcAnchor.top); | |
| 332 t2 = (int)(rcAnchor.bottom - pageViewRect.bottom); | |
| 333 if (rcAnchor.right > pageViewRect.right) | |
| 334 rtPopup.left -= rcAnchor.right - pageViewRect.right; | |
| 335 break; | |
| 336 } | |
| 337 } | |
| 338 | |
| 339 int t; | |
| 340 uint32_t dwPos; | |
| 341 if (t1 <= 0 && t2 <= 0) | |
| 342 return FALSE; | |
| 343 if (t1 <= 0) { | |
| 344 t = t2; | |
| 345 dwPos = 1; | |
| 346 } else if (t2 <= 0) { | |
| 347 t = t1; | |
| 348 dwPos = 0; | |
| 349 } else if (t1 > t2) { | |
| 350 t = t1; | |
| 351 dwPos = 0; | |
| 352 } else { | |
| 353 t = t2; | |
| 354 dwPos = 1; | |
| 355 } | |
| 356 | |
| 357 FX_FLOAT fPopupHeight; | |
| 358 if (t < fMinPopup) | |
| 359 fPopupHeight = fMinPopup; | |
| 360 else if (t > fMaxPopup) | |
| 361 fPopupHeight = fMaxPopup; | |
| 362 else | |
| 363 fPopupHeight = static_cast<FX_FLOAT>(t); | |
| 364 | |
| 365 switch (nRotate) { | |
| 366 case 0: | |
| 367 case 180: { | |
| 368 if (dwPos == 0) { | |
| 369 rtPopup.top = rtAnchor.height; | |
| 370 rtPopup.height = fPopupHeight; | |
| 371 } else { | |
| 372 rtPopup.top = -fPopupHeight; | |
| 373 rtPopup.height = fPopupHeight; | |
| 374 } | |
| 375 break; | |
| 376 } | |
| 377 case 90: | |
| 378 case 270: { | |
| 379 if (dwPos == 0) { | |
| 380 rtPopup.top = rtAnchor.width; | |
| 381 rtPopup.height = fPopupHeight; | |
| 382 } else { | |
| 383 rtPopup.top = -fPopupHeight; | |
| 384 rtPopup.height = fPopupHeight; | |
| 385 } | |
| 386 break; | |
| 387 } | |
| 388 default: | |
| 389 break; | |
| 390 } | |
| 391 | |
| 392 return TRUE; | |
| 393 } | |
| 394 | |
| 395 FX_BOOL CPDFXFA_Document::PopupMenu(CXFA_FFWidget* hWidget, | |
| 396 CFX_PointF ptPopup) { | |
| 397 if (!hWidget) | |
| 398 return FALSE; | |
| 399 | |
| 400 CXFA_FFPageView* pXFAPageView = hWidget->GetPageView(); | |
| 401 if (!pXFAPageView) | |
| 402 return FALSE; | |
| 403 | |
| 404 CPDFXFA_Page* pPage = GetPage(pXFAPageView); | |
| 405 if (!pPage) | |
| 406 return FALSE; | |
| 407 | |
| 408 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 409 if (!pEnv) | |
| 410 return FALSE; | |
| 411 | |
| 412 int menuFlag = 0; | |
| 413 if (hWidget->CanUndo()) | |
| 414 menuFlag |= FXFA_MENU_UNDO; | |
| 415 if (hWidget->CanRedo()) | |
| 416 menuFlag |= FXFA_MENU_REDO; | |
| 417 if (hWidget->CanPaste()) | |
| 418 menuFlag |= FXFA_MENU_PASTE; | |
| 419 if (hWidget->CanCopy()) | |
| 420 menuFlag |= FXFA_MENU_COPY; | |
| 421 if (hWidget->CanCut()) | |
| 422 menuFlag |= FXFA_MENU_CUT; | |
| 423 if (hWidget->CanSelectAll()) | |
| 424 menuFlag |= FXFA_MENU_SELECTALL; | |
| 425 | |
| 426 return pEnv->FFI_PopupMenu(pPage, hWidget, menuFlag, ptPopup, nullptr); | |
| 427 } | |
| 428 | |
| 429 void CPDFXFA_Document::PageViewEvent(CXFA_FFPageView* pPageView, | |
| 430 uint32_t dwFlags) { | |
| 431 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 432 if (!pEnv) | |
| 433 return; | |
| 434 | |
| 435 if (m_nLoadStatus == FXFA_LOADSTATUS_LOADING || | |
| 436 m_nLoadStatus == FXFA_LOADSTATUS_CLOSING || | |
| 437 XFA_PAGEVIEWEVENT_StopLayout != dwFlags) | |
| 438 return; | |
| 439 | |
| 440 int nNewCount = GetPageCount(); | |
| 441 if (nNewCount == m_nPageCount) | |
| 442 return; | |
| 443 | |
| 444 CXFA_FFDocView* pXFADocView = GetXFADocView(); | |
| 445 if (!pXFADocView) | |
| 446 return; | |
| 447 | |
| 448 for (int iPageIter = 0; iPageIter < m_nPageCount; iPageIter++) { | |
| 449 CPDFXFA_Page* pPage = m_XFAPageList.GetAt(iPageIter); | |
| 450 if (!pPage) | |
| 451 continue; | |
| 452 | |
| 453 m_pSDKDoc->RemovePageView(pPage); | |
| 454 pPage->SetXFAPageView(pXFADocView->GetPageView(iPageIter)); | |
| 455 } | |
| 456 | |
| 457 int flag = (nNewCount < m_nPageCount) ? FXFA_PAGEVIEWEVENT_POSTREMOVED | |
| 458 : FXFA_PAGEVIEWEVENT_POSTADDED; | |
| 459 int count = FXSYS_abs(nNewCount - m_nPageCount); | |
| 460 m_nPageCount = nNewCount; | |
| 461 m_XFAPageList.SetSize(nNewCount); | |
| 462 pEnv->FFI_PageEvent(count, flag); | |
| 463 } | |
| 464 | |
| 465 void CPDFXFA_Document::WidgetPostAdd(CXFA_FFWidget* hWidget, | |
| 466 CXFA_WidgetAcc* pWidgetData) { | |
| 467 if (m_iDocType != DOCTYPE_DYNAMIC_XFA || !hWidget) | |
| 468 return; | |
| 469 | |
| 470 CXFA_FFPageView* pPageView = hWidget->GetPageView(); | |
| 471 if (!pPageView) | |
| 472 return; | |
| 473 | |
| 474 CPDFXFA_Page* pXFAPage = GetPage(pPageView); | |
| 475 if (!pXFAPage) | |
| 476 return; | |
| 477 | |
| 478 m_pSDKDoc->GetPageView(pXFAPage, true)->AddAnnot(hWidget); | |
| 479 } | |
| 480 | |
| 481 void CPDFXFA_Document::WidgetPreRemove(CXFA_FFWidget* hWidget, | |
| 482 CXFA_WidgetAcc* pWidgetData) { | |
| 483 if (m_iDocType != DOCTYPE_DYNAMIC_XFA || !hWidget) | |
| 484 return; | |
| 485 | |
| 486 CXFA_FFPageView* pPageView = hWidget->GetPageView(); | |
| 487 if (!pPageView) | |
| 488 return; | |
| 489 | |
| 490 CPDFXFA_Page* pXFAPage = GetPage(pPageView); | |
| 491 if (!pXFAPage) | |
| 492 return; | |
| 493 | |
| 494 CPDFSDK_PageView* pSdkPageView = m_pSDKDoc->GetPageView(pXFAPage, true); | |
| 495 if (CPDFSDK_Annot* pAnnot = pSdkPageView->GetAnnotByXFAWidget(hWidget)) | |
| 496 pSdkPageView->DeleteAnnot(pAnnot); | |
| 497 } | |
| 498 | |
| 499 int32_t CPDFXFA_Document::CountPages(CXFA_FFDoc* hDoc) { | |
| 500 if (hDoc == m_pXFADoc.get() && m_pSDKDoc) | |
| 501 return GetPageCount(); | |
| 502 return 0; | |
| 503 } | |
| 504 | |
| 505 int32_t CPDFXFA_Document::GetCurrentPage(CXFA_FFDoc* hDoc) { | |
| 506 if (hDoc != m_pXFADoc.get() || !m_pSDKDoc) | |
| 507 return -1; | |
| 508 if (m_iDocType != DOCTYPE_DYNAMIC_XFA) | |
| 509 return -1; | |
| 510 | |
| 511 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 512 if (!pEnv) | |
| 513 return -1; | |
| 514 | |
| 515 return pEnv->FFI_GetCurrentPageIndex(this); | |
| 516 } | |
| 517 | |
| 518 void CPDFXFA_Document::SetCurrentPage(CXFA_FFDoc* hDoc, int32_t iCurPage) { | |
| 519 if (hDoc != m_pXFADoc.get() || !m_pSDKDoc || | |
| 520 m_iDocType != DOCTYPE_DYNAMIC_XFA || iCurPage < 0 || | |
| 521 iCurPage >= m_pSDKDoc->GetPageCount()) { | |
| 522 return; | |
| 523 } | |
| 524 | |
| 525 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 526 if (!pEnv) | |
| 527 return; | |
| 528 pEnv->FFI_SetCurrentPage(this, iCurPage); | |
| 529 } | |
| 530 | |
| 531 FX_BOOL CPDFXFA_Document::IsCalculationsEnabled(CXFA_FFDoc* hDoc) { | |
| 532 if (hDoc != m_pXFADoc.get() || !m_pSDKDoc) | |
| 533 return FALSE; | |
| 534 if (m_pSDKDoc->GetInterForm()) | |
| 535 return m_pSDKDoc->GetInterForm()->IsXfaCalculateEnabled(); | |
| 536 return FALSE; | |
| 537 } | |
| 538 | |
| 539 void CPDFXFA_Document::SetCalculationsEnabled(CXFA_FFDoc* hDoc, | |
| 540 FX_BOOL bEnabled) { | |
| 541 if (hDoc != m_pXFADoc.get() || !m_pSDKDoc) | |
| 542 return; | |
| 543 if (m_pSDKDoc->GetInterForm()) | |
| 544 m_pSDKDoc->GetInterForm()->XfaEnableCalculate(bEnabled); | |
| 545 } | |
| 546 | |
| 547 void CPDFXFA_Document::GetTitle(CXFA_FFDoc* hDoc, CFX_WideString& wsTitle) { | |
| 548 if (hDoc != m_pXFADoc.get() || !m_pPDFDoc) | |
| 549 return; | |
| 550 | |
| 551 CPDF_Dictionary* pInfoDict = m_pPDFDoc->GetInfo(); | |
| 552 if (!pInfoDict) | |
| 553 return; | |
| 554 | |
| 555 CFX_ByteString csTitle = pInfoDict->GetStringBy("Title"); | |
| 556 wsTitle = wsTitle.FromLocal(csTitle.GetBuffer(csTitle.GetLength())); | |
| 557 csTitle.ReleaseBuffer(csTitle.GetLength()); | |
| 558 } | |
| 559 | |
| 560 void CPDFXFA_Document::SetTitle(CXFA_FFDoc* hDoc, | |
| 561 const CFX_WideString& wsTitle) { | |
| 562 if (hDoc != m_pXFADoc.get() || !m_pPDFDoc) | |
| 563 return; | |
| 564 | |
| 565 if (CPDF_Dictionary* pInfoDict = m_pPDFDoc->GetInfo()) | |
| 566 pInfoDict->SetAt("Title", new CPDF_String(wsTitle)); | |
| 567 } | |
| 568 | |
| 569 void CPDFXFA_Document::ExportData(CXFA_FFDoc* hDoc, | |
| 570 const CFX_WideString& wsFilePath, | |
| 571 FX_BOOL bXDP) { | |
| 572 if (hDoc != m_pXFADoc.get()) | |
| 573 return; | |
| 574 | |
| 575 if (m_iDocType != DOCTYPE_DYNAMIC_XFA && m_iDocType != DOCTYPE_STATIC_XFA) | |
| 576 return; | |
| 577 | |
| 578 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 579 if (!pEnv) | |
| 580 return; | |
| 581 | |
| 582 int fileType = bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML; | |
| 583 CFX_ByteString bs = wsFilePath.UTF16LE_Encode(); | |
| 584 if (wsFilePath.IsEmpty()) { | |
| 585 if (!pEnv->GetFormFillInfo() || !pEnv->GetFormFillInfo()->m_pJsPlatform) | |
| 586 return; | |
| 587 | |
| 588 CFX_WideString filepath = pEnv->JS_fieldBrowse(); | |
| 589 bs = filepath.UTF16LE_Encode(); | |
| 590 } | |
| 591 int len = bs.GetLength(); | |
| 592 FPDF_FILEHANDLER* pFileHandler = | |
| 593 pEnv->FFI_OpenFile(bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML, | |
| 594 (FPDF_WIDESTRING)bs.GetBuffer(len), "wb"); | |
| 595 bs.ReleaseBuffer(len); | |
| 596 if (!pFileHandler) | |
| 597 return; | |
| 598 | |
| 599 CFPDF_FileStream fileWrite(pFileHandler); | |
| 600 CFX_ByteString content; | |
| 601 if (fileType == FXFA_SAVEAS_XML) { | |
| 602 content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; | |
| 603 fileWrite.WriteBlock(content.c_str(), fileWrite.GetSize(), | |
| 604 content.GetLength()); | |
| 605 m_pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Data, &fileWrite, | |
| 606 nullptr); | |
| 607 } else if (fileType == FXFA_SAVEAS_XDP) { | |
| 608 if (!m_pPDFDoc) | |
| 609 return; | |
| 610 | |
| 611 CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot(); | |
| 612 if (!pRoot) | |
| 613 return; | |
| 614 | |
| 615 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); | |
| 616 if (!pAcroForm) | |
| 617 return; | |
| 618 | |
| 619 CPDF_Array* pArray = ToArray(pAcroForm->GetObjectBy("XFA")); | |
| 620 if (!pArray) | |
| 621 return; | |
| 622 | |
| 623 int size = pArray->GetCount(); | |
| 624 for (int i = 1; i < size; i += 2) { | |
| 625 CPDF_Object* pPDFObj = pArray->GetObjectAt(i); | |
| 626 CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1); | |
| 627 if (!pPrePDFObj->IsString()) | |
| 628 continue; | |
| 629 if (!pPDFObj->IsReference()) | |
| 630 continue; | |
| 631 | |
| 632 CPDF_Stream* pStream = ToStream(pPDFObj->GetDirect()); | |
| 633 if (!pStream) | |
| 634 continue; | |
| 635 if (pPrePDFObj->GetString() == "form") { | |
| 636 m_pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Form, &fileWrite, | |
| 637 nullptr); | |
| 638 continue; | |
| 639 } | |
| 640 if (pPrePDFObj->GetString() == "datasets") { | |
| 641 m_pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Datasets, &fileWrite, | |
| 642 nullptr); | |
| 643 continue; | |
| 644 } | |
| 645 if (i == size - 1) { | |
| 646 CFX_WideString wPath = CFX_WideString::FromUTF16LE( | |
| 647 reinterpret_cast<const unsigned short*>(bs.c_str()), | |
| 648 bs.GetLength() / sizeof(unsigned short)); | |
| 649 CFX_ByteString bPath = wPath.UTF8Encode(); | |
| 650 const char* szFormat = | |
| 651 "\n<pdf href=\"%s\" xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>"; | |
| 652 content.Format(szFormat, bPath.c_str()); | |
| 653 fileWrite.WriteBlock(content.c_str(), fileWrite.GetSize(), | |
| 654 content.GetLength()); | |
| 655 } | |
| 656 std::unique_ptr<CPDF_StreamAcc> pAcc(new CPDF_StreamAcc); | |
| 657 pAcc->LoadAllData(pStream); | |
| 658 fileWrite.WriteBlock(pAcc->GetData(), fileWrite.GetSize(), | |
| 659 pAcc->GetSize()); | |
| 660 } | |
| 661 } | |
| 662 if (!fileWrite.Flush()) { | |
| 663 // Ignoring flush error. | |
| 664 } | |
| 665 } | |
| 666 | |
| 667 void CPDFXFA_Document::GotoURL(CXFA_FFDoc* hDoc, | |
| 668 const CFX_WideString& bsURL, | |
| 669 FX_BOOL bAppend) { | |
| 670 if (hDoc != m_pXFADoc.get()) | |
| 671 return; | |
| 672 | |
| 673 if (m_iDocType != DOCTYPE_DYNAMIC_XFA) | |
| 674 return; | |
| 675 | |
| 676 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 677 if (!pEnv) | |
| 678 return; | |
| 679 | |
| 680 CFX_WideStringC str(bsURL.c_str()); | |
| 681 | |
| 682 pEnv->FFI_GotoURL(this, str, bAppend); | |
| 683 } | |
| 684 | |
| 685 FX_BOOL CPDFXFA_Document::IsValidationsEnabled(CXFA_FFDoc* hDoc) { | |
| 686 if (hDoc != m_pXFADoc.get() || !m_pSDKDoc) | |
| 687 return FALSE; | |
| 688 if (m_pSDKDoc->GetInterForm()) | |
| 689 return m_pSDKDoc->GetInterForm()->IsXfaValidationsEnabled(); | |
| 690 return TRUE; | |
| 691 } | |
| 692 | |
| 693 void CPDFXFA_Document::SetValidationsEnabled(CXFA_FFDoc* hDoc, | |
| 694 FX_BOOL bEnabled) { | |
| 695 if (hDoc != m_pXFADoc.get() || !m_pSDKDoc) | |
| 696 return; | |
| 697 if (m_pSDKDoc->GetInterForm()) | |
| 698 m_pSDKDoc->GetInterForm()->XfaSetValidationsEnabled(bEnabled); | |
| 699 } | |
| 700 | |
| 701 void CPDFXFA_Document::SetFocusWidget(CXFA_FFDoc* hDoc, | |
| 702 CXFA_FFWidget* hWidget) { | |
| 703 if (hDoc != m_pXFADoc.get()) | |
| 704 return; | |
| 705 | |
| 706 if (!hWidget) { | |
| 707 m_pSDKDoc->SetFocusAnnot(nullptr); | |
| 708 return; | |
| 709 } | |
| 710 | |
| 711 int pageViewCount = m_pSDKDoc->GetPageViewCount(); | |
| 712 for (int i = 0; i < pageViewCount; i++) { | |
| 713 CPDFSDK_PageView* pPageView = m_pSDKDoc->GetPageView(i); | |
| 714 if (!pPageView) | |
| 715 continue; | |
| 716 | |
| 717 CPDFSDK_Annot* pAnnot = pPageView->GetAnnotByXFAWidget(hWidget); | |
| 718 if (pAnnot) { | |
| 719 m_pSDKDoc->SetFocusAnnot(pAnnot); | |
| 720 break; | |
| 721 } | |
| 722 } | |
| 723 } | |
| 724 | |
| 725 void CPDFXFA_Document::Print(CXFA_FFDoc* hDoc, | |
| 726 int32_t nStartPage, | |
| 727 int32_t nEndPage, | |
| 728 uint32_t dwOptions) { | |
| 729 if (hDoc != m_pXFADoc.get()) | |
| 730 return; | |
| 731 | |
| 732 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 733 if (!pEnv || !pEnv->GetFormFillInfo() || | |
| 734 !pEnv->GetFormFillInfo()->m_pJsPlatform || | |
| 735 !pEnv->GetFormFillInfo()->m_pJsPlatform->Doc_print) { | |
| 736 return; | |
| 737 } | |
| 738 | |
| 739 pEnv->GetFormFillInfo()->m_pJsPlatform->Doc_print( | |
| 740 pEnv->GetFormFillInfo()->m_pJsPlatform, | |
| 741 dwOptions & XFA_PRINTOPT_ShowDialog, nStartPage, nEndPage, | |
| 742 dwOptions & XFA_PRINTOPT_CanCancel, dwOptions & XFA_PRINTOPT_ShrinkPage, | |
| 743 dwOptions & XFA_PRINTOPT_AsImage, dwOptions & XFA_PRINTOPT_ReverseOrder, | |
| 744 dwOptions & XFA_PRINTOPT_PrintAnnot); | |
| 745 } | |
| 746 | |
| 747 FX_ARGB CPDFXFA_Document::GetHighlightColor(CXFA_FFDoc* hDoc) { | |
| 748 if (hDoc != m_pXFADoc.get() || !m_pSDKDoc) | |
| 749 return 0; | |
| 750 | |
| 751 CPDFSDK_InterForm* pInterForm = m_pSDKDoc->GetInterForm(); | |
| 752 if (!pInterForm) | |
| 753 return 0; | |
| 754 | |
| 755 return ArgbEncode(pInterForm->GetHighlightAlpha(), | |
| 756 pInterForm->GetHighlightColor(FPDF_FORMFIELD_XFA)); | |
| 757 } | |
| 758 | |
| 759 FX_BOOL CPDFXFA_Document::NotifySubmit(FX_BOOL bPrevOrPost) { | |
| 760 if (bPrevOrPost) | |
| 761 return OnBeforeNotifySubmit(); | |
| 762 | |
| 763 OnAfterNotifySubmit(); | |
| 764 return TRUE; | |
| 765 } | |
| 766 | |
| 767 FX_BOOL CPDFXFA_Document::OnBeforeNotifySubmit() { | |
| 768 if (m_iDocType != DOCTYPE_DYNAMIC_XFA && m_iDocType != DOCTYPE_STATIC_XFA) | |
| 769 return TRUE; | |
| 770 | |
| 771 if (!m_pXFADocView) | |
| 772 return TRUE; | |
| 773 | |
| 774 CXFA_FFWidgetHandler* pWidgetHandler = m_pXFADocView->GetWidgetHandler(); | |
| 775 if (!pWidgetHandler) | |
| 776 return TRUE; | |
| 777 | |
| 778 std::unique_ptr<CXFA_WidgetAccIterator> pWidgetAccIterator( | |
| 779 m_pXFADocView->CreateWidgetAccIterator()); | |
| 780 if (pWidgetAccIterator) { | |
| 781 CXFA_EventParam Param; | |
| 782 Param.m_eType = XFA_EVENT_PreSubmit; | |
| 783 while (CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext()) | |
| 784 pWidgetHandler->ProcessEvent(pWidgetAcc, &Param); | |
| 785 } | |
| 786 | |
| 787 pWidgetAccIterator.reset(m_pXFADocView->CreateWidgetAccIterator()); | |
| 788 if (!pWidgetAccIterator) | |
| 789 return TRUE; | |
| 790 | |
| 791 CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext(); | |
| 792 pWidgetAcc = pWidgetAccIterator->MoveToNext(); | |
| 793 while (pWidgetAcc) { | |
| 794 int fRet = pWidgetAcc->ProcessValidate(-1); | |
| 795 if (fRet == XFA_EVENTERROR_Error) { | |
| 796 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 797 if (!pEnv) | |
| 798 return FALSE; | |
| 799 | |
| 800 CFX_WideString ws; | |
| 801 ws.FromLocal(IDS_XFA_Validate_Input); | |
| 802 CFX_ByteString bs = ws.UTF16LE_Encode(); | |
| 803 int len = bs.GetLength(); | |
| 804 pEnv->FFI_Alert((FPDF_WIDESTRING)bs.GetBuffer(len), (FPDF_WIDESTRING)L"", | |
| 805 0, 1); | |
| 806 bs.ReleaseBuffer(len); | |
| 807 return FALSE; | |
| 808 } | |
| 809 pWidgetAcc = pWidgetAccIterator->MoveToNext(); | |
| 810 } | |
| 811 m_pXFADocView->UpdateDocView(); | |
| 812 | |
| 813 return TRUE; | |
| 814 } | |
| 815 | |
| 816 void CPDFXFA_Document::OnAfterNotifySubmit() { | |
| 817 if (m_iDocType != DOCTYPE_DYNAMIC_XFA && m_iDocType != DOCTYPE_STATIC_XFA) | |
| 818 return; | |
| 819 | |
| 820 if (!m_pXFADocView) | |
| 821 return; | |
| 822 | |
| 823 CXFA_FFWidgetHandler* pWidgetHandler = m_pXFADocView->GetWidgetHandler(); | |
| 824 if (!pWidgetHandler) | |
| 825 return; | |
| 826 | |
| 827 std::unique_ptr<CXFA_WidgetAccIterator> pWidgetAccIterator( | |
| 828 m_pXFADocView->CreateWidgetAccIterator()); | |
| 829 if (!pWidgetAccIterator) | |
| 830 return; | |
| 831 | |
| 832 CXFA_EventParam Param; | |
| 833 Param.m_eType = XFA_EVENT_PostSubmit; | |
| 834 CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext(); | |
| 835 while (pWidgetAcc) { | |
| 836 pWidgetHandler->ProcessEvent(pWidgetAcc, &Param); | |
| 837 pWidgetAcc = pWidgetAccIterator->MoveToNext(); | |
| 838 } | |
| 839 m_pXFADocView->UpdateDocView(); | |
| 840 } | |
| 841 | |
| 842 FX_BOOL CPDFXFA_Document::SubmitData(CXFA_FFDoc* hDoc, CXFA_Submit submit) { | |
| 843 if (!NotifySubmit(TRUE) || !m_pXFADocView) | |
| 844 return FALSE; | |
| 845 | |
| 846 m_pXFADocView->UpdateDocView(); | |
| 847 FX_BOOL ret = SubmitDataInternal(hDoc, submit); | |
| 848 NotifySubmit(FALSE); | |
| 849 return ret; | |
| 850 } | |
| 851 | |
| 852 IFX_FileRead* CPDFXFA_Document::OpenLinkedFile(CXFA_FFDoc* hDoc, | |
| 853 const CFX_WideString& wsLink) { | |
| 854 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 855 if (!pEnv) | |
| 856 return FALSE; | |
| 857 | |
| 858 CFX_ByteString bs = wsLink.UTF16LE_Encode(); | |
| 859 int len = bs.GetLength(); | |
| 860 FPDF_FILEHANDLER* pFileHandler = | |
| 861 pEnv->FFI_OpenFile(0, (FPDF_WIDESTRING)bs.GetBuffer(len), "rb"); | |
| 862 bs.ReleaseBuffer(len); | |
| 863 | |
| 864 if (!pFileHandler) | |
| 865 return nullptr; | |
| 866 return new CFPDF_FileStream(pFileHandler); | |
| 867 } | |
| 868 | |
| 869 FX_BOOL CPDFXFA_Document::ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler, | |
| 870 int fileType, | |
| 871 FPDF_DWORD encodeType, | |
| 872 FPDF_DWORD flag) { | |
| 873 if (!m_pXFADocView) | |
| 874 return FALSE; | |
| 875 | |
| 876 CFX_ByteString content; | |
| 877 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 878 if (!pEnv) | |
| 879 return FALSE; | |
| 880 | |
| 881 CFPDF_FileStream fileStream(pFileHandler); | |
| 882 if (fileType == FXFA_SAVEAS_XML) { | |
| 883 const char kContent[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; | |
| 884 fileStream.WriteBlock(kContent, 0, strlen(kContent)); | |
| 885 m_pXFADoc->SavePackage(XFA_HASHCODE_Data, &fileStream, nullptr); | |
| 886 return TRUE; | |
| 887 } | |
| 888 | |
| 889 if (fileType != FXFA_SAVEAS_XDP) | |
| 890 return TRUE; | |
| 891 | |
| 892 if (!flag) { | |
| 893 flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS | | |
| 894 FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM; | |
| 895 } | |
| 896 if (!m_pPDFDoc) { | |
| 897 fileStream.Flush(); | |
| 898 return FALSE; | |
| 899 } | |
| 900 | |
| 901 CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot(); | |
| 902 if (!pRoot) { | |
| 903 fileStream.Flush(); | |
| 904 return FALSE; | |
| 905 } | |
| 906 | |
| 907 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); | |
| 908 if (!pAcroForm) { | |
| 909 fileStream.Flush(); | |
| 910 return FALSE; | |
| 911 } | |
| 912 | |
| 913 CPDF_Array* pArray = ToArray(pAcroForm->GetObjectBy("XFA")); | |
| 914 if (!pArray) { | |
| 915 fileStream.Flush(); | |
| 916 return FALSE; | |
| 917 } | |
| 918 | |
| 919 int size = pArray->GetCount(); | |
| 920 for (int i = 1; i < size; i += 2) { | |
| 921 CPDF_Object* pPDFObj = pArray->GetObjectAt(i); | |
| 922 CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1); | |
| 923 if (!pPrePDFObj->IsString()) | |
| 924 continue; | |
| 925 if (!pPDFObj->IsReference()) | |
| 926 continue; | |
| 927 | |
| 928 CPDF_Object* pDirectObj = pPDFObj->GetDirect(); | |
| 929 if (!pDirectObj->IsStream()) | |
| 930 continue; | |
| 931 if (pPrePDFObj->GetString() == "config" && !(flag & FXFA_CONFIG)) | |
| 932 continue; | |
| 933 if (pPrePDFObj->GetString() == "template" && !(flag & FXFA_TEMPLATE)) | |
| 934 continue; | |
| 935 if (pPrePDFObj->GetString() == "localeSet" && !(flag & FXFA_LOCALESET)) | |
| 936 continue; | |
| 937 if (pPrePDFObj->GetString() == "datasets" && !(flag & FXFA_DATASETS)) | |
| 938 continue; | |
| 939 if (pPrePDFObj->GetString() == "xmpmeta" && !(flag & FXFA_XMPMETA)) | |
| 940 continue; | |
| 941 if (pPrePDFObj->GetString() == "xfdf" && !(flag & FXFA_XFDF)) | |
| 942 continue; | |
| 943 if (pPrePDFObj->GetString() == "form" && !(flag & FXFA_FORM)) | |
| 944 continue; | |
| 945 if (pPrePDFObj->GetString() == "form") { | |
| 946 m_pXFADoc->SavePackage(XFA_HASHCODE_Form, &fileStream, nullptr); | |
| 947 } else if (pPrePDFObj->GetString() == "datasets") { | |
| 948 m_pXFADoc->SavePackage(XFA_HASHCODE_Datasets, &fileStream, nullptr); | |
| 949 } else { | |
| 950 // PDF,creator. | |
| 951 } | |
| 952 } | |
| 953 return TRUE; | |
| 954 } | |
| 955 | |
| 956 void CPDFXFA_Document::ClearChangeMark() { | 201 void CPDFXFA_Document::ClearChangeMark() { |
| 957 if (m_pSDKDoc) | 202 if (m_pSDKDoc) |
| 958 m_pSDKDoc->ClearChangeMark(); | 203 m_pSDKDoc->ClearChangeMark(); |
| 959 } | 204 } |
| 960 | |
| 961 void CPDFXFA_Document::ToXFAContentFlags(CFX_WideString csSrcContent, | |
| 962 FPDF_DWORD& flag) { | |
| 963 if (csSrcContent.Find(L" config ", 0) != -1) | |
| 964 flag |= FXFA_CONFIG; | |
| 965 if (csSrcContent.Find(L" template ", 0) != -1) | |
| 966 flag |= FXFA_TEMPLATE; | |
| 967 if (csSrcContent.Find(L" localeSet ", 0) != -1) | |
| 968 flag |= FXFA_LOCALESET; | |
| 969 if (csSrcContent.Find(L" datasets ", 0) != -1) | |
| 970 flag |= FXFA_DATASETS; | |
| 971 if (csSrcContent.Find(L" xmpmeta ", 0) != -1) | |
| 972 flag |= FXFA_XMPMETA; | |
| 973 if (csSrcContent.Find(L" xfdf ", 0) != -1) | |
| 974 flag |= FXFA_XFDF; | |
| 975 if (csSrcContent.Find(L" form ", 0) != -1) | |
| 976 flag |= FXFA_FORM; | |
| 977 if (flag == 0) { | |
| 978 flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS | | |
| 979 FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM; | |
| 980 } | |
| 981 } | |
| 982 | |
| 983 FX_BOOL CPDFXFA_Document::MailToInfo(CFX_WideString& csURL, | |
| 984 CFX_WideString& csToAddress, | |
| 985 CFX_WideString& csCCAddress, | |
| 986 CFX_WideString& csBCCAddress, | |
| 987 CFX_WideString& csSubject, | |
| 988 CFX_WideString& csMsg) { | |
| 989 CFX_WideString srcURL = csURL; | |
| 990 srcURL.TrimLeft(); | |
| 991 if (srcURL.Left(7).CompareNoCase(L"mailto:") != 0) | |
| 992 return FALSE; | |
| 993 | |
| 994 int pos = srcURL.Find(L'?', 0); | |
| 995 CFX_WideString tmp; | |
| 996 if (pos == -1) { | |
| 997 pos = srcURL.Find(L'@', 0); | |
| 998 if (pos == -1) | |
| 999 return FALSE; | |
| 1000 | |
| 1001 tmp = srcURL.Right(csURL.GetLength() - 7); | |
| 1002 } else { | |
| 1003 tmp = srcURL.Left(pos); | |
| 1004 tmp = tmp.Right(tmp.GetLength() - 7); | |
| 1005 } | |
| 1006 tmp.TrimLeft(); | |
| 1007 tmp.TrimRight(); | |
| 1008 | |
| 1009 csToAddress = tmp; | |
| 1010 | |
| 1011 srcURL = srcURL.Right(srcURL.GetLength() - (pos + 1)); | |
| 1012 while (!srcURL.IsEmpty()) { | |
| 1013 srcURL.TrimLeft(); | |
| 1014 srcURL.TrimRight(); | |
| 1015 pos = srcURL.Find(L'&', 0); | |
| 1016 | |
| 1017 tmp = (pos == -1) ? srcURL : srcURL.Left(pos); | |
| 1018 tmp.TrimLeft(); | |
| 1019 tmp.TrimRight(); | |
| 1020 if (tmp.GetLength() >= 3 && tmp.Left(3).CompareNoCase(L"cc=") == 0) { | |
| 1021 tmp = tmp.Right(tmp.GetLength() - 3); | |
| 1022 if (!csCCAddress.IsEmpty()) | |
| 1023 csCCAddress += L';'; | |
| 1024 csCCAddress += tmp; | |
| 1025 } else if (tmp.GetLength() >= 4 && | |
| 1026 tmp.Left(4).CompareNoCase(L"bcc=") == 0) { | |
| 1027 tmp = tmp.Right(tmp.GetLength() - 4); | |
| 1028 if (!csBCCAddress.IsEmpty()) | |
| 1029 csBCCAddress += L';'; | |
| 1030 csBCCAddress += tmp; | |
| 1031 } else if (tmp.GetLength() >= 8 && | |
| 1032 tmp.Left(8).CompareNoCase(L"subject=") == 0) { | |
| 1033 tmp = tmp.Right(tmp.GetLength() - 8); | |
| 1034 csSubject += tmp; | |
| 1035 } else if (tmp.GetLength() >= 5 && | |
| 1036 tmp.Left(5).CompareNoCase(L"body=") == 0) { | |
| 1037 tmp = tmp.Right(tmp.GetLength() - 5); | |
| 1038 csMsg += tmp; | |
| 1039 } | |
| 1040 srcURL = (pos == -1) ? L"" : srcURL.Right(csURL.GetLength() - (pos + 1)); | |
| 1041 } | |
| 1042 csToAddress.Replace(L",", L";"); | |
| 1043 csCCAddress.Replace(L",", L";"); | |
| 1044 csBCCAddress.Replace(L",", L";"); | |
| 1045 return TRUE; | |
| 1046 } | |
| 1047 | |
| 1048 FX_BOOL CPDFXFA_Document::SubmitDataInternal(CXFA_FFDoc* hDoc, | |
| 1049 CXFA_Submit submit) { | |
| 1050 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 1051 if (!pEnv) | |
| 1052 return FALSE; | |
| 1053 | |
| 1054 CFX_WideStringC csURLC; | |
| 1055 submit.GetSubmitTarget(csURLC); | |
| 1056 CFX_WideString csURL(csURLC); | |
| 1057 if (csURL.IsEmpty()) { | |
| 1058 CFX_WideString ws; | |
| 1059 ws.FromLocal("Submit cancelled."); | |
| 1060 CFX_ByteString bs = ws.UTF16LE_Encode(); | |
| 1061 int len = bs.GetLength(); | |
| 1062 pEnv->FFI_Alert((FPDF_WIDESTRING)bs.GetBuffer(len), (FPDF_WIDESTRING)L"", 0, | |
| 1063 4); | |
| 1064 bs.ReleaseBuffer(len); | |
| 1065 return FALSE; | |
| 1066 } | |
| 1067 | |
| 1068 FPDF_BOOL bRet = TRUE; | |
| 1069 FPDF_FILEHANDLER* pFileHandler = nullptr; | |
| 1070 int fileFlag = -1; | |
| 1071 switch (submit.GetSubmitFormat()) { | |
| 1072 case XFA_ATTRIBUTEENUM_Xdp: { | |
| 1073 CFX_WideStringC csContentC; | |
| 1074 submit.GetSubmitXDPContent(csContentC); | |
| 1075 CFX_WideString csContent; | |
| 1076 csContent = csContentC; | |
| 1077 csContent.TrimLeft(); | |
| 1078 csContent.TrimRight(); | |
| 1079 CFX_WideString space; | |
| 1080 space.FromLocal(" "); | |
| 1081 csContent = space + csContent + space; | |
| 1082 FPDF_DWORD flag = 0; | |
| 1083 if (submit.IsSubmitEmbedPDF()) | |
| 1084 flag |= FXFA_PDF; | |
| 1085 | |
| 1086 ToXFAContentFlags(csContent, flag); | |
| 1087 pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XDP, nullptr, "wb"); | |
| 1088 fileFlag = FXFA_SAVEAS_XDP; | |
| 1089 ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XDP, 0, flag); | |
| 1090 break; | |
| 1091 } | |
| 1092 case XFA_ATTRIBUTEENUM_Xml: | |
| 1093 pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XML, nullptr, "wb"); | |
| 1094 fileFlag = FXFA_SAVEAS_XML; | |
| 1095 ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0, FXFA_XFA_ALL); | |
| 1096 break; | |
| 1097 case XFA_ATTRIBUTEENUM_Pdf: | |
| 1098 break; | |
| 1099 case XFA_ATTRIBUTEENUM_Urlencoded: | |
| 1100 pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XML, nullptr, "wb"); | |
| 1101 fileFlag = FXFA_SAVEAS_XML; | |
| 1102 ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0, FXFA_XFA_ALL); | |
| 1103 break; | |
| 1104 default: | |
| 1105 return false; | |
| 1106 } | |
| 1107 if (!pFileHandler) | |
| 1108 return FALSE; | |
| 1109 if (csURL.Left(7).CompareNoCase(L"mailto:") == 0) { | |
| 1110 CFX_WideString csToAddress; | |
| 1111 CFX_WideString csCCAddress; | |
| 1112 CFX_WideString csBCCAddress; | |
| 1113 CFX_WideString csSubject; | |
| 1114 CFX_WideString csMsg; | |
| 1115 bRet = MailToInfo(csURL, csToAddress, csCCAddress, csBCCAddress, csSubject, | |
| 1116 csMsg); | |
| 1117 if (!bRet) | |
| 1118 return FALSE; | |
| 1119 | |
| 1120 CFX_ByteString bsTo = CFX_WideString(csToAddress).UTF16LE_Encode(); | |
| 1121 CFX_ByteString bsCC = CFX_WideString(csCCAddress).UTF16LE_Encode(); | |
| 1122 CFX_ByteString bsBcc = CFX_WideString(csBCCAddress).UTF16LE_Encode(); | |
| 1123 CFX_ByteString bsSubject = CFX_WideString(csSubject).UTF16LE_Encode(); | |
| 1124 CFX_ByteString bsMsg = CFX_WideString(csMsg).UTF16LE_Encode(); | |
| 1125 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength()); | |
| 1126 FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength()); | |
| 1127 FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength()); | |
| 1128 FPDF_WIDESTRING pSubject = | |
| 1129 (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength()); | |
| 1130 FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength()); | |
| 1131 pEnv->FFI_EmailTo(pFileHandler, pTo, pSubject, pCC, pBcc, pMsg); | |
| 1132 bsTo.ReleaseBuffer(); | |
| 1133 bsCC.ReleaseBuffer(); | |
| 1134 bsBcc.ReleaseBuffer(); | |
| 1135 bsSubject.ReleaseBuffer(); | |
| 1136 bsMsg.ReleaseBuffer(); | |
| 1137 } else { | |
| 1138 // HTTP or FTP | |
| 1139 CFX_WideString ws; | |
| 1140 CFX_ByteString bs = csURL.UTF16LE_Encode(); | |
| 1141 int len = bs.GetLength(); | |
| 1142 pEnv->FFI_UploadTo(pFileHandler, fileFlag, | |
| 1143 (FPDF_WIDESTRING)bs.GetBuffer(len)); | |
| 1144 bs.ReleaseBuffer(len); | |
| 1145 } | |
| 1146 return bRet; | |
| 1147 } | |
| 1148 | |
| 1149 FX_BOOL CPDFXFA_Document::SetGlobalProperty(CXFA_FFDoc* hDoc, | |
| 1150 const CFX_ByteStringC& szPropName, | |
| 1151 CFXJSE_Value* pValue) { | |
| 1152 if (hDoc != m_pXFADoc.get()) | |
| 1153 return FALSE; | |
| 1154 | |
| 1155 if (m_pSDKDoc && m_pSDKDoc->GetEnv()->GetJSRuntime()) | |
| 1156 return m_pSDKDoc->GetEnv()->GetJSRuntime()->SetValueByName(szPropName, | |
| 1157 pValue); | |
| 1158 return FALSE; | |
| 1159 } | |
| 1160 | |
| 1161 FX_BOOL CPDFXFA_Document::GetGlobalProperty(CXFA_FFDoc* hDoc, | |
| 1162 const CFX_ByteStringC& szPropName, | |
| 1163 CFXJSE_Value* pValue) { | |
| 1164 if (hDoc != m_pXFADoc.get()) | |
| 1165 return FALSE; | |
| 1166 if (!m_pSDKDoc || !m_pSDKDoc->GetEnv()->GetJSRuntime()) | |
| 1167 return FALSE; | |
| 1168 | |
| 1169 if (!m_pJSContext) { | |
| 1170 m_pSDKDoc->GetEnv()->GetJSRuntime()->SetReaderDocument(m_pSDKDoc.get()); | |
| 1171 m_pJSContext = m_pSDKDoc->GetEnv()->GetJSRuntime()->NewContext(); | |
| 1172 } | |
| 1173 | |
| 1174 return m_pSDKDoc->GetEnv()->GetJSRuntime()->GetValueByName(szPropName, | |
| 1175 pValue); | |
| 1176 } | |
| OLD | NEW |