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_save.h" | 8 #include "../../public/fpdf_save.h" |
9 #include "../include/fsdk_define.h" | 9 #include "../include/fsdk_define.h" |
10 | 10 |
11 #if _FX_OS_ == _FX_ANDROID_ | 11 #if _FX_OS_ == _FX_ANDROID_ |
12 #include "time.h" | 12 #include "time.h" |
13 #else | 13 #else |
14 #include <ctime> | 14 #include <ctime> |
15 #endif | 15 #endif |
16 | 16 |
17 class CFX_IFileWrite final : public IFX_StreamWrite | 17 class CFX_IFileWrite final : public IFX_StreamWrite { |
18 { | 18 public: |
| 19 CFX_IFileWrite(); |
| 20 FX_BOOL Init(FPDF_FILEWRITE* pFileWriteStruct); |
| 21 virtual FX_BOOL WriteBlock(const void* pData, size_t size) override; |
| 22 virtual void Release() override {} |
19 | 23 |
20 public: | 24 protected: |
21 CFX_IFileWrite(); | 25 FPDF_FILEWRITE* m_pFileWriteStruct; |
22 FX_BOOL Init( FPDF_FILEWRITE * pFileWriteStruct ); | |
23 virtual FX_BOOL WriteBlock(const void* pData, size_t size) override; | |
24 virtual void Release() override {} | |
25 | |
26 protected: | |
27 FPDF_FILEWRITE* m_pFileWriteStruct; | |
28 }; | 26 }; |
29 | 27 |
30 CFX_IFileWrite::CFX_IFileWrite() | 28 CFX_IFileWrite::CFX_IFileWrite() { |
31 { | 29 m_pFileWriteStruct = NULL; |
32 m_pFileWriteStruct = NULL; | |
33 } | 30 } |
34 | 31 |
35 FX_BOOL CFX_IFileWrite::Init( FPDF_FILEWRITE * pFileWriteStruct ) | 32 FX_BOOL CFX_IFileWrite::Init(FPDF_FILEWRITE* pFileWriteStruct) { |
36 { | 33 if (!pFileWriteStruct) |
37 if (!pFileWriteStruct) | 34 return FALSE; |
38 return FALSE; | |
39 | 35 |
40 m_pFileWriteStruct = pFileWriteStruct; | 36 m_pFileWriteStruct = pFileWriteStruct; |
41 return TRUE; | 37 return TRUE; |
42 } | 38 } |
43 | 39 |
44 FX_BOOL CFX_IFileWrite::WriteBlock(const void* pData, size_t size) | 40 FX_BOOL CFX_IFileWrite::WriteBlock(const void* pData, size_t size) { |
45 { | 41 if (!m_pFileWriteStruct) |
46 if (!m_pFileWriteStruct) | 42 return FALSE; |
47 return FALSE; | |
48 | 43 |
49 m_pFileWriteStruct->WriteBlock( m_pFileWriteStruct, pData, size ); | 44 m_pFileWriteStruct->WriteBlock(m_pFileWriteStruct, pData, size); |
50 return TRUE; | 45 return TRUE; |
51 } | 46 } |
52 | 47 |
53 FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document,FPDF_FILEWRITE * pFileWrite,FPDF
_DWORD flags, FPDF_BOOL bSetVersion, | 48 FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document, |
54 int fileVerion) | 49 FPDF_FILEWRITE* pFileWrite, |
55 { | 50 FPDF_DWORD flags, |
56 CPDF_Document* pDoc = (CPDF_Document*)document; | 51 FPDF_BOOL bSetVersion, |
57 if (!pDoc) | 52 int fileVerion) { |
58 return 0; | 53 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 54 if (!pDoc) |
| 55 return 0; |
59 | 56 |
60 if ( flags < FPDF_INCREMENTAL || flags > FPDF_REMOVE_SECURITY ) | 57 if (flags < FPDF_INCREMENTAL || flags > FPDF_REMOVE_SECURITY) { |
61 { | 58 flags = 0; |
62 flags = 0; | 59 } |
63 } | |
64 | 60 |
65 CPDF_Creator FileMaker(pDoc); | 61 CPDF_Creator FileMaker(pDoc); |
66 if(bSetVersion) | 62 if (bSetVersion) |
67 FileMaker.SetFileVersion(fileVerion); | 63 FileMaker.SetFileVersion(fileVerion); |
68 if(flags == FPDF_REMOVE_SECURITY) | 64 if (flags == FPDF_REMOVE_SECURITY) { |
69 { | 65 flags = 0; |
70 flags = 0; | 66 FileMaker.RemoveSecurity(); |
71 FileMaker.RemoveSecurity(); | 67 } |
72 } | 68 CFX_IFileWrite* pStreamWrite = NULL; |
73 CFX_IFileWrite* pStreamWrite = NULL; | 69 FX_BOOL bRet; |
74 FX_BOOL bRet; | 70 pStreamWrite = new CFX_IFileWrite; |
75 pStreamWrite = new CFX_IFileWrite; | 71 pStreamWrite->Init(pFileWrite); |
76 pStreamWrite->Init( pFileWrite ); | 72 bRet = FileMaker.Create(pStreamWrite, flags); |
77 bRet = FileMaker.Create(pStreamWrite, flags); | 73 delete pStreamWrite; |
78 delete pStreamWrite; | 74 return bRet; |
79 return bRet; | |
80 } | 75 } |
81 | 76 |
82 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveAsCopy( FPDF_DOCUMENT document,FPDF_FILE
WRITE * pFileWrite, | 77 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveAsCopy(FPDF_DOCUMENT document, |
83 FPDF_DWORD flags ) | 78 FPDF_FILEWRITE* pFileWrite, |
84 { | 79 FPDF_DWORD flags) { |
85 return _FPDF_Doc_Save(document, pFileWrite, flags, FALSE , 0); | 80 return _FPDF_Doc_Save(document, pFileWrite, flags, FALSE, 0); |
86 } | 81 } |
87 | 82 |
88 | 83 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion(FPDF_DOCUMENT document, |
89 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion( FPDF_DOCUMENT document,FPDF_
FILEWRITE * pFileWrite, | 84 FPDF_FILEWRITE* pFileWrite, |
90 FPDF_DWORD flags, int fileVersion) | 85 FPDF_DWORD flags, |
91 { | 86 int fileVersion) { |
92 return _FPDF_Doc_Save(document, pFileWrite, flags, TRUE , fileVersion); | 87 return _FPDF_Doc_Save(document, pFileWrite, flags, TRUE, fileVersion); |
93 } | 88 } |
OLD | NEW |