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