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