FX_BOOL considered harmful, part 2.
[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 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
29     CPDF_ObjArchiveLoader(const uint8_t* 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 class CPDF_PageArchiveLoader : public CPDF_ObjArchiveLoader
70 {
71 public:
72
73     CPDF_PageArchiveLoader(CPDF_PageObjects* pPageObjs, const uint8_t* pData, FX_DWORD dwSize);
74
75     friend CPDF_PageArchiveLoader&      operator >> (CPDF_PageArchiveLoader& ar, CPDF_PageObject*& pObj);
76
77
78
79     friend CPDF_PageArchiveLoader&      operator >> (CPDF_PageArchiveLoader& ar, CPDF_ClipPath& clip_path);
80
81     friend CPDF_PageArchiveLoader&      operator >> (CPDF_PageArchiveLoader& ar, CPDF_GraphState& graph_state);
82
83     friend CPDF_PageArchiveLoader&      operator >> (CPDF_PageArchiveLoader& ar, CPDF_TextState& text_state);
84
85     friend CPDF_PageArchiveLoader&      operator >> (CPDF_PageArchiveLoader& ar, CPDF_ColorState& color_state);
86
87     friend CPDF_PageArchiveLoader&      operator >> (CPDF_PageArchiveLoader& ar, CPDF_GeneralState& general_state);
88
89 protected:
90     void                                PostProcColor(CPDF_Color& color);
91
92     CPDF_Object*                AddResource(CPDF_Object* pSrcObj, const FX_CHAR* type);
93
94     CPDF_ClipPath               m_LastClipPath;
95
96     CPDF_GraphState             m_LastGraphState;
97
98     CPDF_ColorState             m_LastColorState;
99
100     CPDF_TextState              m_LastTextState;
101
102     CPDF_GeneralState   m_LastGeneralState;
103
104     CFX_MapPtrToPtr             m_ObjectMap;
105 };
106 #define FPDFCREATE_INCREMENTAL          1
107 #define FPDFCREATE_NO_ORIGINAL          2
108 #define FPDFCREATE_PROGRESSIVE          4
109 #define FPDFCREATE_OBJECTSTREAM         8
110 class CPDF_Creator
111 {
112 public:
113
114     CPDF_Creator(CPDF_Document* pDoc);
115
116     ~CPDF_Creator();
117
118     void                                RemoveSecurity();
119
120     bool                                Create(const FX_WCHAR* filename, FX_DWORD flags = 0);
121
122     bool                                Create(const FX_CHAR* filename, FX_DWORD flags = 0);
123
124     bool                                Create(IFX_StreamWrite* pFile, FX_DWORD flags = 0);
125
126     int32_t                     Continue(IFX_Pause *pPause = NULL);
127
128     bool                                SetFileVersion(int32_t fileVersion = 17);
129 protected:
130
131     CPDF_Document*              m_pDocument;
132
133     CPDF_Parser*                m_pParser;
134
135     bool                                m_bCompress;
136
137     bool                                m_bSecurityChanged;
138
139     CPDF_Dictionary*    m_pEncryptDict;
140     FX_DWORD                    m_dwEnryptObjNum;
141     bool                                m_bEncryptCloned;
142
143     bool                                m_bStandardSecurity;
144
145     CPDF_CryptoHandler* m_pCryptoHandler;
146     bool                                m_bNewCrypto;
147
148     bool                                m_bEncryptMetadata;
149
150     CPDF_Object*                m_pMetadata;
151
152     CPDF_XRefStream*    m_pXRefStream;
153
154     int32_t                     m_ObjectStreamSize;
155
156     FX_DWORD                    m_dwLastObjNum;
157     bool                                Create(FX_DWORD flags);
158     void                                ResetStandardSecurity();
159     void                                Clear();
160     int32_t                     WriteDoc_Stage1(IFX_Pause *pPause);
161     int32_t                     WriteDoc_Stage2(IFX_Pause *pPause);
162     int32_t                     WriteDoc_Stage3(IFX_Pause *pPause);
163     int32_t                     WriteDoc_Stage4(IFX_Pause *pPause);
164
165     CFX_FileBufferArchive       m_File;
166
167     FX_FILESIZE                 m_Offset;
168     void                                InitOldObjNumOffsets();
169     void                                InitNewObjNumOffsets();
170     void                                AppendNewObjNum(FX_DWORD objbum);
171     int32_t                     WriteOldIndirectObject(FX_DWORD objnum);
172     int32_t                     WriteOldObjs(IFX_Pause *pPause);
173     int32_t                     WriteNewObjs(bool bIncremental, IFX_Pause *pPause);
174     int32_t                     WriteIndirectObj(const CPDF_Object* pObj);
175     int32_t                     WriteDirectObj(FX_DWORD objnum, const CPDF_Object* pObj, bool bEncrypt = true);
176     int32_t                     WriteIndirectObjectToStream(const CPDF_Object* pObj);
177     int32_t                     WriteIndirectObj(FX_DWORD objnum, const CPDF_Object* pObj);
178     int32_t                     WriteIndirectObjectToStream(FX_DWORD objnum, const uint8_t* pBuffer, FX_DWORD dwSize);
179     int32_t                     AppendObjectNumberToXRef(FX_DWORD objnum);
180     void                                InitID(bool bDefault = true);
181     int32_t                     WriteStream(const CPDF_Object* pStream, FX_DWORD objnum, CPDF_CryptoHandler* pCrypto);
182
183     int32_t                     m_iStage;
184     FX_DWORD                    m_dwFlags;
185     FX_POSITION                 m_Pos;
186     FX_FILESIZE                 m_XrefStart;
187
188     CFX_FileSizeListArray       m_ObjectOffset;
189
190     CFX_DWordListArray          m_ObjectSize;
191     CFX_DWordArray              m_NewObjNumArray;
192
193     CPDF_Array*                 m_pIDArray;
194
195     int32_t                     m_FileVersion;
196     friend class CPDF_ObjectStream;
197     friend class CPDF_XRefStream;
198 };
199
200 #endif  // CORE_INCLUDE_FPDFAPI_FPDF_SERIAL_H_