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

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

Issue 1415803002: XFA: add CPDFDocumentToFPDFDocument() (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Address comments Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/fpdfview.cpp ('k') | fpdfsdk/src/fsdk_baseform.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "../../../public/fpdf_formfill.h" 7 #include "../../../public/fpdf_formfill.h"
8 #include "../../include/fsdk_define.h" 8 #include "../../include/fsdk_define.h"
9 #include "../../include/fpdfxfa/fpdfxfa_doc.h" 9 #include "../../include/fpdfxfa/fpdfxfa_doc.h"
10 #include "../../include/fsdk_mgr.h" 10 #include "../../include/fsdk_mgr.h"
(...skipping 17 matching lines...) Expand all
28 #define FXFA_PDF 0x10000000 28 #define FXFA_PDF 0x10000000
29 29
30 #ifndef _WIN32 30 #ifndef _WIN32
31 extern void SetLastError(int err); 31 extern void SetLastError(int err);
32 32
33 extern int GetLastError(); 33 extern int GetLastError();
34 #endif 34 #endif
35 35
36 CPDFXFA_Document::CPDFXFA_Document(CPDF_Document* pPDFDoc, 36 CPDFXFA_Document::CPDFXFA_Document(CPDF_Document* pPDFDoc,
37 CPDFXFA_App* pProvider) 37 CPDFXFA_App* pProvider)
38 : m_pPDFDoc(pPDFDoc), 38 : m_iDocType(DOCTYPE_PDF),
39 m_pPDFDoc(pPDFDoc),
40 m_pSDKDoc(nullptr),
41 m_pXFADoc(nullptr),
42 m_pXFADocView(nullptr),
39 m_pApp(pProvider), 43 m_pApp(pProvider),
40 m_pXFADoc(NULL), 44 m_pJSContext(nullptr) {
41 m_pXFADocView(NULL),
42 m_iDocType(DOCTYPE_PDF),
43 m_pJSContext(NULL),
44 m_pSDKDoc(NULL) {
45 m_XFAPageList.RemoveAll();
46 } 45 }
47 46
48 CPDFXFA_Document::~CPDFXFA_Document() { 47 CPDFXFA_Document::~CPDFXFA_Document() {
49 if (m_pPDFDoc) { 48 if (m_pPDFDoc) {
50 CPDF_Parser* pParser = (CPDF_Parser*)m_pPDFDoc->GetParser(); 49 CPDF_Parser* pParser = (CPDF_Parser*)m_pPDFDoc->GetParser();
51 if (pParser == NULL) { 50 if (pParser == NULL) {
52 delete m_pPDFDoc; 51 delete m_pPDFDoc;
53 } else { 52 } else {
54 delete pParser; 53 delete pParser;
55 } 54 }
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 484
486 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); 485 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
487 if (pEnv == NULL) 486 if (pEnv == NULL)
488 return FALSE; 487 return FALSE;
489 488
490 return pEnv->FFI_PopupMenu(pPage, hWidget, menuFlag, ptPopup, NULL); 489 return pEnv->FFI_PopupMenu(pPage, hWidget, menuFlag, ptPopup, NULL);
491 } 490 }
492 491
493 void CPDFXFA_Document::PageViewEvent(IXFA_PageView* pPageView, 492 void CPDFXFA_Document::PageViewEvent(IXFA_PageView* pPageView,
494 FX_DWORD dwFlags) { 493 FX_DWORD dwFlags) {
495 if (m_iDocType != DOCTYPE_DYNIMIC_XFA)
496 return;
497
498 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
499 if (pEnv == NULL)
500 return;
501
502 CPDFXFA_Page* pPage = GetPage(pPageView);
503 if (pPage == NULL)
504 return;
505
506 if (dwFlags == FXFA_PAGEVIEWEVENT_POSTADDED) {
507 // pEnv->FFI_PageEvent(pPage, FXFA_PAGEVIEWEVENT_POSTADDED);
508 } else if (dwFlags == FXFA_PAGEVIEWEVENT_POSTREMOVED) {
509 // pEnv->FFI_PageEvent(pPage, FXFA_PAGEVIEWEVENT_POSTREMOVED);
510 // RemovePage(pPage);
511 // delete pPage;
512 }
513 } 494 }
514 495
515 void CPDFXFA_Document::WidgetEvent(IXFA_Widget* hWidget, 496 void CPDFXFA_Document::WidgetEvent(IXFA_Widget* hWidget,
516 CXFA_WidgetAcc* pWidgetData, 497 CXFA_WidgetAcc* pWidgetData,
517 FX_DWORD dwEvent, 498 FX_DWORD dwEvent,
518 void* pParam, 499 void* pParam,
519 void* pAdditional) { 500 void* pAdditional) {
520 if (m_iDocType != DOCTYPE_DYNIMIC_XFA || NULL == hWidget) 501 if (m_iDocType != DOCTYPE_DYNIMIC_XFA || !hWidget)
521 return; 502 return;
522 503
523 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); 504 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
524 if (pEnv == NULL) 505 if (!pEnv)
525 return;
526
527 if (NULL == hWidget)
528 return; 506 return;
529 507
530 IXFA_PageView* pPageView = 508 IXFA_PageView* pPageView =
531 m_pXFADocView->GetWidgetHandler()->GetPageView(hWidget); 509 m_pXFADocView->GetWidgetHandler()->GetPageView(hWidget);
532
533 if (pPageView == NULL) 510 if (pPageView == NULL)
534 return; 511 return;
512
535 CPDFXFA_Page* pXFAPage = GetPage(pPageView); 513 CPDFXFA_Page* pXFAPage = GetPage(pPageView);
536 if (pXFAPage == NULL) 514 if (pXFAPage == NULL)
537 return; 515 return;
538 516
539 CPDFSDK_PageView* pSdkPageView = m_pSDKDoc->GetPageView(pXFAPage); 517 CPDFSDK_PageView* pSdkPageView = m_pSDKDoc->GetPageView(pXFAPage);
540
541 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
542
543 if (dwEvent == XFA_WIDGETEVENT_PostAdded) { 518 if (dwEvent == XFA_WIDGETEVENT_PostAdded) {
544 // CPDFSDK_Annot* pAnnot =
545 // pAnnotHandlerMgr->NewAnnot(hWidget,
546 // pSdkPageView);
547 // pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
548
549 // pEnv->FFI_WidgetEvent(hWidget, XFA_WIDGETEVENT_PostAdded);
550 // IXFA_PageView* pOldPageView = (IXFA_PageView*)pAdditional;
551 // if (pOldPageView)
552 // {
553 // CPDFXFA_Page* pDestPage =
554 // m_pSDKDoc->GetPageView((IXFA_PageView*)pOldPageView);
555 // ASSERT(pDestPage);
556 // CPDFSDK_Annot* pAnnot =
557 // pDestPage->GetAnnotByXFAWidget(hWidget);
558 // if (pAnnot)
559 // {
560 // if (m_pSDKDoc->GetFocusAnnot() == pAnnot)
561 // {
562 // m_pSDKDoc->SetFocusAnnot(NULL);
563 // }
564 // pDestPage->DeleteAnnot(pAnnot);
565 // }
566 // }
567 pSdkPageView->AddAnnot(hWidget); 519 pSdkPageView->AddAnnot(hWidget);
568 520
569 } else if (dwEvent == XFA_WIDGETEVENT_PreRemoved) { 521 } else if (dwEvent == XFA_WIDGETEVENT_PreRemoved) {
570 CPDFSDK_Annot* pAnnot = pSdkPageView->GetAnnotByXFAWidget(hWidget); 522 CPDFSDK_Annot* pAnnot = pSdkPageView->GetAnnotByXFAWidget(hWidget);
571 if (pAnnot) { 523 if (pAnnot) {
572 pSdkPageView->DeleteAnnot(pAnnot); 524 pSdkPageView->DeleteAnnot(pAnnot);
573 // pEnv->FFI_WidgetEvent(hWidget, XFA_WIDGETEVENT_PreRemoved);
574 } 525 }
575 } 526 }
576 } 527 }
577 528
578 int32_t CPDFXFA_Document::CountPages(IXFA_Doc* hDoc) { 529 int32_t CPDFXFA_Document::CountPages(IXFA_Doc* hDoc) {
579 if (hDoc == m_pXFADoc && m_pSDKDoc) { 530 if (hDoc == m_pXFADoc && m_pSDKDoc) {
580 return GetPageCount(); 531 return GetPageCount();
581 } 532 }
582 return 0; 533 return 0;
583 } 534 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 CFPDF_FileStream fileWrite(pFileHandler); 630 CFPDF_FileStream fileWrite(pFileHandler);
680 631
681 IXFA_DocHandler* pXFADocHander = m_pApp->GetXFAApp()->GetDocHandler(); 632 IXFA_DocHandler* pXFADocHander = m_pApp->GetXFAApp()->GetDocHandler();
682 CFX_ByteString content; 633 CFX_ByteString content;
683 if (fileType == FXFA_SAVEAS_XML) { 634 if (fileType == FXFA_SAVEAS_XML) {
684 content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; 635 content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
685 fileWrite.WriteBlock((const FX_CHAR*)content, fileWrite.GetSize(), 636 fileWrite.WriteBlock((const FX_CHAR*)content, fileWrite.GetSize(),
686 content.GetLength()); 637 content.GetLength());
687 CFX_WideStringC data(L"data"); 638 CFX_WideStringC data(L"data");
688 if (pXFADocHander->SavePackage(m_pXFADocView->GetDoc(), data, &fileWrite)) { 639 if (pXFADocHander->SavePackage(m_pXFADocView->GetDoc(), data, &fileWrite)) {
689 NULL; 640 // TODO: Maybe report error.
690 } 641 }
691 } 642 } else if (fileType == FXFA_SAVEAS_XDP) {
692 /*else if (fileType == FXFA_FILE_STATIC_XDP)
693 {
694 content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
695 fileWrite.WriteBlock((const FX_CHAR*)content, fileWrite.GetSize(),
696 content.GetLength());
697 CFX_WideStringC data(L"data");
698 if( pXFADocHander->SavePackage(m_pXFADocView->GetDoc(), data,
699 &fileWrite))
700 {
701 NULL;
702 }
703 CFX_WideString wPath = pEnv->FFI_GetFilePath(pFileHandler);
704 // » » CFX_WideString wPath;
705 // » » wPath.FromUTF16LE(filePath);
706 CFX_ByteString bPath = wPath.UTF8Encode();
707 CFX_ByteString szFormat = "\n<pdf href=\"%s\"
708 xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>";
709 content.Format(szFormat,(char*)(const FX_CHAR*)bPath);
710 fileWrite.WriteBlock((const FX_CHAR*)content,fileWrite.GetSize(),
711 content.GetLength());
712 }
713 */
714 else if (fileType == FXFA_SAVEAS_XDP) {
715 if (m_pPDFDoc == NULL) 643 if (m_pPDFDoc == NULL)
716 return; 644 return;
717 CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot(); 645 CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot();
718 if (pRoot == NULL) 646 if (pRoot == NULL)
719 return; 647 return;
720 CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm"); 648 CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm");
721 if (NULL == pAcroForm) 649 if (NULL == pAcroForm)
722 return; 650 return;
723 CPDF_Object* pXFA = pAcroForm->GetElement("XFA"); 651 CPDF_Object* pXFA = pAcroForm->GetElement("XFA");
724 if (pXFA == NULL) 652 if (pXFA == NULL)
725 return; 653 return;
726 if (pXFA->GetType() != PDFOBJ_ARRAY) 654 if (pXFA->GetType() != PDFOBJ_ARRAY)
727 return; 655 return;
728 CPDF_Array* pArray = pXFA->GetArray(); 656 CPDF_Array* pArray = pXFA->GetArray();
729 if (NULL == pArray) 657 if (NULL == pArray)
730 return; 658 return;
731 int size = pArray->GetCount(); 659 int size = pArray->GetCount();
732 int iFormIndex = -1;
733 int iDataSetsIndex = -1;
734 for (int i = 1; i < size; i += 2) { 660 for (int i = 1; i < size; i += 2) {
735 CPDF_Object* pPDFObj = pArray->GetElement(i); 661 CPDF_Object* pPDFObj = pArray->GetElement(i);
736 CPDF_Object* pPrePDFObj = pArray->GetElement(i - 1); 662 CPDF_Object* pPrePDFObj = pArray->GetElement(i - 1);
737 if (pPrePDFObj->GetType() != PDFOBJ_STRING) 663 if (pPrePDFObj->GetType() != PDFOBJ_STRING)
738 continue; 664 continue;
739 if (pPDFObj->GetType() != PDFOBJ_REFERENCE) 665 if (pPDFObj->GetType() != PDFOBJ_REFERENCE)
740 continue; 666 continue;
741 CPDF_Object* pDirectObj = pPDFObj->GetDirect(); 667 CPDF_Object* pDirectObj = pPDFObj->GetDirect();
742 if (pDirectObj->GetType() != PDFOBJ_STREAM) 668 if (pDirectObj->GetType() != PDFOBJ_STREAM)
743 continue; 669 continue;
744 if (pPrePDFObj->GetString() == "form") { 670 if (pPrePDFObj->GetString() == "form") {
745 CFX_WideStringC form(L"form"); 671 CFX_WideStringC form(L"form");
746 pXFADocHander->SavePackage(m_pXFADocView->GetDoc(), form, &fileWrite); 672 pXFADocHander->SavePackage(m_pXFADocView->GetDoc(), form, &fileWrite);
747 } else if (pPrePDFObj->GetString() == "datasets") { 673 } else if (pPrePDFObj->GetString() == "datasets") {
748 CFX_WideStringC datasets(L"datasets"); 674 CFX_WideStringC datasets(L"datasets");
749 pXFADocHander->SavePackage(m_pXFADocView->GetDoc(), datasets, 675 pXFADocHander->SavePackage(m_pXFADocView->GetDoc(), datasets,
750 &fileWrite); 676 &fileWrite);
751 } else { 677 } else {
752 if (i == size - 1) { 678 if (i == size - 1) {
753 // CFX_WideString wPath = pEnv->FFI_GetFilePath(pFileHandler);
754 CFX_WideString wPath = CFX_WideString::FromUTF16LE( 679 CFX_WideString wPath = CFX_WideString::FromUTF16LE(
755 (unsigned short*)(const FX_CHAR*)bs, 680 (unsigned short*)(const FX_CHAR*)bs,
756 bs.GetLength() / sizeof(unsigned short)); 681 bs.GetLength() / sizeof(unsigned short));
757 CFX_ByteString bPath = wPath.UTF8Encode(); 682 CFX_ByteString bPath = wPath.UTF8Encode();
758 CFX_ByteString szFormat = 683 CFX_ByteString szFormat =
759 "\n<pdf href=\"%s\" xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>"; 684 "\n<pdf href=\"%s\" xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>";
760 content.Format(szFormat, (char*)(const FX_CHAR*)bPath); 685 content.Format(szFormat, (char*)(const FX_CHAR*)bPath);
761 fileWrite.WriteBlock((const FX_CHAR*)content, fileWrite.GetSize(), 686 fileWrite.WriteBlock((const FX_CHAR*)content, fileWrite.GetSize(),
762 content.GetLength()); 687 content.GetLength());
763 } 688 }
764 689
765 CPDF_Stream* pStream = (CPDF_Stream*)pDirectObj; 690 CPDF_Stream* pStream = (CPDF_Stream*)pDirectObj;
766 CPDF_StreamAcc* pAcc = new CPDF_StreamAcc; 691 CPDF_StreamAcc* pAcc = new CPDF_StreamAcc;
767 pAcc->LoadAllData(pStream); 692 pAcc->LoadAllData(pStream);
768 fileWrite.WriteBlock(pAcc->GetData(), fileWrite.GetSize(), 693 fileWrite.WriteBlock(pAcc->GetData(), fileWrite.GetSize(),
769 pAcc->GetSize()); 694 pAcc->GetSize());
770 delete pAcc; 695 delete pAcc;
771 } 696 }
772 } 697 }
773 } 698 }
774 FX_BOOL bError = fileWrite.Flush(); 699 if (!fileWrite.Flush()) {
700 // TODO: Report error.
701 }
775 } 702 }
776 void CPDFXFA_Document::ImportData(IXFA_Doc* hDoc, 703 void CPDFXFA_Document::ImportData(IXFA_Doc* hDoc,
777 const CFX_WideStringC& wsFilePath) { 704 const CFX_WideStringC& wsFilePath) {
778 // TODO... 705 // TODO...
779 } 706 }
780 707
781 void CPDFXFA_Document::GotoURL(IXFA_Doc* hDoc, 708 void CPDFXFA_Document::GotoURL(IXFA_Doc* hDoc,
782 const CFX_WideStringC& bsURL, 709 const CFX_WideStringC& bsURL,
783 FX_BOOL bAppend) { 710 FX_BOOL bAppend) {
784 if (hDoc != m_pXFADoc) 711 if (hDoc != m_pXFADoc)
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 if (pXFA->GetType() != PDFOBJ_ARRAY) { 971 if (pXFA->GetType() != PDFOBJ_ARRAY) {
1045 fileStream.Flush(); 972 fileStream.Flush();
1046 return FALSE; 973 return FALSE;
1047 } 974 }
1048 CPDF_Array* pArray = pXFA->GetArray(); 975 CPDF_Array* pArray = pXFA->GetArray();
1049 if (NULL == pArray) { 976 if (NULL == pArray) {
1050 fileStream.Flush(); 977 fileStream.Flush();
1051 return FALSE; 978 return FALSE;
1052 } 979 }
1053 int size = pArray->GetCount(); 980 int size = pArray->GetCount();
1054 int iFormIndex = -1;
1055 int iDataSetsIndex = -1;
1056 for (int i = 1; i < size; i += 2) { 981 for (int i = 1; i < size; i += 2) {
1057 CPDF_Object* pPDFObj = pArray->GetElement(i); 982 CPDF_Object* pPDFObj = pArray->GetElement(i);
1058 CPDF_Object* pPrePDFObj = pArray->GetElement(i - 1); 983 CPDF_Object* pPrePDFObj = pArray->GetElement(i - 1);
1059 if (pPrePDFObj->GetType() != PDFOBJ_STRING) 984 if (pPrePDFObj->GetType() != PDFOBJ_STRING)
1060 continue; 985 continue;
1061 if (pPDFObj->GetType() != PDFOBJ_REFERENCE) 986 if (pPDFObj->GetType() != PDFOBJ_REFERENCE)
1062 continue; 987 continue;
1063 CPDF_Object* pDirectObj = pPDFObj->GetDirect(); 988 CPDF_Object* pDirectObj = pPDFObj->GetDirect();
1064 if (pDirectObj->GetType() != PDFOBJ_STREAM) 989 if (pDirectObj->GetType() != PDFOBJ_STREAM)
1065 continue; 990 continue;
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 } 1267 }
1343 1268
1344 return _GetHValueByName(szPropName, hValue, 1269 return _GetHValueByName(szPropName, hValue,
1345 m_pSDKDoc->GetEnv()->GetJSRuntime()); 1270 m_pSDKDoc->GetEnv()->GetJSRuntime());
1346 } 1271 }
1347 FX_BOOL CPDFXFA_Document::_GetHValueByName(const CFX_ByteStringC& utf8Name, 1272 FX_BOOL CPDFXFA_Document::_GetHValueByName(const CFX_ByteStringC& utf8Name,
1348 FXJSE_HVALUE hValue, 1273 FXJSE_HVALUE hValue,
1349 IJS_Runtime* runTime) { 1274 IJS_Runtime* runTime) {
1350 return runTime->GetHValueByName(utf8Name, hValue); 1275 return runTime->GetHValueByName(utf8Name, hValue);
1351 } 1276 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/fpdfview.cpp ('k') | fpdfsdk/src/fsdk_baseform.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698