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