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

Side by Side Diff: core/fpdfdoc/cpdf_interform.cpp

Issue 2538533003: Make FDF document creation return unique_ptrs (Closed)
Patch Set: Created 4 years 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
OLDNEW
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 "core/fpdfdoc/cpdf_interform.h" 7 #include "core/fpdfdoc/cpdf_interform.h"
8 8
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 1167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1178 bFind = pdfium::ContainsValue(*fields, pField); 1178 bFind = pdfium::ContainsValue(*fields, pField);
1179 if (bIncludeOrExclude == bFind) { 1179 if (bIncludeOrExclude == bFind) {
1180 CPDF_Dictionary* pFieldDict = pField->m_pDict; 1180 CPDF_Dictionary* pFieldDict = pField->m_pDict;
1181 if ((dwFlags & 0x02) != 0 && pFieldDict->GetStringFor("V").IsEmpty()) 1181 if ((dwFlags & 0x02) != 0 && pFieldDict->GetStringFor("V").IsEmpty())
1182 return pField; 1182 return pField;
1183 } 1183 }
1184 } 1184 }
1185 return nullptr; 1185 return nullptr;
1186 } 1186 }
1187 1187
1188 CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, 1188 std::unique_ptr<CFDF_Document> CPDF_InterForm::ExportToFDF(
1189 bool bSimpleFileSpec) const { 1189 const CFX_WideStringC& pdf_path,
1190 bool bSimpleFileSpec) const {
1190 std::vector<CPDF_FormField*> fields; 1191 std::vector<CPDF_FormField*> fields;
1191 size_t nCount = m_pFieldTree->m_Root.CountFields(); 1192 size_t nCount = m_pFieldTree->m_Root.CountFields();
1192 for (size_t i = 0; i < nCount; ++i) 1193 for (size_t i = 0; i < nCount; ++i)
1193 fields.push_back(m_pFieldTree->m_Root.GetFieldAtIndex(i)); 1194 fields.push_back(m_pFieldTree->m_Root.GetFieldAtIndex(i));
1194 return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec); 1195 return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec);
1195 } 1196 }
1196 1197
1197 CFDF_Document* CPDF_InterForm::ExportToFDF( 1198 std::unique_ptr<CFDF_Document> CPDF_InterForm::ExportToFDF(
1198 const CFX_WideStringC& pdf_path, 1199 const CFX_WideStringC& pdf_path,
1199 const std::vector<CPDF_FormField*>& fields, 1200 const std::vector<CPDF_FormField*>& fields,
1200 bool bIncludeOrExclude, 1201 bool bIncludeOrExclude,
1201 bool bSimpleFileSpec) const { 1202 bool bSimpleFileSpec) const {
1202 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc(); 1203 std::unique_ptr<CFDF_Document> pDoc = CFDF_Document::CreateNewDoc();
1203 if (!pDoc) 1204 if (!pDoc)
1204 return nullptr; 1205 return nullptr;
1205 1206
1206 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictFor("FDF"); 1207 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictFor("FDF");
1207 if (!pdf_path.IsEmpty()) { 1208 if (!pdf_path.IsEmpty()) {
1208 if (bSimpleFileSpec) { 1209 if (bSimpleFileSpec) {
1209 CFX_WideString wsFilePath = CPDF_FileSpec::EncodeFileName(pdf_path); 1210 CFX_WideString wsFilePath = CPDF_FileSpec::EncodeFileName(pdf_path);
1210 pMainDict->SetNewFor<CPDF_String>( 1211 pMainDict->SetNewFor<CPDF_String>(
1211 "F", CFX_ByteString::FromUnicode(wsFilePath), false); 1212 "F", CFX_ByteString::FromUnicode(wsFilePath), false);
1212 pMainDict->SetNewFor<CPDF_String>("UF", PDF_EncodeText(wsFilePath), 1213 pMainDict->SetNewFor<CPDF_String>("UF", PDF_EncodeText(wsFilePath),
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 else if (iType == FIELDTYPE_LISTBOX) 1310 else if (iType == FIELDTYPE_LISTBOX)
1310 m_pFormNotify->AfterSelectionChange(pField); 1311 m_pFormNotify->AfterSelectionChange(pField);
1311 else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) 1312 else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD)
1312 m_pFormNotify->AfterValueChange(pField); 1313 m_pFormNotify->AfterValueChange(pField);
1313 } 1314 }
1314 } 1315 }
1315 1316
1316 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) { 1317 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) {
1317 m_pFormNotify = pNotify; 1318 m_pFormNotify = pNotify;
1318 } 1319 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698