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