Revert "FX_BOOL considered harmful, part 2."
[pdfium.git] / core / include / fpdfapi / fpdf_page.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_PAGE_H_
8 #define CORE_INCLUDE_FPDFAPI_FPDF_PAGE_H_
9
10 #include "../fxge/fx_dib.h"
11 #include "fpdf_parser.h"
12 #include "fpdf_resource.h"
13
14 class CPDF_PageObjects;
15 class CPDF_Page;
16 class CPDF_Form;
17 class CPDF_ParseOptions;
18 class CPDF_PageObject;
19 class CPDF_PageRenderCache;
20 class CPDF_StreamFilter;
21 class CPDF_AllStates;
22 class CPDF_ContentParser;
23 class CPDF_StreamContentParser;
24 #define PDFTRANS_GROUP                  0x0100
25 #define PDFTRANS_ISOLATED               0x0200
26 #define PDFTRANS_KNOCKOUT               0x0400
27 #define PDF_CONTENT_NOT_PARSED  0
28 #define PDF_CONTENT_PARSING             1
29 #define PDF_CONTENT_PARSED              2
30 class CPDF_PageObjects
31 {
32 public:
33
34     CPDF_PageObjects(FX_BOOL bReleaseMembers = TRUE);
35
36     ~CPDF_PageObjects();
37
38
39
40
41     void                                ContinueParse(IFX_Pause* pPause);
42
43     int                                 GetParseState() const
44     {
45         return m_ParseState;
46     }
47
48     FX_BOOL                             IsParsed() const
49     {
50         return m_ParseState == PDF_CONTENT_PARSED;
51     }
52
53     int                                 EstimateParseProgress() const;
54
55
56
57
58     FX_POSITION                 GetFirstObjectPosition() const
59     {
60         return m_ObjectList.GetHeadPosition();
61     }
62
63     FX_POSITION                 GetLastObjectPosition() const
64     {
65         return m_ObjectList.GetTailPosition();
66     }
67
68     CPDF_PageObject*    GetNextObject(FX_POSITION& pos) const
69     {
70         return (CPDF_PageObject*)m_ObjectList.GetNext(pos);
71     }
72
73     CPDF_PageObject*    GetPrevObject(FX_POSITION& pos) const
74     {
75         return (CPDF_PageObject*)m_ObjectList.GetPrev(pos);
76     }
77
78     CPDF_PageObject*    GetObjectAt(FX_POSITION pos) const
79     {
80         return (CPDF_PageObject*)m_ObjectList.GetAt(pos);
81     }
82
83     FX_DWORD                    CountObjects() const
84     {
85         return m_ObjectList.GetCount();
86     }
87
88     int                                 GetObjectIndex(CPDF_PageObject* pObj) const;
89
90     CPDF_PageObject*    GetObjectByIndex(int index) const;
91
92
93
94
95
96     FX_POSITION                 InsertObject(FX_POSITION posInsertAfter, CPDF_PageObject* pNewObject);
97
98     void                                Transform(const CFX_AffineMatrix& matrix);
99
100     FX_BOOL                             BackgroundAlphaNeeded() const
101     {
102         return m_bBackgroundAlphaNeeded;
103     }
104
105     CFX_FloatRect               CalcBoundingBox() const;
106
107     CPDF_Dictionary*    m_pFormDict;
108
109     CPDF_Stream*                m_pFormStream;
110
111     CPDF_Document*              m_pDocument;
112
113     CPDF_Dictionary*    m_pPageResources;
114
115     CPDF_Dictionary*    m_pResources;
116
117     CFX_FloatRect               m_BBox;
118
119     int                                 m_Transparency;
120
121 protected:
122     friend class                CPDF_ContentParser;
123     friend class                CPDF_StreamContentParser;
124     friend class                CPDF_AllStates;
125
126     CFX_PtrList                 m_ObjectList;
127
128     FX_BOOL                             m_bBackgroundAlphaNeeded;
129
130     FX_BOOL                             m_bReleaseMembers;
131     void                                LoadTransInfo();
132     void                ClearCacheObjects();
133
134     CPDF_ContentParser* m_pParser;
135
136     FX_BOOL                             m_ParseState;
137 };
138 class CPDF_Page : public CPDF_PageObjects, public CFX_PrivateData
139 {
140 public:
141
142     CPDF_Page();
143
144     ~CPDF_Page();
145
146     void                                Load(CPDF_Document* pDocument, CPDF_Dictionary* pPageDict, FX_BOOL bPageCache = TRUE);
147
148     void                                StartParse(CPDF_ParseOptions* pOptions = NULL, FX_BOOL bReParse = FALSE);
149
150     void                                ParseContent(CPDF_ParseOptions* pOptions = NULL, FX_BOOL bReParse = FALSE);
151
152     void                                GetDisplayMatrix(CFX_AffineMatrix& matrix, int xPos, int yPos,
153                                          int xSize, int ySize, int iRotate) const;
154
155     FX_FLOAT                    GetPageWidth() const
156     {
157         return m_PageWidth;
158     }
159
160     FX_FLOAT                    GetPageHeight() const
161     {
162         return m_PageHeight;
163     }
164
165     CFX_FloatRect               GetPageBBox() const
166     {
167         return m_BBox;
168     }
169
170     const CFX_AffineMatrix&     GetPageMatrix() const
171     {
172         return m_PageMatrix;
173     }
174
175     CPDF_Object*                GetPageAttr(const CFX_ByteStringC& name) const;
176
177
178
179     CPDF_PageRenderCache*       GetRenderCache() const
180     {
181         return m_pPageRender;
182     }
183
184     void                                ClearRenderCache();
185
186 protected:
187     friend class                CPDF_ContentParser;
188
189     FX_FLOAT                    m_PageWidth;
190
191     FX_FLOAT                    m_PageHeight;
192
193     CFX_AffineMatrix    m_PageMatrix;
194
195     CPDF_PageRenderCache*       m_pPageRender;
196 };
197 class CPDF_ParseOptions
198 {
199 public:
200
201     CPDF_ParseOptions();
202
203     FX_BOOL                             m_bTextOnly;
204
205     FX_BOOL                             m_bMarkedContent;
206
207     FX_BOOL                             m_bSeparateForm;
208
209     FX_BOOL                             m_bDecodeInlineImage;
210 };
211 class CPDF_Form : public CPDF_PageObjects
212 {
213 public:
214
215     CPDF_Form(CPDF_Document* pDocument, CPDF_Dictionary* pPageResources, CPDF_Stream* pFormStream, CPDF_Dictionary* pParentResources = NULL);
216
217     ~CPDF_Form();
218
219     void                                StartParse(CPDF_AllStates* pGraphicStates,  CFX_AffineMatrix* pParentMatrix,
220                                    CPDF_Type3Char* pType3Char, CPDF_ParseOptions* pOptions, int level = 0);
221
222     void                                ParseContent(CPDF_AllStates* pGraphicStates, CFX_AffineMatrix* pParentMatrix,
223                                      CPDF_Type3Char* pType3Char, CPDF_ParseOptions* pOptions, int level = 0);
224
225     CPDF_Form*                  Clone() const;
226 };
227 class CPDF_PageContentGenerate
228 {
229 public:
230     CPDF_PageContentGenerate(CPDF_Page* pPage);
231     ~CPDF_PageContentGenerate();
232     FX_BOOL InsertPageObject(CPDF_PageObject* pPageObject);
233     void GenerateContent();
234     void TransformContent(CFX_Matrix& matrix);
235 protected:
236     void            ProcessImage(CFX_ByteTextBuf& buf, CPDF_ImageObject* pImageObj);
237     void            ProcessForm(CFX_ByteTextBuf& buf, const uint8_t* data, FX_DWORD size, CFX_Matrix& matrix);
238     CFX_ByteString  RealizeResource(CPDF_Object* pResourceObj, const FX_CHAR* szType);
239 private:
240     CPDF_Page*      m_pPage;
241     CPDF_Document*  m_pDocument;
242     CFX_PtrArray    m_pageObjects;
243 };
244
245 #endif  // CORE_INCLUDE_FPDFAPI_FPDF_PAGE_H_