OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
10 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" | 10 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 strcpy(lf.lfFaceName, pcsFontName); | 530 strcpy(lf.lfFaceName, pcsFontName); |
531 } | 531 } |
532 return RetrieveSpecificFont(lf); | 532 return RetrieveSpecificFont(lf); |
533 } | 533 } |
534 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 534 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
535 | 535 |
536 } // namespace | 536 } // namespace |
537 | 537 |
538 class CFieldTree { | 538 class CFieldTree { |
539 public: | 539 public: |
540 struct Node { | 540 class Node { |
541 Node* parent; | 541 public: |
542 CFX_ArrayTemplate<Node*> children; | 542 Node() : m_pField(nullptr) {} |
543 CFX_WideString short_name; | 543 Node(const CFX_WideString& short_name, CPDF_FormField* pField) |
544 CPDF_FormField* field_ptr; | 544 : m_ShortName(short_name), m_pField(pField) {} |
545 int CountFields(int nLevel = 0) { | 545 ~Node() {} |
546 if (nLevel > nMaxRecursion) | |
547 return 0; | |
548 if (field_ptr) | |
549 return 1; | |
550 | 546 |
551 int count = 0; | 547 void AddChildNode(Node* pNode) { m_Children.push_back(pNode); } |
552 for (int i = 0; i < children.GetSize(); i++) | 548 |
553 count += children.GetAt(i)->CountFields(nLevel + 1); | 549 size_t GetChildrenCount() const { return m_Children.size(); } |
554 return count; | 550 |
| 551 Node* GetChildAt(size_t i) { return m_Children[i]; } |
| 552 const Node* GetChildAt(size_t i) const { return m_Children[i]; } |
| 553 |
| 554 CPDF_FormField* GetFieldAtIndex(int index) { |
| 555 int nFieldsToGo = index; |
| 556 return GetFieldInternal(&nFieldsToGo); |
555 } | 557 } |
556 | 558 |
557 CPDF_FormField* GetField(int* fields_to_go) { | 559 int CountFields() const { return CountFieldsInternal(0); } |
558 if (field_ptr) { | |
559 if (*fields_to_go == 0) | |
560 return field_ptr; | |
561 | 560 |
562 --*fields_to_go; | 561 void SetField(CPDF_FormField* pField) { m_pField = pField; } |
| 562 |
| 563 CPDF_FormField* GetField() { return m_pField; } |
| 564 const CPDF_FormField* GetField() const { return m_pField; } |
| 565 |
| 566 const CFX_WideString& GetShortName() const { return m_ShortName; } |
| 567 |
| 568 private: |
| 569 CPDF_FormField* GetFieldInternal(int* pFieldsToGo) { |
| 570 if (m_pField) { |
| 571 if (*pFieldsToGo == 0) |
| 572 return m_pField; |
| 573 |
| 574 --*pFieldsToGo; |
563 return nullptr; | 575 return nullptr; |
564 } | 576 } |
565 for (int i = 0; i < children.GetSize(); i++) { | 577 for (size_t i = 0; i < GetChildrenCount(); ++i) { |
566 if (CPDF_FormField* pField = children.GetAt(i)->GetField(fields_to_go)) | 578 CPDF_FormField* pField = GetChildAt(i)->GetFieldInternal(pFieldsToGo); |
| 579 if (pField) |
567 return pField; | 580 return pField; |
568 } | 581 } |
569 return nullptr; | 582 return nullptr; |
570 } | 583 } |
571 | 584 |
572 CPDF_FormField* GetField(int index) { | 585 int CountFieldsInternal(int nLevel) const { |
573 int fields_to_go = index; | 586 if (nLevel > nMaxRecursion) |
574 return GetField(&fields_to_go); | 587 return 0; |
| 588 if (m_pField) |
| 589 return 1; |
| 590 |
| 591 int count = 0; |
| 592 for (size_t i = 0; i < GetChildrenCount(); ++i) |
| 593 count += GetChildAt(i)->CountFieldsInternal(nLevel + 1); |
| 594 return count; |
575 } | 595 } |
| 596 |
| 597 std::vector<Node*> m_Children; |
| 598 CFX_WideString m_ShortName; |
| 599 CPDF_FormField* m_pField; |
576 }; | 600 }; |
577 | 601 |
578 CFieldTree(); | 602 CFieldTree(); |
579 ~CFieldTree(); | 603 ~CFieldTree(); |
580 | 604 |
581 void SetField(const CFX_WideString& full_name, CPDF_FormField* field_ptr); | 605 void SetField(const CFX_WideString& full_name, CPDF_FormField* pField); |
582 CPDF_FormField* GetField(const CFX_WideString& full_name); | 606 CPDF_FormField* GetField(const CFX_WideString& full_name); |
583 CPDF_FormField* RemoveField(const CFX_WideString& full_name); | |
584 void RemoveAll(); | 607 void RemoveAll(); |
585 | 608 |
586 Node* FindNode(const CFX_WideString& full_name); | 609 Node* FindNode(const CFX_WideString& full_name); |
587 Node* AddChild(Node* pParent, | 610 Node* AddChild(Node* pParent, |
588 const CFX_WideString& short_name, | 611 const CFX_WideString& short_name, |
589 CPDF_FormField* field_ptr); | 612 CPDF_FormField* pField); |
590 void RemoveNode(Node* pNode, int nLevel = 0); | 613 void RemoveNode(Node* pNode, int nLevel = 0); |
591 | 614 |
592 Node* Lookup(Node* pParent, const CFX_WideString& short_name); | 615 Node* Lookup(Node* pParent, const CFX_WideString& short_name); |
593 | 616 |
594 Node m_Root; | 617 Node m_Root; |
595 }; | 618 }; |
596 | 619 |
597 CFieldTree::CFieldTree() { | 620 CFieldTree::CFieldTree() {} |
598 m_Root.parent = nullptr; | |
599 m_Root.field_ptr = nullptr; | |
600 } | |
601 | 621 |
602 CFieldTree::~CFieldTree() { | 622 CFieldTree::~CFieldTree() { |
603 RemoveAll(); | 623 RemoveAll(); |
604 } | 624 } |
605 | 625 |
606 CFieldTree::Node* CFieldTree::AddChild(Node* pParent, | 626 CFieldTree::Node* CFieldTree::AddChild(Node* pParent, |
607 const CFX_WideString& short_name, | 627 const CFX_WideString& short_name, |
608 CPDF_FormField* field_ptr) { | 628 CPDF_FormField* pField) { |
609 if (!pParent) | 629 if (!pParent) |
610 return nullptr; | 630 return nullptr; |
611 | 631 |
612 Node* pNode = new Node; | 632 Node* pNode = new Node(short_name, pField); |
613 pNode->parent = pParent; | 633 pParent->AddChildNode(pNode); |
614 pNode->short_name = short_name; | |
615 pNode->field_ptr = field_ptr; | |
616 pParent->children.Add(pNode); | |
617 return pNode; | 634 return pNode; |
618 } | 635 } |
619 | 636 |
620 void CFieldTree::RemoveNode(Node* pNode, int nLevel) { | 637 void CFieldTree::RemoveNode(Node* pNode, int nLevel) { |
621 if (!pNode) | 638 if (!pNode) |
622 return; | 639 return; |
| 640 |
623 if (nLevel <= nMaxRecursion) { | 641 if (nLevel <= nMaxRecursion) { |
624 for (int i = 0; i < pNode->children.GetSize(); i++) | 642 for (size_t i = 0; i < pNode->GetChildrenCount(); ++i) |
625 RemoveNode(pNode->children[i], nLevel + 1); | 643 RemoveNode(pNode->GetChildAt(i), nLevel + 1); |
626 } | 644 } |
627 delete pNode; | 645 delete pNode; |
628 } | 646 } |
629 | 647 |
630 CFieldTree::Node* CFieldTree::Lookup(Node* pParent, | 648 CFieldTree::Node* CFieldTree::Lookup(Node* pParent, |
631 const CFX_WideString& short_name) { | 649 const CFX_WideString& short_name) { |
632 if (!pParent) | 650 if (!pParent) |
633 return nullptr; | 651 return nullptr; |
634 | 652 |
635 for (int i = 0; i < pParent->children.GetSize(); i++) { | 653 for (size_t i = 0; i < pParent->GetChildrenCount(); ++i) { |
636 Node* pNode = pParent->children[i]; | 654 Node* pNode = pParent->GetChildAt(i); |
637 if (pNode->short_name == short_name) | 655 if (pNode->GetShortName() == short_name) |
638 return pNode; | 656 return pNode; |
639 } | 657 } |
640 return nullptr; | 658 return nullptr; |
641 } | 659 } |
642 | 660 |
643 void CFieldTree::RemoveAll() { | 661 void CFieldTree::RemoveAll() { |
644 for (int i = 0; i < m_Root.children.GetSize(); i++) | 662 for (size_t i = 0; i < m_Root.GetChildrenCount(); ++i) |
645 RemoveNode(m_Root.children[i]); | 663 RemoveNode(m_Root.GetChildAt(i)); |
646 } | 664 } |
647 | 665 |
648 void CFieldTree::SetField(const CFX_WideString& full_name, | 666 void CFieldTree::SetField(const CFX_WideString& full_name, |
649 CPDF_FormField* field_ptr) { | 667 CPDF_FormField* pField) { |
650 if (full_name == L"") | 668 if (full_name.IsEmpty()) |
651 return; | 669 return; |
652 | 670 |
653 CFieldNameExtractor name_extractor(full_name); | 671 CFieldNameExtractor name_extractor(full_name); |
654 const FX_WCHAR* pName; | 672 const FX_WCHAR* pName; |
655 FX_STRSIZE nLength; | 673 FX_STRSIZE nLength; |
656 name_extractor.GetNext(pName, nLength); | 674 name_extractor.GetNext(pName, nLength); |
657 Node* pNode = &m_Root; | 675 Node* pNode = &m_Root; |
658 Node* pLast = nullptr; | 676 Node* pLast = nullptr; |
659 while (nLength > 0) { | 677 while (nLength > 0) { |
660 pLast = pNode; | 678 pLast = pNode; |
661 CFX_WideString name = CFX_WideString(pName, nLength); | 679 CFX_WideString name = CFX_WideString(pName, nLength); |
662 pNode = Lookup(pLast, name); | 680 pNode = Lookup(pLast, name); |
663 if (!pNode) | 681 if (!pNode) |
664 pNode = AddChild(pLast, name, nullptr); | 682 pNode = AddChild(pLast, name, nullptr); |
665 | 683 |
666 name_extractor.GetNext(pName, nLength); | 684 name_extractor.GetNext(pName, nLength); |
667 } | 685 } |
668 if (pNode != &m_Root) | 686 if (pNode != &m_Root) |
669 pNode->field_ptr = field_ptr; | 687 pNode->SetField(pField); |
670 } | 688 } |
671 | 689 |
672 CPDF_FormField* CFieldTree::GetField(const CFX_WideString& full_name) { | 690 CPDF_FormField* CFieldTree::GetField(const CFX_WideString& full_name) { |
673 if (full_name == L"") | 691 if (full_name.IsEmpty()) |
674 return nullptr; | 692 return nullptr; |
675 | 693 |
676 CFieldNameExtractor name_extractor(full_name); | 694 CFieldNameExtractor name_extractor(full_name); |
677 const FX_WCHAR* pName; | |
678 FX_STRSIZE nLength; | |
679 name_extractor.GetNext(pName, nLength); | |
680 Node* pNode = &m_Root; | |
681 Node* pLast = nullptr; | |
682 while (nLength > 0 && pNode) { | |
683 pLast = pNode; | |
684 CFX_WideString name = CFX_WideString(pName, nLength); | |
685 pNode = Lookup(pLast, name); | |
686 name_extractor.GetNext(pName, nLength); | |
687 } | |
688 return pNode ? pNode->field_ptr : nullptr; | |
689 } | |
690 | |
691 CPDF_FormField* CFieldTree::RemoveField(const CFX_WideString& full_name) { | |
692 if (full_name == L"") | |
693 return nullptr; | |
694 | |
695 CFieldNameExtractor name_extractor(full_name); | |
696 const FX_WCHAR* pName; | 695 const FX_WCHAR* pName; |
697 FX_STRSIZE nLength; | 696 FX_STRSIZE nLength; |
698 name_extractor.GetNext(pName, nLength); | 697 name_extractor.GetNext(pName, nLength); |
699 Node* pNode = &m_Root; | 698 Node* pNode = &m_Root; |
700 Node* pLast = nullptr; | 699 Node* pLast = nullptr; |
701 while (nLength > 0 && pNode) { | 700 while (nLength > 0 && pNode) { |
702 pLast = pNode; | 701 pLast = pNode; |
703 CFX_WideString name = CFX_WideString(pName, nLength); | 702 CFX_WideString name = CFX_WideString(pName, nLength); |
704 pNode = Lookup(pLast, name); | 703 pNode = Lookup(pLast, name); |
705 name_extractor.GetNext(pName, nLength); | 704 name_extractor.GetNext(pName, nLength); |
706 } | 705 } |
707 | 706 return pNode ? pNode->GetField() : nullptr; |
708 if (pNode && pNode != &m_Root) { | |
709 for (int i = 0; i < pLast->children.GetSize(); i++) { | |
710 if (pNode == pLast->children[i]) { | |
711 pLast->children.RemoveAt(i); | |
712 break; | |
713 } | |
714 } | |
715 CPDF_FormField* pField = pNode->field_ptr; | |
716 RemoveNode(pNode); | |
717 return pField; | |
718 } | |
719 return nullptr; | |
720 } | 707 } |
721 | 708 |
722 CFieldTree::Node* CFieldTree::FindNode(const CFX_WideString& full_name) { | 709 CFieldTree::Node* CFieldTree::FindNode(const CFX_WideString& full_name) { |
723 if (full_name == L"") | 710 if (full_name.IsEmpty()) |
724 return nullptr; | 711 return nullptr; |
725 | 712 |
726 CFieldNameExtractor name_extractor(full_name); | 713 CFieldNameExtractor name_extractor(full_name); |
727 const FX_WCHAR* pName; | 714 const FX_WCHAR* pName; |
728 FX_STRSIZE nLength; | 715 FX_STRSIZE nLength; |
729 name_extractor.GetNext(pName, nLength); | 716 name_extractor.GetNext(pName, nLength); |
730 Node* pNode = &m_Root; | 717 Node* pNode = &m_Root; |
731 Node* pLast = nullptr; | 718 Node* pLast = nullptr; |
732 while (nLength > 0 && pNode) { | 719 while (nLength > 0 && pNode) { |
733 pLast = pNode; | 720 pLast = pNode; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 for (size_t i = 0; i < pFields->GetCount(); i++) | 813 for (size_t i = 0; i < pFields->GetCount(); i++) |
827 LoadField(pFields->GetDictAt(i)); | 814 LoadField(pFields->GetDictAt(i)); |
828 } | 815 } |
829 | 816 |
830 CPDF_InterForm::~CPDF_InterForm() { | 817 CPDF_InterForm::~CPDF_InterForm() { |
831 for (auto it : m_ControlMap) | 818 for (auto it : m_ControlMap) |
832 delete it.second; | 819 delete it.second; |
833 | 820 |
834 int nCount = m_pFieldTree->m_Root.CountFields(); | 821 int nCount = m_pFieldTree->m_Root.CountFields(); |
835 for (int i = 0; i < nCount; ++i) | 822 for (int i = 0; i < nCount; ++i) |
836 delete m_pFieldTree->m_Root.GetField(i); | 823 delete m_pFieldTree->m_Root.GetFieldAtIndex(i); |
837 } | 824 } |
838 | 825 |
839 FX_BOOL CPDF_InterForm::s_bUpdateAP = TRUE; | 826 FX_BOOL CPDF_InterForm::s_bUpdateAP = TRUE; |
840 | 827 |
841 FX_BOOL CPDF_InterForm::IsUpdateAPEnabled() { | 828 FX_BOOL CPDF_InterForm::IsUpdateAPEnabled() { |
842 return s_bUpdateAP; | 829 return s_bUpdateAP; |
843 } | 830 } |
844 | 831 |
845 void CPDF_InterForm::SetUpdateAP(FX_BOOL bUpdateAP) { | 832 void CPDF_InterForm::SetUpdateAP(FX_BOOL bUpdateAP) { |
846 s_bUpdateAP = bUpdateAP; | 833 s_bUpdateAP = bUpdateAP; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 while (iPos < iLength && csNewFieldName[iPos] != L'.') | 991 while (iPos < iLength && csNewFieldName[iPos] != L'.') |
1005 csSub += csNewFieldName[iPos++]; | 992 csSub += csNewFieldName[iPos++]; |
1006 for (int i = csSub.GetLength() - 1; i > -1; i--) { | 993 for (int i = csSub.GetLength() - 1; i > -1; i--) { |
1007 if (csSub[i] == L' ' || csSub[i] == L'.') | 994 if (csSub[i] == L' ' || csSub[i] == L'.') |
1008 csSub.SetAt(i, L'\0'); | 995 csSub.SetAt(i, L'\0'); |
1009 else | 996 else |
1010 break; | 997 break; |
1011 } | 998 } |
1012 uint32_t dwCount = m_pFieldTree->m_Root.CountFields(); | 999 uint32_t dwCount = m_pFieldTree->m_Root.CountFields(); |
1013 for (uint32_t m = 0; m < dwCount; m++) { | 1000 for (uint32_t m = 0; m < dwCount; m++) { |
1014 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(m); | 1001 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(m); |
1015 if (!pField) | 1002 if (!pField) |
1016 continue; | 1003 continue; |
1017 if (pField == pExcludedField) { | 1004 if (pField == pExcludedField) { |
1018 if (pExcludedControl) { | 1005 if (pExcludedControl) { |
1019 if (pField->CountControls() < 2) | 1006 if (pField->CountControls() < 2) |
1020 continue; | 1007 continue; |
1021 } else { | 1008 } else { |
1022 continue; | 1009 continue; |
1023 } | 1010 } |
1024 } | 1011 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1104 uint32_t CPDF_InterForm::CountFields(const CFX_WideString& csFieldName) { | 1091 uint32_t CPDF_InterForm::CountFields(const CFX_WideString& csFieldName) { |
1105 if (csFieldName.IsEmpty()) | 1092 if (csFieldName.IsEmpty()) |
1106 return (uint32_t)m_pFieldTree->m_Root.CountFields(); | 1093 return (uint32_t)m_pFieldTree->m_Root.CountFields(); |
1107 | 1094 |
1108 CFieldTree::Node* pNode = m_pFieldTree->FindNode(csFieldName); | 1095 CFieldTree::Node* pNode = m_pFieldTree->FindNode(csFieldName); |
1109 return pNode ? pNode->CountFields() : 0; | 1096 return pNode ? pNode->CountFields() : 0; |
1110 } | 1097 } |
1111 | 1098 |
1112 CPDF_FormField* CPDF_InterForm::GetField(uint32_t index, | 1099 CPDF_FormField* CPDF_InterForm::GetField(uint32_t index, |
1113 const CFX_WideString& csFieldName) { | 1100 const CFX_WideString& csFieldName) { |
1114 if (csFieldName == L"") | 1101 if (csFieldName.IsEmpty()) |
1115 return m_pFieldTree->m_Root.GetField(index); | 1102 return m_pFieldTree->m_Root.GetFieldAtIndex(index); |
1116 | 1103 |
1117 CFieldTree::Node* pNode = m_pFieldTree->FindNode(csFieldName); | 1104 CFieldTree::Node* pNode = m_pFieldTree->FindNode(csFieldName); |
1118 return pNode ? pNode->GetField(index) : nullptr; | 1105 return pNode ? pNode->GetFieldAtIndex(index) : nullptr; |
1119 } | 1106 } |
1120 | 1107 |
1121 CPDF_FormField* CPDF_InterForm::GetFieldByDict( | 1108 CPDF_FormField* CPDF_InterForm::GetFieldByDict( |
1122 CPDF_Dictionary* pFieldDict) const { | 1109 CPDF_Dictionary* pFieldDict) const { |
1123 if (!pFieldDict) | 1110 if (!pFieldDict) |
1124 return nullptr; | 1111 return nullptr; |
1125 | 1112 |
1126 CFX_WideString csWName = FPDF_GetFullName(pFieldDict); | 1113 CFX_WideString csWName = FPDF_GetFullName(pFieldDict); |
1127 return m_pFieldTree->GetField(csWName); | 1114 return m_pFieldTree->GetField(csWName); |
1128 } | 1115 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 } | 1265 } |
1279 | 1266 |
1280 bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields, | 1267 bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields, |
1281 bool bIncludeOrExclude, | 1268 bool bIncludeOrExclude, |
1282 bool bNotify) { | 1269 bool bNotify) { |
1283 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) | 1270 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) |
1284 return false; | 1271 return false; |
1285 | 1272 |
1286 int nCount = m_pFieldTree->m_Root.CountFields(); | 1273 int nCount = m_pFieldTree->m_Root.CountFields(); |
1287 for (int i = 0; i < nCount; ++i) { | 1274 for (int i = 0; i < nCount; ++i) { |
1288 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); | 1275 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); |
1289 if (!pField) | 1276 if (!pField) |
1290 continue; | 1277 continue; |
1291 | 1278 |
1292 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) | 1279 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) |
1293 pField->ResetField(bNotify); | 1280 pField->ResetField(bNotify); |
1294 } | 1281 } |
1295 if (bNotify && m_pFormNotify) | 1282 if (bNotify && m_pFormNotify) |
1296 m_pFormNotify->AfterFormReset(this); | 1283 m_pFormNotify->AfterFormReset(this); |
1297 return true; | 1284 return true; |
1298 } | 1285 } |
1299 | 1286 |
1300 bool CPDF_InterForm::ResetForm(bool bNotify) { | 1287 bool CPDF_InterForm::ResetForm(bool bNotify) { |
1301 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) | 1288 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) |
1302 return false; | 1289 return false; |
1303 | 1290 |
1304 int nCount = m_pFieldTree->m_Root.CountFields(); | 1291 int nCount = m_pFieldTree->m_Root.CountFields(); |
1305 for (int i = 0; i < nCount; ++i) { | 1292 for (int i = 0; i < nCount; ++i) { |
1306 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); | 1293 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); |
1307 if (!pField) | 1294 if (!pField) |
1308 continue; | 1295 continue; |
1309 | 1296 |
1310 pField->ResetField(bNotify); | 1297 pField->ResetField(bNotify); |
1311 } | 1298 } |
1312 if (bNotify && m_pFormNotify) | 1299 if (bNotify && m_pFormNotify) |
1313 m_pFormNotify->AfterFormReset(this); | 1300 m_pFormNotify->AfterFormReset(this); |
1314 return true; | 1301 return true; |
1315 } | 1302 } |
1316 | 1303 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1404 CPDF_Object* pClone = pTObj->CloneDirectObject(); | 1391 CPDF_Object* pClone = pTObj->CloneDirectObject(); |
1405 if (pClone) | 1392 if (pClone) |
1406 pDict->SetFor("T", pClone); | 1393 pDict->SetFor("T", pClone); |
1407 else | 1394 else |
1408 pDict->SetNameFor("T", ""); | 1395 pDict->SetNameFor("T", ""); |
1409 } | 1396 } |
1410 m_pFieldTree->SetField(csWName, pField); | 1397 m_pFieldTree->SetField(csWName, pField); |
1411 } | 1398 } |
1412 | 1399 |
1413 CPDF_Array* pKids = pFieldDict->GetArrayFor("Kids"); | 1400 CPDF_Array* pKids = pFieldDict->GetArrayFor("Kids"); |
1414 if (!pKids) { | 1401 if (pKids) { |
1415 if (pFieldDict->GetStringFor("Subtype") == "Widget") | |
1416 AddControl(pField, pFieldDict); | |
1417 } else { | |
1418 for (size_t i = 0; i < pKids->GetCount(); i++) { | 1402 for (size_t i = 0; i < pKids->GetCount(); i++) { |
1419 CPDF_Dictionary* pKid = pKids->GetDictAt(i); | 1403 CPDF_Dictionary* pKid = pKids->GetDictAt(i); |
1420 if (!pKid) | 1404 if (!pKid) |
1421 continue; | 1405 continue; |
1422 if (pKid->GetStringFor("Subtype") != "Widget") | 1406 if (pKid->GetStringFor("Subtype") != "Widget") |
1423 continue; | 1407 continue; |
1424 | 1408 |
1425 AddControl(pField, pKid); | 1409 AddControl(pField, pKid); |
1426 } | 1410 } |
| 1411 } else { |
| 1412 if (pFieldDict->GetStringFor("Subtype") == "Widget") |
| 1413 AddControl(pField, pFieldDict); |
1427 } | 1414 } |
1428 return pField; | 1415 return pField; |
1429 } | 1416 } |
1430 | 1417 |
1431 CPDF_FormControl* CPDF_InterForm::AddControl(CPDF_FormField* pField, | 1418 CPDF_FormControl* CPDF_InterForm::AddControl(CPDF_FormField* pField, |
1432 CPDF_Dictionary* pWidgetDict) { | 1419 CPDF_Dictionary* pWidgetDict) { |
1433 const auto it = m_ControlMap.find(pWidgetDict); | 1420 const auto it = m_ControlMap.find(pWidgetDict); |
1434 if (it != m_ControlMap.end()) | 1421 if (it != m_ControlMap.end()) |
1435 return it->second; | 1422 return it->second; |
1436 | 1423 |
1437 CPDF_FormControl* pControl = new CPDF_FormControl(pField, pWidgetDict); | 1424 CPDF_FormControl* pControl = new CPDF_FormControl(pField, pWidgetDict); |
1438 m_ControlMap[pWidgetDict] = pControl; | 1425 m_ControlMap[pWidgetDict] = pControl; |
1439 pField->m_ControlList.Add(pControl); | 1426 pField->m_ControlList.Add(pControl); |
1440 return pControl; | 1427 return pControl; |
1441 } | 1428 } |
1442 | 1429 |
1443 CPDF_FormField* CPDF_InterForm::CheckRequiredFields( | 1430 CPDF_FormField* CPDF_InterForm::CheckRequiredFields( |
1444 const std::vector<CPDF_FormField*>* fields, | 1431 const std::vector<CPDF_FormField*>* fields, |
1445 bool bIncludeOrExclude) const { | 1432 bool bIncludeOrExclude) const { |
1446 int nCount = m_pFieldTree->m_Root.CountFields(); | 1433 int nCount = m_pFieldTree->m_Root.CountFields(); |
1447 for (int i = 0; i < nCount; ++i) { | 1434 for (int i = 0; i < nCount; ++i) { |
1448 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); | 1435 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); |
1449 if (!pField) | 1436 if (!pField) |
1450 continue; | 1437 continue; |
1451 | 1438 |
1452 int32_t iType = pField->GetType(); | 1439 int32_t iType = pField->GetType(); |
1453 if (iType == CPDF_FormField::PushButton || | 1440 if (iType == CPDF_FormField::PushButton || |
1454 iType == CPDF_FormField::CheckBox || iType == CPDF_FormField::ListBox) { | 1441 iType == CPDF_FormField::CheckBox || iType == CPDF_FormField::ListBox) { |
1455 continue; | 1442 continue; |
1456 } | 1443 } |
1457 uint32_t dwFlags = pField->GetFieldFlags(); | 1444 uint32_t dwFlags = pField->GetFieldFlags(); |
1458 // TODO(thestig): Look up these magic numbers and add constants for them. | 1445 // TODO(thestig): Look up these magic numbers and add constants for them. |
(...skipping 10 matching lines...) Expand all Loading... |
1469 } | 1456 } |
1470 } | 1457 } |
1471 return nullptr; | 1458 return nullptr; |
1472 } | 1459 } |
1473 | 1460 |
1474 CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, | 1461 CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, |
1475 bool bSimpleFileSpec) const { | 1462 bool bSimpleFileSpec) const { |
1476 std::vector<CPDF_FormField*> fields; | 1463 std::vector<CPDF_FormField*> fields; |
1477 int nCount = m_pFieldTree->m_Root.CountFields(); | 1464 int nCount = m_pFieldTree->m_Root.CountFields(); |
1478 for (int i = 0; i < nCount; ++i) | 1465 for (int i = 0; i < nCount; ++i) |
1479 fields.push_back(m_pFieldTree->m_Root.GetField(i)); | 1466 fields.push_back(m_pFieldTree->m_Root.GetFieldAtIndex(i)); |
1480 return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec); | 1467 return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec); |
1481 } | 1468 } |
1482 | 1469 |
1483 CFDF_Document* CPDF_InterForm::ExportToFDF( | 1470 CFDF_Document* CPDF_InterForm::ExportToFDF( |
1484 const CFX_WideStringC& pdf_path, | 1471 const CFX_WideStringC& pdf_path, |
1485 const std::vector<CPDF_FormField*>& fields, | 1472 const std::vector<CPDF_FormField*>& fields, |
1486 bool bIncludeOrExclude, | 1473 bool bIncludeOrExclude, |
1487 bool bSimpleFileSpec) const { | 1474 bool bSimpleFileSpec) const { |
1488 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc(); | 1475 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc(); |
1489 if (!pDoc) | 1476 if (!pDoc) |
1490 return nullptr; | 1477 return nullptr; |
1491 | 1478 |
1492 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictFor("FDF"); | 1479 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictFor("FDF"); |
1493 if (!pdf_path.IsEmpty()) { | 1480 if (!pdf_path.IsEmpty()) { |
1494 if (bSimpleFileSpec) { | 1481 if (bSimpleFileSpec) { |
1495 CFX_WideString wsFilePath = CPDF_FileSpec::EncodeFileName(pdf_path); | 1482 CFX_WideString wsFilePath = CPDF_FileSpec::EncodeFileName(pdf_path); |
1496 pMainDict->SetStringFor("F", CFX_ByteString::FromUnicode(wsFilePath)); | 1483 pMainDict->SetStringFor("F", CFX_ByteString::FromUnicode(wsFilePath)); |
1497 pMainDict->SetStringFor("UF", PDF_EncodeText(wsFilePath)); | 1484 pMainDict->SetStringFor("UF", PDF_EncodeText(wsFilePath)); |
1498 } else { | 1485 } else { |
1499 CPDF_FileSpec filespec; | 1486 CPDF_FileSpec filespec; |
1500 filespec.SetFileName(pdf_path); | 1487 filespec.SetFileName(pdf_path); |
1501 pMainDict->SetFor("F", filespec.GetObj()); | 1488 pMainDict->SetFor("F", filespec.GetObj()); |
1502 } | 1489 } |
1503 } | 1490 } |
1504 | 1491 |
1505 CPDF_Array* pFields = new CPDF_Array; | 1492 CPDF_Array* pFields = new CPDF_Array; |
1506 pMainDict->SetFor("Fields", pFields); | 1493 pMainDict->SetFor("Fields", pFields); |
1507 int nCount = m_pFieldTree->m_Root.CountFields(); | 1494 int nCount = m_pFieldTree->m_Root.CountFields(); |
1508 for (int i = 0; i < nCount; i++) { | 1495 for (int i = 0; i < nCount; i++) { |
1509 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); | 1496 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); |
1510 if (!pField || pField->GetType() == CPDF_FormField::PushButton) | 1497 if (!pField || pField->GetType() == CPDF_FormField::PushButton) |
1511 continue; | 1498 continue; |
1512 | 1499 |
1513 uint32_t dwFlags = pField->GetFieldFlags(); | 1500 uint32_t dwFlags = pField->GetFieldFlags(); |
1514 if (dwFlags & 0x04) | 1501 if (dwFlags & 0x04) |
1515 continue; | 1502 continue; |
1516 | 1503 |
1517 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) { | 1504 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) { |
1518 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetStringFor("V").IsEmpty()) | 1505 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetStringFor("V").IsEmpty()) |
1519 continue; | 1506 continue; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1624 FDF_ImportField(pField, L"", bNotify); | 1611 FDF_ImportField(pField, L"", bNotify); |
1625 } | 1612 } |
1626 if (bNotify && m_pFormNotify) | 1613 if (bNotify && m_pFormNotify) |
1627 m_pFormNotify->AfterFormImportData(this); | 1614 m_pFormNotify->AfterFormImportData(this); |
1628 return TRUE; | 1615 return TRUE; |
1629 } | 1616 } |
1630 | 1617 |
1631 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) { | 1618 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) { |
1632 m_pFormNotify = pNotify; | 1619 m_pFormNotify = pNotify; |
1633 } | 1620 } |
OLD | NEW |