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 class CPDF_ObjArchiveSaver : public CFX_ArchiveSaver 17 { 18 public: 19 20 friend CPDF_ObjArchiveSaver& operator << (CPDF_ObjArchiveSaver& ar, const CPDF_Object* pObj); 21 protected: 22 23 CFX_MapPtrToPtr m_ObjectMap; 24 }; 25 class CPDF_ObjArchiveLoader : public CFX_ArchiveLoader 26 { 27 public: 28 CPDF_ObjArchiveLoader(FX_LPCBYTE pData,FX_DWORD dwSize)29 CPDF_ObjArchiveLoader(FX_LPCBYTE pData, FX_DWORD dwSize) : CFX_ArchiveLoader(pData, dwSize), 30 m_IndirectObjects(NULL) {} 31 32 friend CPDF_ObjArchiveLoader& operator >> (CPDF_ObjArchiveLoader& ar, CPDF_Object*& pObj); 33 protected: 34 35 CPDF_IndirectObjects m_IndirectObjects; 36 }; 37 class CPDF_PageArchiveSaver : public CPDF_ObjArchiveSaver 38 { 39 public: 40 41 CPDF_PageArchiveSaver(CPDF_PageObjects* pPageObjs); 42 43 friend CPDF_PageArchiveSaver& operator << (CPDF_PageArchiveSaver& ar, CPDF_PageObject* pObj); 44 45 46 47 friend CPDF_PageArchiveSaver& operator << (CPDF_PageArchiveSaver& ar, CPDF_ClipPath clip_path); 48 49 friend CPDF_PageArchiveSaver& operator << (CPDF_PageArchiveSaver& ar, CPDF_GraphState graph_state); 50 51 friend CPDF_PageArchiveSaver& operator << (CPDF_PageArchiveSaver& ar, CPDF_TextState text_state); 52 53 friend CPDF_PageArchiveSaver& operator << (CPDF_PageArchiveSaver& ar, CPDF_ColorState color_state); 54 55 friend CPDF_PageArchiveSaver& operator << (CPDF_PageArchiveSaver& ar, CPDF_GeneralState general_state); 56 57 protected: 58 59 CPDF_ClipPath m_LastClipPath; 60 61 CPDF_GraphState m_LastGraphState; 62 63 CPDF_ColorState m_LastColorState; 64 65 CPDF_TextState m_LastTextState; 66 67 CPDF_GeneralState m_LastGeneralState; 68 69 CPDF_PageObjects* m_pCurPage; 70 }; 71 class CPDF_PageArchiveLoader : public CPDF_ObjArchiveLoader 72 { 73 public: 74 75 CPDF_PageArchiveLoader(CPDF_PageObjects* pPageObjs, FX_LPCBYTE pData, FX_DWORD dwSize); 76 77 friend CPDF_PageArchiveLoader& operator >> (CPDF_PageArchiveLoader& ar, CPDF_PageObject*& pObj); 78 79 80 81 friend CPDF_PageArchiveLoader& operator >> (CPDF_PageArchiveLoader& ar, CPDF_ClipPath& clip_path); 82 83 friend CPDF_PageArchiveLoader& operator >> (CPDF_PageArchiveLoader& ar, CPDF_GraphState& graph_state); 84 85 friend CPDF_PageArchiveLoader& operator >> (CPDF_PageArchiveLoader& ar, CPDF_TextState& text_state); 86 87 friend CPDF_PageArchiveLoader& operator >> (CPDF_PageArchiveLoader& ar, CPDF_ColorState& color_state); 88 89 friend CPDF_PageArchiveLoader& operator >> (CPDF_PageArchiveLoader& ar, CPDF_GeneralState& general_state); 90 91 protected: 92 void PostProcColor(CPDF_Color& color); 93 94 CPDF_Object* AddResource(CPDF_Object* pSrcObj, FX_LPCSTR type); 95 96 CPDF_ClipPath m_LastClipPath; 97 98 CPDF_GraphState m_LastGraphState; 99 100 CPDF_ColorState m_LastColorState; 101 102 CPDF_TextState m_LastTextState; 103 104 CPDF_GeneralState m_LastGeneralState; 105 106 CPDF_PageObjects* m_pCurPage; 107 108 CFX_MapPtrToPtr m_ObjectMap; 109 }; 110 #define FPDFCREATE_INCREMENTAL 1 111 #define FPDFCREATE_NO_ORIGINAL 2 112 #define FPDFCREATE_PROGRESSIVE 4 113 #define FPDFCREATE_OBJECTSTREAM 8 114 class CPDF_Creator 115 { 116 public: 117 118 CPDF_Creator(CPDF_Document* pDoc); 119 120 ~CPDF_Creator(); 121 122 void RemoveSecurity(); 123 124 FX_BOOL Create(FX_LPCWSTR filename, FX_DWORD flags = 0); 125 126 FX_BOOL Create(FX_LPCSTR filename, FX_DWORD flags = 0); 127 128 FX_BOOL Create(IFX_StreamWrite* pFile, FX_DWORD flags = 0); 129 130 FX_INT32 Continue(IFX_Pause *pPause = NULL); 131 132 FX_BOOL SetFileVersion(FX_INT32 fileVersion = 17); 133 protected: 134 135 CPDF_Document* m_pDocument; 136 137 CPDF_Parser* m_pParser; 138 139 FX_BOOL m_bCompress; 140 141 FX_BOOL m_bSecurityChanged; 142 143 CPDF_Dictionary* m_pEncryptDict; 144 FX_DWORD m_dwEnryptObjNum; 145 FX_BOOL m_bEncryptCloned; 146 147 FX_BOOL m_bStandardSecurity; 148 149 CPDF_CryptoHandler* m_pCryptoHandler; 150 FX_BOOL m_bNewCrypto; 151 152 FX_BOOL m_bEncryptMetadata; 153 154 CPDF_Object* m_pMetadata; 155 156 CPDF_XRefStream* m_pXRefStream; 157 158 FX_INT32 m_ObjectStreamSize; 159 160 FX_DWORD m_dwLastObjNum; 161 FX_BOOL Create(FX_DWORD flags); 162 void ResetStandardSecurity(); 163 void Clear(); 164 FX_INT32 WriteDoc_Stage1(IFX_Pause *pPause); 165 FX_INT32 WriteDoc_Stage2(IFX_Pause *pPause); 166 FX_INT32 WriteDoc_Stage3(IFX_Pause *pPause); 167 FX_INT32 WriteDoc_Stage4(IFX_Pause *pPause); 168 169 CFX_FileBufferArchive m_File; 170 171 FX_FILESIZE m_Offset; 172 void InitOldObjNumOffsets(); 173 void InitNewObjNumOffsets(); 174 void AppendNewObjNum(FX_DWORD objbum); 175 FX_INT32 WriteOldIndirectObject(FX_DWORD objnum); 176 FX_INT32 WriteOldObjs(IFX_Pause *pPause); 177 FX_INT32 WriteNewObjs(FX_BOOL bIncremental, IFX_Pause *pPause); 178 FX_INT32 WriteIndirectObj(const CPDF_Object* pObj); 179 FX_INT32 WriteDirectObj(FX_DWORD objnum, const CPDF_Object* pObj, FX_BOOL bEncrypt = TRUE); 180 FX_INT32 WriteIndirectObjectToStream(const CPDF_Object* pObj); 181 FX_INT32 WriteIndirectObj(FX_DWORD objnum, const CPDF_Object* pObj); 182 FX_INT32 WriteIndirectObjectToStream(FX_DWORD objnum, FX_LPCBYTE pBuffer, FX_DWORD dwSize); 183 FX_INT32 AppendObjectNumberToXRef(FX_DWORD objnum); 184 void InitID(FX_BOOL bDefault = TRUE); 185 FX_INT32 WriteStream(const CPDF_Object* pStream, FX_DWORD objnum, CPDF_CryptoHandler* pCrypto); 186 187 FX_INT32 m_iStage; 188 FX_DWORD m_dwFlags; 189 FX_POSITION m_Pos; 190 FX_FILESIZE m_XrefStart; 191 192 CFX_FileSizeListArray m_ObjectOffset; 193 194 CFX_DWordListArray m_ObjectSize; 195 CFX_DWordArray m_NewObjNumArray; 196 197 CPDF_Array* m_pIDArray; 198 199 FX_INT32 m_FileVersion; 200 friend class CPDF_ObjectStream; 201 friend class CPDF_XRefStream; 202 }; 203 204 #endif // CORE_INCLUDE_FPDFAPI_FPDF_SERIAL_H_ 205