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

Side by Side Diff: core/src/fpdfdoc/doc_form.cpp

Issue 1528763003: Merge to XFA: Get rid of most instance of 'foo == NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years 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
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 "core/include/fpdfdoc/fpdf_doc.h" 7 #include "core/include/fpdfdoc/fpdf_doc.h"
8 #include "doc_utils.h" 8 #include "doc_utils.h"
9 9
10 const int nMaxRecursion = 32; 10 const int nMaxRecursion = 32;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 CFieldTree::CFieldTree() { 88 CFieldTree::CFieldTree() {
89 m_Root.parent = NULL; 89 m_Root.parent = NULL;
90 m_Root.field_ptr = NULL; 90 m_Root.field_ptr = NULL;
91 } 91 }
92 CFieldTree::~CFieldTree() { 92 CFieldTree::~CFieldTree() {
93 RemoveAll(); 93 RemoveAll();
94 } 94 }
95 CFieldTree::_Node* CFieldTree::AddChild(_Node* pParent, 95 CFieldTree::_Node* CFieldTree::AddChild(_Node* pParent,
96 const CFX_WideString& short_name, 96 const CFX_WideString& short_name,
97 CPDF_FormField* field_ptr) { 97 CPDF_FormField* field_ptr) {
98 if (pParent == NULL) { 98 if (!pParent) {
99 return NULL; 99 return NULL;
100 } 100 }
101 _Node* pNode = new _Node; 101 _Node* pNode = new _Node;
102 pNode->parent = pParent; 102 pNode->parent = pParent;
103 pNode->short_name = short_name; 103 pNode->short_name = short_name;
104 pNode->field_ptr = field_ptr; 104 pNode->field_ptr = field_ptr;
105 pParent->children.Add(pNode); 105 pParent->children.Add(pNode);
106 return pNode; 106 return pNode;
107 } 107 }
108 void CFieldTree::RemoveNode(_Node* pNode, int nLevel) { 108 void CFieldTree::RemoveNode(_Node* pNode, int nLevel) {
109 if (!pNode) { 109 if (!pNode) {
110 return; 110 return;
111 } 111 }
112 if (nLevel <= nMaxRecursion) { 112 if (nLevel <= nMaxRecursion) {
113 for (int i = 0; i < pNode->children.GetSize(); i++) { 113 for (int i = 0; i < pNode->children.GetSize(); i++) {
114 RemoveNode(pNode->children[i], nLevel + 1); 114 RemoveNode(pNode->children[i], nLevel + 1);
115 } 115 }
116 } 116 }
117 delete pNode; 117 delete pNode;
118 } 118 }
119 CFieldTree::_Node* CFieldTree::_Lookup(_Node* pParent, 119 CFieldTree::_Node* CFieldTree::_Lookup(_Node* pParent,
120 const CFX_WideString& short_name) { 120 const CFX_WideString& short_name) {
121 if (pParent == NULL) { 121 if (!pParent) {
122 return NULL; 122 return NULL;
123 } 123 }
124 for (int i = 0; i < pParent->children.GetSize(); i++) { 124 for (int i = 0; i < pParent->children.GetSize(); i++) {
125 _Node* pNode = pParent->children[i]; 125 _Node* pNode = pParent->children[i];
126 if (pNode->short_name.GetLength() == short_name.GetLength() && 126 if (pNode->short_name.GetLength() == short_name.GetLength() &&
127 FXSYS_memcmp(pNode->short_name.c_str(), short_name.c_str(), 127 FXSYS_memcmp(pNode->short_name.c_str(), short_name.c_str(),
128 short_name.GetLength() * sizeof(FX_WCHAR)) == 0) { 128 short_name.GetLength() * sizeof(FX_WCHAR)) == 0) {
129 return pNode; 129 return pNode;
130 } 130 }
131 } 131 }
(...skipping 11 matching lines...) Expand all
143 } 143 }
144 CFieldNameExtractor name_extractor(full_name); 144 CFieldNameExtractor name_extractor(full_name);
145 const FX_WCHAR* pName; 145 const FX_WCHAR* pName;
146 FX_STRSIZE nLength; 146 FX_STRSIZE nLength;
147 name_extractor.GetNext(pName, nLength); 147 name_extractor.GetNext(pName, nLength);
148 _Node *pNode = &m_Root, *pLast = NULL; 148 _Node *pNode = &m_Root, *pLast = NULL;
149 while (nLength > 0) { 149 while (nLength > 0) {
150 pLast = pNode; 150 pLast = pNode;
151 CFX_WideString name = CFX_WideString(pName, nLength); 151 CFX_WideString name = CFX_WideString(pName, nLength);
152 pNode = _Lookup(pLast, name); 152 pNode = _Lookup(pLast, name);
153 if (pNode == NULL) { 153 if (!pNode) {
154 pNode = AddChild(pLast, name, NULL); 154 pNode = AddChild(pLast, name, NULL);
155 } 155 }
156 name_extractor.GetNext(pName, nLength); 156 name_extractor.GetNext(pName, nLength);
157 } 157 }
158 if (pNode != &m_Root) { 158 if (pNode != &m_Root) {
159 pNode->field_ptr = field_ptr; 159 pNode->field_ptr = field_ptr;
160 } 160 }
161 } 161 }
162 CPDF_FormField* CFieldTree::GetField(const CFX_WideString& full_name) { 162 CPDF_FormField* CFieldTree::GetField(const CFX_WideString& full_name) {
163 if (full_name == L"") { 163 if (full_name == L"") {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 while (m < iMinLen && m < iCount) { 290 while (m < iMinLen && m < iCount) {
291 csTmp += csStr[m++]; 291 csTmp += csStr[m++];
292 } 292 }
293 while (m < iMinLen) { 293 while (m < iMinLen) {
294 csTmp += '0' + m % 10; 294 csTmp += '0' + m % 10;
295 m++; 295 m++;
296 } 296 }
297 } else { 297 } else {
298 m = iCount; 298 m = iCount;
299 } 299 }
300 if (pResDict == NULL) { 300 if (!pResDict) {
301 return csTmp; 301 return csTmp;
302 } 302 }
303 CPDF_Dictionary* pDict = pResDict->GetDict(csType); 303 CPDF_Dictionary* pDict = pResDict->GetDict(csType);
304 if (pDict == NULL) { 304 if (!pDict) {
305 return csTmp; 305 return csTmp;
306 } 306 }
307 int num = 0; 307 int num = 0;
308 CFX_ByteString bsNum; 308 CFX_ByteString bsNum;
309 while (TRUE) { 309 while (TRUE) {
310 if (!pDict->KeyExist(csTmp + bsNum)) { 310 if (!pDict->KeyExist(csTmp + bsNum)) {
311 return csTmp + bsNum; 311 return csTmp + bsNum;
312 } 312 }
313 if (m < iCount) { 313 if (m < iCount) {
314 csTmp += csStr[m++]; 314 csTmp += csStr[m++];
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 for (int i = csSub.GetLength() - 1; i > -1; i--) { 544 for (int i = csSub.GetLength() - 1; i > -1; i--) {
545 if (csSub[i] == L' ' || csSub[i] == L'.') { 545 if (csSub[i] == L' ' || csSub[i] == L'.') {
546 csSub.SetAt(i, L'\0'); 546 csSub.SetAt(i, L'\0');
547 } else { 547 } else {
548 break; 548 break;
549 } 549 }
550 } 550 }
551 FX_DWORD dwCount = m_pFieldTree->m_Root.CountFields(); 551 FX_DWORD dwCount = m_pFieldTree->m_Root.CountFields();
552 for (FX_DWORD m = 0; m < dwCount; m++) { 552 for (FX_DWORD m = 0; m < dwCount; m++) {
553 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(m); 553 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(m);
554 if (pField == NULL) { 554 if (!pField) {
555 continue; 555 continue;
556 } 556 }
557 if (pField == pExcludedField) { 557 if (pField == pExcludedField) {
558 if (pExcludedControl) { 558 if (pExcludedControl) {
559 if (pField->CountControls() < 2) { 559 if (pField->CountControls() < 2) {
560 continue; 560 continue;
561 } 561 }
562 } else { 562 } else {
563 continue; 563 continue;
564 } 564 }
(...skipping 23 matching lines...) Expand all
588 } 588 }
589 csNewFieldName = csSub; 589 csNewFieldName = csSub;
590 return TRUE; 590 return TRUE;
591 } 591 }
592 FX_BOOL CPDF_InterForm::ValidateFieldName(CFX_WideString& csNewFieldName, 592 FX_BOOL CPDF_InterForm::ValidateFieldName(CFX_WideString& csNewFieldName,
593 int iType) { 593 int iType) {
594 return ValidateFieldName(csNewFieldName, iType, NULL, NULL); 594 return ValidateFieldName(csNewFieldName, iType, NULL, NULL);
595 } 595 }
596 FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormField* pField, 596 FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormField* pField,
597 CFX_WideString& csNewFieldName) { 597 CFX_WideString& csNewFieldName) {
598 if (pField == NULL || csNewFieldName.IsEmpty()) { 598 return pField && !csNewFieldName.IsEmpty() &&
599 return FALSE; 599 ValidateFieldName(csNewFieldName,
600 } 600 ((CPDF_FormField*)pField)->GetFieldType(), pField,
601 return ValidateFieldName( 601 NULL);
602 csNewFieldName, ((CPDF_FormField*)pField)->GetFieldType(), pField, NULL);
603 } 602 }
604 FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormControl* pControl, 603 FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormControl* pControl,
605 CFX_WideString& csNewFieldName) { 604 CFX_WideString& csNewFieldName) {
606 if (pControl == NULL || csNewFieldName.IsEmpty()) { 605 if (!pControl || csNewFieldName.IsEmpty()) {
607 return FALSE; 606 return FALSE;
608 } 607 }
609 CPDF_FormField* pField = ((CPDF_FormControl*)pControl)->GetField(); 608 CPDF_FormField* pField = ((CPDF_FormControl*)pControl)->GetField();
610 return ValidateFieldName(csNewFieldName, pField->GetFieldType(), pField, 609 return ValidateFieldName(csNewFieldName, pField->GetFieldType(), pField,
611 pControl); 610 pControl);
612 } 611 }
613 int CPDF_InterForm::CompareFieldName(const CFX_ByteString& name1, 612 int CPDF_InterForm::CompareFieldName(const CFX_ByteString& name1,
614 const CFX_ByteString& name2) { 613 const CFX_ByteString& name2) {
615 const FX_CHAR* ptr1 = name1; 614 const FX_CHAR* ptr1 = name1;
616 const FX_CHAR* ptr2 = name2; 615 const FX_CHAR* ptr2 = name2;
(...skipping 29 matching lines...) Expand all
646 if (i == name2.GetLength()) { 645 if (i == name2.GetLength()) {
647 return 3; 646 return 3;
648 } 647 }
649 return 0; 648 return 0;
650 } 649 }
651 FX_DWORD CPDF_InterForm::CountFields(const CFX_WideString& csFieldName) { 650 FX_DWORD CPDF_InterForm::CountFields(const CFX_WideString& csFieldName) {
652 if (csFieldName.IsEmpty()) { 651 if (csFieldName.IsEmpty()) {
653 return (FX_DWORD)m_pFieldTree->m_Root.CountFields(); 652 return (FX_DWORD)m_pFieldTree->m_Root.CountFields();
654 } 653 }
655 CFieldTree::_Node* pNode = m_pFieldTree->FindNode(csFieldName); 654 CFieldTree::_Node* pNode = m_pFieldTree->FindNode(csFieldName);
656 if (pNode == NULL) { 655 return pNode ? pNode->CountFields() : 0;
657 return 0;
658 }
659 return pNode->CountFields();
660 } 656 }
661 CPDF_FormField* CPDF_InterForm::GetField(FX_DWORD index, 657 CPDF_FormField* CPDF_InterForm::GetField(FX_DWORD index,
662 const CFX_WideString& csFieldName) { 658 const CFX_WideString& csFieldName) {
663 if (csFieldName == L"") { 659 if (csFieldName == L"") {
664 return m_pFieldTree->m_Root.GetField(index); 660 return m_pFieldTree->m_Root.GetField(index);
665 } 661 }
666 CFieldTree::_Node* pNode = m_pFieldTree->FindNode(csFieldName); 662 CFieldTree::_Node* pNode = m_pFieldTree->FindNode(csFieldName);
667 if (pNode == NULL) { 663 return pNode ? pNode->GetField(index) : nullptr;
668 return NULL;
669 }
670 return pNode->GetField(index);
671 } 664 }
672 void CPDF_InterForm::GetAllFieldNames(CFX_WideStringArray& allFieldNames) { 665 void CPDF_InterForm::GetAllFieldNames(CFX_WideStringArray& allFieldNames) {
673 allFieldNames.RemoveAll(); 666 allFieldNames.RemoveAll();
674 int nCount = m_pFieldTree->m_Root.CountFields(); 667 int nCount = m_pFieldTree->m_Root.CountFields();
675 for (int i = 0; i < nCount; i++) { 668 for (int i = 0; i < nCount; i++) {
676 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); 669 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i);
677 if (pField) { 670 if (pField) {
678 CFX_WideString full_name = GetFullName(pField->GetFieldDict()); 671 CFX_WideString full_name = GetFullName(pField->GetFieldDict());
679 allFieldNames.Add(full_name); 672 allFieldNames.Add(full_name);
680 } 673 }
681 } 674 }
682 } 675 }
683 676
684 CPDF_FormField* CPDF_InterForm::GetFieldByDict( 677 CPDF_FormField* CPDF_InterForm::GetFieldByDict(
685 CPDF_Dictionary* pFieldDict) const { 678 CPDF_Dictionary* pFieldDict) const {
686 if (pFieldDict == NULL) { 679 if (!pFieldDict) {
687 return NULL; 680 return NULL;
688 } 681 }
689 CFX_WideString csWName = GetFullName(pFieldDict); 682 CFX_WideString csWName = GetFullName(pFieldDict);
690 return m_pFieldTree->GetField(csWName); 683 return m_pFieldTree->GetField(csWName);
691 } 684 }
692 685
693 CPDF_FormControl* CPDF_InterForm::GetControlAtPoint(CPDF_Page* pPage, 686 CPDF_FormControl* CPDF_InterForm::GetControlAtPoint(CPDF_Page* pPage,
694 FX_FLOAT pdf_x, 687 FX_FLOAT pdf_x,
695 FX_FLOAT pdf_y, 688 FX_FLOAT pdf_y,
696 int* z_order) const { 689 int* z_order) const {
(...skipping 23 matching lines...) Expand all
720 return nullptr; 713 return nullptr;
721 } 714 }
722 715
723 CPDF_FormControl* CPDF_InterForm::GetControlByDict( 716 CPDF_FormControl* CPDF_InterForm::GetControlByDict(
724 const CPDF_Dictionary* pWidgetDict) const { 717 const CPDF_Dictionary* pWidgetDict) const {
725 const auto it = m_ControlMap.find(pWidgetDict); 718 const auto it = m_ControlMap.find(pWidgetDict);
726 return it != m_ControlMap.end() ? it->second : nullptr; 719 return it != m_ControlMap.end() ? it->second : nullptr;
727 } 720 }
728 721
729 FX_BOOL CPDF_InterForm::NeedConstructAP() { 722 FX_BOOL CPDF_InterForm::NeedConstructAP() {
730 if (m_pFormDict == NULL) { 723 return m_pFormDict && m_pFormDict->GetBoolean("NeedAppearances");
731 return FALSE;
732 }
733 return m_pFormDict->GetBoolean("NeedAppearances");
734 } 724 }
735 void CPDF_InterForm::NeedConstructAP(FX_BOOL bNeedAP) { 725 void CPDF_InterForm::NeedConstructAP(FX_BOOL bNeedAP) {
736 if (m_pFormDict == NULL) { 726 if (!m_pFormDict) {
737 InitInterFormDict(m_pFormDict, m_pDocument); 727 InitInterFormDict(m_pFormDict, m_pDocument);
738 } 728 }
739 m_pFormDict->SetAtBoolean("NeedAppearances", bNeedAP); 729 m_pFormDict->SetAtBoolean("NeedAppearances", bNeedAP);
740 m_bGenerateAP = bNeedAP; 730 m_bGenerateAP = bNeedAP;
741 } 731 }
742 int CPDF_InterForm::CountFieldsInCalculationOrder() { 732 int CPDF_InterForm::CountFieldsInCalculationOrder() {
743 if (m_pFormDict == NULL) { 733 if (!m_pFormDict) {
744 return 0; 734 return 0;
745 } 735 }
746 CPDF_Array* pArray = m_pFormDict->GetArray("CO"); 736 CPDF_Array* pArray = m_pFormDict->GetArray("CO");
747 if (pArray == NULL) { 737 return pArray ? pArray->GetCount() : 0;
748 return 0;
749 }
750 return pArray->GetCount();
751 } 738 }
752 CPDF_FormField* CPDF_InterForm::GetFieldInCalculationOrder(int index) { 739 CPDF_FormField* CPDF_InterForm::GetFieldInCalculationOrder(int index) {
753 if (m_pFormDict == NULL || index < 0) { 740 if (!m_pFormDict || index < 0) {
754 return NULL; 741 return NULL;
755 } 742 }
756 CPDF_Array* pArray = m_pFormDict->GetArray("CO"); 743 CPDF_Array* pArray = m_pFormDict->GetArray("CO");
757 if (pArray == NULL) { 744 if (!pArray) {
758 return NULL; 745 return NULL;
759 } 746 }
760 if (CPDF_Dictionary* pElement = 747 if (CPDF_Dictionary* pElement =
761 ToDictionary(pArray->GetElementValue(index))) { 748 ToDictionary(pArray->GetElementValue(index))) {
762 return GetFieldByDict(pElement); 749 return GetFieldByDict(pElement);
763 } 750 }
764 return NULL; 751 return NULL;
765 } 752 }
766 int CPDF_InterForm::FindFieldInCalculationOrder(const CPDF_FormField* pField) { 753 int CPDF_InterForm::FindFieldInCalculationOrder(const CPDF_FormField* pField) {
767 if (m_pFormDict == NULL || pField == NULL) { 754 if (!m_pFormDict || !pField) {
768 return -1; 755 return -1;
769 } 756 }
770 CPDF_Array* pArray = m_pFormDict->GetArray("CO"); 757 CPDF_Array* pArray = m_pFormDict->GetArray("CO");
771 if (pArray == NULL) { 758 if (!pArray) {
772 return -1; 759 return -1;
773 } 760 }
774 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { 761 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) {
775 CPDF_Object* pElement = pArray->GetElementValue(i); 762 CPDF_Object* pElement = pArray->GetElementValue(i);
776 if (pElement == pField->m_pDict) { 763 if (pElement == pField->m_pDict) {
777 return i; 764 return i;
778 } 765 }
779 } 766 }
780 return -1; 767 return -1;
781 } 768 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 void CPDF_InterForm::RemoveFormFont(const CPDF_Font* pFont) { 814 void CPDF_InterForm::RemoveFormFont(const CPDF_Font* pFont) {
828 m_bUpdated = TRUE; 815 m_bUpdated = TRUE;
829 RemoveInterFormFont(m_pFormDict, pFont); 816 RemoveInterFormFont(m_pFormDict, pFont);
830 } 817 }
831 void CPDF_InterForm::RemoveFormFont(CFX_ByteString csNameTag) { 818 void CPDF_InterForm::RemoveFormFont(CFX_ByteString csNameTag) {
832 m_bUpdated = TRUE; 819 m_bUpdated = TRUE;
833 RemoveInterFormFont(m_pFormDict, csNameTag); 820 RemoveInterFormFont(m_pFormDict, csNameTag);
834 } 821 }
835 CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() { 822 CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() {
836 CFX_ByteString csDA; 823 CFX_ByteString csDA;
837 if (m_pFormDict == NULL) { 824 if (!m_pFormDict) {
838 return csDA; 825 return csDA;
839 } 826 }
840 csDA = m_pFormDict->GetString("DA"); 827 csDA = m_pFormDict->GetString("DA");
841 return csDA; 828 return csDA;
842 } 829 }
843 CPDF_Font* CPDF_InterForm::GetDefaultFormFont() { 830 CPDF_Font* CPDF_InterForm::GetDefaultFormFont() {
844 return GetDefaultInterFormFont(m_pFormDict, m_pDocument); 831 return GetDefaultInterFormFont(m_pFormDict, m_pDocument);
845 } 832 }
846 int CPDF_InterForm::GetFormAlignment() { 833 int CPDF_InterForm::GetFormAlignment() {
847 if (m_pFormDict == NULL) { 834 return m_pFormDict ? m_pFormDict->GetInteger("Q", 0) : 0;
848 return 0;
849 }
850 return m_pFormDict->GetInteger("Q", 0);
851 } 835 }
852 836
853 bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields, 837 bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields,
854 bool bIncludeOrExclude, 838 bool bIncludeOrExclude,
855 bool bNotify) { 839 bool bNotify) {
856 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) 840 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0)
857 return false; 841 return false;
858 842
859 int nCount = m_pFieldTree->m_Root.CountFields(); 843 int nCount = m_pFieldTree->m_Root.CountFields();
860 for (int i = 0; i < nCount; ++i) { 844 for (int i = 0; i < nCount; ++i) {
(...skipping 24 matching lines...) Expand all
885 } 869 }
886 if (bNotify && m_pFormNotify) 870 if (bNotify && m_pFormNotify)
887 m_pFormNotify->AfterFormReset(this); 871 m_pFormNotify->AfterFormReset(this);
888 return true; 872 return true;
889 } 873 }
890 874
891 void CPDF_InterForm::LoadField(CPDF_Dictionary* pFieldDict, int nLevel) { 875 void CPDF_InterForm::LoadField(CPDF_Dictionary* pFieldDict, int nLevel) {
892 if (nLevel > nMaxRecursion) { 876 if (nLevel > nMaxRecursion) {
893 return; 877 return;
894 } 878 }
895 if (pFieldDict == NULL) { 879 if (!pFieldDict) {
896 return; 880 return;
897 } 881 }
898 FX_DWORD dwParentObjNum = pFieldDict->GetObjNum(); 882 FX_DWORD dwParentObjNum = pFieldDict->GetObjNum();
899 CPDF_Array* pKids = pFieldDict->GetArray("Kids"); 883 CPDF_Array* pKids = pFieldDict->GetArray("Kids");
900 if (!pKids) { 884 if (!pKids) {
901 AddTerminalField(pFieldDict); 885 AddTerminalField(pFieldDict);
902 return; 886 return;
903 } 887 }
904 CPDF_Dictionary* pFirstKid = pKids->GetDict(0); 888 CPDF_Dictionary* pFirstKid = pKids->GetDict(0);
905 if (pFirstKid == NULL) { 889 if (!pFirstKid) {
906 return; 890 return;
907 } 891 }
908 if (pFirstKid->KeyExist("T") || pFirstKid->KeyExist("Kids")) { 892 if (pFirstKid->KeyExist("T") || pFirstKid->KeyExist("Kids")) {
909 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { 893 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) {
910 CPDF_Dictionary* pChildDict = pKids->GetDict(i); 894 CPDF_Dictionary* pChildDict = pKids->GetDict(i);
911 if (pChildDict) { 895 if (pChildDict) {
912 if (pChildDict->GetObjNum() != dwParentObjNum) { 896 if (pChildDict->GetObjNum() != dwParentObjNum) {
913 LoadField(pChildDict, nLevel + 1); 897 LoadField(pChildDict, nLevel + 1);
914 } 898 }
915 } 899 }
916 } 900 }
917 } else { 901 } else {
918 AddTerminalField(pFieldDict); 902 AddTerminalField(pFieldDict);
919 } 903 }
920 } 904 }
921 FX_BOOL CPDF_InterForm::HasXFAForm() const { 905 FX_BOOL CPDF_InterForm::HasXFAForm() const {
922 return m_pFormDict && m_pFormDict->GetArray("XFA"); 906 return m_pFormDict && m_pFormDict->GetArray("XFA");
923 } 907 }
924 void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) { 908 void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) {
925 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; 909 CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
926 if (pPageDict == NULL) { 910 if (!pPageDict) {
927 return; 911 return;
928 } 912 }
929 CPDF_Array* pAnnots = pPageDict->GetArray("Annots"); 913 CPDF_Array* pAnnots = pPageDict->GetArray("Annots");
930 if (pAnnots == NULL) { 914 if (!pAnnots) {
931 return; 915 return;
932 } 916 }
933 int iAnnotCount = pAnnots->GetCount(); 917 int iAnnotCount = pAnnots->GetCount();
934 for (int i = 0; i < iAnnotCount; i++) { 918 for (int i = 0; i < iAnnotCount; i++) {
935 CPDF_Dictionary* pAnnot = pAnnots->GetDict(i); 919 CPDF_Dictionary* pAnnot = pAnnots->GetDict(i);
936 if (pAnnot && pAnnot->GetString("Subtype") == "Widget") { 920 if (pAnnot && pAnnot->GetString("Subtype") == "Widget") {
937 LoadField(pAnnot); 921 LoadField(pAnnot);
938 } 922 }
939 } 923 }
940 } 924 }
941 CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { 925 CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) {
942 if (!pFieldDict->KeyExist("T")) { 926 if (!pFieldDict->KeyExist("T")) {
943 return NULL; 927 return NULL;
944 } 928 }
945 CPDF_Dictionary* pDict = pFieldDict; 929 CPDF_Dictionary* pDict = pFieldDict;
946 CFX_WideString csWName = GetFullName(pFieldDict); 930 CFX_WideString csWName = GetFullName(pFieldDict);
947 if (csWName.IsEmpty()) { 931 if (csWName.IsEmpty()) {
948 return NULL; 932 return NULL;
949 } 933 }
950 CPDF_FormField* pField = NULL; 934 CPDF_FormField* pField = NULL;
951 pField = m_pFieldTree->GetField(csWName); 935 pField = m_pFieldTree->GetField(csWName);
952 if (pField == NULL) { 936 if (!pField) {
953 CPDF_Dictionary* pParent = pFieldDict; 937 CPDF_Dictionary* pParent = pFieldDict;
954 if (!pFieldDict->KeyExist("T") && 938 if (!pFieldDict->KeyExist("T") &&
955 pFieldDict->GetString("Subtype") == "Widget") { 939 pFieldDict->GetString("Subtype") == "Widget") {
956 pParent = pFieldDict->GetDict("Parent"); 940 pParent = pFieldDict->GetDict("Parent");
957 if (!pParent) { 941 if (!pParent) {
958 pParent = pFieldDict; 942 pParent = pFieldDict;
959 } 943 }
960 } 944 }
961 if (pParent && pParent != pFieldDict && !pParent->KeyExist("FT")) { 945 if (pParent && pParent != pFieldDict && !pParent->KeyExist("FT")) {
962 if (pFieldDict->KeyExist("FT")) { 946 if (pFieldDict->KeyExist("FT")) {
(...skipping 14 matching lines...) Expand all
977 if (ToReference(pTObj)) { 961 if (ToReference(pTObj)) {
978 CPDF_Object* pClone = pTObj->Clone(TRUE); 962 CPDF_Object* pClone = pTObj->Clone(TRUE);
979 if (pClone) 963 if (pClone)
980 pDict->SetAt("T", pClone); 964 pDict->SetAt("T", pClone);
981 else 965 else
982 pDict->SetAtName("T", ""); 966 pDict->SetAtName("T", "");
983 } 967 }
984 m_pFieldTree->SetField(csWName, pField); 968 m_pFieldTree->SetField(csWName, pField);
985 } 969 }
986 CPDF_Array* pKids = pFieldDict->GetArray("Kids"); 970 CPDF_Array* pKids = pFieldDict->GetArray("Kids");
987 if (pKids == NULL) { 971 if (!pKids) {
988 if (pFieldDict->GetString("Subtype") == "Widget") { 972 if (pFieldDict->GetString("Subtype") == "Widget") {
989 AddControl(pField, pFieldDict); 973 AddControl(pField, pFieldDict);
990 } 974 }
991 } else { 975 } else {
992 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { 976 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) {
993 CPDF_Dictionary* pKid = pKids->GetDict(i); 977 CPDF_Dictionary* pKid = pKids->GetDict(i);
994 if (pKid == NULL) { 978 if (!pKid) {
995 continue; 979 continue;
996 } 980 }
997 if (pKid->GetString("Subtype") != "Widget") { 981 if (pKid->GetString("Subtype") != "Widget") {
998 continue; 982 continue;
999 } 983 }
1000 AddControl(pField, pKid); 984 AddControl(pField, pKid);
1001 } 985 }
1002 } 986 }
1003 return pField; 987 return pField;
1004 } 988 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 fields.push_back(m_pFieldTree->m_Root.GetField(i)); 1041 fields.push_back(m_pFieldTree->m_Root.GetField(i));
1058 return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec); 1042 return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec);
1059 } 1043 }
1060 1044
1061 CFDF_Document* CPDF_InterForm::ExportToFDF( 1045 CFDF_Document* CPDF_InterForm::ExportToFDF(
1062 const CFX_WideStringC& pdf_path, 1046 const CFX_WideStringC& pdf_path,
1063 const std::vector<CPDF_FormField*>& fields, 1047 const std::vector<CPDF_FormField*>& fields,
1064 bool bIncludeOrExclude, 1048 bool bIncludeOrExclude,
1065 bool bSimpleFileSpec) const { 1049 bool bSimpleFileSpec) const {
1066 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc(); 1050 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc();
1067 if (pDoc == NULL) { 1051 if (!pDoc) {
1068 return NULL; 1052 return NULL;
1069 } 1053 }
1070 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDict("FDF"); 1054 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDict("FDF");
1071 if (!pdf_path.IsEmpty()) { 1055 if (!pdf_path.IsEmpty()) {
1072 if (bSimpleFileSpec) { 1056 if (bSimpleFileSpec) {
1073 CFX_WideString wsFilePath = FILESPEC_EncodeFileName(pdf_path); 1057 CFX_WideString wsFilePath = FILESPEC_EncodeFileName(pdf_path);
1074 pMainDict->SetAtString("F", CFX_ByteString::FromUnicode(wsFilePath)); 1058 pMainDict->SetAtString("F", CFX_ByteString::FromUnicode(wsFilePath));
1075 pMainDict->SetAtString("UF", PDF_EncodeText(wsFilePath)); 1059 pMainDict->SetAtString("UF", PDF_EncodeText(wsFilePath));
1076 } else { 1060 } else {
1077 CPDF_FileSpec filespec; 1061 CPDF_FileSpec filespec;
1078 filespec.SetFileName(pdf_path); 1062 filespec.SetFileName(pdf_path);
1079 pMainDict->SetAt("F", static_cast<CPDF_Object*>(filespec)); 1063 pMainDict->SetAt("F", static_cast<CPDF_Object*>(filespec));
1080 } 1064 }
1081 } 1065 }
1082 CPDF_Array* pFields = CPDF_Array::Create(); 1066 CPDF_Array* pFields = CPDF_Array::Create();
1083 if (pFields == NULL) { 1067 if (!pFields) {
1084 return NULL; 1068 return NULL;
1085 } 1069 }
1086 pMainDict->SetAt("Fields", pFields); 1070 pMainDict->SetAt("Fields", pFields);
1087 int nCount = m_pFieldTree->m_Root.CountFields(); 1071 int nCount = m_pFieldTree->m_Root.CountFields();
1088 for (int i = 0; i < nCount; i++) { 1072 for (int i = 0; i < nCount; i++) {
1089 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); 1073 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i);
1090 if (pField == NULL || pField->GetType() == CPDF_FormField::PushButton) { 1074 if (!pField || pField->GetType() == CPDF_FormField::PushButton) {
1091 continue; 1075 continue;
1092 } 1076 }
1093 FX_DWORD dwFlags = pField->GetFieldFlags(); 1077 FX_DWORD dwFlags = pField->GetFieldFlags();
1094 if (dwFlags & 0x04) 1078 if (dwFlags & 0x04)
1095 continue; 1079 continue;
1096 1080
1097 auto it = std::find(fields.begin(), fields.end(), pField); 1081 auto it = std::find(fields.begin(), fields.end(), pField);
1098 if (bIncludeOrExclude == (it != fields.end())) { 1082 if (bIncludeOrExclude == (it != fields.end())) {
1099 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetString("V").IsEmpty()) 1083 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetString("V").IsEmpty())
1100 continue; 1084 continue;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 int nLevel) { 1152 int nLevel) {
1169 CFX_WideString name; 1153 CFX_WideString name;
1170 if (!parent_name.IsEmpty()) { 1154 if (!parent_name.IsEmpty()) {
1171 name = parent_name + L"."; 1155 name = parent_name + L".";
1172 } 1156 }
1173 name += pFieldDict->GetUnicodeText("T"); 1157 name += pFieldDict->GetUnicodeText("T");
1174 CPDF_Array* pKids = pFieldDict->GetArray("Kids"); 1158 CPDF_Array* pKids = pFieldDict->GetArray("Kids");
1175 if (pKids) { 1159 if (pKids) {
1176 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { 1160 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) {
1177 CPDF_Dictionary* pKid = pKids->GetDict(i); 1161 CPDF_Dictionary* pKid = pKids->GetDict(i);
1178 if (pKid == NULL) { 1162 if (!pKid) {
1179 continue; 1163 continue;
1180 } 1164 }
1181 if (nLevel <= nMaxRecursion) { 1165 if (nLevel <= nMaxRecursion) {
1182 FDF_ImportField(pKid, name, bNotify, nLevel + 1); 1166 FDF_ImportField(pKid, name, bNotify, nLevel + 1);
1183 } 1167 }
1184 } 1168 }
1185 return; 1169 return;
1186 } 1170 }
1187 if (!pFieldDict->KeyExist("V")) { 1171 if (!pFieldDict->KeyExist("V")) {
1188 return; 1172 return;
1189 } 1173 }
1190 CPDF_FormField* pField = m_pFieldTree->GetField(name); 1174 CPDF_FormField* pField = m_pFieldTree->GetField(name);
1191 if (pField == NULL) { 1175 if (!pField) {
1192 return; 1176 return;
1193 } 1177 }
1194 CFX_WideString csWValue; 1178 CFX_WideString csWValue;
1195 FPDFDOC_FDF_GetFieldValue(pFieldDict, csWValue, m_bsEncoding); 1179 FPDFDOC_FDF_GetFieldValue(pFieldDict, csWValue, m_bsEncoding);
1196 int iType = pField->GetFieldType(); 1180 int iType = pField->GetFieldType();
1197 if (bNotify && m_pFormNotify) { 1181 if (bNotify && m_pFormNotify) {
1198 int iRet = 0; 1182 int iRet = 0;
1199 if (iType == FIELDTYPE_LISTBOX) { 1183 if (iType == FIELDTYPE_LISTBOX) {
1200 iRet = m_pFormNotify->BeforeSelectionChange(pField, csWValue); 1184 iRet = m_pFormNotify->BeforeSelectionChange(pField, csWValue);
1201 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) { 1185 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) {
(...skipping 22 matching lines...) Expand all
1224 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) { 1208 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) {
1225 m_pFormNotify->AfterValueChange(pField); 1209 m_pFormNotify->AfterValueChange(pField);
1226 } 1210 }
1227 } 1211 }
1228 if (CPDF_InterForm::m_bUpdateAP) { 1212 if (CPDF_InterForm::m_bUpdateAP) {
1229 pField->UpdateAP(NULL); 1213 pField->UpdateAP(NULL);
1230 } 1214 }
1231 } 1215 }
1232 FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF, 1216 FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF,
1233 FX_BOOL bNotify) { 1217 FX_BOOL bNotify) {
1234 if (pFDF == NULL) { 1218 if (!pFDF) {
1235 return FALSE; 1219 return FALSE;
1236 } 1220 }
1237 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF"); 1221 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF");
1238 if (pMainDict == NULL) { 1222 if (!pMainDict) {
1239 return FALSE; 1223 return FALSE;
1240 } 1224 }
1241 CPDF_Array* pFields = pMainDict->GetArray("Fields"); 1225 CPDF_Array* pFields = pMainDict->GetArray("Fields");
1242 if (pFields == NULL) { 1226 if (!pFields) {
1243 return FALSE; 1227 return FALSE;
1244 } 1228 }
1245 m_bsEncoding = pMainDict->GetString("Encoding"); 1229 m_bsEncoding = pMainDict->GetString("Encoding");
1246 if (bNotify && m_pFormNotify) { 1230 if (bNotify && m_pFormNotify) {
1247 int iRet = m_pFormNotify->BeforeFormImportData(this); 1231 int iRet = m_pFormNotify->BeforeFormImportData(this);
1248 if (iRet < 0) { 1232 if (iRet < 0) {
1249 return FALSE; 1233 return FALSE;
1250 } 1234 }
1251 } 1235 }
1252 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) { 1236 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) {
1253 CPDF_Dictionary* pField = pFields->GetDict(i); 1237 CPDF_Dictionary* pField = pFields->GetDict(i);
1254 if (pField == NULL) { 1238 if (!pField) {
1255 continue; 1239 continue;
1256 } 1240 }
1257 FDF_ImportField(pField, L"", bNotify); 1241 FDF_ImportField(pField, L"", bNotify);
1258 } 1242 }
1259 if (bNotify && m_pFormNotify) { 1243 if (bNotify && m_pFormNotify) {
1260 m_pFormNotify->AfterFormImportData(this); 1244 m_pFormNotify->AfterFormImportData(this);
1261 } 1245 }
1262 return TRUE; 1246 return TRUE;
1263 } 1247 }
1264 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) { 1248 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) {
1265 m_pFormNotify = (CPDF_FormNotify*)pNotify; 1249 m_pFormNotify = (CPDF_FormNotify*)pNotify;
1266 } 1250 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698