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_edit.h" | 7 #include "../../public/fpdf_edit.h" |
8 #include "../../public/fpdf_formfill.h" | 8 #include "../../public/fpdf_formfill.h" |
9 #include "../../public/fpdf_save.h" | 9 #include "../../public/fpdf_save.h" |
10 #include "../include/fsdk_define.h" | 10 #include "../include/fsdk_define.h" |
11 #include "../include/fpdfxfa/fpdfxfa_doc.h" | 11 #include "../include/fpdfxfa/fpdfxfa_doc.h" |
12 #include "../include/fpdfxfa/fpdfxfa_app.h" | 12 #include "../include/fpdfxfa/fpdfxfa_app.h" |
13 #include "../include/fpdfxfa/fpdfxfa_util.h" | 13 #include "../include/fpdfxfa/fpdfxfa_util.h" |
14 | 14 |
15 #if _FX_OS_ == _FX_ANDROID_ | 15 #if _FX_OS_ == _FX_ANDROID_ |
16 #include "time.h" | 16 #include "time.h" |
17 #else | 17 #else |
18 #include <ctime> | 18 #include <ctime> |
19 #endif | 19 #endif |
20 | 20 |
21 class CFX_IFileWrite final : public IFX_StreamWrite { | 21 class CFX_IFileWrite final : public IFX_StreamWrite { |
22 public: | 22 public: |
23 CFX_IFileWrite(); | 23 CFX_IFileWrite(); |
24 FX_BOOL Init(FPDF_FILEWRITE* pFileWriteStruct); | 24 FX_BOOL Init(FPDF_FILEWRITE* pFileWriteStruct); |
25 virtual FX_BOOL WriteBlock(const void* pData, size_t size) override; | 25 FX_BOOL WriteBlock(const void* pData, size_t size) override; |
26 virtual void Release() override {} | 26 void Release() override; |
27 | 27 |
28 protected: | 28 protected: |
| 29 ~CFX_IFileWrite() override {} |
| 30 |
29 FPDF_FILEWRITE* m_pFileWriteStruct; | 31 FPDF_FILEWRITE* m_pFileWriteStruct; |
30 }; | 32 }; |
31 | 33 |
32 CFX_IFileWrite::CFX_IFileWrite() { | 34 CFX_IFileWrite::CFX_IFileWrite() { |
33 m_pFileWriteStruct = NULL; | 35 m_pFileWriteStruct = NULL; |
34 } | 36 } |
35 | 37 |
36 FX_BOOL CFX_IFileWrite::Init(FPDF_FILEWRITE* pFileWriteStruct) { | 38 FX_BOOL CFX_IFileWrite::Init(FPDF_FILEWRITE* pFileWriteStruct) { |
37 if (!pFileWriteStruct) | 39 if (!pFileWriteStruct) |
38 return FALSE; | 40 return FALSE; |
39 | 41 |
40 m_pFileWriteStruct = pFileWriteStruct; | 42 m_pFileWriteStruct = pFileWriteStruct; |
41 return TRUE; | 43 return TRUE; |
42 } | 44 } |
43 | 45 |
44 FX_BOOL CFX_IFileWrite::WriteBlock(const void* pData, size_t size) { | 46 FX_BOOL CFX_IFileWrite::WriteBlock(const void* pData, size_t size) { |
45 if (!m_pFileWriteStruct) | 47 if (!m_pFileWriteStruct) |
46 return FALSE; | 48 return FALSE; |
47 | 49 |
48 m_pFileWriteStruct->WriteBlock(m_pFileWriteStruct, pData, size); | 50 m_pFileWriteStruct->WriteBlock(m_pFileWriteStruct, pData, size); |
49 return TRUE; | 51 return TRUE; |
50 } | 52 } |
51 | 53 |
| 54 void CFX_IFileWrite::Release() { |
| 55 delete this; |
| 56 } |
| 57 |
52 #define XFA_DATASETS 0 | 58 #define XFA_DATASETS 0 |
53 #define XFA_FORMS 1 | 59 #define XFA_FORMS 1 |
54 | 60 |
55 FX_BOOL _SaveXFADocumentData(CPDFXFA_Document* pDocument, | 61 FX_BOOL _SaveXFADocumentData(CPDFXFA_Document* pDocument, |
56 CFX_PtrArray& fileList) { | 62 CFX_PtrArray& fileList) { |
57 if (!pDocument) | 63 if (!pDocument) |
58 return FALSE; | 64 return FALSE; |
59 if (pDocument->GetDocType() != DOCTYPE_DYNIMIC_XFA && | 65 if (pDocument->GetDocType() != DOCTYPE_DYNIMIC_XFA && |
60 pDocument->GetDocType() != DOCTYPE_STATIC_XFA) | 66 pDocument->GetDocType() != DOCTYPE_STATIC_XFA) |
61 return TRUE; | 67 return TRUE; |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 flags = 0; | 310 flags = 0; |
305 FileMaker.RemoveSecurity(); | 311 FileMaker.RemoveSecurity(); |
306 } | 312 } |
307 CFX_IFileWrite* pStreamWrite = NULL; | 313 CFX_IFileWrite* pStreamWrite = NULL; |
308 FX_BOOL bRet; | 314 FX_BOOL bRet; |
309 pStreamWrite = new CFX_IFileWrite; | 315 pStreamWrite = new CFX_IFileWrite; |
310 pStreamWrite->Init(pFileWrite); | 316 pStreamWrite->Init(pFileWrite); |
311 bRet = FileMaker.Create(pStreamWrite, flags); | 317 bRet = FileMaker.Create(pStreamWrite, flags); |
312 | 318 |
313 _SendPostSaveToXFADoc(pDoc); | 319 _SendPostSaveToXFADoc(pDoc); |
314 // pDoc->_ClearChangeMark(); | |
315 | 320 |
316 for (int i = 0; i < fileList.GetSize(); i++) { | 321 for (int i = 0; i < fileList.GetSize(); i++) { |
317 IFX_FileStream* pFile = (IFX_FileStream*)fileList.GetAt(i); | 322 IFX_FileStream* pFile = (IFX_FileStream*)fileList.GetAt(i); |
318 pFile->Release(); | 323 pFile->Release(); |
319 } | 324 } |
320 fileList.RemoveAll(); | 325 fileList.RemoveAll(); |
321 | 326 |
322 delete pStreamWrite; | 327 pStreamWrite->Release(); |
323 return bRet; | 328 return bRet; |
324 } | 329 } |
325 | 330 |
326 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveAsCopy(FPDF_DOCUMENT document, | 331 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveAsCopy(FPDF_DOCUMENT document, |
327 FPDF_FILEWRITE* pFileWrite, | 332 FPDF_FILEWRITE* pFileWrite, |
328 FPDF_DWORD flags) { | 333 FPDF_DWORD flags) { |
329 return _FPDF_Doc_Save(document, pFileWrite, flags, FALSE, 0); | 334 return _FPDF_Doc_Save(document, pFileWrite, flags, FALSE, 0); |
330 } | 335 } |
331 | 336 |
332 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion(FPDF_DOCUMENT document, | 337 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion(FPDF_DOCUMENT document, |
333 FPDF_FILEWRITE* pFileWrite, | 338 FPDF_FILEWRITE* pFileWrite, |
334 FPDF_DWORD flags, | 339 FPDF_DWORD flags, |
335 int fileVersion) { | 340 int fileVersion) { |
336 return _FPDF_Doc_Save(document, pFileWrite, flags, TRUE, fileVersion); | 341 return _FPDF_Doc_Save(document, pFileWrite, flags, TRUE, fileVersion); |
337 } | 342 } |
OLD | NEW |