From 81f02f4c8347890ce66d6ec48781589d10098689 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 26 Sep 2017 12:02:16 -0400 Subject: Move font source into CFGAS_FontMgr This CL moves the font source into the font manager so it doesn't need to be stored by each caller (and removes the platform dependant code). The |EnumFonts| method is exposed on the CFGAS_FontMgr so the caller can clear the manager if the enumeration fails. Change-Id: Iecce3d2e09ff01152b7bb79a34fe2b728320da9c Reviewed-on: https://pdfium-review.googlesource.com/14816 Reviewed-by: Henrique Nakashima Commit-Queue: dsinclair --- testing/unit_test_main.cpp | 15 +++------------ xfa/fgas/font/cfgas_fontmgr.cpp | 24 ++++-------------------- xfa/fgas/font/cfgas_fontmgr.h | 16 +++++++--------- xfa/fwl/theme/cfwl_widgettp.cpp | 10 ++++------ xfa/fwl/theme/cfwl_widgettp.h | 3 --- xfa/fxfa/cxfa_ffapp.cpp | 9 +++------ xfa/fxfa/cxfa_ffapp.h | 3 --- 7 files changed, 21 insertions(+), 59 deletions(-) diff --git a/testing/unit_test_main.cpp b/testing/unit_test_main.cpp index 1b1dcb0e32..ffc95216cc 100644 --- a/testing/unit_test_main.cpp +++ b/testing/unit_test_main.cpp @@ -26,26 +26,17 @@ class Environment : public testing::Environment { CFX_GEModule::Get()->GetFontMgr()->SetSystemFontInfo( IFX_SystemFontInfo::CreateDefault(nullptr)); -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - font_mgr_ = CFGAS_FontMgr::Create(FX_GetDefFontEnumerator()); -#else - font_source_ = pdfium::MakeUnique(); - font_mgr_ = CFGAS_FontMgr::Create(font_source_.get()); -#endif + font_mgr_ = pdfium::MakeUnique(); + if (!font_mgr_->EnumFonts()) + font_mgr_ = nullptr; } void TearDown() override { font_mgr_.reset(); -#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ - font_source_.reset(); -#endif } CFGAS_FontMgr* FontManager() const { return font_mgr_.get(); } private: -#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ - std::unique_ptr font_source_; -#endif std::unique_ptr font_mgr_; }; diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp index 2175a23288..df7c36fd53 100644 --- a/xfa/fgas/font/cfgas_fontmgr.cpp +++ b/xfa/fgas/font/cfgas_fontmgr.cpp @@ -184,13 +184,8 @@ uint32_t GetFontFamilyHash(const wchar_t* pszFontFamily, } // namespace -std::unique_ptr CFGAS_FontMgr::Create( - FX_LPEnumAllFonts pEnumerator) { - return pdfium::MakeUnique(pEnumerator); -} - -CFGAS_FontMgr::CFGAS_FontMgr(FX_LPEnumAllFonts pEnumerator) - : m_pEnumerator(pEnumerator), m_FontFaces(100) { +CFGAS_FontMgr::CFGAS_FontMgr() + : m_pEnumerator(FX_GetDefFontEnumerator()), m_FontFaces(100) { if (m_pEnumerator) m_pEnumerator(&m_FontFaces, nullptr, 0xFEFF); } @@ -688,19 +683,8 @@ RetainPtr CFX_FontSourceEnum_File::GetNext() { return pAccess; } -std::unique_ptr CFGAS_FontMgr::Create( - CFX_FontSourceEnum_File* pFontEnum) { - if (!pFontEnum) - return nullptr; - - auto pFontMgr = pdfium::MakeUnique(pFontEnum); - if (!pFontMgr->EnumFonts()) - return nullptr; - return pFontMgr; -} - -CFGAS_FontMgr::CFGAS_FontMgr(CFX_FontSourceEnum_File* pFontEnum) - : m_pFontSource(pFontEnum) {} +CFGAS_FontMgr::CFGAS_FontMgr() + : m_pFontSource(pdfium::MakeUnique()) {} CFGAS_FontMgr::~CFGAS_FontMgr() {} diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h index 9424cd9657..d0d73bb688 100644 --- a/xfa/fgas/font/cfgas_fontmgr.h +++ b/xfa/fgas/font/cfgas_fontmgr.h @@ -83,9 +83,7 @@ FX_LPEnumAllFonts FX_GetDefFontEnumerator(); class CFGAS_FontMgr : public Observable { public: - static std::unique_ptr Create(FX_LPEnumAllFonts pEnumerator); - - explicit CFGAS_FontMgr(FX_LPEnumAllFonts pEnumerator); + CFGAS_FontMgr(); ~CFGAS_FontMgr(); RetainPtr GetFontByCodePage(uint16_t wCodePage, @@ -99,6 +97,8 @@ class CFGAS_FontMgr : public Observable { uint16_t wCodePage); void RemoveFont(const RetainPtr& pFont); + bool EnumFonts() { return true; } + private: RetainPtr LoadFont(const RetainPtr& pSrcFont, uint32_t dwFontStyles, @@ -181,10 +181,7 @@ class CFX_FontSourceEnum_File { class CFGAS_FontMgr : public Observable { public: - static std::unique_ptr Create( - CFX_FontSourceEnum_File* pFontEnum); - - explicit CFGAS_FontMgr(CFX_FontSourceEnum_File* pFontEnum); + CFGAS_FontMgr(); ~CFGAS_FontMgr(); RetainPtr GetFontByCodePage(uint16_t wCodePage, @@ -198,8 +195,9 @@ class CFGAS_FontMgr : public Observable { uint16_t wCodePage); void RemoveFont(const RetainPtr& pFont); - private: bool EnumFonts(); + + private: bool EnumFontsFromFontMapper(); bool EnumFontsFromFiles(); void RegisterFace(FXFT_Face pFace, const WideString* pFaceName); @@ -234,7 +232,7 @@ class CFGAS_FontMgr : public Observable { RetainPtr CreateFontStream( const ByteString& bsFaceName); - CFX_FontSourceEnum_File* const m_pFontSource; + std::unique_ptr m_pFontSource; std::vector> m_InstalledFonts; std::map>> m_Hash2CandidateList; diff --git a/xfa/fwl/theme/cfwl_widgettp.cpp b/xfa/fwl/theme/cfwl_widgettp.cpp index 630da7793d..b2c1c9aa74 100644 --- a/xfa/fwl/theme/cfwl_widgettp.cpp +++ b/xfa/fwl/theme/cfwl_widgettp.cpp @@ -274,13 +274,11 @@ bool CFWL_FontData::LoadFont(const WideStringView& wsFontFamily, m_dwStyles = dwFontStyles; m_dwCodePage = dwCodePage; if (!m_pFontMgr) { -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - m_pFontMgr = CFGAS_FontMgr::Create(FX_GetDefFontEnumerator()); -#else - m_pFontSource = pdfium::MakeUnique(); - m_pFontMgr = CFGAS_FontMgr::Create(m_pFontSource.get()); -#endif + m_pFontMgr = pdfium::MakeUnique(); + if (!m_pFontMgr->EnumFonts()) + m_pFontMgr = nullptr; } + // TODO(tsepez): check usage of c_str() below. m_pFont = CFGAS_GEFont::LoadFont(wsFontFamily.unterminated_c_str(), dwFontStyles, dwCodePage, m_pFontMgr.get()); diff --git a/xfa/fwl/theme/cfwl_widgettp.h b/xfa/fwl/theme/cfwl_widgettp.h index eb1423e602..32a48d136d 100644 --- a/xfa/fwl/theme/cfwl_widgettp.h +++ b/xfa/fwl/theme/cfwl_widgettp.h @@ -118,9 +118,6 @@ class CFWL_FontData { WideString m_wsFamily; uint32_t m_dwStyles; uint32_t m_dwCodePage; -#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ - std::unique_ptr m_pFontSource; -#endif std::unique_ptr m_pFontMgr; RetainPtr m_pFont; }; diff --git a/xfa/fxfa/cxfa_ffapp.cpp b/xfa/fxfa/cxfa_ffapp.cpp index 8ec23e19c4..e3ca42c129 100644 --- a/xfa/fxfa/cxfa_ffapp.cpp +++ b/xfa/fxfa/cxfa_ffapp.cpp @@ -62,12 +62,9 @@ CXFA_FontMgr* CXFA_FFApp::GetXFAFontMgr() const { CFGAS_FontMgr* CXFA_FFApp::GetFDEFontMgr() { if (!m_pFDEFontMgr) { -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - m_pFDEFontMgr = CFGAS_FontMgr::Create(FX_GetDefFontEnumerator()); -#else - m_pFontSource = pdfium::MakeUnique(); - m_pFDEFontMgr = CFGAS_FontMgr::Create(m_pFontSource.get()); -#endif + m_pFDEFontMgr = pdfium::MakeUnique(); + if (!m_pFDEFontMgr->EnumFonts()) + m_pFDEFontMgr = nullptr; } return m_pFDEFontMgr.get(); } diff --git a/xfa/fxfa/cxfa_ffapp.h b/xfa/fxfa/cxfa_ffapp.h index 351ba032a0..2ce718a36a 100644 --- a/xfa/fxfa/cxfa_ffapp.h +++ b/xfa/fxfa/cxfa_ffapp.h @@ -67,9 +67,6 @@ class CXFA_FFApp { std::unique_ptr m_pFDEFontMgr; std::unique_ptr m_pFontMgr; -#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ - std::unique_ptr m_pFontSource; -#endif std::unique_ptr m_pAdapterWidgetMgr; // |m_pFWLApp| has to be released first, then |m_pFWLTheme| since the former -- cgit v1.2.3