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