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

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

Issue 1430213002: Remove CFX_PtrArray usage in fpdfsdk. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: address most comments Created 5 years, 1 month 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_action.cpp ('k') | fpdfsdk/include/fsdk_baseform.h » ('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 "../../include/fpdfdoc/fpdf_doc.h" 7 #include "../../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;
11 11
12 class _CFieldNameExtractor { 12 class CFieldNameExtractor {
13 public: 13 public:
14 _CFieldNameExtractor(const CFX_WideString& full_name) { 14 explicit CFieldNameExtractor(const CFX_WideString& full_name) {
15 m_pStart = full_name.c_str(); 15 m_pStart = full_name.c_str();
16 m_pEnd = m_pStart + full_name.GetLength(); 16 m_pEnd = m_pStart + full_name.GetLength();
17 m_pCur = m_pStart; 17 m_pCur = m_pStart;
18 } 18 }
19 void GetNext(const FX_WCHAR*& pSubName, FX_STRSIZE& size) { 19 void GetNext(const FX_WCHAR*& pSubName, FX_STRSIZE& size) {
20 pSubName = m_pCur; 20 pSubName = m_pCur;
21 while (m_pCur < m_pEnd && m_pCur[0] != L'.') { 21 while (m_pCur < m_pEnd && m_pCur[0] != L'.') {
22 m_pCur++; 22 m_pCur++;
23 } 23 }
24 size = (FX_STRSIZE)(m_pCur - pSubName); 24 size = (FX_STRSIZE)(m_pCur - pSubName);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 for (int i = 0; i < ptr_array.GetSize(); i++) { 144 for (int i = 0; i < ptr_array.GetSize(); i++) {
145 _Node* pNode = (_Node*)ptr_array[i]; 145 _Node* pNode = (_Node*)ptr_array[i];
146 RemoveNode(pNode); 146 RemoveNode(pNode);
147 } 147 }
148 } 148 }
149 void CFieldTree::SetField(const CFX_WideString& full_name, 149 void CFieldTree::SetField(const CFX_WideString& full_name,
150 CPDF_FormField* field_ptr) { 150 CPDF_FormField* field_ptr) {
151 if (full_name == L"") { 151 if (full_name == L"") {
152 return; 152 return;
153 } 153 }
154 _CFieldNameExtractor name_extractor(full_name); 154 CFieldNameExtractor name_extractor(full_name);
155 const FX_WCHAR* pName; 155 const FX_WCHAR* pName;
156 FX_STRSIZE nLength; 156 FX_STRSIZE nLength;
157 name_extractor.GetNext(pName, nLength); 157 name_extractor.GetNext(pName, nLength);
158 _Node *pNode = &m_Root, *pLast = NULL; 158 _Node *pNode = &m_Root, *pLast = NULL;
159 while (nLength > 0) { 159 while (nLength > 0) {
160 pLast = pNode; 160 pLast = pNode;
161 CFX_WideString name = CFX_WideString(pName, nLength); 161 CFX_WideString name = CFX_WideString(pName, nLength);
162 pNode = _Lookup(pLast, name); 162 pNode = _Lookup(pLast, name);
163 if (pNode == NULL) { 163 if (pNode == NULL) {
164 pNode = AddChild(pLast, name, NULL); 164 pNode = AddChild(pLast, name, NULL);
165 } 165 }
166 name_extractor.GetNext(pName, nLength); 166 name_extractor.GetNext(pName, nLength);
167 } 167 }
168 if (pNode != &m_Root) { 168 if (pNode != &m_Root) {
169 pNode->field_ptr = field_ptr; 169 pNode->field_ptr = field_ptr;
170 } 170 }
171 } 171 }
172 CPDF_FormField* CFieldTree::GetField(const CFX_WideString& full_name) { 172 CPDF_FormField* CFieldTree::GetField(const CFX_WideString& full_name) {
173 if (full_name == L"") { 173 if (full_name == L"") {
174 return NULL; 174 return NULL;
175 } 175 }
176 _CFieldNameExtractor name_extractor(full_name); 176 CFieldNameExtractor name_extractor(full_name);
177 const FX_WCHAR* pName; 177 const FX_WCHAR* pName;
178 FX_STRSIZE nLength; 178 FX_STRSIZE nLength;
179 name_extractor.GetNext(pName, nLength); 179 name_extractor.GetNext(pName, nLength);
180 _Node *pNode = &m_Root, *pLast = NULL; 180 _Node *pNode = &m_Root, *pLast = NULL;
181 while (nLength > 0 && pNode) { 181 while (nLength > 0 && pNode) {
182 pLast = pNode; 182 pLast = pNode;
183 CFX_WideString name = CFX_WideString(pName, nLength); 183 CFX_WideString name = CFX_WideString(pName, nLength);
184 pNode = _Lookup(pLast, name); 184 pNode = _Lookup(pLast, name);
185 name_extractor.GetNext(pName, nLength); 185 name_extractor.GetNext(pName, nLength);
186 } 186 }
187 return pNode ? pNode->field_ptr : NULL; 187 return pNode ? pNode->field_ptr : NULL;
188 } 188 }
189 CPDF_FormField* CFieldTree::RemoveField(const CFX_WideString& full_name) { 189 CPDF_FormField* CFieldTree::RemoveField(const CFX_WideString& full_name) {
190 if (full_name == L"") { 190 if (full_name == L"") {
191 return NULL; 191 return NULL;
192 } 192 }
193 _CFieldNameExtractor name_extractor(full_name); 193 CFieldNameExtractor name_extractor(full_name);
194 const FX_WCHAR* pName; 194 const FX_WCHAR* pName;
195 FX_STRSIZE nLength; 195 FX_STRSIZE nLength;
196 name_extractor.GetNext(pName, nLength); 196 name_extractor.GetNext(pName, nLength);
197 _Node *pNode = &m_Root, *pLast = NULL; 197 _Node *pNode = &m_Root, *pLast = NULL;
198 while (nLength > 0 && pNode) { 198 while (nLength > 0 && pNode) {
199 pLast = pNode; 199 pLast = pNode;
200 CFX_WideString name = CFX_WideString(pName, nLength); 200 CFX_WideString name = CFX_WideString(pName, nLength);
201 pNode = _Lookup(pLast, name); 201 pNode = _Lookup(pLast, name);
202 name_extractor.GetNext(pName, nLength); 202 name_extractor.GetNext(pName, nLength);
203 } 203 }
204 if (pNode && pNode != &m_Root) { 204 if (pNode && pNode != &m_Root) {
205 CFX_PtrArray& ptr_array = pLast->children; 205 CFX_PtrArray& ptr_array = pLast->children;
206 for (int i = 0; i < ptr_array.GetSize(); i++) { 206 for (int i = 0; i < ptr_array.GetSize(); i++) {
207 if (pNode == (_Node*)ptr_array[i]) { 207 if (pNode == (_Node*)ptr_array[i]) {
208 ptr_array.RemoveAt(i); 208 ptr_array.RemoveAt(i);
209 break; 209 break;
210 } 210 }
211 } 211 }
212 CPDF_FormField* pField = pNode->field_ptr; 212 CPDF_FormField* pField = pNode->field_ptr;
213 RemoveNode(pNode); 213 RemoveNode(pNode);
214 return pField; 214 return pField;
215 } 215 }
216 return NULL; 216 return NULL;
217 } 217 }
218 CFieldTree::_Node* CFieldTree::FindNode(const CFX_WideString& full_name) { 218 CFieldTree::_Node* CFieldTree::FindNode(const CFX_WideString& full_name) {
219 if (full_name == L"") { 219 if (full_name == L"") {
220 return NULL; 220 return NULL;
221 } 221 }
222 _CFieldNameExtractor name_extractor(full_name); 222 CFieldNameExtractor name_extractor(full_name);
223 const FX_WCHAR* pName; 223 const FX_WCHAR* pName;
224 FX_STRSIZE nLength; 224 FX_STRSIZE nLength;
225 name_extractor.GetNext(pName, nLength); 225 name_extractor.GetNext(pName, nLength);
226 _Node *pNode = &m_Root, *pLast = NULL; 226 _Node *pNode = &m_Root, *pLast = NULL;
227 while (nLength > 0 && pNode) { 227 while (nLength > 0 && pNode) {
228 pLast = pNode; 228 pLast = pNode;
229 CFX_WideString name = CFX_WideString(pName, nLength); 229 CFX_WideString name = CFX_WideString(pName, nLength);
230 pNode = _Lookup(pLast, name); 230 pNode = _Lookup(pLast, name);
231 name_extractor.GetNext(pName, nLength); 231 name_extractor.GetNext(pName, nLength);
232 } 232 }
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 allFieldNames.RemoveAll(); 758 allFieldNames.RemoveAll();
759 int nCount = m_pFieldTree->m_Root.CountFields(); 759 int nCount = m_pFieldTree->m_Root.CountFields();
760 for (int i = 0; i < nCount; i++) { 760 for (int i = 0; i < nCount; i++) {
761 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); 761 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i);
762 if (pField) { 762 if (pField) {
763 CFX_WideString full_name = GetFullName(pField->GetFieldDict()); 763 CFX_WideString full_name = GetFullName(pField->GetFieldDict());
764 allFieldNames.Add(full_name); 764 allFieldNames.Add(full_name);
765 } 765 }
766 } 766 }
767 } 767 }
768 FX_BOOL CPDF_InterForm::IsValidFormField(const void* pField) { 768
769 if (pField == NULL) {
770 return FALSE;
771 }
772 int nCount = m_pFieldTree->m_Root.CountFields();
773 for (int i = 0; i < nCount; i++) {
774 CPDF_FormField* pFormField = m_pFieldTree->m_Root.GetField(i);
775 if (pField == pFormField) {
776 return TRUE;
777 }
778 }
779 return FALSE;
780 }
781 CPDF_FormField* CPDF_InterForm::GetFieldByDict( 769 CPDF_FormField* CPDF_InterForm::GetFieldByDict(
782 CPDF_Dictionary* pFieldDict) const { 770 CPDF_Dictionary* pFieldDict) const {
783 if (pFieldDict == NULL) { 771 if (pFieldDict == NULL) {
784 return NULL; 772 return NULL;
785 } 773 }
786 CFX_WideString csWName = GetFullName(pFieldDict); 774 CFX_WideString csWName = GetFullName(pFieldDict);
787 return m_pFieldTree->GetField(csWName); 775 return m_pFieldTree->GetField(csWName);
788 } 776 }
789 777
790 CPDF_FormControl* CPDF_InterForm::GetControlAtPoint(CPDF_Page* pPage, 778 CPDF_FormControl* CPDF_InterForm::GetControlAtPoint(CPDF_Page* pPage,
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 } 927 }
940 CPDF_Font* CPDF_InterForm::GetDefaultFormFont() { 928 CPDF_Font* CPDF_InterForm::GetDefaultFormFont() {
941 return GetDefaultInterFormFont(m_pFormDict, m_pDocument); 929 return GetDefaultInterFormFont(m_pFormDict, m_pDocument);
942 } 930 }
943 int CPDF_InterForm::GetFormAlignment() { 931 int CPDF_InterForm::GetFormAlignment() {
944 if (m_pFormDict == NULL) { 932 if (m_pFormDict == NULL) {
945 return 0; 933 return 0;
946 } 934 }
947 return m_pFormDict->GetInteger("Q", 0); 935 return m_pFormDict->GetInteger("Q", 0);
948 } 936 }
949 FX_BOOL CPDF_InterForm::ResetForm(const CFX_PtrArray& fields, 937
950 FX_BOOL bIncludeOrExclude, 938 bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields,
951 FX_BOOL bNotify) { 939 bool bIncludeOrExclude,
952 if (bNotify && m_pFormNotify != NULL) { 940 bool bNotify) {
953 int iRet = m_pFormNotify->BeforeFormReset(this); 941 if (bNotify && m_pFormNotify && (m_pFormNotify->BeforeFormReset(this) < 0))
Tom Sepez 2015/11/09 23:02:20 nit: overparenthesized
Lei Zhang 2015/11/10 06:39:54 Done.
954 if (iRet < 0) { 942 return false;
955 return FALSE; 943
956 } 944 int nCount = m_pFieldTree->m_Root.CountFields();
945 for (int i = 0; i < nCount; ++i) {
946 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i);
947 if (!pField)
948 continue;
949
950 auto it = std::find(fields.begin(), fields.end(), pField);
951 if (bIncludeOrExclude == (it != fields.end()))
952 pField->ResetField(bNotify);
957 } 953 }
954 if (bNotify && m_pFormNotify)
955 m_pFormNotify->AfterFormReset(this);
956 return true;
957 }
958
959 bool CPDF_InterForm::ResetForm(bool bNotify) {
960 if (bNotify && m_pFormNotify && (m_pFormNotify->BeforeFormReset(this) < 0))
Tom Sepez 2015/11/09 23:02:20 ditto
Lei Zhang 2015/11/10 06:39:54 Done.
961 return false;
962
958 int nCount = m_pFieldTree->m_Root.CountFields(); 963 int nCount = m_pFieldTree->m_Root.CountFields();
959 for (int i = 0; i < nCount; i++) { 964 for (int i = 0; i < nCount; ++i) {
960 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); 965 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i);
961 if (pField == NULL) { 966 if (!pField)
962 continue; 967 continue;
963 } 968
964 FX_BOOL bFind = FALSE;
965 int iCount = fields.GetSize();
966 for (int i = 0; i < iCount; i++) {
967 if (pField == (CPDF_FormField*)fields[i]) {
968 bFind = TRUE;
969 break;
970 }
971 }
972 if ((bIncludeOrExclude && bFind) || (!bIncludeOrExclude && !bFind)) {
973 pField->ResetField(bNotify);
974 }
975 }
976 if (bNotify && m_pFormNotify != NULL) {
977 m_pFormNotify->AfterFormReset(this);
978 }
979 return TRUE;
980 }
981 FX_BOOL CPDF_InterForm::ResetForm(FX_BOOL bNotify) {
982 if (bNotify && m_pFormNotify != NULL) {
983 int iRet = m_pFormNotify->BeforeFormReset(this);
984 if (iRet < 0) {
985 return FALSE;
986 }
987 }
988 int nCount = m_pFieldTree->m_Root.CountFields();
989 for (int i = 0; i < nCount; i++) {
990 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i);
991 if (pField == NULL) {
992 continue;
993 }
994 pField->ResetField(bNotify); 969 pField->ResetField(bNotify);
995 } 970 }
996 if (bNotify && m_pFormNotify != NULL) { 971 if (bNotify && m_pFormNotify)
997 m_pFormNotify->AfterFormReset(this); 972 m_pFormNotify->AfterFormReset(this);
998 } 973 return true;
999 return TRUE;
1000 } 974 }
975
1001 void CPDF_InterForm::LoadField(CPDF_Dictionary* pFieldDict, int nLevel) { 976 void CPDF_InterForm::LoadField(CPDF_Dictionary* pFieldDict, int nLevel) {
1002 if (nLevel > nMaxRecursion) { 977 if (nLevel > nMaxRecursion) {
1003 return; 978 return;
1004 } 979 }
1005 if (pFieldDict == NULL) { 980 if (pFieldDict == NULL) {
1006 return; 981 return;
1007 } 982 }
1008 FX_DWORD dwParentObjNum = pFieldDict->GetObjNum(); 983 FX_DWORD dwParentObjNum = pFieldDict->GetObjNum();
1009 CPDF_Array* pKids = pFieldDict->GetArray("Kids"); 984 CPDF_Array* pKids = pFieldDict->GetArray("Kids");
1010 if (!pKids) { 985 if (!pKids) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 const auto it = m_ControlMap.find(pWidgetDict); 1094 const auto it = m_ControlMap.find(pWidgetDict);
1120 if (it != m_ControlMap.end()) 1095 if (it != m_ControlMap.end())
1121 return it->second; 1096 return it->second;
1122 1097
1123 CPDF_FormControl* pControl = 1098 CPDF_FormControl* pControl =
1124 new CPDF_FormControl((CPDF_FormField*)pField, pWidgetDict); 1099 new CPDF_FormControl((CPDF_FormField*)pField, pWidgetDict);
1125 m_ControlMap[pWidgetDict] = pControl; 1100 m_ControlMap[pWidgetDict] = pControl;
1126 ((CPDF_FormField*)pField)->m_ControlList.Add(pControl); 1101 ((CPDF_FormField*)pField)->m_ControlList.Add(pControl);
1127 return pControl; 1102 return pControl;
1128 } 1103 }
1104
1129 CPDF_FormField* CPDF_InterForm::CheckRequiredFields( 1105 CPDF_FormField* CPDF_InterForm::CheckRequiredFields(
1130 const CFX_PtrArray* fields, 1106 const std::vector<CPDF_FormField*>* fields,
1131 FX_BOOL bIncludeOrExclude) const { 1107 bool bIncludeOrExclude) const {
1132 int nCount = m_pFieldTree->m_Root.CountFields(); 1108 int nCount = m_pFieldTree->m_Root.CountFields();
1133 for (int i = 0; i < nCount; i++) { 1109 for (int i = 0; i < nCount; ++i) {
1134 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); 1110 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i);
1135 if (pField == NULL) { 1111 if (!pField)
1136 continue; 1112 continue;
1137 } 1113
1138 int32_t iType = pField->GetType(); 1114 int32_t iType = pField->GetType();
1139 if (iType == CPDF_FormField::PushButton || 1115 if (iType == CPDF_FormField::PushButton ||
1140 iType == CPDF_FormField::CheckBox || iType == CPDF_FormField::ListBox) { 1116 iType == CPDF_FormField::CheckBox || iType == CPDF_FormField::ListBox) {
1141 continue; 1117 continue;
1142 } 1118 }
1143 FX_DWORD dwFlags = pField->GetFieldFlags(); 1119 FX_DWORD dwFlags = pField->GetFieldFlags();
1144 if (dwFlags & 0x04) { 1120 // TODO(thestig): Look up these magic numbers and add constants for them.
1121 if (dwFlags & 0x04)
1145 continue; 1122 continue;
1123
1124 bool bFind = true;
1125 if (fields) {
1126 auto it = std::find(fields->begin(), fields->end(), pField);
1127 bFind = (it != fields->end());
1146 } 1128 }
1147 FX_BOOL bFind = TRUE; 1129 if (bIncludeOrExclude == bFind) {
1148 if (fields != NULL) {
1149 bFind = fields->Find(pField, 0) >= 0;
1150 }
1151 if ((bIncludeOrExclude && bFind) || (!bIncludeOrExclude && !bFind)) {
1152 CPDF_Dictionary* pFieldDict = pField->m_pDict; 1130 CPDF_Dictionary* pFieldDict = pField->m_pDict;
1153 if ((dwFlags & 0x02) != 0 && pFieldDict->GetString("V").IsEmpty()) { 1131 if ((dwFlags & 0x02) != 0 && pFieldDict->GetString("V").IsEmpty()) {
1154 return pField; 1132 return pField;
1155 } 1133 }
1156 } 1134 }
1157 } 1135 }
1158 return NULL; 1136 return nullptr;
1159 } 1137 }
1138
1160 CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, 1139 CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path,
1161 FX_BOOL bSimpleFileSpec) const { 1140 bool bSimpleFileSpec) const {
1162 CFX_PtrArray fields; 1141 std::vector<CPDF_FormField*> fields;
1163 int nCount = m_pFieldTree->m_Root.CountFields(); 1142 int nCount = m_pFieldTree->m_Root.CountFields();
1164 for (int i = 0; i < nCount; i++) { 1143 for (int i = 0; i < nCount; ++i)
1165 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); 1144 fields.push_back(m_pFieldTree->m_Root.GetField(i));
1166 fields.Add(pField); 1145 return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec);
1167 }
1168 return ExportToFDF(pdf_path, fields, TRUE, bSimpleFileSpec);
1169 } 1146 }
1147
1148 // TODO(thestig): Fix this.
1170 CFX_WideString FILESPEC_EncodeFileName(const CFX_WideStringC& filepath); 1149 CFX_WideString FILESPEC_EncodeFileName(const CFX_WideStringC& filepath);
1171 CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, 1150
1172 CFX_PtrArray& fields, 1151 CFDF_Document* CPDF_InterForm::ExportToFDF(
1173 FX_BOOL bIncludeOrExclude, 1152 const CFX_WideStringC& pdf_path,
1174 FX_BOOL bSimpleFileSpec) const { 1153 const std::vector<CPDF_FormField*>& fields,
1154 bool bIncludeOrExclude,
1155 bool bSimpleFileSpec) const {
1175 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc(); 1156 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc();
1176 if (pDoc == NULL) { 1157 if (pDoc == NULL) {
1177 return NULL; 1158 return NULL;
1178 } 1159 }
1179 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDict("FDF"); 1160 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDict("FDF");
1180 if (!pdf_path.IsEmpty()) { 1161 if (!pdf_path.IsEmpty()) {
1181 if (bSimpleFileSpec) { 1162 if (bSimpleFileSpec) {
1182 CFX_WideString wsFilePath = FILESPEC_EncodeFileName(pdf_path); 1163 CFX_WideString wsFilePath = FILESPEC_EncodeFileName(pdf_path);
1183 pMainDict->SetAtString(FX_BSTRC("F"), 1164 pMainDict->SetAtString(FX_BSTRC("F"),
1184 CFX_ByteString::FromUnicode(wsFilePath)); 1165 CFX_ByteString::FromUnicode(wsFilePath));
1185 pMainDict->SetAtString(FX_BSTRC("UF"), PDF_EncodeText(wsFilePath)); 1166 pMainDict->SetAtString(FX_BSTRC("UF"), PDF_EncodeText(wsFilePath));
1186 } else { 1167 } else {
1187 CPDF_FileSpec filespec; 1168 CPDF_FileSpec filespec;
1188 filespec.SetFileName(pdf_path); 1169 filespec.SetFileName(pdf_path);
1189 pMainDict->SetAt("F", static_cast<CPDF_Object*>(filespec)); 1170 pMainDict->SetAt("F", static_cast<CPDF_Object*>(filespec));
1190 } 1171 }
1191 } 1172 }
1192 CPDF_Array* pFields = CPDF_Array::Create(); 1173 CPDF_Array* pFields = CPDF_Array::Create();
1193 if (pFields == NULL) { 1174 if (pFields == NULL) {
1194 return NULL; 1175 return NULL;
1195 } 1176 }
1196 pMainDict->SetAt("Fields", pFields); 1177 pMainDict->SetAt("Fields", pFields);
1197 int nCount = m_pFieldTree->m_Root.CountFields(); 1178 int nCount = m_pFieldTree->m_Root.CountFields();
1198 for (int i = 0; i < nCount; i++) { 1179 for (int i = 0; i < nCount; i++) {
1199 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); 1180 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i);
1200 if (pField == NULL || pField->GetType() == CPDF_FormField::PushButton) { 1181 if (pField == NULL || pField->GetType() == CPDF_FormField::PushButton) {
1201 continue; 1182 continue;
1202 } 1183 }
1203 FX_DWORD dwFlags = pField->GetFieldFlags(); 1184 FX_DWORD dwFlags = pField->GetFieldFlags();
1204 if (dwFlags & 0x04) { 1185 if (dwFlags & 0x04)
1205 continue; 1186 continue;
1206 } 1187
1207 FX_BOOL bFind = fields.Find(pField, 0) >= 0; 1188 auto it = std::find(fields.begin(), fields.end(), pField);
1208 if ((bIncludeOrExclude && bFind) || (!bIncludeOrExclude && !bFind)) { 1189 if (bIncludeOrExclude == (it != fields.end())) {
1209 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetString("V").IsEmpty()) { 1190 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetString("V").IsEmpty())
1210 continue; 1191 continue;
1211 } 1192
1212 CFX_WideString fullname = GetFullName(pField->GetFieldDict()); 1193 CFX_WideString fullname = GetFullName(pField->GetFieldDict());
1213 CPDF_Dictionary* pFieldDict = CPDF_Dictionary::Create(); 1194 CPDF_Dictionary* pFieldDict = CPDF_Dictionary::Create();
1214 if (pFieldDict == NULL) { 1195 if (!pFieldDict)
1215 return NULL; 1196 return nullptr;
1216 } 1197
1217 CPDF_String* pString = CPDF_String::Create(fullname); 1198 CPDF_String* pString = CPDF_String::Create(fullname);
1218 if (pString == NULL) { 1199 if (!pString) {
1219 pFieldDict->Release(); 1200 pFieldDict->Release();
1220 return NULL; 1201 return nullptr;
1221 } 1202 }
1222 pFieldDict->SetAt("T", pString); 1203 pFieldDict->SetAt("T", pString);
1223 if (pField->GetType() == CPDF_FormField::CheckBox || 1204 if (pField->GetType() == CPDF_FormField::CheckBox ||
1224 pField->GetType() == CPDF_FormField::RadioButton) { 1205 pField->GetType() == CPDF_FormField::RadioButton) {
1225 CFX_WideString csExport = pField->GetCheckValue(FALSE); 1206 CFX_WideString csExport = pField->GetCheckValue(FALSE);
1226 CFX_ByteString csBExport = PDF_EncodeText(csExport); 1207 CFX_ByteString csBExport = PDF_EncodeText(csExport);
1227 CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->m_pDict, "Opt"); 1208 CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->m_pDict, "Opt");
1228 if (pOpt == NULL) { 1209 if (pOpt)
1210 pFieldDict->SetAtString("V", csBExport);
1211 else
1229 pFieldDict->SetAtName("V", csBExport); 1212 pFieldDict->SetAtName("V", csBExport);
1230 } else {
1231 pFieldDict->SetAtString("V", csBExport);
1232 }
1233 } else { 1213 } else {
1234 CPDF_Object* pV = FPDF_GetFieldAttr(pField->m_pDict, "V"); 1214 CPDF_Object* pV = FPDF_GetFieldAttr(pField->m_pDict, "V");
1235 if (pV != NULL) { 1215 if (pV)
1236 pFieldDict->SetAt("V", pV->Clone(TRUE)); 1216 pFieldDict->SetAt("V", pV->Clone(TRUE));
1237 }
1238 } 1217 }
1239 pFields->Add(pFieldDict); 1218 pFields->Add(pFieldDict);
1240 } 1219 }
1241 } 1220 }
1242 return pDoc; 1221 return pDoc;
1243 } 1222 }
1244 const struct _SupportFieldEncoding { 1223 const struct _SupportFieldEncoding {
1245 const FX_CHAR* m_name; 1224 const FX_CHAR* m_name;
1246 int32_t m_codePage; 1225 int32_t m_codePage;
1247 } g_fieldEncoding[] = { 1226 } g_fieldEncoding[] = {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1370 FDF_ImportField(pField, L"", bNotify); 1349 FDF_ImportField(pField, L"", bNotify);
1371 } 1350 }
1372 if (bNotify && m_pFormNotify != NULL) { 1351 if (bNotify && m_pFormNotify != NULL) {
1373 m_pFormNotify->AfterFormImportData(this); 1352 m_pFormNotify->AfterFormImportData(this);
1374 } 1353 }
1375 return TRUE; 1354 return TRUE;
1376 } 1355 }
1377 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) { 1356 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) {
1378 m_pFormNotify = (CPDF_FormNotify*)pNotify; 1357 m_pFormNotify = (CPDF_FormNotify*)pNotify;
1379 } 1358 }
OLDNEW
« no previous file with comments | « core/src/fpdfdoc/doc_action.cpp ('k') | fpdfsdk/include/fsdk_baseform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698