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