1 // Copyright 2017 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 #include "fpdfsdk/formfiller/cffl_textobject.h" 8 9 #include "core/fpdfapi/page/cpdf_page.h" 10 #include "core/fpdfdoc/cpdf_bafontmap.h" 11 #include "fpdfsdk/cpdfsdk_widget.h" 12 CFFL_TextObject(CFFL_InteractiveFormFiller * pFormFiller,CPDFSDK_Widget * pWidget)13CFFL_TextObject::CFFL_TextObject(CFFL_InteractiveFormFiller* pFormFiller, 14 CPDFSDK_Widget* pWidget) 15 : CFFL_FormField(pFormFiller, pWidget) {} 16 ~CFFL_TextObject()17CFFL_TextObject::~CFFL_TextObject() { 18 // Destroy view classes before this object's members are destroyed since 19 // the view classes have pointers to m_pFontMap that would be left dangling. 20 DestroyWindows(); 21 } 22 ResetPWLWindow(const CPDFSDK_PageView * pPageView)23CPWL_Wnd* CFFL_TextObject::ResetPWLWindow(const CPDFSDK_PageView* pPageView) { 24 DestroyPWLWindow(pPageView); 25 ObservedPtr<CPWL_Wnd> pRet(CreateOrUpdatePWLWindow(pPageView)); 26 m_pWidget->UpdateField(); // May invoke JS, invalidating |pRet|. 27 return pRet.Get(); 28 } 29 RestorePWLWindow(const CPDFSDK_PageView * pPageView)30CPWL_Wnd* CFFL_TextObject::RestorePWLWindow(const CPDFSDK_PageView* pPageView) { 31 SavePWLWindowState(pPageView); 32 DestroyPWLWindow(pPageView); 33 RecreatePWLWindowFromSavedState(pPageView); 34 ObservedPtr<CPWL_Wnd> pRet(GetPWLWindow(pPageView)); 35 m_pWidget->UpdateField(); // May invoke JS, invalidating |pRet|. 36 return pRet.Get(); 37 } 38 GetOrCreateFontMap()39CPDF_BAFontMap* CFFL_TextObject::GetOrCreateFontMap() { 40 if (!m_pFontMap) { 41 m_pFontMap = std::make_unique<CPDF_BAFontMap>( 42 m_pWidget->GetPDFPage()->GetDocument(), 43 m_pWidget->GetPDFAnnot()->GetMutableAnnotDict(), "N"); 44 } 45 return m_pFontMap.get(); 46 } 47