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 "public/fpdf_save.h" | 7 #include "public/fpdf_save.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 } | 169 } |
170 // L"datasets" | 170 // L"datasets" |
171 { | 171 { |
172 ScopedFileStream pDsfileWrite(FX_CreateMemoryStream()); | 172 ScopedFileStream pDsfileWrite(FX_CreateMemoryStream()); |
173 if (pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Datasets, | 173 if (pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Datasets, |
174 pDsfileWrite.get(), nullptr) && | 174 pDsfileWrite.get(), nullptr) && |
175 pDsfileWrite->GetSize() > 0) { | 175 pDsfileWrite->GetSize() > 0) { |
176 // Datasets | 176 // Datasets |
177 pChecksum->UpdateChecksum(pDsfileWrite.get()); | 177 pChecksum->UpdateChecksum(pDsfileWrite.get()); |
178 pChecksum->FinishChecksum(); | 178 pChecksum->FinishChecksum(); |
179 CPDF_Dictionary* pDataDict = | 179 auto pDataDict = pdfium::MakeUnique<CPDF_Dictionary>( |
180 new CPDF_Dictionary(pPDFDocument->GetByteStringPool()); | 180 pPDFDocument->GetByteStringPool()); |
181 if (iDataSetsIndex != -1) { | 181 if (iDataSetsIndex != -1) { |
182 if (pDataSetsStream) | 182 if (pDataSetsStream) { |
183 pDataSetsStream->InitStreamFromFile(pDsfileWrite.get(), pDataDict); | 183 pDataSetsStream->InitStreamFromFile(pDsfileWrite.get(), |
| 184 std::move(pDataDict)); |
| 185 } |
184 } else { | 186 } else { |
185 CPDF_Stream* pData = pPDFDocument->NewIndirect<CPDF_Stream>(); | 187 CPDF_Stream* pData = pPDFDocument->NewIndirect<CPDF_Stream>(); |
186 pData->InitStreamFromFile(pDsfileWrite.get(), pDataDict); | 188 pData->InitStreamFromFile(pDsfileWrite.get(), std::move(pDataDict)); |
187 iLast = pArray->GetCount() - 2; | 189 iLast = pArray->GetCount() - 2; |
188 pArray->InsertNewAt<CPDF_String>(iLast, "datasets", false); | 190 pArray->InsertNewAt<CPDF_String>(iLast, "datasets", false); |
189 pArray->InsertNewAt<CPDF_Reference>(iLast + 1, pPDFDocument, | 191 pArray->InsertNewAt<CPDF_Reference>(iLast + 1, pPDFDocument, |
190 pData->GetObjNum()); | 192 pData->GetObjNum()); |
191 } | 193 } |
192 fileList->push_back(std::move(pDsfileWrite)); | 194 fileList->push_back(std::move(pDsfileWrite)); |
193 } | 195 } |
194 } | 196 } |
195 // L"form" | 197 // L"form" |
196 { | 198 { |
197 ScopedFileStream pfileWrite(FX_CreateMemoryStream()); | 199 ScopedFileStream pfileWrite(FX_CreateMemoryStream()); |
198 if (pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Form, pfileWrite.get(), | 200 if (pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Form, pfileWrite.get(), |
199 pChecksum.get()) && | 201 pChecksum.get()) && |
200 pfileWrite->GetSize() > 0) { | 202 pfileWrite->GetSize() > 0) { |
201 CPDF_Dictionary* pDataDict = | 203 auto pDataDict = pdfium::MakeUnique<CPDF_Dictionary>( |
202 new CPDF_Dictionary(pPDFDocument->GetByteStringPool()); | 204 pPDFDocument->GetByteStringPool()); |
203 if (iFormIndex != -1) { | 205 if (iFormIndex != -1) { |
204 if (pFormStream) | 206 if (pFormStream) { |
205 pFormStream->InitStreamFromFile(pfileWrite.get(), pDataDict); | 207 pFormStream->InitStreamFromFile(pfileWrite.get(), |
| 208 std::move(pDataDict)); |
| 209 } |
206 } else { | 210 } else { |
207 CPDF_Stream* pData = pPDFDocument->NewIndirect<CPDF_Stream>(); | 211 CPDF_Stream* pData = pPDFDocument->NewIndirect<CPDF_Stream>(); |
208 pData->InitStreamFromFile(pfileWrite.get(), pDataDict); | 212 pData->InitStreamFromFile(pfileWrite.get(), std::move(pDataDict)); |
209 iLast = pArray->GetCount() - 2; | 213 iLast = pArray->GetCount() - 2; |
210 pArray->InsertNewAt<CPDF_String>(iLast, "form", false); | 214 pArray->InsertNewAt<CPDF_String>(iLast, "form", false); |
211 pArray->InsertNewAt<CPDF_Reference>(iLast + 1, pPDFDocument, | 215 pArray->InsertNewAt<CPDF_Reference>(iLast + 1, pPDFDocument, |
212 pData->GetObjNum()); | 216 pData->GetObjNum()); |
213 } | 217 } |
214 fileList->push_back(std::move(pfileWrite)); | 218 fileList->push_back(std::move(pfileWrite)); |
215 } | 219 } |
216 } | 220 } |
217 return true; | 221 return true; |
218 } | 222 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 FPDF_DWORD flags) { | 312 FPDF_DWORD flags) { |
309 return FPDF_Doc_Save(document, pFileWrite, flags, false, 0); | 313 return FPDF_Doc_Save(document, pFileWrite, flags, false, 0); |
310 } | 314 } |
311 | 315 |
312 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion(FPDF_DOCUMENT document, | 316 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion(FPDF_DOCUMENT document, |
313 FPDF_FILEWRITE* pFileWrite, | 317 FPDF_FILEWRITE* pFileWrite, |
314 FPDF_DWORD flags, | 318 FPDF_DWORD flags, |
315 int fileVersion) { | 319 int fileVersion) { |
316 return FPDF_Doc_Save(document, pFileWrite, flags, true, fileVersion); | 320 return FPDF_Doc_Save(document, pFileWrite, flags, true, fileVersion); |
317 } | 321 } |
OLD | NEW |