Home | History | Annotate | Download | only in fpdfapi
      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 #ifndef CORE_INCLUDE_FPDFAPI_FPDF_SERIAL_H_
      8 #define CORE_INCLUDE_FPDFAPI_FPDF_SERIAL_H_
      9 
     10 #include "fpdf_page.h"
     11 #include "fpdf_pageobj.h"
     12 
     13 class CPDF_ObjectStream;
     14 class CPDF_XRefStream;
     15 CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& buf, const CPDF_Object* pObj);
     16 #define FPDFCREATE_INCREMENTAL 1
     17 #define FPDFCREATE_NO_ORIGINAL 2
     18 #define FPDFCREATE_PROGRESSIVE 4
     19 #define FPDFCREATE_OBJECTSTREAM 8
     20 
     21 class CPDF_Creator {
     22  public:
     23   CPDF_Creator(CPDF_Document* pDoc);
     24   ~CPDF_Creator();
     25 
     26   void RemoveSecurity();
     27   FX_BOOL Create(IFX_StreamWrite* pFile, FX_DWORD flags = 0);
     28   int32_t Continue(IFX_Pause* pPause = NULL);
     29   FX_BOOL SetFileVersion(int32_t fileVersion = 17);
     30 
     31  protected:
     32   CPDF_Document* m_pDocument;
     33 
     34   CPDF_Parser* m_pParser;
     35 
     36   FX_BOOL m_bCompress;
     37 
     38   FX_BOOL m_bSecurityChanged;
     39 
     40   CPDF_Dictionary* m_pEncryptDict;
     41   FX_DWORD m_dwEnryptObjNum;
     42   FX_BOOL m_bEncryptCloned;
     43 
     44   FX_BOOL m_bStandardSecurity;
     45 
     46   CPDF_CryptoHandler* m_pCryptoHandler;
     47   FX_BOOL m_bNewCrypto;
     48 
     49   FX_BOOL m_bEncryptMetadata;
     50 
     51   CPDF_Object* m_pMetadata;
     52 
     53   CPDF_XRefStream* m_pXRefStream;
     54 
     55   int32_t m_ObjectStreamSize;
     56 
     57   FX_DWORD m_dwLastObjNum;
     58   FX_BOOL Create(FX_DWORD flags);
     59   void ResetStandardSecurity();
     60   void Clear();
     61   int32_t WriteDoc_Stage1(IFX_Pause* pPause);
     62   int32_t WriteDoc_Stage2(IFX_Pause* pPause);
     63   int32_t WriteDoc_Stage3(IFX_Pause* pPause);
     64   int32_t WriteDoc_Stage4(IFX_Pause* pPause);
     65 
     66   CFX_FileBufferArchive m_File;
     67 
     68   FX_FILESIZE m_Offset;
     69   void InitOldObjNumOffsets();
     70   void InitNewObjNumOffsets();
     71   void AppendNewObjNum(FX_DWORD objbum);
     72   int32_t WriteOldIndirectObject(FX_DWORD objnum);
     73   int32_t WriteOldObjs(IFX_Pause* pPause);
     74   int32_t WriteNewObjs(FX_BOOL bIncremental, IFX_Pause* pPause);
     75   int32_t WriteIndirectObj(const CPDF_Object* pObj);
     76   int32_t WriteDirectObj(FX_DWORD objnum,
     77                          const CPDF_Object* pObj,
     78                          FX_BOOL bEncrypt = TRUE);
     79   int32_t WriteIndirectObjectToStream(const CPDF_Object* pObj);
     80   int32_t WriteIndirectObj(FX_DWORD objnum, const CPDF_Object* pObj);
     81   int32_t WriteIndirectObjectToStream(FX_DWORD objnum,
     82                                       const uint8_t* pBuffer,
     83                                       FX_DWORD dwSize);
     84   int32_t AppendObjectNumberToXRef(FX_DWORD objnum);
     85   void InitID(FX_BOOL bDefault = TRUE);
     86   int32_t WriteStream(const CPDF_Object* pStream,
     87                       FX_DWORD objnum,
     88                       CPDF_CryptoHandler* pCrypto);
     89 
     90   int32_t m_iStage;
     91   FX_DWORD m_dwFlags;
     92   FX_POSITION m_Pos;
     93   FX_FILESIZE m_XrefStart;
     94   CFX_FileSizeListArray m_ObjectOffset;
     95   CFX_DWordArray m_NewObjNumArray;
     96   CPDF_Array* m_pIDArray;
     97   int32_t m_FileVersion;
     98 
     99   friend class CPDF_ObjectStream;
    100   friend class CPDF_XRefStream;
    101 };
    102 
    103 #endif  // CORE_INCLUDE_FPDFAPI_FPDF_SERIAL_H_
    104