From e6ce3428fce89f17e2e416adc567a401901f340b Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 27 Mar 2018 19:36:04 +0000 Subject: Simplify some XFA font manager creation For the cases where we always initialize the font managers, do it in the constructor instead of as a secondary call. Change-Id: Ic59b331d1eb357878cd5786b187b5b79bace4498 Reviewed-on: https://pdfium-review.googlesource.com/29291 Reviewed-by: Henrique Nakashima Commit-Queue: dsinclair --- fpdfsdk/fpdfxfa/cpdfxfa_context.cpp | 1 - xfa/fxfa/cxfa_ffapp.cpp | 11 ----------- xfa/fxfa/cxfa_ffapp.h | 8 ++++---- xfa/fxfa/cxfa_fontmgr.cpp | 21 ++++++++------------- xfa/fxfa/cxfa_fontmgr.h | 3 +-- 5 files changed, 13 insertions(+), 31 deletions(-) diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp index 79599e15dc..18f5f99b0e 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp @@ -40,7 +40,6 @@ CPDFXFA_Context::CPDFXFA_Context(std::unique_ptr pPDFDoc) : m_pPDFDoc(std::move(pPDFDoc)), m_pXFAApp(pdfium::MakeUnique(this)), m_DocEnv(this) { - m_pXFAApp->SetDefaultFontMgr(pdfium::MakeUnique()); } CPDFXFA_Context::~CPDFXFA_Context() { diff --git a/xfa/fxfa/cxfa_ffapp.cpp b/xfa/fxfa/cxfa_ffapp.cpp index 881d05d6b9..21ac081629 100644 --- a/xfa/fxfa/cxfa_ffapp.cpp +++ b/xfa/fxfa/cxfa_ffapp.cpp @@ -53,17 +53,6 @@ std::unique_ptr CXFA_FFApp::CreateDoc( return pDoc; } -void CXFA_FFApp::SetDefaultFontMgr( - std::unique_ptr pFontMgr) { - if (!m_pFontMgr) - m_pFontMgr = pdfium::MakeUnique(); - m_pFontMgr->SetDefFontMgr(std::move(pFontMgr)); -} - -CXFA_FontMgr* CXFA_FFApp::GetXFAFontMgr() const { - return m_pFontMgr.get(); -} - CFGAS_FontMgr* CXFA_FFApp::GetFDEFontMgr() { if (!m_pFDEFontMgr) { m_pFDEFontMgr = pdfium::MakeUnique(); diff --git a/xfa/fxfa/cxfa_ffapp.h b/xfa/fxfa/cxfa_ffapp.h index b63f058367..bd4cf363fe 100644 --- a/xfa/fxfa/cxfa_ffapp.h +++ b/xfa/fxfa/cxfa_ffapp.h @@ -15,6 +15,7 @@ #include "core/fxcrt/retain_ptr.h" #include "core/fxcrt/unowned_ptr.h" #include "xfa/fwl/cfwl_app.h" +#include "xfa/fxfa/cxfa_fontmgr.h" #include "xfa/fxfa/fxfa.h" class CFGAS_DefaultFontManager; @@ -22,7 +23,6 @@ class CFGAS_FontMgr; class CFWL_WidgetMgr; class CPDF_Document; class CXFA_FFDocHandler; -class CXFA_FontMgr; class CXFA_FWLAdapterWidgetMgr; class CXFA_FWLTheme; class IFWL_AdapterTimerMgr; @@ -47,7 +47,7 @@ class CXFA_FFApp { IXFA_AppProvider* GetAppProvider() const { return m_pProvider.Get(); } const CFWL_App* GetFWLApp() const { return m_pFWLApp.get(); } IFWL_AdapterTimerMgr* GetTimerMgr() const; - CXFA_FontMgr* GetXFAFontMgr() const; + CXFA_FontMgr* GetXFAFontMgr() { return &m_pFontMgr; } void ClearEventTargets(); @@ -58,14 +58,14 @@ class CXFA_FFApp { // font manager. The GEFont::LoadFont call takes the manager as a param and // stores it internally. When you destroy the GEFont it tries to unregister // from the font manager and if the default font manager was destroyed first - // get get a use-after-free. The m_pFWLTheme can try to cleanup a GEFont + // you get a use-after-free. The m_pFWLTheme can try to cleanup a GEFont // when it frees, so make sure it gets cleaned up first. That requires // m_pFWLApp to be cleaned up as well. // // TODO(dsinclair): The GEFont should have the FontMgr as the pointer instead // of the DEFFontMgr so this goes away. Bug 561. std::unique_ptr m_pFDEFontMgr; - std::unique_ptr m_pFontMgr; + CXFA_FontMgr m_pFontMgr; std::unique_ptr m_pAdapterWidgetMgr; diff --git a/xfa/fxfa/cxfa_fontmgr.cpp b/xfa/fxfa/cxfa_fontmgr.cpp index 0956806698..7770825b26 100644 --- a/xfa/fxfa/cxfa_fontmgr.cpp +++ b/xfa/fxfa/cxfa_fontmgr.cpp @@ -19,9 +19,9 @@ #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffdoc.h" -CXFA_FontMgr::CXFA_FontMgr() {} +CXFA_FontMgr::CXFA_FontMgr() = default; -CXFA_FontMgr::~CXFA_FontMgr() {} +CXFA_FontMgr::~CXFA_FontMgr() = default; RetainPtr CXFA_FontMgr::GetFont( CXFA_FFDoc* hDoc, @@ -44,9 +44,9 @@ RetainPtr CXFA_FontMgr::GetFont( if (pFont) return pFont; } - if (!pFont && m_pDefFontMgr) - pFont = m_pDefFontMgr->GetFont(hDoc->GetApp()->GetFDEFontMgr(), - wsFontFamily, dwFontStyles); + if (!pFont) + pFont = m_pDefFontMgr.GetFont(hDoc->GetApp()->GetFDEFontMgr(), wsFontFamily, + dwFontStyles); if (!pFont && pMgr) { pPDFFont = nullptr; @@ -55,9 +55,9 @@ RetainPtr CXFA_FontMgr::GetFont( if (pFont) return pFont; } - if (!pFont && m_pDefFontMgr) { - pFont = m_pDefFontMgr->GetDefaultFont(hDoc->GetApp()->GetFDEFontMgr(), - wsFontFamily, dwFontStyles); + if (!pFont) { + pFont = m_pDefFontMgr.GetDefaultFont(hDoc->GetApp()->GetFDEFontMgr(), + wsFontFamily, dwFontStyles); } if (pFont) { @@ -69,8 +69,3 @@ RetainPtr CXFA_FontMgr::GetFont( } return pFont; } - -void CXFA_FontMgr::SetDefFontMgr( - std::unique_ptr pFontMgr) { - m_pDefFontMgr = std::move(pFontMgr); -} diff --git a/xfa/fxfa/cxfa_fontmgr.h b/xfa/fxfa/cxfa_fontmgr.h index a940fafc46..7d067bddb6 100644 --- a/xfa/fxfa/cxfa_fontmgr.h +++ b/xfa/fxfa/cxfa_fontmgr.h @@ -29,10 +29,9 @@ class CXFA_FontMgr { RetainPtr GetFont(CXFA_FFDoc* hDoc, const WideStringView& wsFontFamily, uint32_t dwFontStyles); - void SetDefFontMgr(std::unique_ptr pFontMgr); private: - std::unique_ptr m_pDefFontMgr; + CFGAS_DefaultFontManager m_pDefFontMgr; std::map> m_FontMap; }; -- cgit v1.2.3