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