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