1 // Copyright 2014 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 XFA_FXFA_CXFA_FFDOC_H_
8 #define XFA_FXFA_CXFA_FFDOC_H_
9 
10 #include <map>
11 #include <memory>
12 
13 #include "core/fxcrt/fx_stream.h"
14 #include "core/fxcrt/unowned_ptr.h"
15 #include "xfa/fxfa/fxfa.h"
16 #include "xfa/fxfa/parser/cxfa_document.h"
17 
18 class CFGAS_PDFFontMgr;
19 class CFX_ChecksumContext;
20 class CFX_DIBBase;
21 class CFX_DIBitmap;
22 class CFX_XMLDocument;
23 class CPDF_Document;
24 class CXFA_FFApp;
25 class CXFA_FFNotify;
26 class CXFA_FFDocView;
27 class CXFA_LayoutProcessor;
28 
29 struct FX_IMAGEDIB_AND_DPI {
30   FX_IMAGEDIB_AND_DPI();
31   FX_IMAGEDIB_AND_DPI(const FX_IMAGEDIB_AND_DPI& that);
32   FX_IMAGEDIB_AND_DPI(const RetainPtr<CFX_DIBBase>& pDib,
33                       int32_t xDpi,
34                       int32_t yDpi);
35   ~FX_IMAGEDIB_AND_DPI();
36 
37   RetainPtr<CFX_DIBBase> pDibSource;
38   int32_t iImageXDpi;
39   int32_t iImageYDpi;
40 };
41 
42 class CXFA_FFDoc {
43  public:
44   static std::unique_ptr<CXFA_FFDoc> CreateAndOpen(
45       CXFA_FFApp* pApp,
46       IXFA_DocEnvironment* pDocEnvironment,
47       CPDF_Document* pPDFDoc,
48       const RetainPtr<IFX_SeekableStream>& stream);
49 
50   ~CXFA_FFDoc();
51 
GetDocEnvironment()52   IXFA_DocEnvironment* GetDocEnvironment() const {
53     return m_pDocEnvironment.Get();
54   }
GetFormType()55   FormType GetFormType() const { return m_FormType; }
GetXMLDocument()56   CFX_XMLDocument* GetXMLDocument() const { return m_pXMLDoc.get(); }
57 
58   CXFA_FFDocView* CreateDocView();
59 
GetXFADoc()60   CXFA_Document* GetXFADoc() const { return m_pDocument.get(); }
GetApp()61   CXFA_FFApp* GetApp() const { return m_pApp.Get(); }
GetPDFDoc()62   CPDF_Document* GetPDFDoc() const { return m_pPDFDoc.Get(); }
63   CXFA_FFDocView* GetDocView(CXFA_LayoutProcessor* pLayout);
64   CXFA_FFDocView* GetDocView();
65   RetainPtr<CFX_DIBitmap> GetPDFNamedImage(WideStringView wsName,
66                                            int32_t& iImageXDpi,
67                                            int32_t& iImageYDpi);
GetPDFFontMgr()68   CFGAS_PDFFontMgr* GetPDFFontMgr() const { return m_pPDFFontMgr.get(); }
69 
70   bool SavePackage(CXFA_Node* pNode,
71                    const RetainPtr<IFX_SeekableStream>& pFile);
72 
73  private:
74   CXFA_FFDoc(CXFA_FFApp* pApp,
75              IXFA_DocEnvironment* pDocEnvironment,
76              CPDF_Document* pPDFDoc);
77   bool OpenDoc(const RetainPtr<IFX_SeekableStream>& stream);
78   bool ParseDoc(const RetainPtr<IFX_SeekableStream>& stream);
79 
80   UnownedPtr<IXFA_DocEnvironment> const m_pDocEnvironment;
81   UnownedPtr<CXFA_FFApp> const m_pApp;
82   UnownedPtr<CPDF_Document> const m_pPDFDoc;
83   std::unique_ptr<CFX_XMLDocument> m_pXMLDoc;
84   std::unique_ptr<CXFA_FFNotify> m_pNotify;
85   std::unique_ptr<CXFA_Document> m_pDocument;
86   std::unique_ptr<CXFA_FFDocView> m_DocView;
87   std::unique_ptr<CFGAS_PDFFontMgr> m_pPDFFontMgr;
88   std::map<uint32_t, FX_IMAGEDIB_AND_DPI> m_HashToDibDpiMap;
89   FormType m_FormType = FormType::kXFAForeground;
90 };
91 
92 #endif  // XFA_FXFA_CXFA_FFDOC_H_
93