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

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

Issue 1520063002: Get rid of most instance of 'foo == NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@bstr_isnull
Patch Set: self review 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 for (int i = csSub.GetLength() - 1; i > -1; i--) { 529 for (int i = csSub.GetLength() - 1; i > -1; i--) {
530 if (csSub[i] == L' ' || csSub[i] == L'.') { 530 if (csSub[i] == L' ' || csSub[i] == L'.') {
531 csSub.SetAt(i, L'\0'); 531 csSub.SetAt(i, L'\0');
532 } else { 532 } else {
533 break; 533 break;
534 } 534 }
535 } 535 }
536 FX_DWORD dwCount = m_pFieldTree->m_Root.CountFields(); 536 FX_DWORD dwCount = m_pFieldTree->m_Root.CountFields();
537 for (FX_DWORD m = 0; m < dwCount; m++) { 537 for (FX_DWORD m = 0; m < dwCount; m++) {
538 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(m); 538 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(m);
539 if (pField == NULL) { 539 if (!pField) {
540 continue; 540 continue;
541 } 541 }
542 if (pField == pExcludedField) { 542 if (pField == pExcludedField) {
543 if (pExcludedControl) { 543 if (pExcludedControl) {
544 if (pField->CountControls() < 2) { 544 if (pField->CountControls() < 2) {
545 continue; 545 continue;
546 } 546 }
547 } else { 547 } else {
548 continue; 548 continue;
549 } 549 }
(...skipping 23 matching lines...) Expand all
573 } 573 }
574 csNewFieldName = csSub; 574 csNewFieldName = csSub;
575 return TRUE; 575 return TRUE;
576 } 576 }
577 FX_BOOL CPDF_InterForm::ValidateFieldName(CFX_WideString& csNewFieldName, 577 FX_BOOL CPDF_InterForm::ValidateFieldName(CFX_WideString& csNewFieldName,
578 int iType) { 578 int iType) {
579 return ValidateFieldName(csNewFieldName, iType, NULL, NULL); 579 return ValidateFieldName(csNewFieldName, iType, NULL, NULL);
580 } 580 }
581 FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormField* pField, 581 FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormField* pField,
582 CFX_WideString& csNewFieldName) { 582 CFX_WideString& csNewFieldName) {
583 if (pField == NULL || csNewFieldName.IsEmpty()) { 583 if (!pField || csNewFieldName.IsEmpty()) {
584 return FALSE; 584 return FALSE;
Tom Sepez 2015/12/14 18:27:00 nit: return pField && !csNewFieldName.IsEmpty() &&
Lei Zhang 2015/12/15 01:58:35 Done.
585 } 585 }
586 return ValidateFieldName( 586 return ValidateFieldName(
587 csNewFieldName, ((CPDF_FormField*)pField)->GetFieldType(), pField, NULL); 587 csNewFieldName, ((CPDF_FormField*)pField)->GetFieldType(), pField, NULL);
588 } 588 }
589 FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormControl* pControl, 589 FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormControl* pControl,
590 CFX_WideString& csNewFieldName) { 590 CFX_WideString& csNewFieldName) {
591 if (pControl == NULL || csNewFieldName.IsEmpty()) { 591 if (!pControl || csNewFieldName.IsEmpty()) {
592 return FALSE; 592 return FALSE;
593 } 593 }
594 CPDF_FormField* pField = ((CPDF_FormControl*)pControl)->GetField(); 594 CPDF_FormField* pField = ((CPDF_FormControl*)pControl)->GetField();
595 return ValidateFieldName(csNewFieldName, pField->GetFieldType(), pField, 595 return ValidateFieldName(csNewFieldName, pField->GetFieldType(), pField,
596 pControl); 596 pControl);
597 } 597 }
598 int CPDF_InterForm::CompareFieldName(const CFX_ByteString& name1, 598 int CPDF_InterForm::CompareFieldName(const CFX_ByteString& name1,
599 const CFX_ByteString& name2) { 599 const CFX_ByteString& name2) {
600 const FX_CHAR* ptr1 = name1; 600 const FX_CHAR* ptr1 = name1;
601 const FX_CHAR* ptr2 = name2; 601 const FX_CHAR* ptr2 = name2;
(...skipping 29 matching lines...) Expand all
631 if (i == name2.GetLength()) { 631 if (i == name2.GetLength()) {
632 return 3; 632 return 3;
633 } 633 }
634 return 0; 634 return 0;
635 } 635 }
636 FX_DWORD CPDF_InterForm::CountFields(const CFX_WideString& csFieldName) { 636 FX_DWORD CPDF_InterForm::CountFields(const CFX_WideString& csFieldName) {
637 if (csFieldName.IsEmpty()) { 637 if (csFieldName.IsEmpty()) {
638 return (FX_DWORD)m_pFieldTree->m_Root.CountFields(); 638 return (FX_DWORD)m_pFieldTree->m_Root.CountFields();
639 } 639 }
640 CFieldTree::_Node* pNode = m_pFieldTree->FindNode(csFieldName); 640 CFieldTree::_Node* pNode = m_pFieldTree->FindNode(csFieldName);
641 if (pNode == NULL) { 641 return pNode ? pNode->CountFields() : 0;
642 return 0;
643 }
644 return pNode->CountFields();
645 } 642 }
646 CPDF_FormField* CPDF_InterForm::GetField(FX_DWORD index, 643 CPDF_FormField* CPDF_InterForm::GetField(FX_DWORD index,
647 const CFX_WideString& csFieldName) { 644 const CFX_WideString& csFieldName) {
648 if (csFieldName == L"") { 645 if (csFieldName == L"") {
649 return m_pFieldTree->m_Root.GetField(index); 646 return m_pFieldTree->m_Root.GetField(index);
650 } 647 }
651 CFieldTree::_Node* pNode = m_pFieldTree->FindNode(csFieldName); 648 CFieldTree::_Node* pNode = m_pFieldTree->FindNode(csFieldName);
652 if (pNode == NULL) { 649 return pNode ? pNode->GetField(index) : nullptr;
653 return NULL;
654 }
655 return pNode->GetField(index);
656 } 650 }
657 void CPDF_InterForm::GetAllFieldNames(CFX_WideStringArray& allFieldNames) { 651 void CPDF_InterForm::GetAllFieldNames(CFX_WideStringArray& allFieldNames) {
658 allFieldNames.RemoveAll(); 652 allFieldNames.RemoveAll();
659 int nCount = m_pFieldTree->m_Root.CountFields(); 653 int nCount = m_pFieldTree->m_Root.CountFields();
660 for (int i = 0; i < nCount; i++) { 654 for (int i = 0; i < nCount; i++) {
661 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); 655 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i);
662 if (pField) { 656 if (pField) {
663 CFX_WideString full_name = GetFullName(pField->GetFieldDict()); 657 CFX_WideString full_name = GetFullName(pField->GetFieldDict());
664 allFieldNames.Add(full_name); 658 allFieldNames.Add(full_name);
665 } 659 }
666 } 660 }
667 } 661 }
668 662
669 CPDF_FormField* CPDF_InterForm::GetFieldByDict( 663 CPDF_FormField* CPDF_InterForm::GetFieldByDict(
670 CPDF_Dictionary* pFieldDict) const { 664 CPDF_Dictionary* pFieldDict) const {
671 if (pFieldDict == NULL) { 665 if (!pFieldDict) {
672 return NULL; 666 return NULL;
673 } 667 }
674 CFX_WideString csWName = GetFullName(pFieldDict); 668 CFX_WideString csWName = GetFullName(pFieldDict);
675 return m_pFieldTree->GetField(csWName); 669 return m_pFieldTree->GetField(csWName);
676 } 670 }
677 671
678 CPDF_FormControl* CPDF_InterForm::GetControlAtPoint(CPDF_Page* pPage, 672 CPDF_FormControl* CPDF_InterForm::GetControlAtPoint(CPDF_Page* pPage,
679 FX_FLOAT pdf_x, 673 FX_FLOAT pdf_x,
680 FX_FLOAT pdf_y, 674 FX_FLOAT pdf_y,
681 int* z_order) const { 675 int* z_order) const {
(...skipping 23 matching lines...) Expand all
705 return nullptr; 699 return nullptr;
706 } 700 }
707 701
708 CPDF_FormControl* CPDF_InterForm::GetControlByDict( 702 CPDF_FormControl* CPDF_InterForm::GetControlByDict(
709 const CPDF_Dictionary* pWidgetDict) const { 703 const CPDF_Dictionary* pWidgetDict) const {
710 const auto it = m_ControlMap.find(pWidgetDict); 704 const auto it = m_ControlMap.find(pWidgetDict);
711 return it != m_ControlMap.end() ? it->second : nullptr; 705 return it != m_ControlMap.end() ? it->second : nullptr;
712 } 706 }
713 707
714 FX_BOOL CPDF_InterForm::NeedConstructAP() { 708 FX_BOOL CPDF_InterForm::NeedConstructAP() {
715 if (m_pFormDict == NULL) { 709 return m_pFormDict ? m_pFormDict->GetBoolean("NeedAppearances") : FALSE;
Tom Sepez 2015/12/14 18:27:00 nit: return m_pFormDict && m_pFormDict->GetBoolean
Lei Zhang 2015/12/15 01:58:36 Done.
716 return FALSE;
717 }
718 return m_pFormDict->GetBoolean("NeedAppearances");
719 } 710 }
720 void CPDF_InterForm::NeedConstructAP(FX_BOOL bNeedAP) { 711 void CPDF_InterForm::NeedConstructAP(FX_BOOL bNeedAP) {
721 if (m_pFormDict == NULL) { 712 if (!m_pFormDict) {
722 InitInterFormDict(m_pFormDict, m_pDocument); 713 InitInterFormDict(m_pFormDict, m_pDocument);
723 } 714 }
724 m_pFormDict->SetAtBoolean("NeedAppearances", bNeedAP); 715 m_pFormDict->SetAtBoolean("NeedAppearances", bNeedAP);
725 m_bGenerateAP = bNeedAP; 716 m_bGenerateAP = bNeedAP;
726 } 717 }
727 int CPDF_InterForm::CountFieldsInCalculationOrder() { 718 int CPDF_InterForm::CountFieldsInCalculationOrder() {
728 if (m_pFormDict == NULL) { 719 if (!m_pFormDict) {
729 return 0; 720 return 0;
730 } 721 }
731 CPDF_Array* pArray = m_pFormDict->GetArray("CO"); 722 CPDF_Array* pArray = m_pFormDict->GetArray("CO");
732 if (pArray == NULL) { 723 return pArray ? pArray->GetCount() : 0;
733 return 0;
734 }
735 return pArray->GetCount();
736 } 724 }
737 CPDF_FormField* CPDF_InterForm::GetFieldInCalculationOrder(int index) { 725 CPDF_FormField* CPDF_InterForm::GetFieldInCalculationOrder(int index) {
738 if (m_pFormDict == NULL || index < 0) { 726 if (!m_pFormDict || index < 0) {
739 return NULL; 727 return NULL;
740 } 728 }
741 CPDF_Array* pArray = m_pFormDict->GetArray("CO"); 729 CPDF_Array* pArray = m_pFormDict->GetArray("CO");
742 if (pArray == NULL) { 730 if (!pArray) {
743 return NULL; 731 return NULL;
744 } 732 }
745 if (CPDF_Dictionary* pElement = 733 if (CPDF_Dictionary* pElement =
746 ToDictionary(pArray->GetElementValue(index))) { 734 ToDictionary(pArray->GetElementValue(index))) {
747 return GetFieldByDict(pElement); 735 return GetFieldByDict(pElement);
748 } 736 }
749 return NULL; 737 return NULL;
750 } 738 }
751 int CPDF_InterForm::FindFieldInCalculationOrder(const CPDF_FormField* pField) { 739 int CPDF_InterForm::FindFieldInCalculationOrder(const CPDF_FormField* pField) {
752 if (m_pFormDict == NULL || pField == NULL) { 740 if (!m_pFormDict || !pField) {
753 return -1; 741 return -1;
754 } 742 }
755 CPDF_Array* pArray = m_pFormDict->GetArray("CO"); 743 CPDF_Array* pArray = m_pFormDict->GetArray("CO");
756 if (pArray == NULL) { 744 if (!pArray) {
757 return -1; 745 return -1;
758 } 746 }
759 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { 747 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) {
760 CPDF_Object* pElement = pArray->GetElementValue(i); 748 CPDF_Object* pElement = pArray->GetElementValue(i);
761 if (pElement == pField->m_pDict) { 749 if (pElement == pField->m_pDict) {
762 return i; 750 return i;
763 } 751 }
764 } 752 }
765 return -1; 753 return -1;
766 } 754 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 void CPDF_InterForm::RemoveFormFont(const CPDF_Font* pFont) { 800 void CPDF_InterForm::RemoveFormFont(const CPDF_Font* pFont) {
813 m_bUpdated = TRUE; 801 m_bUpdated = TRUE;
814 RemoveInterFormFont(m_pFormDict, pFont); 802 RemoveInterFormFont(m_pFormDict, pFont);
815 } 803 }
816 void CPDF_InterForm::RemoveFormFont(CFX_ByteString csNameTag) { 804 void CPDF_InterForm::RemoveFormFont(CFX_ByteString csNameTag) {
817 m_bUpdated = TRUE; 805 m_bUpdated = TRUE;
818 RemoveInterFormFont(m_pFormDict, csNameTag); 806 RemoveInterFormFont(m_pFormDict, csNameTag);
819 } 807 }
820 CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() { 808 CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() {
821 CFX_ByteString csDA; 809 CFX_ByteString csDA;
822 if (m_pFormDict == NULL) { 810 if (!m_pFormDict) {
823 return csDA; 811 return csDA;
824 } 812 }
825 csDA = m_pFormDict->GetString("DA"); 813 csDA = m_pFormDict->GetString("DA");
826 return csDA; 814 return csDA;
827 } 815 }
828 CPDF_Font* CPDF_InterForm::GetDefaultFormFont() { 816 CPDF_Font* CPDF_InterForm::GetDefaultFormFont() {
829 return GetDefaultInterFormFont(m_pFormDict, m_pDocument); 817 return GetDefaultInterFormFont(m_pFormDict, m_pDocument);
830 } 818 }
831 int CPDF_InterForm::GetFormAlignment() { 819 int CPDF_InterForm::GetFormAlignment() {
832 if (m_pFormDict == NULL) { 820 if (!m_pFormDict) {
Tom Sepez 2015/12/14 18:27:00 nit: return m_pFormDict ? ... : 0;
Lei Zhang 2015/12/15 01:58:35 Done.
833 return 0; 821 return 0;
834 } 822 }
835 return m_pFormDict->GetInteger("Q", 0); 823 return m_pFormDict->GetInteger("Q", 0);
836 } 824 }
837 825
838 bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields, 826 bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields,
839 bool bIncludeOrExclude, 827 bool bIncludeOrExclude,
840 bool bNotify) { 828 bool bNotify) {
841 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) 829 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0)
842 return false; 830 return false;
(...skipping 27 matching lines...) Expand all
870 } 858 }
871 if (bNotify && m_pFormNotify) 859 if (bNotify && m_pFormNotify)
872 m_pFormNotify->AfterFormReset(this); 860 m_pFormNotify->AfterFormReset(this);
873 return true; 861 return true;
874 } 862 }
875 863
876 void CPDF_InterForm::LoadField(CPDF_Dictionary* pFieldDict, int nLevel) { 864 void CPDF_InterForm::LoadField(CPDF_Dictionary* pFieldDict, int nLevel) {
877 if (nLevel > nMaxRecursion) { 865 if (nLevel > nMaxRecursion) {
878 return; 866 return;
879 } 867 }
880 if (pFieldDict == NULL) { 868 if (!pFieldDict) {
881 return; 869 return;
882 } 870 }
883 FX_DWORD dwParentObjNum = pFieldDict->GetObjNum(); 871 FX_DWORD dwParentObjNum = pFieldDict->GetObjNum();
884 CPDF_Array* pKids = pFieldDict->GetArray("Kids"); 872 CPDF_Array* pKids = pFieldDict->GetArray("Kids");
885 if (!pKids) { 873 if (!pKids) {
886 AddTerminalField(pFieldDict); 874 AddTerminalField(pFieldDict);
887 return; 875 return;
888 } 876 }
889 CPDF_Dictionary* pFirstKid = pKids->GetDict(0); 877 CPDF_Dictionary* pFirstKid = pKids->GetDict(0);
890 if (pFirstKid == NULL) { 878 if (!pFirstKid) {
891 return; 879 return;
892 } 880 }
893 if (pFirstKid->KeyExist("T") || pFirstKid->KeyExist("Kids")) { 881 if (pFirstKid->KeyExist("T") || pFirstKid->KeyExist("Kids")) {
894 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { 882 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) {
895 CPDF_Dictionary* pChildDict = pKids->GetDict(i); 883 CPDF_Dictionary* pChildDict = pKids->GetDict(i);
896 if (pChildDict) { 884 if (pChildDict) {
897 if (pChildDict->GetObjNum() != dwParentObjNum) { 885 if (pChildDict->GetObjNum() != dwParentObjNum) {
898 LoadField(pChildDict, nLevel + 1); 886 LoadField(pChildDict, nLevel + 1);
899 } 887 }
900 } 888 }
901 } 889 }
902 } else { 890 } else {
903 AddTerminalField(pFieldDict); 891 AddTerminalField(pFieldDict);
904 } 892 }
905 } 893 }
906 FX_BOOL CPDF_InterForm::HasXFAForm() const { 894 FX_BOOL CPDF_InterForm::HasXFAForm() const {
907 return m_pFormDict && m_pFormDict->GetArray("XFA"); 895 return m_pFormDict && m_pFormDict->GetArray("XFA");
908 } 896 }
909 void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) { 897 void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) {
910 ASSERT(pPage); 898 ASSERT(pPage);
911 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; 899 CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
912 if (pPageDict == NULL) { 900 if (!pPageDict) {
913 return; 901 return;
914 } 902 }
915 CPDF_Array* pAnnots = pPageDict->GetArray("Annots"); 903 CPDF_Array* pAnnots = pPageDict->GetArray("Annots");
916 if (pAnnots == NULL) { 904 if (!pAnnots) {
917 return; 905 return;
918 } 906 }
919 int iAnnotCount = pAnnots->GetCount(); 907 int iAnnotCount = pAnnots->GetCount();
920 for (int i = 0; i < iAnnotCount; i++) { 908 for (int i = 0; i < iAnnotCount; i++) {
921 CPDF_Dictionary* pAnnot = pAnnots->GetDict(i); 909 CPDF_Dictionary* pAnnot = pAnnots->GetDict(i);
922 if (pAnnot && pAnnot->GetString("Subtype") == "Widget") { 910 if (pAnnot && pAnnot->GetString("Subtype") == "Widget") {
923 LoadField(pAnnot); 911 LoadField(pAnnot);
924 } 912 }
925 } 913 }
926 } 914 }
927 CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { 915 CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) {
928 if (!pFieldDict->KeyExist("T")) { 916 if (!pFieldDict->KeyExist("T")) {
929 return NULL; 917 return NULL;
930 } 918 }
931 CPDF_Dictionary* pDict = pFieldDict; 919 CPDF_Dictionary* pDict = pFieldDict;
932 CFX_WideString csWName = GetFullName(pFieldDict); 920 CFX_WideString csWName = GetFullName(pFieldDict);
933 if (csWName.IsEmpty()) { 921 if (csWName.IsEmpty()) {
934 return NULL; 922 return NULL;
935 } 923 }
936 CPDF_FormField* pField = NULL; 924 CPDF_FormField* pField = NULL;
937 pField = m_pFieldTree->GetField(csWName); 925 pField = m_pFieldTree->GetField(csWName);
938 if (pField == NULL) { 926 if (!pField) {
939 CPDF_Dictionary* pParent = pFieldDict; 927 CPDF_Dictionary* pParent = pFieldDict;
940 if (!pFieldDict->KeyExist("T") && 928 if (!pFieldDict->KeyExist("T") &&
941 pFieldDict->GetString("Subtype") == "Widget") { 929 pFieldDict->GetString("Subtype") == "Widget") {
942 pParent = pFieldDict->GetDict("Parent"); 930 pParent = pFieldDict->GetDict("Parent");
943 if (!pParent) { 931 if (!pParent) {
944 pParent = pFieldDict; 932 pParent = pFieldDict;
945 } 933 }
946 } 934 }
947 if (pParent && pParent != pFieldDict && !pParent->KeyExist("FT")) { 935 if (pParent && pParent != pFieldDict && !pParent->KeyExist("FT")) {
948 if (pFieldDict->KeyExist("FT")) { 936 if (pFieldDict->KeyExist("FT")) {
(...skipping 14 matching lines...) Expand all
963 if (ToReference(pTObj)) { 951 if (ToReference(pTObj)) {
964 CPDF_Object* pClone = pTObj->Clone(TRUE); 952 CPDF_Object* pClone = pTObj->Clone(TRUE);
965 if (pClone) 953 if (pClone)
966 pDict->SetAt("T", pClone); 954 pDict->SetAt("T", pClone);
967 else 955 else
968 pDict->SetAtName("T", ""); 956 pDict->SetAtName("T", "");
969 } 957 }
970 m_pFieldTree->SetField(csWName, pField); 958 m_pFieldTree->SetField(csWName, pField);
971 } 959 }
972 CPDF_Array* pKids = pFieldDict->GetArray("Kids"); 960 CPDF_Array* pKids = pFieldDict->GetArray("Kids");
973 if (pKids == NULL) { 961 if (!pKids) {
974 if (pFieldDict->GetString("Subtype") == "Widget") { 962 if (pFieldDict->GetString("Subtype") == "Widget") {
975 AddControl(pField, pFieldDict); 963 AddControl(pField, pFieldDict);
976 } 964 }
977 } else { 965 } else {
978 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { 966 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) {
979 CPDF_Dictionary* pKid = pKids->GetDict(i); 967 CPDF_Dictionary* pKid = pKids->GetDict(i);
980 if (pKid == NULL) { 968 if (!pKid) {
981 continue; 969 continue;
982 } 970 }
983 if (pKid->GetString("Subtype") != "Widget") { 971 if (pKid->GetString("Subtype") != "Widget") {
984 continue; 972 continue;
985 } 973 }
986 AddControl(pField, pKid); 974 AddControl(pField, pKid);
987 } 975 }
988 } 976 }
989 return pField; 977 return pField;
990 } 978 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 fields.push_back(m_pFieldTree->m_Root.GetField(i)); 1031 fields.push_back(m_pFieldTree->m_Root.GetField(i));
1044 return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec); 1032 return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec);
1045 } 1033 }
1046 1034
1047 CFDF_Document* CPDF_InterForm::ExportToFDF( 1035 CFDF_Document* CPDF_InterForm::ExportToFDF(
1048 const CFX_WideStringC& pdf_path, 1036 const CFX_WideStringC& pdf_path,
1049 const std::vector<CPDF_FormField*>& fields, 1037 const std::vector<CPDF_FormField*>& fields,
1050 bool bIncludeOrExclude, 1038 bool bIncludeOrExclude,
1051 bool bSimpleFileSpec) const { 1039 bool bSimpleFileSpec) const {
1052 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc(); 1040 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc();
1053 if (pDoc == NULL) { 1041 if (!pDoc) {
1054 return NULL; 1042 return NULL;
1055 } 1043 }
1056 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDict("FDF"); 1044 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDict("FDF");
1057 if (!pdf_path.IsEmpty()) { 1045 if (!pdf_path.IsEmpty()) {
1058 if (bSimpleFileSpec) { 1046 if (bSimpleFileSpec) {
1059 CFX_WideString wsFilePath = FILESPEC_EncodeFileName(pdf_path); 1047 CFX_WideString wsFilePath = FILESPEC_EncodeFileName(pdf_path);
1060 pMainDict->SetAtString("F", CFX_ByteString::FromUnicode(wsFilePath)); 1048 pMainDict->SetAtString("F", CFX_ByteString::FromUnicode(wsFilePath));
1061 pMainDict->SetAtString("UF", PDF_EncodeText(wsFilePath)); 1049 pMainDict->SetAtString("UF", PDF_EncodeText(wsFilePath));
1062 } else { 1050 } else {
1063 CPDF_FileSpec filespec; 1051 CPDF_FileSpec filespec;
1064 filespec.SetFileName(pdf_path); 1052 filespec.SetFileName(pdf_path);
1065 pMainDict->SetAt("F", static_cast<CPDF_Object*>(filespec)); 1053 pMainDict->SetAt("F", static_cast<CPDF_Object*>(filespec));
1066 } 1054 }
1067 } 1055 }
1068 CPDF_Array* pFields = CPDF_Array::Create(); 1056 CPDF_Array* pFields = CPDF_Array::Create();
1069 if (pFields == NULL) { 1057 if (!pFields) {
1070 return NULL; 1058 return NULL;
1071 } 1059 }
1072 pMainDict->SetAt("Fields", pFields); 1060 pMainDict->SetAt("Fields", pFields);
1073 int nCount = m_pFieldTree->m_Root.CountFields(); 1061 int nCount = m_pFieldTree->m_Root.CountFields();
1074 for (int i = 0; i < nCount; i++) { 1062 for (int i = 0; i < nCount; i++) {
1075 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); 1063 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i);
1076 if (pField == NULL || pField->GetType() == CPDF_FormField::PushButton) { 1064 if (!pField || pField->GetType() == CPDF_FormField::PushButton) {
1077 continue; 1065 continue;
1078 } 1066 }
1079 FX_DWORD dwFlags = pField->GetFieldFlags(); 1067 FX_DWORD dwFlags = pField->GetFieldFlags();
1080 if (dwFlags & 0x04) 1068 if (dwFlags & 0x04)
1081 continue; 1069 continue;
1082 1070
1083 auto it = std::find(fields.begin(), fields.end(), pField); 1071 auto it = std::find(fields.begin(), fields.end(), pField);
1084 if (bIncludeOrExclude == (it != fields.end())) { 1072 if (bIncludeOrExclude == (it != fields.end())) {
1085 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetString("V").IsEmpty()) 1073 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetString("V").IsEmpty())
1086 continue; 1074 continue;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 int nLevel) { 1143 int nLevel) {
1156 CFX_WideString name; 1144 CFX_WideString name;
1157 if (!parent_name.IsEmpty()) { 1145 if (!parent_name.IsEmpty()) {
1158 name = parent_name + L"."; 1146 name = parent_name + L".";
1159 } 1147 }
1160 name += pFieldDict->GetUnicodeText("T"); 1148 name += pFieldDict->GetUnicodeText("T");
1161 CPDF_Array* pKids = pFieldDict->GetArray("Kids"); 1149 CPDF_Array* pKids = pFieldDict->GetArray("Kids");
1162 if (pKids) { 1150 if (pKids) {
1163 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { 1151 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) {
1164 CPDF_Dictionary* pKid = pKids->GetDict(i); 1152 CPDF_Dictionary* pKid = pKids->GetDict(i);
1165 if (pKid == NULL) { 1153 if (!pKid) {
1166 continue; 1154 continue;
1167 } 1155 }
1168 if (nLevel <= nMaxRecursion) { 1156 if (nLevel <= nMaxRecursion) {
1169 FDF_ImportField(pKid, name, bNotify, nLevel + 1); 1157 FDF_ImportField(pKid, name, bNotify, nLevel + 1);
1170 } 1158 }
1171 } 1159 }
1172 return; 1160 return;
1173 } 1161 }
1174 if (!pFieldDict->KeyExist("V")) { 1162 if (!pFieldDict->KeyExist("V")) {
1175 return; 1163 return;
1176 } 1164 }
1177 CPDF_FormField* pField = m_pFieldTree->GetField(name); 1165 CPDF_FormField* pField = m_pFieldTree->GetField(name);
1178 if (pField == NULL) { 1166 if (!pField) {
1179 return; 1167 return;
1180 } 1168 }
1181 CFX_WideString csWValue; 1169 CFX_WideString csWValue;
1182 FPDFDOC_FDF_GetFieldValue(pFieldDict, csWValue, m_bsEncoding); 1170 FPDFDOC_FDF_GetFieldValue(pFieldDict, csWValue, m_bsEncoding);
1183 int iType = pField->GetFieldType(); 1171 int iType = pField->GetFieldType();
1184 if (bNotify && m_pFormNotify) { 1172 if (bNotify && m_pFormNotify) {
1185 int iRet = 0; 1173 int iRet = 0;
1186 if (iType == FIELDTYPE_LISTBOX) { 1174 if (iType == FIELDTYPE_LISTBOX) {
1187 iRet = m_pFormNotify->BeforeSelectionChange(pField, csWValue); 1175 iRet = m_pFormNotify->BeforeSelectionChange(pField, csWValue);
1188 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) { 1176 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) {
(...skipping 22 matching lines...) Expand all
1211 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) { 1199 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) {
1212 m_pFormNotify->AfterValueChange(pField); 1200 m_pFormNotify->AfterValueChange(pField);
1213 } 1201 }
1214 } 1202 }
1215 if (CPDF_InterForm::m_bUpdateAP) { 1203 if (CPDF_InterForm::m_bUpdateAP) {
1216 pField->UpdateAP(NULL); 1204 pField->UpdateAP(NULL);
1217 } 1205 }
1218 } 1206 }
1219 FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF, 1207 FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF,
1220 FX_BOOL bNotify) { 1208 FX_BOOL bNotify) {
1221 if (pFDF == NULL) { 1209 if (!pFDF) {
1222 return FALSE; 1210 return FALSE;
1223 } 1211 }
1224 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF"); 1212 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF");
1225 if (pMainDict == NULL) { 1213 if (!pMainDict) {
1226 return FALSE; 1214 return FALSE;
1227 } 1215 }
1228 CPDF_Array* pFields = pMainDict->GetArray("Fields"); 1216 CPDF_Array* pFields = pMainDict->GetArray("Fields");
1229 if (pFields == NULL) { 1217 if (!pFields) {
1230 return FALSE; 1218 return FALSE;
1231 } 1219 }
1232 m_bsEncoding = pMainDict->GetString("Encoding"); 1220 m_bsEncoding = pMainDict->GetString("Encoding");
1233 if (bNotify && m_pFormNotify) { 1221 if (bNotify && m_pFormNotify) {
1234 int iRet = m_pFormNotify->BeforeFormImportData(this); 1222 int iRet = m_pFormNotify->BeforeFormImportData(this);
1235 if (iRet < 0) { 1223 if (iRet < 0) {
1236 return FALSE; 1224 return FALSE;
1237 } 1225 }
1238 } 1226 }
1239 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) { 1227 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) {
1240 CPDF_Dictionary* pField = pFields->GetDict(i); 1228 CPDF_Dictionary* pField = pFields->GetDict(i);
1241 if (pField == NULL) { 1229 if (!pField) {
1242 continue; 1230 continue;
1243 } 1231 }
1244 FDF_ImportField(pField, L"", bNotify); 1232 FDF_ImportField(pField, L"", bNotify);
1245 } 1233 }
1246 if (bNotify && m_pFormNotify) { 1234 if (bNotify && m_pFormNotify) {
1247 m_pFormNotify->AfterFormImportData(this); 1235 m_pFormNotify->AfterFormImportData(this);
1248 } 1236 }
1249 return TRUE; 1237 return TRUE;
1250 } 1238 }
1251 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) { 1239 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) {
1252 m_pFormNotify = (CPDF_FormNotify*)pNotify; 1240 m_pFormNotify = (CPDF_FormNotify*)pNotify;
1253 } 1241 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698