Home | History | Annotate | Download | only in src
      1 // Copyright 2014 PDFium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
      6 
      7 #include "../include/fsdk_define.h"
      8 #include "../include/fpdfsave.h"
      9 #include "../include/fpdfedit.h"
     10 #if _FX_OS_ == _FX_ANDROID_
     11 #include "time.h"
     12 #else
     13 #include <ctime>
     14 #endif
     15 
     16 class CFX_IFileWrite:public IFX_StreamWrite
     17 {
     18 
     19 public:
     20 	CFX_IFileWrite();
     21 	FX_BOOL				Init( FPDF_FILEWRITE * pFileWriteStruct );
     22 	virtual	FX_BOOL		WriteBlock(const void* pData, size_t size);
     23 	virtual void		Release(){};
     24 
     25 protected:
     26 	FPDF_FILEWRITE*		m_pFileWriteStruct;
     27 };
     28 
     29 CFX_IFileWrite::CFX_IFileWrite()
     30 {
     31 	m_pFileWriteStruct = NULL;
     32 }
     33 
     34 FX_BOOL CFX_IFileWrite::Init( FPDF_FILEWRITE * pFileWriteStruct )
     35 {
     36 	if (!pFileWriteStruct)
     37 		return FALSE;
     38 	else
     39 	{
     40 		m_pFileWriteStruct = pFileWriteStruct;
     41 	}
     42 	return TRUE;
     43 }
     44 
     45 FX_BOOL CFX_IFileWrite::WriteBlock(const void* pData, size_t size)
     46 {
     47 	if (m_pFileWriteStruct)
     48 	{
     49 		m_pFileWriteStruct->WriteBlock( m_pFileWriteStruct, pData, size );
     50 		return TRUE;
     51 	}
     52 	else
     53 		return FALSE;
     54 }
     55 
     56 FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document,FPDF_FILEWRITE * pFileWrite,FPDF_DWORD flags, FPDF_BOOL bSetVersion,
     57 						 int fileVerion)
     58 {
     59 	CPDF_Document* pDoc = (CPDF_Document*)document;
     60 	if (!pDoc)
     61 		return 0;
     62 
     63 	if ( flags < 1 || flags > 2 )
     64 	{
     65 		flags = 0;
     66 	}
     67 
     68 	CPDF_Creator FileMaker(pDoc);
     69 	if(bSetVersion)
     70 		FileMaker.SetFileVersion(fileVerion);
     71 	CFX_IFileWrite* pStreamWrite = NULL;
     72 	FX_BOOL bRet;
     73 	pStreamWrite = new CFX_IFileWrite;
     74 	pStreamWrite->Init( pFileWrite );
     75 	bRet = FileMaker.Create(pStreamWrite, flags);
     76 	delete pStreamWrite;
     77 	return bRet;
     78 }
     79 
     80 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveAsCopy(	FPDF_DOCUMENT document,FPDF_FILEWRITE * pFileWrite,
     81 												FPDF_DWORD flags )
     82 {
     83 	return _FPDF_Doc_Save(document, pFileWrite, flags, FALSE , 0);
     84 }
     85 
     86 
     87 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion(	FPDF_DOCUMENT document,FPDF_FILEWRITE * pFileWrite,
     88 	FPDF_DWORD flags, int fileVersion)
     89 {
     90 	return _FPDF_Doc_Save(document, pFileWrite, flags, TRUE , fileVersion);
     91 }
     92