blob: d8743adef24cadf71cf96bd0a712f35d3c441c05 [file]
// Copyright 2017 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "fpdfsdk/formfiller/cffl_textobject.h"
#include "core/fpdfapi/page/cpdf_page.h"
#include "core/fpdfdoc/cpdf_bafontmap.h"
#include "core/fxcrt/observed_ptr.h"
#include "fpdfsdk/cpdfsdk_widget.h"
CFFL_TextObject::CFFL_TextObject(CFFL_InteractiveFormFiller* pFormFiller,
CPDFSDK_Widget* pWidget)
: CFFL_FormField(pFormFiller, pWidget) {}
CFFL_TextObject::~CFFL_TextObject() {
// Destroy view classes before this object's members are destroyed since
// the view classes have pointers to font_map_ that would be left dangling.
DestroyWindows();
}
CPWL_Wnd* CFFL_TextObject::ResetPWLWindow(const CPDFSDK_PageView* pPageView) {
DestroyPWLWindow(pPageView);
ObservedPtr<CFFL_FormField> observed_this(this);
ObservedPtr<CPWL_Wnd> observed_wnd(CreateOrUpdatePWLWindow(pPageView));
if (!observed_this) {
return nullptr;
}
// May invoke JS, invalidating `observed_wnd` and `this`.
widget_->UpdateField();
return observed_this ? observed_wnd.Get() : nullptr;
}
CPWL_Wnd* CFFL_TextObject::RestorePWLWindow(const CPDFSDK_PageView* pPageView) {
SavePWLWindowState(pPageView);
DestroyPWLWindow(pPageView);
RecreatePWLWindowFromSavedState(pPageView);
ObservedPtr<CFFL_FormField> observed_this(this);
ObservedPtr<CPWL_Wnd> observed_wnd(GetPWLWindow(pPageView));
if (!observed_this) {
return nullptr;
}
// May invoke JS, invalidating `observed_wnd` and `this`.
widget_->UpdateField();
return observed_this ? observed_wnd.Get() : nullptr;
}
CPDF_BAFontMap* CFFL_TextObject::GetOrCreateFontMap() {
if (!font_map_) {
font_map_ = std::make_unique<CPDF_BAFontMap>(
widget_->GetPDFPage()->GetDocument(),
widget_->GetPDFAnnot()->GetMutableAnnotDict(), "N");
}
return font_map_.get();
}