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