1 // Copyright 2016 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_FPDFAPI_PAGE_CPDF_PAGEOBJECT_H_ 8 #define CORE_FPDFAPI_PAGE_CPDF_PAGEOBJECT_H_ 9 10 #include "core/fpdfapi/page/cpdf_contentmarks.h" 11 #include "core/fpdfapi/page/cpdf_graphicstates.h" 12 #include "core/fxcrt/fx_coordinates.h" 13 #include "core/fxcrt/fx_system.h" 14 15 class CPDF_FormObject; 16 class CPDF_ImageObject; 17 class CPDF_PathObject; 18 class CPDF_ShadingObject; 19 class CPDF_TextObject; 20 21 class CPDF_PageObject : public CPDF_GraphicStates { 22 public: 23 enum Type { 24 TEXT = 1, 25 PATH, 26 IMAGE, 27 SHADING, 28 FORM, 29 }; 30 31 static constexpr int32_t kNoContentStream = -1; 32 33 explicit CPDF_PageObject(int32_t content_stream); 34 CPDF_PageObject(const CPDF_PageObject& src) = delete; 35 CPDF_PageObject& operator=(const CPDF_PageObject& src) = delete; 36 ~CPDF_PageObject() override; 37 38 virtual Type GetType() const = 0; 39 virtual void Transform(const CFX_Matrix& matrix) = 0; 40 virtual bool IsText() const; 41 virtual bool IsPath() const; 42 virtual bool IsImage() const; 43 virtual bool IsShading() const; 44 virtual bool IsForm() const; 45 virtual CPDF_TextObject* AsText(); 46 virtual const CPDF_TextObject* AsText() const; 47 virtual CPDF_PathObject* AsPath(); 48 virtual const CPDF_PathObject* AsPath() const; 49 virtual CPDF_ImageObject* AsImage(); 50 virtual const CPDF_ImageObject* AsImage() const; 51 virtual CPDF_ShadingObject* AsShading(); 52 virtual const CPDF_ShadingObject* AsShading() const; 53 virtual CPDF_FormObject* AsForm(); 54 virtual const CPDF_FormObject* AsForm() const; 55 SetDirty(bool value)56 void SetDirty(bool value) { m_bDirty = value; } IsDirty()57 bool IsDirty() const { return m_bDirty; } 58 void TransformClipPath(const CFX_Matrix& matrix); 59 void TransformGeneralState(const CFX_Matrix& matrix); 60 SetRect(const CFX_FloatRect & rect)61 void SetRect(const CFX_FloatRect& rect) { m_Rect = rect; } GetRect()62 const CFX_FloatRect& GetRect() const { return m_Rect; } 63 FX_RECT GetBBox() const; 64 FX_RECT GetTransformedBBox(const CFX_Matrix& matrix) const; 65 66 // Get what content stream the object was parsed from in its page. This number 67 // is the index of the content stream in the "Contents" array, or 0 if there 68 // is a single content stream. If the object is newly created, 69 // |kNoContentStream| is returned. 70 // 71 // If the object is spread among more than one content stream, this is the 72 // index of the last stream. GetContentStream()73 int32_t GetContentStream() const { return m_ContentStream; } SetContentStream(int32_t new_content_stream)74 void SetContentStream(int32_t new_content_stream) { 75 m_ContentStream = new_content_stream; 76 } 77 78 CPDF_ContentMarks m_ContentMarks; 79 80 protected: 81 void CopyData(const CPDF_PageObject* pSrcObject); 82 83 CFX_FloatRect m_Rect; 84 85 private: 86 bool m_bDirty = false; 87 int32_t m_ContentStream; 88 }; 89 90 #endif // CORE_FPDFAPI_PAGE_CPDF_PAGEOBJECT_H_ 91