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

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

Issue 1648233002: Merge to XFA: Member function name refactoring (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: more xfa changes Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fpdfdoc/doc_bookmark.cpp ('k') | core/src/fpdfdoc/doc_formcontrol.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/include/fpdfdoc/fpdf_doc.h" 7 #include "core/include/fpdfdoc/fpdf_doc.h"
8 #include "doc_utils.h" 8 #include "doc_utils.h"
9 #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
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
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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 return NULL; 681 return NULL;
682 } 682 }
683 CFX_WideString csWName = GetFullName(pFieldDict); 683 CFX_WideString csWName = GetFullName(pFieldDict);
684 return m_pFieldTree->GetField(csWName); 684 return m_pFieldTree->GetField(csWName);
685 } 685 }
686 686
687 CPDF_FormControl* CPDF_InterForm::GetControlAtPoint(CPDF_Page* pPage, 687 CPDF_FormControl* CPDF_InterForm::GetControlAtPoint(CPDF_Page* pPage,
688 FX_FLOAT pdf_x, 688 FX_FLOAT pdf_x,
689 FX_FLOAT pdf_y, 689 FX_FLOAT pdf_y,
690 int* z_order) const { 690 int* z_order) const {
691 CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArray("Annots"); 691 CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArrayBy("Annots");
692 if (!pAnnotList) 692 if (!pAnnotList)
693 return nullptr; 693 return nullptr;
694 694
695 for (FX_DWORD i = pAnnotList->GetCount(); i > 0; --i) { 695 for (FX_DWORD i = pAnnotList->GetCount(); i > 0; --i) {
696 FX_DWORD annot_index = i - 1; 696 FX_DWORD annot_index = i - 1;
697 CPDF_Dictionary* pAnnot = pAnnotList->GetDict(annot_index); 697 CPDF_Dictionary* pAnnot = pAnnotList->GetDictAt(annot_index);
698 if (!pAnnot) 698 if (!pAnnot)
699 continue; 699 continue;
700 700
701 const auto it = m_ControlMap.find(pAnnot); 701 const auto it = m_ControlMap.find(pAnnot);
702 if (it == m_ControlMap.end()) 702 if (it == m_ControlMap.end())
703 continue; 703 continue;
704 704
705 CPDF_FormControl* pControl = it->second; 705 CPDF_FormControl* pControl = it->second;
706 CFX_FloatRect rect = pControl->GetRect(); 706 CFX_FloatRect rect = pControl->GetRect();
707 if (!rect.Contains(pdf_x, pdf_y)) 707 if (!rect.Contains(pdf_x, pdf_y))
708 continue; 708 continue;
709 709
710 if (z_order) 710 if (z_order)
711 *z_order = annot_index; 711 *z_order = annot_index;
712 return pControl; 712 return pControl;
713 } 713 }
714 return nullptr; 714 return nullptr;
715 } 715 }
716 716
717 CPDF_FormControl* CPDF_InterForm::GetControlByDict( 717 CPDF_FormControl* CPDF_InterForm::GetControlByDict(
718 const CPDF_Dictionary* pWidgetDict) const { 718 const CPDF_Dictionary* pWidgetDict) const {
719 const auto it = m_ControlMap.find(pWidgetDict); 719 const auto it = m_ControlMap.find(pWidgetDict);
720 return it != m_ControlMap.end() ? it->second : nullptr; 720 return it != m_ControlMap.end() ? it->second : nullptr;
721 } 721 }
722 722
723 FX_BOOL CPDF_InterForm::NeedConstructAP() { 723 FX_BOOL CPDF_InterForm::NeedConstructAP() {
724 return m_pFormDict && m_pFormDict->GetBoolean("NeedAppearances"); 724 return m_pFormDict && m_pFormDict->GetBooleanBy("NeedAppearances");
725 } 725 }
726 void CPDF_InterForm::NeedConstructAP(FX_BOOL bNeedAP) { 726 void CPDF_InterForm::NeedConstructAP(FX_BOOL bNeedAP) {
727 if (!m_pFormDict) { 727 if (!m_pFormDict) {
728 InitInterFormDict(m_pFormDict, m_pDocument); 728 InitInterFormDict(m_pFormDict, m_pDocument);
729 } 729 }
730 m_pFormDict->SetAtBoolean("NeedAppearances", bNeedAP); 730 m_pFormDict->SetAtBoolean("NeedAppearances", bNeedAP);
731 m_bGenerateAP = bNeedAP; 731 m_bGenerateAP = bNeedAP;
732 } 732 }
733 int CPDF_InterForm::CountFieldsInCalculationOrder() { 733 int CPDF_InterForm::CountFieldsInCalculationOrder() {
734 if (!m_pFormDict) { 734 if (!m_pFormDict) {
735 return 0; 735 return 0;
736 } 736 }
737 CPDF_Array* pArray = m_pFormDict->GetArray("CO"); 737 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO");
738 return pArray ? pArray->GetCount() : 0; 738 return pArray ? pArray->GetCount() : 0;
739 } 739 }
740 CPDF_FormField* CPDF_InterForm::GetFieldInCalculationOrder(int index) { 740 CPDF_FormField* CPDF_InterForm::GetFieldInCalculationOrder(int index) {
741 if (!m_pFormDict || index < 0) { 741 if (!m_pFormDict || index < 0) {
742 return NULL; 742 return NULL;
743 } 743 }
744 CPDF_Array* pArray = m_pFormDict->GetArray("CO"); 744 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO");
745 if (!pArray) { 745 if (!pArray) {
746 return NULL; 746 return NULL;
747 } 747 }
748 if (CPDF_Dictionary* pElement = 748 if (CPDF_Dictionary* pElement =
749 ToDictionary(pArray->GetElementValue(index))) { 749 ToDictionary(pArray->GetElementValue(index))) {
750 return GetFieldByDict(pElement); 750 return GetFieldByDict(pElement);
751 } 751 }
752 return NULL; 752 return NULL;
753 } 753 }
754 int CPDF_InterForm::FindFieldInCalculationOrder(const CPDF_FormField* pField) { 754 int CPDF_InterForm::FindFieldInCalculationOrder(const CPDF_FormField* pField) {
755 if (!m_pFormDict || !pField) { 755 if (!m_pFormDict || !pField) {
756 return -1; 756 return -1;
757 } 757 }
758 CPDF_Array* pArray = m_pFormDict->GetArray("CO"); 758 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO");
759 if (!pArray) { 759 if (!pArray) {
760 return -1; 760 return -1;
761 } 761 }
762 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { 762 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) {
763 CPDF_Object* pElement = pArray->GetElementValue(i); 763 CPDF_Object* pElement = pArray->GetElementValue(i);
764 if (pElement == pField->m_pDict) { 764 if (pElement == pField->m_pDict) {
765 return i; 765 return i;
766 } 766 }
767 } 767 }
768 return -1; 768 return -1;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 } 818 }
819 void CPDF_InterForm::RemoveFormFont(CFX_ByteString csNameTag) { 819 void CPDF_InterForm::RemoveFormFont(CFX_ByteString csNameTag) {
820 m_bUpdated = TRUE; 820 m_bUpdated = TRUE;
821 RemoveInterFormFont(m_pFormDict, csNameTag); 821 RemoveInterFormFont(m_pFormDict, csNameTag);
822 } 822 }
823 CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() { 823 CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() {
824 CFX_ByteString csDA; 824 CFX_ByteString csDA;
825 if (!m_pFormDict) { 825 if (!m_pFormDict) {
826 return csDA; 826 return csDA;
827 } 827 }
828 csDA = m_pFormDict->GetString("DA"); 828 csDA = m_pFormDict->GetStringBy("DA");
829 return csDA; 829 return csDA;
830 } 830 }
831 CPDF_Font* CPDF_InterForm::GetDefaultFormFont() { 831 CPDF_Font* CPDF_InterForm::GetDefaultFormFont() {
832 return GetDefaultInterFormFont(m_pFormDict, m_pDocument); 832 return GetDefaultInterFormFont(m_pFormDict, m_pDocument);
833 } 833 }
834 int CPDF_InterForm::GetFormAlignment() { 834 int CPDF_InterForm::GetFormAlignment() {
835 return m_pFormDict ? m_pFormDict->GetInteger("Q", 0) : 0; 835 return m_pFormDict ? m_pFormDict->GetIntegerBy("Q", 0) : 0;
836 } 836 }
837 837
838 bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields, 838 bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields,
839 bool bIncludeOrExclude, 839 bool bIncludeOrExclude,
840 bool bNotify) { 840 bool bNotify) {
841 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) 841 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0)
842 return false; 842 return false;
843 843
844 int nCount = m_pFieldTree->m_Root.CountFields(); 844 int nCount = m_pFieldTree->m_Root.CountFields();
845 for (int i = 0; i < nCount; ++i) { 845 for (int i = 0; i < nCount; ++i) {
(...skipping 27 matching lines...) Expand all
873 } 873 }
874 874
875 void CPDF_InterForm::LoadField(CPDF_Dictionary* pFieldDict, int nLevel) { 875 void CPDF_InterForm::LoadField(CPDF_Dictionary* pFieldDict, int nLevel) {
876 if (nLevel > nMaxRecursion) { 876 if (nLevel > nMaxRecursion) {
877 return; 877 return;
878 } 878 }
879 if (!pFieldDict) { 879 if (!pFieldDict) {
880 return; 880 return;
881 } 881 }
882 FX_DWORD dwParentObjNum = pFieldDict->GetObjNum(); 882 FX_DWORD dwParentObjNum = pFieldDict->GetObjNum();
883 CPDF_Array* pKids = pFieldDict->GetArray("Kids"); 883 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids");
884 if (!pKids) { 884 if (!pKids) {
885 AddTerminalField(pFieldDict); 885 AddTerminalField(pFieldDict);
886 return; 886 return;
887 } 887 }
888 CPDF_Dictionary* pFirstKid = pKids->GetDict(0); 888 CPDF_Dictionary* pFirstKid = pKids->GetDictAt(0);
889 if (!pFirstKid) { 889 if (!pFirstKid) {
890 return; 890 return;
891 } 891 }
892 if (pFirstKid->KeyExist("T") || pFirstKid->KeyExist("Kids")) { 892 if (pFirstKid->KeyExist("T") || pFirstKid->KeyExist("Kids")) {
893 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { 893 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) {
894 CPDF_Dictionary* pChildDict = pKids->GetDict(i); 894 CPDF_Dictionary* pChildDict = pKids->GetDictAt(i);
895 if (pChildDict) { 895 if (pChildDict) {
896 if (pChildDict->GetObjNum() != dwParentObjNum) { 896 if (pChildDict->GetObjNum() != dwParentObjNum) {
897 LoadField(pChildDict, nLevel + 1); 897 LoadField(pChildDict, nLevel + 1);
898 } 898 }
899 } 899 }
900 } 900 }
901 } else { 901 } else {
902 AddTerminalField(pFieldDict); 902 AddTerminalField(pFieldDict);
903 } 903 }
904 } 904 }
905 FX_BOOL CPDF_InterForm::HasXFAForm() const { 905 FX_BOOL CPDF_InterForm::HasXFAForm() const {
906 return m_pFormDict && m_pFormDict->GetArray("XFA"); 906 return m_pFormDict && m_pFormDict->GetArrayBy("XFA");
907 } 907 }
908 void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) { 908 void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) {
909 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; 909 CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
910 if (!pPageDict) { 910 if (!pPageDict) {
911 return; 911 return;
912 } 912 }
913 CPDF_Array* pAnnots = pPageDict->GetArray("Annots"); 913 CPDF_Array* pAnnots = pPageDict->GetArrayBy("Annots");
914 if (!pAnnots) { 914 if (!pAnnots) {
915 return; 915 return;
916 } 916 }
917 int iAnnotCount = pAnnots->GetCount(); 917 int iAnnotCount = pAnnots->GetCount();
918 for (int i = 0; i < iAnnotCount; i++) { 918 for (int i = 0; i < iAnnotCount; i++) {
919 CPDF_Dictionary* pAnnot = pAnnots->GetDict(i); 919 CPDF_Dictionary* pAnnot = pAnnots->GetDictAt(i);
920 if (pAnnot && pAnnot->GetString("Subtype") == "Widget") { 920 if (pAnnot && pAnnot->GetStringBy("Subtype") == "Widget") {
921 LoadField(pAnnot); 921 LoadField(pAnnot);
922 } 922 }
923 } 923 }
924 } 924 }
925 CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { 925 CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) {
926 if (!pFieldDict->KeyExist("T")) { 926 if (!pFieldDict->KeyExist("T")) {
927 return NULL; 927 return NULL;
928 } 928 }
929 CPDF_Dictionary* pDict = pFieldDict; 929 CPDF_Dictionary* pDict = pFieldDict;
930 CFX_WideString csWName = GetFullName(pFieldDict); 930 CFX_WideString csWName = GetFullName(pFieldDict);
931 if (csWName.IsEmpty()) { 931 if (csWName.IsEmpty()) {
932 return NULL; 932 return NULL;
933 } 933 }
934 CPDF_FormField* pField = NULL; 934 CPDF_FormField* pField = NULL;
935 pField = m_pFieldTree->GetField(csWName); 935 pField = m_pFieldTree->GetField(csWName);
936 if (!pField) { 936 if (!pField) {
937 CPDF_Dictionary* pParent = pFieldDict; 937 CPDF_Dictionary* pParent = pFieldDict;
938 if (!pFieldDict->KeyExist("T") && 938 if (!pFieldDict->KeyExist("T") &&
939 pFieldDict->GetString("Subtype") == "Widget") { 939 pFieldDict->GetStringBy("Subtype") == "Widget") {
940 pParent = pFieldDict->GetDict("Parent"); 940 pParent = pFieldDict->GetDictBy("Parent");
941 if (!pParent) { 941 if (!pParent) {
942 pParent = pFieldDict; 942 pParent = pFieldDict;
943 } 943 }
944 } 944 }
945 if (pParent && pParent != pFieldDict && !pParent->KeyExist("FT")) { 945 if (pParent && pParent != pFieldDict && !pParent->KeyExist("FT")) {
946 if (pFieldDict->KeyExist("FT")) { 946 if (pFieldDict->KeyExist("FT")) {
947 CPDF_Object* pFTValue = pFieldDict->GetElementValue("FT"); 947 CPDF_Object* pFTValue = pFieldDict->GetElementValue("FT");
948 if (pFTValue) { 948 if (pFTValue) {
949 pParent->SetAt("FT", pFTValue->Clone()); 949 pParent->SetAt("FT", pFTValue->Clone());
950 } 950 }
951 } 951 }
952 if (pFieldDict->KeyExist("Ff")) { 952 if (pFieldDict->KeyExist("Ff")) {
953 CPDF_Object* pFfValue = pFieldDict->GetElementValue("Ff"); 953 CPDF_Object* pFfValue = pFieldDict->GetElementValue("Ff");
954 if (pFfValue) { 954 if (pFfValue) {
955 pParent->SetAt("Ff", pFfValue->Clone()); 955 pParent->SetAt("Ff", pFfValue->Clone());
956 } 956 }
957 } 957 }
958 } 958 }
959 pField = new CPDF_FormField(this, pParent); 959 pField = new CPDF_FormField(this, pParent);
960 CPDF_Object* pTObj = pDict->GetElement("T"); 960 CPDF_Object* pTObj = pDict->GetElement("T");
961 if (ToReference(pTObj)) { 961 if (ToReference(pTObj)) {
962 CPDF_Object* pClone = pTObj->Clone(TRUE); 962 CPDF_Object* pClone = pTObj->Clone(TRUE);
963 if (pClone) 963 if (pClone)
964 pDict->SetAt("T", pClone); 964 pDict->SetAt("T", pClone);
965 else 965 else
966 pDict->SetAtName("T", ""); 966 pDict->SetAtName("T", "");
967 } 967 }
968 m_pFieldTree->SetField(csWName, pField); 968 m_pFieldTree->SetField(csWName, pField);
969 } 969 }
970 CPDF_Array* pKids = pFieldDict->GetArray("Kids"); 970 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids");
971 if (!pKids) { 971 if (!pKids) {
972 if (pFieldDict->GetString("Subtype") == "Widget") { 972 if (pFieldDict->GetStringBy("Subtype") == "Widget") {
973 AddControl(pField, pFieldDict); 973 AddControl(pField, pFieldDict);
974 } 974 }
975 } else { 975 } else {
976 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { 976 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) {
977 CPDF_Dictionary* pKid = pKids->GetDict(i); 977 CPDF_Dictionary* pKid = pKids->GetDictAt(i);
978 if (!pKid) { 978 if (!pKid) {
979 continue; 979 continue;
980 } 980 }
981 if (pKid->GetString("Subtype") != "Widget") { 981 if (pKid->GetStringBy("Subtype") != "Widget") {
982 continue; 982 continue;
983 } 983 }
984 AddControl(pField, pKid); 984 AddControl(pField, pKid);
985 } 985 }
986 } 986 }
987 return pField; 987 return pField;
988 } 988 }
989 CPDF_FormControl* CPDF_InterForm::AddControl(const CPDF_FormField* pField, 989 CPDF_FormControl* CPDF_InterForm::AddControl(const CPDF_FormField* pField,
990 CPDF_Dictionary* pWidgetDict) { 990 CPDF_Dictionary* pWidgetDict) {
991 const auto it = m_ControlMap.find(pWidgetDict); 991 const auto it = m_ControlMap.find(pWidgetDict);
(...skipping 24 matching lines...) Expand all
1016 FX_DWORD dwFlags = pField->GetFieldFlags(); 1016 FX_DWORD dwFlags = pField->GetFieldFlags();
1017 // TODO(thestig): Look up these magic numbers and add constants for them. 1017 // TODO(thestig): Look up these magic numbers and add constants for them.
1018 if (dwFlags & 0x04) 1018 if (dwFlags & 0x04)
1019 continue; 1019 continue;
1020 1020
1021 bool bFind = true; 1021 bool bFind = true;
1022 if (fields) 1022 if (fields)
1023 bFind = pdfium::ContainsValue(*fields, pField); 1023 bFind = pdfium::ContainsValue(*fields, pField);
1024 if (bIncludeOrExclude == bFind) { 1024 if (bIncludeOrExclude == bFind) {
1025 CPDF_Dictionary* pFieldDict = pField->m_pDict; 1025 CPDF_Dictionary* pFieldDict = pField->m_pDict;
1026 if ((dwFlags & 0x02) != 0 && pFieldDict->GetString("V").IsEmpty()) { 1026 if ((dwFlags & 0x02) != 0 && pFieldDict->GetStringBy("V").IsEmpty()) {
1027 return pField; 1027 return pField;
1028 } 1028 }
1029 } 1029 }
1030 } 1030 }
1031 return nullptr; 1031 return nullptr;
1032 } 1032 }
1033 1033
1034 CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, 1034 CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path,
1035 bool bSimpleFileSpec) const { 1035 bool bSimpleFileSpec) const {
1036 std::vector<CPDF_FormField*> fields; 1036 std::vector<CPDF_FormField*> fields;
1037 int nCount = m_pFieldTree->m_Root.CountFields(); 1037 int nCount = m_pFieldTree->m_Root.CountFields();
1038 for (int i = 0; i < nCount; ++i) 1038 for (int i = 0; i < nCount; ++i)
1039 fields.push_back(m_pFieldTree->m_Root.GetField(i)); 1039 fields.push_back(m_pFieldTree->m_Root.GetField(i));
1040 return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec); 1040 return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec);
1041 } 1041 }
1042 1042
1043 CFDF_Document* CPDF_InterForm::ExportToFDF( 1043 CFDF_Document* CPDF_InterForm::ExportToFDF(
1044 const CFX_WideStringC& pdf_path, 1044 const CFX_WideStringC& pdf_path,
1045 const std::vector<CPDF_FormField*>& fields, 1045 const std::vector<CPDF_FormField*>& fields,
1046 bool bIncludeOrExclude, 1046 bool bIncludeOrExclude,
1047 bool bSimpleFileSpec) const { 1047 bool bSimpleFileSpec) const {
1048 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc(); 1048 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc();
1049 if (!pDoc) { 1049 if (!pDoc) {
1050 return NULL; 1050 return NULL;
1051 } 1051 }
1052 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDict("FDF"); 1052 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictBy("FDF");
1053 if (!pdf_path.IsEmpty()) { 1053 if (!pdf_path.IsEmpty()) {
1054 if (bSimpleFileSpec) { 1054 if (bSimpleFileSpec) {
1055 CFX_WideString wsFilePath = FILESPEC_EncodeFileName(pdf_path); 1055 CFX_WideString wsFilePath = FILESPEC_EncodeFileName(pdf_path);
1056 pMainDict->SetAtString("F", CFX_ByteString::FromUnicode(wsFilePath)); 1056 pMainDict->SetAtString("F", CFX_ByteString::FromUnicode(wsFilePath));
1057 pMainDict->SetAtString("UF", PDF_EncodeText(wsFilePath)); 1057 pMainDict->SetAtString("UF", PDF_EncodeText(wsFilePath));
1058 } else { 1058 } else {
1059 CPDF_FileSpec filespec; 1059 CPDF_FileSpec filespec;
1060 filespec.SetFileName(pdf_path); 1060 filespec.SetFileName(pdf_path);
1061 pMainDict->SetAt("F", static_cast<CPDF_Object*>(filespec)); 1061 pMainDict->SetAt("F", static_cast<CPDF_Object*>(filespec));
1062 } 1062 }
1063 } 1063 }
1064 CPDF_Array* pFields = new CPDF_Array; 1064 CPDF_Array* pFields = new CPDF_Array;
1065 pMainDict->SetAt("Fields", pFields); 1065 pMainDict->SetAt("Fields", pFields);
1066 int nCount = m_pFieldTree->m_Root.CountFields(); 1066 int nCount = m_pFieldTree->m_Root.CountFields();
1067 for (int i = 0; i < nCount; i++) { 1067 for (int i = 0; i < nCount; i++) {
1068 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); 1068 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i);
1069 if (!pField || pField->GetType() == CPDF_FormField::PushButton) { 1069 if (!pField || pField->GetType() == CPDF_FormField::PushButton) {
1070 continue; 1070 continue;
1071 } 1071 }
1072 FX_DWORD dwFlags = pField->GetFieldFlags(); 1072 FX_DWORD dwFlags = pField->GetFieldFlags();
1073 if (dwFlags & 0x04) 1073 if (dwFlags & 0x04)
1074 continue; 1074 continue;
1075 1075
1076 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) { 1076 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) {
1077 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetString("V").IsEmpty()) 1077 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetStringBy("V").IsEmpty())
1078 continue; 1078 continue;
1079 1079
1080 CFX_WideString fullname = GetFullName(pField->GetFieldDict()); 1080 CFX_WideString fullname = GetFullName(pField->GetFieldDict());
1081 CPDF_Dictionary* pFieldDict = new CPDF_Dictionary; 1081 CPDF_Dictionary* pFieldDict = new CPDF_Dictionary;
1082 pFieldDict->SetAt("T", new CPDF_String(fullname)); 1082 pFieldDict->SetAt("T", new CPDF_String(fullname));
1083 if (pField->GetType() == CPDF_FormField::CheckBox || 1083 if (pField->GetType() == CPDF_FormField::CheckBox ||
1084 pField->GetType() == CPDF_FormField::RadioButton) { 1084 pField->GetType() == CPDF_FormField::RadioButton) {
1085 CFX_WideString csExport = pField->GetCheckValue(FALSE); 1085 CFX_WideString csExport = pField->GetCheckValue(FALSE);
1086 CFX_ByteString csBExport = PDF_EncodeText(csExport); 1086 CFX_ByteString csBExport = PDF_EncodeText(csExport);
1087 CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->m_pDict, "Opt"); 1087 CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->m_pDict, "Opt");
(...skipping 16 matching lines...) Expand all
1104 int32_t m_codePage; 1104 int32_t m_codePage;
1105 } g_fieldEncoding[] = { 1105 } g_fieldEncoding[] = {
1106 {"BigFive", 950}, 1106 {"BigFive", 950},
1107 {"GBK", 936}, 1107 {"GBK", 936},
1108 {"Shift-JIS", 932}, 1108 {"Shift-JIS", 932},
1109 {"UHC", 949}, 1109 {"UHC", 949},
1110 }; 1110 };
1111 static void FPDFDOC_FDF_GetFieldValue(CPDF_Dictionary* pFieldDict, 1111 static void FPDFDOC_FDF_GetFieldValue(CPDF_Dictionary* pFieldDict,
1112 CFX_WideString& csValue, 1112 CFX_WideString& csValue,
1113 CFX_ByteString& bsEncoding) { 1113 CFX_ByteString& bsEncoding) {
1114 CFX_ByteString csBValue = pFieldDict->GetString("V"); 1114 CFX_ByteString csBValue = pFieldDict->GetStringBy("V");
1115 int32_t iCount = sizeof(g_fieldEncoding) / sizeof(g_fieldEncoding[0]); 1115 int32_t iCount = sizeof(g_fieldEncoding) / sizeof(g_fieldEncoding[0]);
1116 int32_t i = 0; 1116 int32_t i = 0;
1117 for (; i < iCount; ++i) 1117 for (; i < iCount; ++i)
1118 if (bsEncoding == g_fieldEncoding[i].m_name) { 1118 if (bsEncoding == g_fieldEncoding[i].m_name) {
1119 break; 1119 break;
1120 } 1120 }
1121 if (i < iCount) { 1121 if (i < iCount) {
1122 CFX_CharMap* pCharMap = 1122 CFX_CharMap* pCharMap =
1123 CFX_CharMap::GetDefaultMapper(g_fieldEncoding[i].m_codePage); 1123 CFX_CharMap::GetDefaultMapper(g_fieldEncoding[i].m_codePage);
1124 FXSYS_assert(pCharMap); 1124 FXSYS_assert(pCharMap);
1125 csValue.ConvertFrom(csBValue, pCharMap); 1125 csValue.ConvertFrom(csBValue, pCharMap);
1126 return; 1126 return;
1127 } 1127 }
1128 CFX_ByteString csTemp = csBValue.Left(2); 1128 CFX_ByteString csTemp = csBValue.Left(2);
1129 if (csTemp == "\xFF\xFE" || csTemp == "\xFE\xFF") { 1129 if (csTemp == "\xFF\xFE" || csTemp == "\xFE\xFF") {
1130 csValue = PDF_DecodeText(csBValue); 1130 csValue = PDF_DecodeText(csBValue);
1131 } else { 1131 } else {
1132 csValue = CFX_WideString::FromLocal(csBValue); 1132 csValue = CFX_WideString::FromLocal(csBValue);
1133 } 1133 }
1134 } 1134 }
1135 void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict, 1135 void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict,
1136 const CFX_WideString& parent_name, 1136 const CFX_WideString& parent_name,
1137 FX_BOOL bNotify, 1137 FX_BOOL bNotify,
1138 int nLevel) { 1138 int nLevel) {
1139 CFX_WideString name; 1139 CFX_WideString name;
1140 if (!parent_name.IsEmpty()) { 1140 if (!parent_name.IsEmpty()) {
1141 name = parent_name + L"."; 1141 name = parent_name + L".";
1142 } 1142 }
1143 name += pFieldDict->GetUnicodeText("T"); 1143 name += pFieldDict->GetUnicodeTextBy("T");
1144 CPDF_Array* pKids = pFieldDict->GetArray("Kids"); 1144 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids");
1145 if (pKids) { 1145 if (pKids) {
1146 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { 1146 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) {
1147 CPDF_Dictionary* pKid = pKids->GetDict(i); 1147 CPDF_Dictionary* pKid = pKids->GetDictAt(i);
1148 if (!pKid) { 1148 if (!pKid) {
1149 continue; 1149 continue;
1150 } 1150 }
1151 if (nLevel <= nMaxRecursion) { 1151 if (nLevel <= nMaxRecursion) {
1152 FDF_ImportField(pKid, name, bNotify, nLevel + 1); 1152 FDF_ImportField(pKid, name, bNotify, nLevel + 1);
1153 } 1153 }
1154 } 1154 }
1155 return; 1155 return;
1156 } 1156 }
1157 if (!pFieldDict->KeyExist("V")) { 1157 if (!pFieldDict->KeyExist("V")) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 } 1197 }
1198 if (CPDF_InterForm::m_bUpdateAP) { 1198 if (CPDF_InterForm::m_bUpdateAP) {
1199 pField->UpdateAP(NULL); 1199 pField->UpdateAP(NULL);
1200 } 1200 }
1201 } 1201 }
1202 FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF, 1202 FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF,
1203 FX_BOOL bNotify) { 1203 FX_BOOL bNotify) {
1204 if (!pFDF) { 1204 if (!pFDF) {
1205 return FALSE; 1205 return FALSE;
1206 } 1206 }
1207 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF"); 1207 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictBy("FDF");
1208 if (!pMainDict) { 1208 if (!pMainDict) {
1209 return FALSE; 1209 return FALSE;
1210 } 1210 }
1211 CPDF_Array* pFields = pMainDict->GetArray("Fields"); 1211 CPDF_Array* pFields = pMainDict->GetArrayBy("Fields");
1212 if (!pFields) { 1212 if (!pFields) {
1213 return FALSE; 1213 return FALSE;
1214 } 1214 }
1215 m_bsEncoding = pMainDict->GetString("Encoding"); 1215 m_bsEncoding = pMainDict->GetStringBy("Encoding");
1216 if (bNotify && m_pFormNotify) { 1216 if (bNotify && m_pFormNotify) {
1217 int iRet = m_pFormNotify->BeforeFormImportData(this); 1217 int iRet = m_pFormNotify->BeforeFormImportData(this);
1218 if (iRet < 0) { 1218 if (iRet < 0) {
1219 return FALSE; 1219 return FALSE;
1220 } 1220 }
1221 } 1221 }
1222 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) { 1222 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) {
1223 CPDF_Dictionary* pField = pFields->GetDict(i); 1223 CPDF_Dictionary* pField = pFields->GetDictAt(i);
1224 if (!pField) { 1224 if (!pField) {
1225 continue; 1225 continue;
1226 } 1226 }
1227 FDF_ImportField(pField, L"", bNotify); 1227 FDF_ImportField(pField, L"", bNotify);
1228 } 1228 }
1229 if (bNotify && m_pFormNotify) { 1229 if (bNotify && m_pFormNotify) {
1230 m_pFormNotify->AfterFormImportData(this); 1230 m_pFormNotify->AfterFormImportData(this);
1231 } 1231 }
1232 return TRUE; 1232 return TRUE;
1233 } 1233 }
1234 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) { 1234 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) {
1235 m_pFormNotify = (CPDF_FormNotify*)pNotify; 1235 m_pFormNotify = (CPDF_FormNotify*)pNotify;
1236 } 1236 }
OLDNEW
« no previous file with comments | « core/src/fpdfdoc/doc_bookmark.cpp ('k') | core/src/fpdfdoc/doc_formcontrol.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698