• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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_system.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/base/optional.h"
21 
22 class CPDF_Dictionary;
23 class CPDF_Document;
24 class CPDF_Image;
25 class CPDF_Object;
26 
27 class CPDF_Page final : public IPDF_Page, public CPDF_PageObjectHolder {
28  public:
29   // Caller implements as desired, empty here due to layering.
30   class View : public Observable {};
31 
32   // Data for the render layer to attach to this page.
33   class RenderContextIface {
34    public:
~RenderContextIface()35     virtual ~RenderContextIface() {}
36   };
37 
38   // Cache for the render layer to attach to this page.
39   class RenderCacheIface {
40    public:
~RenderCacheIface()41     virtual ~RenderCacheIface() {}
42     virtual void ResetBitmapForImage(const RetainPtr<CPDF_Image>& pImage) = 0;
43   };
44 
45   class RenderContextClearer {
46    public:
47     explicit RenderContextClearer(CPDF_Page* pPage);
48     ~RenderContextClearer();
49 
50    private:
51     UnownedPtr<CPDF_Page> const m_pPage;
52   };
53 
54   template <typename T, typename... Args>
55   friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
56 
57   // IPDF_Page:
58   CPDF_Page* AsPDFPage() override;
59   CPDFXFA_Page* AsXFAPage() override;
60   CPDF_Document* GetDocument() const override;
61   float GetPageWidth() const override;
62   float GetPageHeight() const override;
63   CFX_Matrix GetDisplayMatrix(const FX_RECT& rect, int iRotate) const override;
64   Optional<CFX_PointF> DeviceToPage(
65       const FX_RECT& rect,
66       int rotate,
67       const CFX_PointF& device_point) const override;
68   Optional<CFX_PointF> PageToDevice(
69       const FX_RECT& rect,
70       int rotate,
71       const CFX_PointF& page_point) const override;
72 
73   // CPDF_PageObjectHolder:
74   bool IsPage() const override;
75 
76   void ParseContent();
GetPageSize()77   const CFX_SizeF& GetPageSize() const { return m_PageSize; }
78   int GetPageRotation() const;
GetRenderCache()79   RenderCacheIface* GetRenderCache() const { return m_pRenderCache.get(); }
SetRenderCache(std::unique_ptr<RenderCacheIface> pCache)80   void SetRenderCache(std::unique_ptr<RenderCacheIface> pCache) {
81     m_pRenderCache = std::move(pCache);
82   }
83 
GetRenderContext()84   RenderContextIface* GetRenderContext() const {
85     return m_pRenderContext.get();
86   }
SetRenderContext(std::unique_ptr<RenderContextIface> pContext)87   void SetRenderContext(std::unique_ptr<RenderContextIface> pContext) {
88     m_pRenderContext = std::move(pContext);
89   }
90 
GetPDFDocument()91   CPDF_Document* GetPDFDocument() const { return m_pPDFDocument.Get(); }
GetView()92   View* GetView() const { return m_pView.Get(); }
SetView(View * pView)93   void SetView(View* pView) { m_pView.Reset(pView); }
94   void UpdateDimensions();
95 
96  private:
97   CPDF_Page(CPDF_Document* pDocument, CPDF_Dictionary* pPageDict);
98   ~CPDF_Page() override;
99 
100   CPDF_Object* GetPageAttr(const ByteString& name) const;
101   CFX_FloatRect GetBox(const ByteString& name) const;
102 
103   CFX_SizeF m_PageSize;
104   CFX_Matrix m_PageMatrix;
105   UnownedPtr<CPDF_Document> m_pPDFDocument;
106   std::unique_ptr<RenderCacheIface> m_pRenderCache;
107   std::unique_ptr<RenderContextIface> m_pRenderContext;
108   ObservedPtr<View> m_pView;
109 };
110 
111 #endif  // CORE_FPDFAPI_PAGE_CPDF_PAGE_H_
112