fpdf_serial.h revision ee451cb395940862dad63c85adfe8f2fd55e864c
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
15class CPDF_ObjectStream;
16class CPDF_XRefStream;
17CFX_ByteTextBuf& operator << (CFX_ByteTextBuf& buf, const CPDF_Object* pObj);
18class CPDF_ObjArchiveSaver : public CFX_ArchiveSaver
19{
20public:
21
22    friend CPDF_ObjArchiveSaver&	operator << (CPDF_ObjArchiveSaver& ar, const CPDF_Object* pObj);
23protected:
24
25    CFX_MapPtrToPtr			m_ObjectMap;
26};
27class CPDF_ObjArchiveLoader : public CFX_ArchiveLoader
28{
29public:
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);
35protected:
36
37    CPDF_IndirectObjects		m_IndirectObjects;
38};
39class CPDF_PageArchiveSaver : public CPDF_ObjArchiveSaver
40{
41public:
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
59protected:
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};
73class CPDF_PageArchiveLoader : public CPDF_ObjArchiveLoader
74{
75public:
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
93protected:
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
116class CPDF_Creator : public CFX_Object
117{
118public:
119
120    CPDF_Creator(CPDF_Document* pDoc);
121
122    ~CPDF_Creator();
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);
133protected:
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#endif
204