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 #include "third_party/base/stl_util.h" | 9 #include "third_party/base/stl_util.h" |
10 | 10 |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 m_pDocument(pDocument), | 227 m_pDocument(pDocument), |
228 m_bGenerateAP(bGenerateAP), | 228 m_bGenerateAP(bGenerateAP), |
229 m_pFormDict(nullptr), | 229 m_pFormDict(nullptr), |
230 m_pFieldTree(new CFieldTree), | 230 m_pFieldTree(new CFieldTree), |
231 m_pFormNotify(nullptr), | 231 m_pFormNotify(nullptr), |
232 m_bUpdated(FALSE) { | 232 m_bUpdated(FALSE) { |
233 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); | 233 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); |
234 if (!pRoot) | 234 if (!pRoot) |
235 return; | 235 return; |
236 | 236 |
237 m_pFormDict = pRoot->GetDict("AcroForm"); | 237 m_pFormDict = pRoot->GetDictBy("AcroForm"); |
238 if (!m_pFormDict) | 238 if (!m_pFormDict) |
239 return; | 239 return; |
240 | 240 |
241 CPDF_Array* pFields = m_pFormDict->GetArray("Fields"); | 241 CPDF_Array* pFields = m_pFormDict->GetArrayBy("Fields"); |
242 if (!pFields) | 242 if (!pFields) |
243 return; | 243 return; |
244 | 244 |
245 int count = pFields->GetCount(); | 245 int count = pFields->GetCount(); |
246 for (int i = 0; i < count; i++) { | 246 for (int i = 0; i < count; i++) { |
247 LoadField(pFields->GetDict(i)); | 247 LoadField(pFields->GetDictAt(i)); |
248 } | 248 } |
249 } | 249 } |
250 | 250 |
251 CPDF_InterForm::~CPDF_InterForm() { | 251 CPDF_InterForm::~CPDF_InterForm() { |
252 for (auto it : m_ControlMap) | 252 for (auto it : m_ControlMap) |
253 delete it.second; | 253 delete it.second; |
254 | 254 |
255 int nCount = m_pFieldTree->m_Root.CountFields(); | 255 int nCount = m_pFieldTree->m_Root.CountFields(); |
256 for (int i = 0; i < nCount; ++i) { | 256 for (int i = 0; i < nCount; ++i) { |
257 delete m_pFieldTree->m_Root.GetField(i); | 257 delete m_pFieldTree->m_Root.GetField(i); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 while (m < iMinLen) { | 294 while (m < iMinLen) { |
295 csTmp += '0' + m % 10; | 295 csTmp += '0' + m % 10; |
296 m++; | 296 m++; |
297 } | 297 } |
298 } else { | 298 } else { |
299 m = iCount; | 299 m = iCount; |
300 } | 300 } |
301 if (!pResDict) { | 301 if (!pResDict) { |
302 return csTmp; | 302 return csTmp; |
303 } | 303 } |
304 CPDF_Dictionary* pDict = pResDict->GetDict(csType); | 304 CPDF_Dictionary* pDict = pResDict->GetDictBy(csType); |
305 if (!pDict) { | 305 if (!pDict) { |
306 return csTmp; | 306 return csTmp; |
307 } | 307 } |
308 int num = 0; | 308 int num = 0; |
309 CFX_ByteString bsNum; | 309 CFX_ByteString bsNum; |
310 while (TRUE) { | 310 while (TRUE) { |
311 if (!pDict->KeyExist(csTmp + bsNum)) { | 311 if (!pDict->KeyExist(csTmp + bsNum)) { |
312 return csTmp + bsNum; | 312 return csTmp + bsNum; |
313 } | 313 } |
314 if (m < iCount) { | 314 if (m < iCount) { |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 return NULL; | 666 return NULL; |
667 } | 667 } |
668 CFX_WideString csWName = GetFullName(pFieldDict); | 668 CFX_WideString csWName = GetFullName(pFieldDict); |
669 return m_pFieldTree->GetField(csWName); | 669 return m_pFieldTree->GetField(csWName); |
670 } | 670 } |
671 | 671 |
672 CPDF_FormControl* CPDF_InterForm::GetControlAtPoint(CPDF_Page* pPage, | 672 CPDF_FormControl* CPDF_InterForm::GetControlAtPoint(CPDF_Page* pPage, |
673 FX_FLOAT pdf_x, | 673 FX_FLOAT pdf_x, |
674 FX_FLOAT pdf_y, | 674 FX_FLOAT pdf_y, |
675 int* z_order) const { | 675 int* z_order) const { |
676 CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArray("Annots"); | 676 CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArrayBy("Annots"); |
677 if (!pAnnotList) | 677 if (!pAnnotList) |
678 return nullptr; | 678 return nullptr; |
679 | 679 |
680 for (FX_DWORD i = pAnnotList->GetCount(); i > 0; --i) { | 680 for (FX_DWORD i = pAnnotList->GetCount(); i > 0; --i) { |
681 FX_DWORD annot_index = i - 1; | 681 FX_DWORD annot_index = i - 1; |
682 CPDF_Dictionary* pAnnot = pAnnotList->GetDict(annot_index); | 682 CPDF_Dictionary* pAnnot = pAnnotList->GetDictAt(annot_index); |
683 if (!pAnnot) | 683 if (!pAnnot) |
684 continue; | 684 continue; |
685 | 685 |
686 const auto it = m_ControlMap.find(pAnnot); | 686 const auto it = m_ControlMap.find(pAnnot); |
687 if (it == m_ControlMap.end()) | 687 if (it == m_ControlMap.end()) |
688 continue; | 688 continue; |
689 | 689 |
690 CPDF_FormControl* pControl = it->second; | 690 CPDF_FormControl* pControl = it->second; |
691 CFX_FloatRect rect = pControl->GetRect(); | 691 CFX_FloatRect rect = pControl->GetRect(); |
692 if (!rect.Contains(pdf_x, pdf_y)) | 692 if (!rect.Contains(pdf_x, pdf_y)) |
693 continue; | 693 continue; |
694 | 694 |
695 if (z_order) | 695 if (z_order) |
696 *z_order = annot_index; | 696 *z_order = annot_index; |
697 return pControl; | 697 return pControl; |
698 } | 698 } |
699 return nullptr; | 699 return nullptr; |
700 } | 700 } |
701 | 701 |
702 CPDF_FormControl* CPDF_InterForm::GetControlByDict( | 702 CPDF_FormControl* CPDF_InterForm::GetControlByDict( |
703 const CPDF_Dictionary* pWidgetDict) const { | 703 const CPDF_Dictionary* pWidgetDict) const { |
704 const auto it = m_ControlMap.find(pWidgetDict); | 704 const auto it = m_ControlMap.find(pWidgetDict); |
705 return it != m_ControlMap.end() ? it->second : nullptr; | 705 return it != m_ControlMap.end() ? it->second : nullptr; |
706 } | 706 } |
707 | 707 |
708 FX_BOOL CPDF_InterForm::NeedConstructAP() { | 708 FX_BOOL CPDF_InterForm::NeedConstructAP() { |
709 return m_pFormDict && m_pFormDict->GetBoolean("NeedAppearances"); | 709 return m_pFormDict && m_pFormDict->GetBooleanBy("NeedAppearances"); |
710 } | 710 } |
711 void CPDF_InterForm::NeedConstructAP(FX_BOOL bNeedAP) { | 711 void CPDF_InterForm::NeedConstructAP(FX_BOOL bNeedAP) { |
712 if (!m_pFormDict) { | 712 if (!m_pFormDict) { |
713 InitInterFormDict(m_pFormDict, m_pDocument); | 713 InitInterFormDict(m_pFormDict, m_pDocument); |
714 } | 714 } |
715 m_pFormDict->SetAtBoolean("NeedAppearances", bNeedAP); | 715 m_pFormDict->SetAtBoolean("NeedAppearances", bNeedAP); |
716 m_bGenerateAP = bNeedAP; | 716 m_bGenerateAP = bNeedAP; |
717 } | 717 } |
718 int CPDF_InterForm::CountFieldsInCalculationOrder() { | 718 int CPDF_InterForm::CountFieldsInCalculationOrder() { |
719 if (!m_pFormDict) { | 719 if (!m_pFormDict) { |
720 return 0; | 720 return 0; |
721 } | 721 } |
722 CPDF_Array* pArray = m_pFormDict->GetArray("CO"); | 722 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); |
723 return pArray ? pArray->GetCount() : 0; | 723 return pArray ? pArray->GetCount() : 0; |
724 } | 724 } |
725 CPDF_FormField* CPDF_InterForm::GetFieldInCalculationOrder(int index) { | 725 CPDF_FormField* CPDF_InterForm::GetFieldInCalculationOrder(int index) { |
726 if (!m_pFormDict || index < 0) { | 726 if (!m_pFormDict || index < 0) { |
727 return NULL; | 727 return NULL; |
728 } | 728 } |
729 CPDF_Array* pArray = m_pFormDict->GetArray("CO"); | 729 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); |
730 if (!pArray) { | 730 if (!pArray) { |
731 return NULL; | 731 return NULL; |
732 } | 732 } |
733 if (CPDF_Dictionary* pElement = | 733 if (CPDF_Dictionary* pElement = |
734 ToDictionary(pArray->GetElementValue(index))) { | 734 ToDictionary(pArray->GetElementValue(index))) { |
735 return GetFieldByDict(pElement); | 735 return GetFieldByDict(pElement); |
736 } | 736 } |
737 return NULL; | 737 return NULL; |
738 } | 738 } |
739 int CPDF_InterForm::FindFieldInCalculationOrder(const CPDF_FormField* pField) { | 739 int CPDF_InterForm::FindFieldInCalculationOrder(const CPDF_FormField* pField) { |
740 if (!m_pFormDict || !pField) { | 740 if (!m_pFormDict || !pField) { |
741 return -1; | 741 return -1; |
742 } | 742 } |
743 CPDF_Array* pArray = m_pFormDict->GetArray("CO"); | 743 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); |
744 if (!pArray) { | 744 if (!pArray) { |
745 return -1; | 745 return -1; |
746 } | 746 } |
747 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { | 747 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { |
748 CPDF_Object* pElement = pArray->GetElementValue(i); | 748 CPDF_Object* pElement = pArray->GetElementValue(i); |
749 if (pElement == pField->m_pDict) { | 749 if (pElement == pField->m_pDict) { |
750 return i; | 750 return i; |
751 } | 751 } |
752 } | 752 } |
753 return -1; | 753 return -1; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 } | 803 } |
804 void CPDF_InterForm::RemoveFormFont(CFX_ByteString csNameTag) { | 804 void CPDF_InterForm::RemoveFormFont(CFX_ByteString csNameTag) { |
805 m_bUpdated = TRUE; | 805 m_bUpdated = TRUE; |
806 RemoveInterFormFont(m_pFormDict, csNameTag); | 806 RemoveInterFormFont(m_pFormDict, csNameTag); |
807 } | 807 } |
808 CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() { | 808 CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() { |
809 CFX_ByteString csDA; | 809 CFX_ByteString csDA; |
810 if (!m_pFormDict) { | 810 if (!m_pFormDict) { |
811 return csDA; | 811 return csDA; |
812 } | 812 } |
813 csDA = m_pFormDict->GetString("DA"); | 813 csDA = m_pFormDict->GetStringBy("DA"); |
814 return csDA; | 814 return csDA; |
815 } | 815 } |
816 CPDF_Font* CPDF_InterForm::GetDefaultFormFont() { | 816 CPDF_Font* CPDF_InterForm::GetDefaultFormFont() { |
817 return GetDefaultInterFormFont(m_pFormDict, m_pDocument); | 817 return GetDefaultInterFormFont(m_pFormDict, m_pDocument); |
818 } | 818 } |
819 int CPDF_InterForm::GetFormAlignment() { | 819 int CPDF_InterForm::GetFormAlignment() { |
820 return m_pFormDict ? m_pFormDict->GetInteger("Q", 0) : 0; | 820 return m_pFormDict ? m_pFormDict->GetIntegerBy("Q", 0) : 0; |
821 } | 821 } |
822 | 822 |
823 bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields, | 823 bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields, |
824 bool bIncludeOrExclude, | 824 bool bIncludeOrExclude, |
825 bool bNotify) { | 825 bool bNotify) { |
826 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) | 826 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) |
827 return false; | 827 return false; |
828 | 828 |
829 int nCount = m_pFieldTree->m_Root.CountFields(); | 829 int nCount = m_pFieldTree->m_Root.CountFields(); |
830 for (int i = 0; i < nCount; ++i) { | 830 for (int i = 0; i < nCount; ++i) { |
(...skipping 27 matching lines...) Expand all Loading... |
858 } | 858 } |
859 | 859 |
860 void CPDF_InterForm::LoadField(CPDF_Dictionary* pFieldDict, int nLevel) { | 860 void CPDF_InterForm::LoadField(CPDF_Dictionary* pFieldDict, int nLevel) { |
861 if (nLevel > nMaxRecursion) { | 861 if (nLevel > nMaxRecursion) { |
862 return; | 862 return; |
863 } | 863 } |
864 if (!pFieldDict) { | 864 if (!pFieldDict) { |
865 return; | 865 return; |
866 } | 866 } |
867 FX_DWORD dwParentObjNum = pFieldDict->GetObjNum(); | 867 FX_DWORD dwParentObjNum = pFieldDict->GetObjNum(); |
868 CPDF_Array* pKids = pFieldDict->GetArray("Kids"); | 868 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids"); |
869 if (!pKids) { | 869 if (!pKids) { |
870 AddTerminalField(pFieldDict); | 870 AddTerminalField(pFieldDict); |
871 return; | 871 return; |
872 } | 872 } |
873 CPDF_Dictionary* pFirstKid = pKids->GetDict(0); | 873 CPDF_Dictionary* pFirstKid = pKids->GetDictAt(0); |
874 if (!pFirstKid) { | 874 if (!pFirstKid) { |
875 return; | 875 return; |
876 } | 876 } |
877 if (pFirstKid->KeyExist("T") || pFirstKid->KeyExist("Kids")) { | 877 if (pFirstKid->KeyExist("T") || pFirstKid->KeyExist("Kids")) { |
878 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { | 878 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { |
879 CPDF_Dictionary* pChildDict = pKids->GetDict(i); | 879 CPDF_Dictionary* pChildDict = pKids->GetDictAt(i); |
880 if (pChildDict) { | 880 if (pChildDict) { |
881 if (pChildDict->GetObjNum() != dwParentObjNum) { | 881 if (pChildDict->GetObjNum() != dwParentObjNum) { |
882 LoadField(pChildDict, nLevel + 1); | 882 LoadField(pChildDict, nLevel + 1); |
883 } | 883 } |
884 } | 884 } |
885 } | 885 } |
886 } else { | 886 } else { |
887 AddTerminalField(pFieldDict); | 887 AddTerminalField(pFieldDict); |
888 } | 888 } |
889 } | 889 } |
890 FX_BOOL CPDF_InterForm::HasXFAForm() const { | 890 FX_BOOL CPDF_InterForm::HasXFAForm() const { |
891 return m_pFormDict && m_pFormDict->GetArray("XFA"); | 891 return m_pFormDict && m_pFormDict->GetArrayBy("XFA"); |
892 } | 892 } |
893 void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) { | 893 void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) { |
894 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; | 894 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; |
895 if (!pPageDict) { | 895 if (!pPageDict) { |
896 return; | 896 return; |
897 } | 897 } |
898 CPDF_Array* pAnnots = pPageDict->GetArray("Annots"); | 898 CPDF_Array* pAnnots = pPageDict->GetArrayBy("Annots"); |
899 if (!pAnnots) { | 899 if (!pAnnots) { |
900 return; | 900 return; |
901 } | 901 } |
902 int iAnnotCount = pAnnots->GetCount(); | 902 int iAnnotCount = pAnnots->GetCount(); |
903 for (int i = 0; i < iAnnotCount; i++) { | 903 for (int i = 0; i < iAnnotCount; i++) { |
904 CPDF_Dictionary* pAnnot = pAnnots->GetDict(i); | 904 CPDF_Dictionary* pAnnot = pAnnots->GetDictAt(i); |
905 if (pAnnot && pAnnot->GetString("Subtype") == "Widget") { | 905 if (pAnnot && pAnnot->GetStringBy("Subtype") == "Widget") { |
906 LoadField(pAnnot); | 906 LoadField(pAnnot); |
907 } | 907 } |
908 } | 908 } |
909 } | 909 } |
910 CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { | 910 CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { |
911 if (!pFieldDict->KeyExist("T")) { | 911 if (!pFieldDict->KeyExist("T")) { |
912 return NULL; | 912 return NULL; |
913 } | 913 } |
914 CPDF_Dictionary* pDict = pFieldDict; | 914 CPDF_Dictionary* pDict = pFieldDict; |
915 CFX_WideString csWName = GetFullName(pFieldDict); | 915 CFX_WideString csWName = GetFullName(pFieldDict); |
916 if (csWName.IsEmpty()) { | 916 if (csWName.IsEmpty()) { |
917 return NULL; | 917 return NULL; |
918 } | 918 } |
919 CPDF_FormField* pField = NULL; | 919 CPDF_FormField* pField = NULL; |
920 pField = m_pFieldTree->GetField(csWName); | 920 pField = m_pFieldTree->GetField(csWName); |
921 if (!pField) { | 921 if (!pField) { |
922 CPDF_Dictionary* pParent = pFieldDict; | 922 CPDF_Dictionary* pParent = pFieldDict; |
923 if (!pFieldDict->KeyExist("T") && | 923 if (!pFieldDict->KeyExist("T") && |
924 pFieldDict->GetString("Subtype") == "Widget") { | 924 pFieldDict->GetStringBy("Subtype") == "Widget") { |
925 pParent = pFieldDict->GetDict("Parent"); | 925 pParent = pFieldDict->GetDictBy("Parent"); |
926 if (!pParent) { | 926 if (!pParent) { |
927 pParent = pFieldDict; | 927 pParent = pFieldDict; |
928 } | 928 } |
929 } | 929 } |
930 if (pParent && pParent != pFieldDict && !pParent->KeyExist("FT")) { | 930 if (pParent && pParent != pFieldDict && !pParent->KeyExist("FT")) { |
931 if (pFieldDict->KeyExist("FT")) { | 931 if (pFieldDict->KeyExist("FT")) { |
932 CPDF_Object* pFTValue = pFieldDict->GetElementValue("FT"); | 932 CPDF_Object* pFTValue = pFieldDict->GetElementValue("FT"); |
933 if (pFTValue) { | 933 if (pFTValue) { |
934 pParent->SetAt("FT", pFTValue->Clone()); | 934 pParent->SetAt("FT", pFTValue->Clone()); |
935 } | 935 } |
936 } | 936 } |
937 if (pFieldDict->KeyExist("Ff")) { | 937 if (pFieldDict->KeyExist("Ff")) { |
938 CPDF_Object* pFfValue = pFieldDict->GetElementValue("Ff"); | 938 CPDF_Object* pFfValue = pFieldDict->GetElementValue("Ff"); |
939 if (pFfValue) { | 939 if (pFfValue) { |
940 pParent->SetAt("Ff", pFfValue->Clone()); | 940 pParent->SetAt("Ff", pFfValue->Clone()); |
941 } | 941 } |
942 } | 942 } |
943 } | 943 } |
944 pField = new CPDF_FormField(this, pParent); | 944 pField = new CPDF_FormField(this, pParent); |
945 CPDF_Object* pTObj = pDict->GetElement("T"); | 945 CPDF_Object* pTObj = pDict->GetElement("T"); |
946 if (ToReference(pTObj)) { | 946 if (ToReference(pTObj)) { |
947 CPDF_Object* pClone = pTObj->Clone(TRUE); | 947 CPDF_Object* pClone = pTObj->Clone(TRUE); |
948 if (pClone) | 948 if (pClone) |
949 pDict->SetAt("T", pClone); | 949 pDict->SetAt("T", pClone); |
950 else | 950 else |
951 pDict->SetAtName("T", ""); | 951 pDict->SetAtName("T", ""); |
952 } | 952 } |
953 m_pFieldTree->SetField(csWName, pField); | 953 m_pFieldTree->SetField(csWName, pField); |
954 } | 954 } |
955 CPDF_Array* pKids = pFieldDict->GetArray("Kids"); | 955 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids"); |
956 if (!pKids) { | 956 if (!pKids) { |
957 if (pFieldDict->GetString("Subtype") == "Widget") { | 957 if (pFieldDict->GetStringBy("Subtype") == "Widget") { |
958 AddControl(pField, pFieldDict); | 958 AddControl(pField, pFieldDict); |
959 } | 959 } |
960 } else { | 960 } else { |
961 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { | 961 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { |
962 CPDF_Dictionary* pKid = pKids->GetDict(i); | 962 CPDF_Dictionary* pKid = pKids->GetDictAt(i); |
963 if (!pKid) { | 963 if (!pKid) { |
964 continue; | 964 continue; |
965 } | 965 } |
966 if (pKid->GetString("Subtype") != "Widget") { | 966 if (pKid->GetStringBy("Subtype") != "Widget") { |
967 continue; | 967 continue; |
968 } | 968 } |
969 AddControl(pField, pKid); | 969 AddControl(pField, pKid); |
970 } | 970 } |
971 } | 971 } |
972 return pField; | 972 return pField; |
973 } | 973 } |
974 CPDF_FormControl* CPDF_InterForm::AddControl(const CPDF_FormField* pField, | 974 CPDF_FormControl* CPDF_InterForm::AddControl(const CPDF_FormField* pField, |
975 CPDF_Dictionary* pWidgetDict) { | 975 CPDF_Dictionary* pWidgetDict) { |
976 const auto it = m_ControlMap.find(pWidgetDict); | 976 const auto it = m_ControlMap.find(pWidgetDict); |
(...skipping 24 matching lines...) Expand all Loading... |
1001 FX_DWORD dwFlags = pField->GetFieldFlags(); | 1001 FX_DWORD dwFlags = pField->GetFieldFlags(); |
1002 // TODO(thestig): Look up these magic numbers and add constants for them. | 1002 // TODO(thestig): Look up these magic numbers and add constants for them. |
1003 if (dwFlags & 0x04) | 1003 if (dwFlags & 0x04) |
1004 continue; | 1004 continue; |
1005 | 1005 |
1006 bool bFind = true; | 1006 bool bFind = true; |
1007 if (fields) | 1007 if (fields) |
1008 bFind = pdfium::ContainsValue(*fields, pField); | 1008 bFind = pdfium::ContainsValue(*fields, pField); |
1009 if (bIncludeOrExclude == bFind) { | 1009 if (bIncludeOrExclude == bFind) { |
1010 CPDF_Dictionary* pFieldDict = pField->m_pDict; | 1010 CPDF_Dictionary* pFieldDict = pField->m_pDict; |
1011 if ((dwFlags & 0x02) != 0 && pFieldDict->GetString("V").IsEmpty()) { | 1011 if ((dwFlags & 0x02) != 0 && pFieldDict->GetStringBy("V").IsEmpty()) { |
1012 return pField; | 1012 return pField; |
1013 } | 1013 } |
1014 } | 1014 } |
1015 } | 1015 } |
1016 return nullptr; | 1016 return nullptr; |
1017 } | 1017 } |
1018 | 1018 |
1019 CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, | 1019 CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, |
1020 bool bSimpleFileSpec) const { | 1020 bool bSimpleFileSpec) const { |
1021 std::vector<CPDF_FormField*> fields; | 1021 std::vector<CPDF_FormField*> fields; |
1022 int nCount = m_pFieldTree->m_Root.CountFields(); | 1022 int nCount = m_pFieldTree->m_Root.CountFields(); |
1023 for (int i = 0; i < nCount; ++i) | 1023 for (int i = 0; i < nCount; ++i) |
1024 fields.push_back(m_pFieldTree->m_Root.GetField(i)); | 1024 fields.push_back(m_pFieldTree->m_Root.GetField(i)); |
1025 return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec); | 1025 return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec); |
1026 } | 1026 } |
1027 | 1027 |
1028 CFDF_Document* CPDF_InterForm::ExportToFDF( | 1028 CFDF_Document* CPDF_InterForm::ExportToFDF( |
1029 const CFX_WideStringC& pdf_path, | 1029 const CFX_WideStringC& pdf_path, |
1030 const std::vector<CPDF_FormField*>& fields, | 1030 const std::vector<CPDF_FormField*>& fields, |
1031 bool bIncludeOrExclude, | 1031 bool bIncludeOrExclude, |
1032 bool bSimpleFileSpec) const { | 1032 bool bSimpleFileSpec) const { |
1033 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc(); | 1033 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc(); |
1034 if (!pDoc) { | 1034 if (!pDoc) { |
1035 return NULL; | 1035 return NULL; |
1036 } | 1036 } |
1037 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDict("FDF"); | 1037 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictBy("FDF"); |
1038 if (!pdf_path.IsEmpty()) { | 1038 if (!pdf_path.IsEmpty()) { |
1039 if (bSimpleFileSpec) { | 1039 if (bSimpleFileSpec) { |
1040 CFX_WideString wsFilePath = FILESPEC_EncodeFileName(pdf_path); | 1040 CFX_WideString wsFilePath = FILESPEC_EncodeFileName(pdf_path); |
1041 pMainDict->SetAtString("F", CFX_ByteString::FromUnicode(wsFilePath)); | 1041 pMainDict->SetAtString("F", CFX_ByteString::FromUnicode(wsFilePath)); |
1042 pMainDict->SetAtString("UF", PDF_EncodeText(wsFilePath)); | 1042 pMainDict->SetAtString("UF", PDF_EncodeText(wsFilePath)); |
1043 } else { | 1043 } else { |
1044 CPDF_FileSpec filespec; | 1044 CPDF_FileSpec filespec; |
1045 filespec.SetFileName(pdf_path); | 1045 filespec.SetFileName(pdf_path); |
1046 pMainDict->SetAt("F", static_cast<CPDF_Object*>(filespec)); | 1046 pMainDict->SetAt("F", static_cast<CPDF_Object*>(filespec)); |
1047 } | 1047 } |
1048 } | 1048 } |
1049 CPDF_Array* pFields = new CPDF_Array; | 1049 CPDF_Array* pFields = new CPDF_Array; |
1050 pMainDict->SetAt("Fields", pFields); | 1050 pMainDict->SetAt("Fields", pFields); |
1051 int nCount = m_pFieldTree->m_Root.CountFields(); | 1051 int nCount = m_pFieldTree->m_Root.CountFields(); |
1052 for (int i = 0; i < nCount; i++) { | 1052 for (int i = 0; i < nCount; i++) { |
1053 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); | 1053 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); |
1054 if (!pField || pField->GetType() == CPDF_FormField::PushButton) { | 1054 if (!pField || pField->GetType() == CPDF_FormField::PushButton) { |
1055 continue; | 1055 continue; |
1056 } | 1056 } |
1057 FX_DWORD dwFlags = pField->GetFieldFlags(); | 1057 FX_DWORD dwFlags = pField->GetFieldFlags(); |
1058 if (dwFlags & 0x04) | 1058 if (dwFlags & 0x04) |
1059 continue; | 1059 continue; |
1060 | 1060 |
1061 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) { | 1061 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) { |
1062 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetString("V").IsEmpty()) | 1062 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetStringBy("V").IsEmpty()) |
1063 continue; | 1063 continue; |
1064 | 1064 |
1065 CFX_WideString fullname = GetFullName(pField->GetFieldDict()); | 1065 CFX_WideString fullname = GetFullName(pField->GetFieldDict()); |
1066 CPDF_Dictionary* pFieldDict = new CPDF_Dictionary; | 1066 CPDF_Dictionary* pFieldDict = new CPDF_Dictionary; |
1067 pFieldDict->SetAt("T", new CPDF_String(fullname)); | 1067 pFieldDict->SetAt("T", new CPDF_String(fullname)); |
1068 if (pField->GetType() == CPDF_FormField::CheckBox || | 1068 if (pField->GetType() == CPDF_FormField::CheckBox || |
1069 pField->GetType() == CPDF_FormField::RadioButton) { | 1069 pField->GetType() == CPDF_FormField::RadioButton) { |
1070 CFX_WideString csExport = pField->GetCheckValue(FALSE); | 1070 CFX_WideString csExport = pField->GetCheckValue(FALSE); |
1071 CFX_ByteString csBExport = PDF_EncodeText(csExport); | 1071 CFX_ByteString csBExport = PDF_EncodeText(csExport); |
1072 CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->m_pDict, "Opt"); | 1072 CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->m_pDict, "Opt"); |
(...skipping 16 matching lines...) Expand all Loading... |
1089 int32_t m_codePage; | 1089 int32_t m_codePage; |
1090 } g_fieldEncoding[] = { | 1090 } g_fieldEncoding[] = { |
1091 {"BigFive", 950}, | 1091 {"BigFive", 950}, |
1092 {"GBK", 936}, | 1092 {"GBK", 936}, |
1093 {"Shift-JIS", 932}, | 1093 {"Shift-JIS", 932}, |
1094 {"UHC", 949}, | 1094 {"UHC", 949}, |
1095 }; | 1095 }; |
1096 static void FPDFDOC_FDF_GetFieldValue(CPDF_Dictionary* pFieldDict, | 1096 static void FPDFDOC_FDF_GetFieldValue(CPDF_Dictionary* pFieldDict, |
1097 CFX_WideString& csValue, | 1097 CFX_WideString& csValue, |
1098 CFX_ByteString& bsEncoding) { | 1098 CFX_ByteString& bsEncoding) { |
1099 CFX_ByteString csBValue = pFieldDict->GetString("V"); | 1099 CFX_ByteString csBValue = pFieldDict->GetStringBy("V"); |
1100 int32_t iCount = sizeof(g_fieldEncoding) / sizeof(g_fieldEncoding[0]); | 1100 int32_t iCount = sizeof(g_fieldEncoding) / sizeof(g_fieldEncoding[0]); |
1101 int32_t i = 0; | 1101 int32_t i = 0; |
1102 for (; i < iCount; ++i) | 1102 for (; i < iCount; ++i) |
1103 if (bsEncoding == g_fieldEncoding[i].m_name) { | 1103 if (bsEncoding == g_fieldEncoding[i].m_name) { |
1104 break; | 1104 break; |
1105 } | 1105 } |
1106 if (i < iCount) { | 1106 if (i < iCount) { |
1107 CFX_CharMap* pCharMap = | 1107 CFX_CharMap* pCharMap = |
1108 CFX_CharMap::GetDefaultMapper(g_fieldEncoding[i].m_codePage); | 1108 CFX_CharMap::GetDefaultMapper(g_fieldEncoding[i].m_codePage); |
1109 FXSYS_assert(pCharMap); | 1109 FXSYS_assert(pCharMap); |
1110 csValue.ConvertFrom(csBValue, pCharMap); | 1110 csValue.ConvertFrom(csBValue, pCharMap); |
1111 return; | 1111 return; |
1112 } | 1112 } |
1113 CFX_ByteString csTemp = csBValue.Left(2); | 1113 CFX_ByteString csTemp = csBValue.Left(2); |
1114 if (csTemp == "\xFF\xFE" || csTemp == "\xFE\xFF") { | 1114 if (csTemp == "\xFF\xFE" || csTemp == "\xFE\xFF") { |
1115 csValue = PDF_DecodeText(csBValue); | 1115 csValue = PDF_DecodeText(csBValue); |
1116 } else { | 1116 } else { |
1117 csValue = CFX_WideString::FromLocal(csBValue); | 1117 csValue = CFX_WideString::FromLocal(csBValue); |
1118 } | 1118 } |
1119 } | 1119 } |
1120 void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict, | 1120 void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict, |
1121 const CFX_WideString& parent_name, | 1121 const CFX_WideString& parent_name, |
1122 FX_BOOL bNotify, | 1122 FX_BOOL bNotify, |
1123 int nLevel) { | 1123 int nLevel) { |
1124 CFX_WideString name; | 1124 CFX_WideString name; |
1125 if (!parent_name.IsEmpty()) { | 1125 if (!parent_name.IsEmpty()) { |
1126 name = parent_name + L"."; | 1126 name = parent_name + L"."; |
1127 } | 1127 } |
1128 name += pFieldDict->GetUnicodeText("T"); | 1128 name += pFieldDict->GetUnicodeTextBy("T"); |
1129 CPDF_Array* pKids = pFieldDict->GetArray("Kids"); | 1129 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids"); |
1130 if (pKids) { | 1130 if (pKids) { |
1131 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { | 1131 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { |
1132 CPDF_Dictionary* pKid = pKids->GetDict(i); | 1132 CPDF_Dictionary* pKid = pKids->GetDictAt(i); |
1133 if (!pKid) { | 1133 if (!pKid) { |
1134 continue; | 1134 continue; |
1135 } | 1135 } |
1136 if (nLevel <= nMaxRecursion) { | 1136 if (nLevel <= nMaxRecursion) { |
1137 FDF_ImportField(pKid, name, bNotify, nLevel + 1); | 1137 FDF_ImportField(pKid, name, bNotify, nLevel + 1); |
1138 } | 1138 } |
1139 } | 1139 } |
1140 return; | 1140 return; |
1141 } | 1141 } |
1142 if (!pFieldDict->KeyExist("V")) { | 1142 if (!pFieldDict->KeyExist("V")) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 } | 1182 } |
1183 if (CPDF_InterForm::m_bUpdateAP) { | 1183 if (CPDF_InterForm::m_bUpdateAP) { |
1184 pField->UpdateAP(NULL); | 1184 pField->UpdateAP(NULL); |
1185 } | 1185 } |
1186 } | 1186 } |
1187 FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF, | 1187 FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF, |
1188 FX_BOOL bNotify) { | 1188 FX_BOOL bNotify) { |
1189 if (!pFDF) { | 1189 if (!pFDF) { |
1190 return FALSE; | 1190 return FALSE; |
1191 } | 1191 } |
1192 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF"); | 1192 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictBy("FDF"); |
1193 if (!pMainDict) { | 1193 if (!pMainDict) { |
1194 return FALSE; | 1194 return FALSE; |
1195 } | 1195 } |
1196 CPDF_Array* pFields = pMainDict->GetArray("Fields"); | 1196 CPDF_Array* pFields = pMainDict->GetArrayBy("Fields"); |
1197 if (!pFields) { | 1197 if (!pFields) { |
1198 return FALSE; | 1198 return FALSE; |
1199 } | 1199 } |
1200 m_bsEncoding = pMainDict->GetString("Encoding"); | 1200 m_bsEncoding = pMainDict->GetStringBy("Encoding"); |
1201 if (bNotify && m_pFormNotify) { | 1201 if (bNotify && m_pFormNotify) { |
1202 int iRet = m_pFormNotify->BeforeFormImportData(this); | 1202 int iRet = m_pFormNotify->BeforeFormImportData(this); |
1203 if (iRet < 0) { | 1203 if (iRet < 0) { |
1204 return FALSE; | 1204 return FALSE; |
1205 } | 1205 } |
1206 } | 1206 } |
1207 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) { | 1207 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) { |
1208 CPDF_Dictionary* pField = pFields->GetDict(i); | 1208 CPDF_Dictionary* pField = pFields->GetDictAt(i); |
1209 if (!pField) { | 1209 if (!pField) { |
1210 continue; | 1210 continue; |
1211 } | 1211 } |
1212 FDF_ImportField(pField, L"", bNotify); | 1212 FDF_ImportField(pField, L"", bNotify); |
1213 } | 1213 } |
1214 if (bNotify && m_pFormNotify) { | 1214 if (bNotify && m_pFormNotify) { |
1215 m_pFormNotify->AfterFormImportData(this); | 1215 m_pFormNotify->AfterFormImportData(this); |
1216 } | 1216 } |
1217 return TRUE; | 1217 return TRUE; |
1218 } | 1218 } |
1219 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) { | 1219 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) { |
1220 m_pFormNotify = (CPDF_FormNotify*)pNotify; | 1220 m_pFormNotify = (CPDF_FormNotify*)pNotify; |
1221 } | 1221 } |
OLD | NEW |