7#include "xfa/fxfa/cxfa_ffdoc.h"
13#include "core/fpdfapi/parser/cpdf_dictionary.h"
14#include "core/fpdfapi/parser/cpdf_document.h"
15#include "core/fpdfapi/parser/cpdf_stream.h"
16#include "core/fpdfapi/parser/cpdf_stream_acc.h"
17#include "core/fpdfdoc/cpdf_nametree.h"
18#include "core/fxcrt/cfx_read_only_span_stream.h"
19#include "core/fxcrt/fx_extension.h"
20#include "core/fxcrt/xml/cfx_xmldocument.h"
21#include "core/fxcrt/xml/cfx_xmlelement.h"
22#include "core/fxcrt/xml/cfx_xmlnode.h"
23#include "core/fxcrt/xml/cfx_xmlparser.h"
24#include "core/fxge/dib/cfx_dibitmap.h"
25#include "fxjs/xfa/cjx_object.h"
26#include "third_party/base/check.h"
27#include "v8/include/cppgc/allocation.h"
28#include "v8/include/cppgc/heap.h"
29#include "xfa/fgas/font/cfgas_gefont.h"
30#include "xfa/fgas/font/cfgas_pdffontmgr.h"
31#include "xfa/fwl/cfwl_notedriver.h"
32#include "xfa/fxfa/cxfa_ffapp.h"
33#include "xfa/fxfa/cxfa_ffdocview.h"
34#include "xfa/fxfa/cxfa_ffnotify.h"
35#include "xfa/fxfa/cxfa_ffwidget.h"
36#include "xfa/fxfa/cxfa_fontmgr.h"
37#include "xfa/fxfa/layout/cxfa_layoutprocessor.h"
38#include "xfa/fxfa/parser/cxfa_acrobat.h"
39#include "xfa/fxfa/parser/cxfa_acrobat7.h"
40#include "xfa/fxfa/parser/cxfa_dataexporter.h"
41#include "xfa/fxfa/parser/cxfa_document.h"
42#include "xfa/fxfa/parser/cxfa_document_builder.h"
43#include "xfa/fxfa/parser/cxfa_dynamicrender.h"
44#include "xfa/fxfa/parser/cxfa_node.h"
61 : m_pDocEnvironment(pDocEnvironment),
65 m_pNotify(cppgc::MakeGarbageCollected<CXFA_FFNotify>(
66 pHeap->GetAllocationHandle(),
68 m_pDocument(cppgc::MakeGarbageCollected<CXFA_Document>(
69 pHeap->GetAllocationHandle(),
72 cppgc::MakeGarbageCollected<CXFA_LayoutProcessor>(
73 pHeap->GetAllocationHandle(),
80 m_DocView->RunDocClose();
83 m_pDocument->ClearLayoutData();
87 visitor->Trace(m_pApp);
88 visitor->Trace(m_pNotify);
89 visitor->Trace(m_pDocument);
90 visitor->Trace(m_DocView);
100 m_pDocument->SetRoot(builder.GetRootNode());
106 m_DocView = cppgc::MakeGarbageCollected<CXFA_FFDocView>(
107 m_pHeap->GetAllocationHandle(),
this);
113 m_pDocEnvironment->SetChangeMark(
this);
118 m_pDocEnvironment->InvalidateRect(pPageView, rt);
124 return m_pDocEnvironment->DisplayCaret(hWidget, bVisible, pRtAnchor);
132 return m_pDocEnvironment->GetPopupPos(hWidget, fMinPopup, fMaxPopup, rtAnchor,
137 return m_pDocEnvironment->PopupMenu(hWidget, ptPopup);
142 m_pDocEnvironment->OnPageViewEvent(pPageView, eEvent);
146 m_pDocEnvironment->WidgetPostAdd(hWidget);
150 m_pDocEnvironment->WidgetPreRemove(hWidget);
154 return m_pDocEnvironment->CountPages(
this);
158 return m_pDocEnvironment->GetCurrentPage(
this);
162 m_pDocEnvironment->SetCurrentPage(
this, iCurPage);
166 return m_pDocEnvironment->IsCalculationsEnabled(
this);
170 return m_pDocEnvironment->SetCalculationsEnabled(
this, bEnabled);
174 return m_pDocEnvironment->GetTitle(
this);
178 m_pDocEnvironment->SetTitle(
this, wsTitle);
182 m_pDocEnvironment->ExportData(
this, wsFilePath, bXDP);
186 m_pDocEnvironment->GotoURL(
this, bsURL);
190 return m_pDocEnvironment->IsValidationsEnabled(
this);
194 m_pDocEnvironment->SetValidationsEnabled(
this, bEnabled);
198 m_pDocEnvironment->SetFocusWidget(
this, hWidget);
204 m_pDocEnvironment->Print(
this, nStartPage, nEndPage, dwOptions);
208 return m_pDocEnvironment->GetHighlightColor(
this);
212 return m_pDocEnvironment->GetIJSRuntime(
this);
216 return m_pDocEnvironment->GetXMLDoc();
220 const WideString& wsLink) {
221 return m_pDocEnvironment->OpenLinkedFile(
this, wsLink);
225 return m_DocView && m_DocView->GetLayoutProcessor() == pLayout ? m_DocView
239 m_pPDFFontMgr = std::make_unique<CFGAS_PDFFontMgr>(GetPDFDoc());
241 CXFA_Node* pConfig = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config));
245 CXFA_Acrobat* pAcrobat =
246 pConfig->GetFirstChildByClass<CXFA_Acrobat>(
XFA_Element::Acrobat);
250 CXFA_Acrobat7* pAcrobat7 =
251 pAcrobat->GetFirstChildByClass<CXFA_Acrobat7>(
XFA_Element::Acrobat7);
255 CXFA_DynamicRender* pDynamicRender =
256 pAcrobat7->GetFirstChildByClass<CXFA_DynamicRender>(
261 WideString wsType = pDynamicRender->JSObject()->GetContent(
false);
274 return m_pPDFFontMgr->GetFont(family, styles, strict);
279 int32_t& iImageYDpi) {
280 uint32_t dwHash = FX_HashCode_GetW(wsName);
281 auto it = m_HashToDibDpiMap.find(dwHash);
282 if (it != m_HashToDibDpiMap.end()) {
283 iImageXDpi = it->second.iImageXDpi;
284 iImageYDpi = it->second.iImageYDpi;
285 return it->second.pDibSource.As<CFX_DIBitmap>();
288 auto name_tree = CPDF_NameTree::Create(m_pPDFDoc,
"XFAImages");
289 size_t count = name_tree ? name_tree->GetCount() : 0;
294 name_tree->LookupValue(WideString(wsName));
296 for (size_t i = 0; i < count; ++i) {
299 name_tree->LookupValueAndName(i, &wsTemp);
300 if (wsTemp == wsName) {
301 pObject =
std::move(pTempObject);
307 RetainPtr<
const CPDF_Stream> pStream = ToStream(pObject);
311 auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(
std::move(pStream));
312 pAcc->LoadAllDataFiltered();
314 auto pImageFileRead =
315 pdfium::MakeRetain<CFX_ReadOnlySpanStream>(pAcc->GetSpan());
316 RetainPtr<CFX_DIBitmap> pDibSource = XFA_LoadImageFromBuffer(
317 std::move(pImageFileRead), FXCODEC_IMAGE_UNKNOWN, iImageXDpi, iImageYDpi);
318 m_HashToDibDpiMap[dwHash] = {pDibSource, iImageXDpi, iImageYDpi};
324 DCHECK(pNode || GetXFADoc()->GetRoot());
bool Export(const RetainPtr< IFX_SeekableStream > &pWrite, CXFA_Node *pNode)
bool BuildDocument(CFX_XMLDocument *pXML, XFA_PacketType ePacketID)
CXFA_Node * GetRoot() const
bool SavePackage(CXFA_Node *pNode, const RetainPtr< IFX_SeekableStream > &pFile)
CFX_XMLDocument * GetXMLDocument() const
void InvalidateRect(CXFA_FFPageView *pPageView, const CFX_RectF &rt)
CXFA_FFDocView * CreateDocView()
void WidgetPostAdd(CXFA_FFWidget *hWidget)
RetainPtr< CFGAS_GEFont > GetPDFFont(const WideString &family, uint32_t styles, bool strict)
void Print(int32_t nStartPage, int32_t nEndPage, Mask< XFA_PrintOpt > dwOptions)
CXFA_Document * GetXFADoc() const
FX_ARGB GetHighlightColor() const
void SetCurrentPage(int32_t iCurPage)
void SetCalculationsEnabled(bool bEnabled)
void OnPageViewEvent(CXFA_FFPageView *pPageView, PageViewEvent eEvent)
void DisplayCaret(CXFA_FFWidget *hWidget, bool bVisible, const CFX_RectF *pRtAnchor)
bool IsCalculationsEnabled() const
bool PopupMenu(CXFA_FFWidget *hWidget, const CFX_PointF &ptPopup)
CXFA_FFDocView * GetDocView(CXFA_LayoutProcessor *pLayout)
CXFA_FFDocView * GetDocView()
void SetFocusWidget(CXFA_FFWidget *hWidget)
void SetValidationsEnabled(bool bEnabled)
bool OpenDoc(CFX_XMLDocument *pXML)
void GotoURL(const WideString &bsURL)
WideString GetTitle() const
int32_t GetCurrentPage() const
bool IsValidationsEnabled() const
void ExportData(const WideString &wsFilePath, bool bXDP)
void SetTitle(const WideString &wsTitle)
IJS_Runtime * GetIJSRuntime() const
void WidgetPreRemove(CXFA_FFWidget *hWidget)
RetainPtr< CFX_DIBitmap > GetPDFNamedImage(WideStringView wsName, int32_t &iImageXDpi, int32_t &iImageYDpi)
RetainPtr< IFX_SeekableReadStream > OpenLinkedFile(const WideString &wsLink)
bool GetPopupPos(CXFA_FFWidget *hWidget, float fMinPopup, float fMaxPopup, const CFX_RectF &rtAnchor, CFX_RectF *pPopupRect) const
int32_t CountPages() const
bool EqualsASCII(ByteStringView that) const
FX_IMAGEDIB_AND_DPI(const FX_IMAGEDIB_AND_DPI &that)
FX_IMAGEDIB_AND_DPI(const RetainPtr< CFX_DIBBase > &pDib, int32_t xDpi, int32_t yDpi)