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 <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 FX_BOOL WriteBlock(const void* pData, size_t size) override; | 42 FX_BOOL WriteBlock(const void* pData, size_t size) override; |
43 void Release() override; | 43 void Release() override; |
44 | 44 |
45 protected: | 45 protected: |
46 ~CFX_IFileWrite() override {} | 46 ~CFX_IFileWrite() override {} |
47 | 47 |
48 FPDF_FILEWRITE* m_pFileWriteStruct; | 48 FPDF_FILEWRITE* m_pFileWriteStruct; |
49 }; | 49 }; |
50 | 50 |
51 CFX_IFileWrite::CFX_IFileWrite() { | 51 CFX_IFileWrite::CFX_IFileWrite() { |
52 m_pFileWriteStruct = NULL; | 52 m_pFileWriteStruct = nullptr; |
53 } | 53 } |
54 | 54 |
55 FX_BOOL CFX_IFileWrite::Init(FPDF_FILEWRITE* pFileWriteStruct) { | 55 FX_BOOL CFX_IFileWrite::Init(FPDF_FILEWRITE* pFileWriteStruct) { |
56 if (!pFileWriteStruct) | 56 if (!pFileWriteStruct) |
57 return FALSE; | 57 return FALSE; |
58 | 58 |
59 m_pFileWriteStruct = pFileWriteStruct; | 59 m_pFileWriteStruct = pFileWriteStruct; |
60 return TRUE; | 60 return TRUE; |
61 } | 61 } |
62 | 62 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 // template | 133 // template |
134 if (iTemplate > -1) { | 134 if (iTemplate > -1) { |
135 CPDF_Stream* pTemplateStream = pArray->GetStreamAt(iTemplate); | 135 CPDF_Stream* pTemplateStream = pArray->GetStreamAt(iTemplate); |
136 CPDF_StreamAcc streamAcc; | 136 CPDF_StreamAcc streamAcc; |
137 streamAcc.LoadAllData(pTemplateStream); | 137 streamAcc.LoadAllData(pTemplateStream); |
138 uint8_t* pData = (uint8_t*)streamAcc.GetData(); | 138 uint8_t* pData = (uint8_t*)streamAcc.GetData(); |
139 uint32_t dwSize2 = streamAcc.GetSize(); | 139 uint32_t dwSize2 = streamAcc.GetSize(); |
140 ScopedFileStream pTemplate(FX_CreateMemoryStream(pData, dwSize2)); | 140 ScopedFileStream pTemplate(FX_CreateMemoryStream(pData, dwSize2)); |
141 pContext->UpdateChecksum(pTemplate.get()); | 141 pContext->UpdateChecksum(pTemplate.get()); |
142 } | 142 } |
143 CPDF_Stream* pFormStream = NULL; | 143 CPDF_Stream* pFormStream = nullptr; |
144 CPDF_Stream* pDataSetsStream = NULL; | 144 CPDF_Stream* pDataSetsStream = nullptr; |
145 if (iFormIndex != -1) { | 145 if (iFormIndex != -1) { |
146 // Get form CPDF_Stream | 146 // Get form CPDF_Stream |
147 CPDF_Object* pFormPDFObj = pArray->GetObjectAt(iFormIndex); | 147 CPDF_Object* pFormPDFObj = pArray->GetObjectAt(iFormIndex); |
148 if (pFormPDFObj->IsReference()) { | 148 if (pFormPDFObj->IsReference()) { |
149 CPDF_Object* pFormDirectObj = pFormPDFObj->GetDirect(); | 149 CPDF_Object* pFormDirectObj = pFormPDFObj->GetDirect(); |
150 if (pFormDirectObj && pFormDirectObj->IsStream()) { | 150 if (pFormDirectObj && pFormDirectObj->IsStream()) { |
151 pFormStream = (CPDF_Stream*)pFormDirectObj; | 151 pFormStream = (CPDF_Stream*)pFormDirectObj; |
152 } | 152 } |
153 } else if (pFormPDFObj->IsStream()) { | 153 } else if (pFormPDFObj->IsStream()) { |
154 pFormStream = (CPDF_Stream*)pFormPDFObj; | 154 pFormStream = (CPDF_Stream*)pFormPDFObj; |
(...skipping 20 matching lines...) Expand all Loading... |
175 pDsfileWrite.get(), nullptr) && | 175 pDsfileWrite.get(), nullptr) && |
176 pDsfileWrite->GetSize() > 0) { | 176 pDsfileWrite->GetSize() > 0) { |
177 // Datasets | 177 // Datasets |
178 pContext->UpdateChecksum(pDsfileWrite.get()); | 178 pContext->UpdateChecksum(pDsfileWrite.get()); |
179 pContext->FinishChecksum(); | 179 pContext->FinishChecksum(); |
180 CPDF_Dictionary* pDataDict = new CPDF_Dictionary; | 180 CPDF_Dictionary* pDataDict = new CPDF_Dictionary; |
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(), pDataDict); |
184 } else { | 184 } else { |
185 CPDF_Stream* pData = new CPDF_Stream(NULL, 0, NULL); | 185 CPDF_Stream* pData = new CPDF_Stream(nullptr, 0, nullptr); |
186 pData->InitStreamFromFile(pDsfileWrite.get(), pDataDict); | 186 pData->InitStreamFromFile(pDsfileWrite.get(), pDataDict); |
187 pPDFDocument->AddIndirectObject(pData); | 187 pPDFDocument->AddIndirectObject(pData); |
188 iLast = pArray->GetCount() - 2; | 188 iLast = pArray->GetCount() - 2; |
189 pArray->InsertAt(iLast, new CPDF_String("datasets", FALSE)); | 189 pArray->InsertAt(iLast, new CPDF_String("datasets", FALSE)); |
190 pArray->InsertAt(iLast + 1, pData, pPDFDocument); | 190 pArray->InsertAt(iLast + 1, pData, pPDFDocument); |
191 } | 191 } |
192 fileList->push_back(std::move(pDsfileWrite)); | 192 fileList->push_back(std::move(pDsfileWrite)); |
193 } | 193 } |
194 } | 194 } |
195 // L"form" | 195 // L"form" |
196 { | 196 { |
197 ScopedFileStream pfileWrite(FX_CreateMemoryStream()); | 197 ScopedFileStream pfileWrite(FX_CreateMemoryStream()); |
198 if (pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Form, pfileWrite.get(), | 198 if (pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Form, pfileWrite.get(), |
199 pContext.get()) && | 199 pContext.get()) && |
200 pfileWrite->GetSize() > 0) { | 200 pfileWrite->GetSize() > 0) { |
201 CPDF_Dictionary* pDataDict = new CPDF_Dictionary; | 201 CPDF_Dictionary* pDataDict = new CPDF_Dictionary; |
202 if (iFormIndex != -1) { | 202 if (iFormIndex != -1) { |
203 if (pFormStream) | 203 if (pFormStream) |
204 pFormStream->InitStreamFromFile(pfileWrite.get(), pDataDict); | 204 pFormStream->InitStreamFromFile(pfileWrite.get(), pDataDict); |
205 } else { | 205 } else { |
206 CPDF_Stream* pData = new CPDF_Stream(NULL, 0, NULL); | 206 CPDF_Stream* pData = new CPDF_Stream(nullptr, 0, nullptr); |
207 pData->InitStreamFromFile(pfileWrite.get(), pDataDict); | 207 pData->InitStreamFromFile(pfileWrite.get(), pDataDict); |
208 pPDFDocument->AddIndirectObject(pData); | 208 pPDFDocument->AddIndirectObject(pData); |
209 iLast = pArray->GetCount() - 2; | 209 iLast = pArray->GetCount() - 2; |
210 pArray->InsertAt(iLast, new CPDF_String("form", FALSE)); | 210 pArray->InsertAt(iLast, new CPDF_String("form", FALSE)); |
211 pArray->InsertAt(iLast + 1, pData, pPDFDocument); | 211 pArray->InsertAt(iLast + 1, pData, pPDFDocument); |
212 } | 212 } |
213 fileList->push_back(std::move(pfileWrite)); | 213 fileList->push_back(std::move(pfileWrite)); |
214 } | 214 } |
215 } | 215 } |
216 return true; | 216 return true; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 flags = 0; | 283 flags = 0; |
284 | 284 |
285 CPDF_Creator FileMaker(pPDFDoc); | 285 CPDF_Creator FileMaker(pPDFDoc); |
286 if (bSetVersion) | 286 if (bSetVersion) |
287 FileMaker.SetFileVersion(fileVerion); | 287 FileMaker.SetFileVersion(fileVerion); |
288 if (flags == FPDF_REMOVE_SECURITY) { | 288 if (flags == FPDF_REMOVE_SECURITY) { |
289 flags = 0; | 289 flags = 0; |
290 FileMaker.RemoveSecurity(); | 290 FileMaker.RemoveSecurity(); |
291 } | 291 } |
292 | 292 |
293 CFX_IFileWrite* pStreamWrite = NULL; | 293 CFX_IFileWrite* pStreamWrite = new CFX_IFileWrite; |
294 pStreamWrite = new CFX_IFileWrite; | |
295 pStreamWrite->Init(pFileWrite); | 294 pStreamWrite->Init(pFileWrite); |
296 bool bRet = FileMaker.Create(pStreamWrite, flags); | 295 bool bRet = FileMaker.Create(pStreamWrite, flags); |
297 #ifdef PDF_ENABLE_XFA | 296 #ifdef PDF_ENABLE_XFA |
298 SendPostSaveToXFADoc(pDoc); | 297 SendPostSaveToXFADoc(pDoc); |
299 #endif // PDF_ENABLE_XFA | 298 #endif // PDF_ENABLE_XFA |
300 pStreamWrite->Release(); | 299 pStreamWrite->Release(); |
301 return bRet; | 300 return bRet; |
302 } | 301 } |
303 | 302 |
304 } // namespace | 303 } // namespace |
305 | 304 |
306 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveAsCopy(FPDF_DOCUMENT document, | 305 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveAsCopy(FPDF_DOCUMENT document, |
307 FPDF_FILEWRITE* pFileWrite, | 306 FPDF_FILEWRITE* pFileWrite, |
308 FPDF_DWORD flags) { | 307 FPDF_DWORD flags) { |
309 return FPDF_Doc_Save(document, pFileWrite, flags, FALSE, 0); | 308 return FPDF_Doc_Save(document, pFileWrite, flags, FALSE, 0); |
310 } | 309 } |
311 | 310 |
312 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion(FPDF_DOCUMENT document, | 311 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion(FPDF_DOCUMENT document, |
313 FPDF_FILEWRITE* pFileWrite, | 312 FPDF_FILEWRITE* pFileWrite, |
314 FPDF_DWORD flags, | 313 FPDF_DWORD flags, |
315 int fileVersion) { | 314 int fileVersion) { |
316 return FPDF_Doc_Save(document, pFileWrite, flags, TRUE, fileVersion); | 315 return FPDF_Doc_Save(document, pFileWrite, flags, TRUE, fileVersion); |
317 } | 316 } |
OLD | NEW |