1 // Copyright 2018 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_IPDF_PAGE_H_ 8 #define CORE_FPDFAPI_PAGE_IPDF_PAGE_H_ 9 10 #include "core/fxcrt/fx_coordinates.h" 11 #include "core/fxcrt/retain_ptr.h" 12 #include "third_party/abseil-cpp/absl/types/optional.h" 13 14 class CPDF_Document; 15 class CPDF_Page; 16 17 // Small layering violation, incomplete type and always null if non-XFA. 18 class CPDFXFA_Page; 19 20 // Interface implemented by both page types (CPDF_Page and CPDFXFA_Page). 21 class IPDF_Page : public Retainable { 22 public: 23 // There are actually 3 cases: a PDF page, an XFA page backed by a PDF page, 24 // and an XFA page not backed by a PDF page. AsPDFPage() will return the 25 // PDF page in either of the first two cases. AsXFAPage() is a straight 26 // downcast and is null if not either of the last two cases. Hence, both 27 // of these may return non-null on a given page. 28 virtual CPDF_Page* AsPDFPage() = 0; 29 virtual CPDFXFA_Page* AsXFAPage() = 0; 30 31 virtual CPDF_Document* GetDocument() const = 0; 32 33 virtual float GetPageWidth() const = 0; 34 virtual float GetPageHeight() const = 0; 35 virtual CFX_Matrix GetDisplayMatrix(const FX_RECT& rect, 36 int iRotate) const = 0; 37 38 virtual absl::optional<CFX_PointF> DeviceToPage( 39 const FX_RECT& rect, 40 int rotate, 41 const CFX_PointF& device_point) const = 0; 42 43 virtual absl::optional<CFX_PointF> PageToDevice( 44 const FX_RECT& rect, 45 int rotate, 46 const CFX_PointF& page_point) const = 0; 47 }; 48 ToPDFPage(IPDF_Page * pBase)49inline CPDF_Page* ToPDFPage(IPDF_Page* pBase) { 50 return pBase ? pBase->AsPDFPage() : nullptr; 51 } 52 ToXFAPage(IPDF_Page * pBase)53inline CPDFXFA_Page* ToXFAPage(IPDF_Page* pBase) { 54 return pBase ? pBase->AsXFAPage() : nullptr; 55 } 56 57 #endif // CORE_FPDFAPI_PAGE_IPDF_PAGE_H_ 58