1*3ac0a46fSAndroid Build Coastguard Worker // Copyright 2017 The PDFium Authors 2*3ac0a46fSAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*3ac0a46fSAndroid Build Coastguard Worker // found in the LICENSE file. 4*3ac0a46fSAndroid Build Coastguard Worker 5*3ac0a46fSAndroid Build Coastguard Worker // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6*3ac0a46fSAndroid Build Coastguard Worker 7*3ac0a46fSAndroid Build Coastguard Worker #include "fpdfsdk/formfiller/cffl_textobject.h" 8*3ac0a46fSAndroid Build Coastguard Worker 9*3ac0a46fSAndroid Build Coastguard Worker #include "core/fpdfapi/page/cpdf_page.h" 10*3ac0a46fSAndroid Build Coastguard Worker #include "core/fpdfdoc/cpdf_bafontmap.h" 11*3ac0a46fSAndroid Build Coastguard Worker #include "fpdfsdk/cpdfsdk_widget.h" 12*3ac0a46fSAndroid Build Coastguard Worker CFFL_TextObject(CFFL_InteractiveFormFiller * pFormFiller,CPDFSDK_Widget * pWidget)13*3ac0a46fSAndroid Build Coastguard WorkerCFFL_TextObject::CFFL_TextObject(CFFL_InteractiveFormFiller* pFormFiller, 14*3ac0a46fSAndroid Build Coastguard Worker CPDFSDK_Widget* pWidget) 15*3ac0a46fSAndroid Build Coastguard Worker : CFFL_FormField(pFormFiller, pWidget) {} 16*3ac0a46fSAndroid Build Coastguard Worker ~CFFL_TextObject()17*3ac0a46fSAndroid Build Coastguard WorkerCFFL_TextObject::~CFFL_TextObject() { 18*3ac0a46fSAndroid Build Coastguard Worker // Destroy view classes before this object's members are destroyed since 19*3ac0a46fSAndroid Build Coastguard Worker // the view classes have pointers to m_pFontMap that would be left dangling. 20*3ac0a46fSAndroid Build Coastguard Worker DestroyWindows(); 21*3ac0a46fSAndroid Build Coastguard Worker } 22*3ac0a46fSAndroid Build Coastguard Worker ResetPWLWindow(const CPDFSDK_PageView * pPageView)23*3ac0a46fSAndroid Build Coastguard WorkerCPWL_Wnd* CFFL_TextObject::ResetPWLWindow(const CPDFSDK_PageView* pPageView) { 24*3ac0a46fSAndroid Build Coastguard Worker DestroyPWLWindow(pPageView); 25*3ac0a46fSAndroid Build Coastguard Worker ObservedPtr<CPWL_Wnd> pRet(CreateOrUpdatePWLWindow(pPageView)); 26*3ac0a46fSAndroid Build Coastguard Worker m_pWidget->UpdateField(); // May invoke JS, invalidating |pRet|. 27*3ac0a46fSAndroid Build Coastguard Worker return pRet.Get(); 28*3ac0a46fSAndroid Build Coastguard Worker } 29*3ac0a46fSAndroid Build Coastguard Worker RestorePWLWindow(const CPDFSDK_PageView * pPageView)30*3ac0a46fSAndroid Build Coastguard WorkerCPWL_Wnd* CFFL_TextObject::RestorePWLWindow(const CPDFSDK_PageView* pPageView) { 31*3ac0a46fSAndroid Build Coastguard Worker SavePWLWindowState(pPageView); 32*3ac0a46fSAndroid Build Coastguard Worker DestroyPWLWindow(pPageView); 33*3ac0a46fSAndroid Build Coastguard Worker RecreatePWLWindowFromSavedState(pPageView); 34*3ac0a46fSAndroid Build Coastguard Worker ObservedPtr<CPWL_Wnd> pRet(GetPWLWindow(pPageView)); 35*3ac0a46fSAndroid Build Coastguard Worker m_pWidget->UpdateField(); // May invoke JS, invalidating |pRet|. 36*3ac0a46fSAndroid Build Coastguard Worker return pRet.Get(); 37*3ac0a46fSAndroid Build Coastguard Worker } 38*3ac0a46fSAndroid Build Coastguard Worker GetOrCreateFontMap()39*3ac0a46fSAndroid Build Coastguard WorkerCPDF_BAFontMap* CFFL_TextObject::GetOrCreateFontMap() { 40*3ac0a46fSAndroid Build Coastguard Worker if (!m_pFontMap) { 41*3ac0a46fSAndroid Build Coastguard Worker m_pFontMap = std::make_unique<CPDF_BAFontMap>( 42*3ac0a46fSAndroid Build Coastguard Worker m_pWidget->GetPDFPage()->GetDocument(), 43*3ac0a46fSAndroid Build Coastguard Worker m_pWidget->GetPDFAnnot()->GetMutableAnnotDict(), "N"); 44*3ac0a46fSAndroid Build Coastguard Worker } 45*3ac0a46fSAndroid Build Coastguard Worker return m_pFontMap.get(); 46*3ac0a46fSAndroid Build Coastguard Worker } 47