1 // Copyright 2016 The PDFium Authors 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_PAGE_H_ 8 #define CORE_FPDFAPI_PAGE_CPDF_PAGE_H_ 9 10 #include <memory> 11 #include <utility> 12 13 #include "core/fpdfapi/page/cpdf_pageobjectholder.h" 14 #include "core/fpdfapi/page/ipdf_page.h" 15 #include "core/fxcrt/fx_coordinates.h" 16 #include "core/fxcrt/fx_memory.h" 17 #include "core/fxcrt/observed_ptr.h" 18 #include "core/fxcrt/retain_ptr.h" 19 #include "core/fxcrt/unowned_ptr.h" 20 #include "third_party/abseil-cpp/absl/types/optional.h" 21 22 class CPDF_Array; 23 class CPDF_Dictionary; 24 class CPDF_Document; 25 class CPDF_Object; 26 class CPDF_PageImageCache; 27 28 class CPDF_Page final : public IPDF_Page, public CPDF_PageObjectHolder { 29 public: 30 // Caller implements as desired, exists here due to layering. 31 class View : public Observable { 32 public: 33 virtual void ClearPage(CPDF_Page* pPage) = 0; 34 }; 35 36 // Data for the render layer to attach to this page. 37 class RenderContextIface { 38 public: 39 virtual ~RenderContextIface() = default; 40 }; 41 42 class RenderContextClearer { 43 public: 44 FX_STACK_ALLOCATED(); 45 explicit RenderContextClearer(CPDF_Page* pPage); 46 ~RenderContextClearer(); 47 48 private: 49 UnownedPtr<CPDF_Page> const m_pPage; 50 }; 51 52 CONSTRUCT_VIA_MAKE_RETAIN; 53 54 // IPDF_Page: 55 CPDF_Page* AsPDFPage() override; 56 CPDFXFA_Page* AsXFAPage() override; 57 CPDF_Document* GetDocument() const override; 58 float GetPageWidth() const override; 59 float GetPageHeight() const override; 60 CFX_Matrix GetDisplayMatrix(const FX_RECT& rect, int iRotate) const override; 61 absl::optional<CFX_PointF> DeviceToPage( 62 const FX_RECT& rect, 63 int rotate, 64 const CFX_PointF& device_point) const override; 65 absl::optional<CFX_PointF> PageToDevice( 66 const FX_RECT& rect, 67 int rotate, 68 const CFX_PointF& page_point) const override; 69 70 // CPDF_PageObjectHolder: 71 bool IsPage() const override; 72 73 void ParseContent(); GetPageSize()74 const CFX_SizeF& GetPageSize() const { return m_PageSize; } GetPageMatrix()75 const CFX_Matrix& GetPageMatrix() const { return m_PageMatrix; } 76 int GetPageRotation() const; 77 78 RetainPtr<CPDF_Array> GetOrCreateAnnotsArray(); 79 RetainPtr<CPDF_Array> GetMutableAnnotsArray(); 80 RetainPtr<const CPDF_Array> GetAnnotsArray() const; 81 82 void AddPageImageCache(); GetPageImageCache()83 CPDF_PageImageCache* GetPageImageCache() { return m_pPageImageCache.get(); } GetRenderContext()84 RenderContextIface* GetRenderContext() { return m_pRenderContext.get(); } 85 86 // `pContext` cannot be null. `SetRenderContext()` cannot be called if the 87 // page already has a render context. Use `ClearRenderContext()` to reset the 88 // render context. 89 void SetRenderContext(std::unique_ptr<RenderContextIface> pContext); 90 void ClearRenderContext(); 91 SetView(View * pView)92 void SetView(View* pView) { m_pView.Reset(pView); } 93 void ClearView(); 94 void UpdateDimensions(); 95 96 private: 97 CPDF_Page(CPDF_Document* pDocument, RetainPtr<CPDF_Dictionary> pPageDict); 98 ~CPDF_Page() override; 99 100 RetainPtr<CPDF_Object> GetMutablePageAttr(const ByteString& name); 101 RetainPtr<const CPDF_Object> GetPageAttr(const ByteString& name) const; 102 CFX_FloatRect GetBox(const ByteString& name) const; 103 104 CFX_SizeF m_PageSize; 105 CFX_Matrix m_PageMatrix; 106 UnownedPtr<CPDF_Document> const m_pPDFDocument; 107 std::unique_ptr<CPDF_PageImageCache> m_pPageImageCache; 108 std::unique_ptr<RenderContextIface> m_pRenderContext; 109 ObservedPtr<View> m_pView; 110 }; 111 112 #endif // CORE_FPDFAPI_PAGE_CPDF_PAGE_H_ 113