From 25fa42f398d1f8007aa36531e0436dc769817ad3 Mon Sep 17 00:00:00 2001 From: thestig Date: Wed, 25 May 2016 21:39:46 -0700 Subject: Clean up fx_ge.h and IWYU. Review-Url: https://codereview.chromium.org/2009253003 --- xfa/fgas/font/fgas_stdfontmgr.cpp | 50 ++++++------ xfa/fgas/font/fgas_stdfontmgr.h | 155 ++++++++++++++++++++------------------ 2 files changed, 105 insertions(+), 100 deletions(-) (limited to 'xfa/fgas/font') diff --git a/xfa/fgas/font/fgas_stdfontmgr.cpp b/xfa/fgas/font/fgas_stdfontmgr.cpp index e840cb2bdd..3506aa2df9 100644 --- a/xfa/fgas/font/fgas_stdfontmgr.cpp +++ b/xfa/fgas/font/fgas_stdfontmgr.cpp @@ -7,6 +7,7 @@ #include "xfa/fgas/font/fgas_stdfontmgr.h" #include "core/fxcrt/include/fx_stream.h" +#include "core/fxge/include/fx_ge.h" #include "xfa/fgas/crt/fgas_codepage.h" #include "xfa/fgas/font/fgas_fontutils.h" @@ -24,7 +25,7 @@ CFX_StdFontMgrImp::CFX_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator) m_FileFonts(4), m_StreamFonts(4), m_DeriveFonts(4) { - if (m_pEnumerator != NULL) { + if (m_pEnumerator) { m_pEnumerator(m_FontFaces, NULL, 0xFEFF); } } @@ -58,7 +59,7 @@ IFX_Font* CFX_StdFontMgrImp::GetDefFontByCodePage( return NULL; } } - ASSERT(pFD != NULL); + ASSERT(pFD); pFont = IFX_Font::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); if (pFont) { m_Fonts.Add(pFont); @@ -139,7 +140,7 @@ IFX_Font* CFX_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFontFamily, return NULL; } } - ASSERT(pFD != NULL); + ASSERT(pFD); if (wCodePage == 0xFFFF) { wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); } @@ -154,10 +155,10 @@ IFX_Font* CFX_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFontFamily, return NULL; } IFX_Font* CFX_StdFontMgrImp::LoadFont(const uint8_t* pBuffer, int32_t iLength) { - ASSERT(pBuffer != NULL && iLength > 0); + ASSERT(pBuffer && iLength > 0); IFX_Font* pFont = NULL; if (m_BufferFonts.Lookup((void*)pBuffer, (void*&)pFont)) { - if (pFont != NULL) { + if (pFont) { return pFont->Retain(); } } @@ -170,11 +171,11 @@ IFX_Font* CFX_StdFontMgrImp::LoadFont(const uint8_t* pBuffer, int32_t iLength) { return NULL; } IFX_Font* CFX_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFileName) { - ASSERT(pszFileName != NULL); + ASSERT(pszFileName); uint32_t dwHash = FX_HashCode_GetW(pszFileName, false); IFX_Font* pFont = NULL; if (m_FileFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { - if (pFont != NULL) { + if (pFont) { return pFont->Retain(); } } @@ -191,11 +192,11 @@ IFX_Font* CFX_StdFontMgrImp::LoadFont(IFX_Stream* pFontStream, uint32_t dwFontStyles, uint16_t wCodePage, FX_BOOL bSaveStream) { - ASSERT(pFontStream != NULL && pFontStream->GetLength() > 0); + ASSERT(pFontStream && pFontStream->GetLength() > 0); IFX_Font* pFont = NULL; if (m_StreamFonts.Lookup((void*)pFontStream, (void*&)pFont)) { - if (pFont != NULL) { - if (pszFontAlias != NULL) { + if (pFont) { + if (pszFontAlias) { uint32_t dwHash = FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); @@ -207,7 +208,7 @@ IFX_Font* CFX_StdFontMgrImp::LoadFont(IFX_Stream* pFontStream, if (pFont) { m_Fonts.Add(pFont); m_StreamFonts.SetAt((void*)pFontStream, (void*)pFont); - if (pszFontAlias != NULL) { + if (pszFontAlias) { uint32_t dwHash = FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); @@ -219,7 +220,7 @@ IFX_Font* CFX_StdFontMgrImp::LoadFont(IFX_Stream* pFontStream, IFX_Font* CFX_StdFontMgrImp::LoadFont(IFX_Font* pSrcFont, uint32_t dwFontStyles, uint16_t wCodePage) { - ASSERT(pSrcFont != NULL); + ASSERT(pSrcFont); if (pSrcFont->GetFontStyles() == dwFontStyles) { return pSrcFont->Retain(); } @@ -230,7 +231,7 @@ IFX_Font* CFX_StdFontMgrImp::LoadFont(IFX_Font* pSrcFont, IFX_Font* pFont = NULL; if (m_DeriveFonts.GetCount() > 0) { m_DeriveFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont); - if (pFont != NULL) { + if (pFont) { return pFont->Retain(); } } @@ -256,7 +257,7 @@ void CFX_StdFontMgrImp::RemoveFont(CFX_MapPtrToPtr& fontMap, IFX_Font* pFont) { FX_POSITION pos = fontMap.GetStartPosition(); void* pKey; void* pFind; - while (pos != NULL) { + while (pos) { pFind = NULL; fontMap.GetNextAssoc(pos, pKey, pFind); if (pFind != (void*)pFont) { @@ -355,13 +356,11 @@ FX_FONTDESCRIPTOR const* FX_DefFontMatcher(FX_LPFONTMATCHPARAMS pParams, } } if (bMatchStyle) { - if ((pFont->dwFontStyles & 0x0F) == (pParams->dwFontStyles & 0x0F)) { + if ((pFont->dwFontStyles & 0x0F) == (pParams->dwFontStyles & 0x0F)) return pFont; - } else { - continue; - } + continue; } - if (pParams->pwsFamily != NULL) { + if (pParams->pwsFamily) { if (FXSYS_wcsicmp(pParams->pwsFamily, pFont->wsFontFace) == 0) { return pFont; } @@ -552,16 +551,17 @@ IFX_FontMgr* IFX_FontMgr::Create(CFX_FontSourceEnum_File* pFontEnum) { if (!pFontEnum) return nullptr; - CFX_FontMgrImp* pFontMgr = new CFX_FontMgrImp(pFontEnum); - if (pFontMgr->EnumFonts()) - return pFontMgr; - - delete pFontMgr; - return nullptr; + std::unique_ptr pFontMgr(new CFX_FontMgrImp(pFontEnum)); + if (!pFontMgr->EnumFonts()) + return nullptr; + return pFontMgr.release(); } + CFX_FontMgrImp::CFX_FontMgrImp(CFX_FontSourceEnum_File* pFontEnum) : m_pFontSource(pFontEnum) {} +CFX_FontMgrImp::~CFX_FontMgrImp() {} + FX_BOOL CFX_FontMgrImp::EnumFontsFromFontMapper() { CFX_FontMapper* pFontMapper = CFX_GEModule::Get()->GetFontMgr()->GetBuiltinMapper(); diff --git a/xfa/fgas/font/fgas_stdfontmgr.h b/xfa/fgas/font/fgas_stdfontmgr.h index bbfa875e5e..a455ee2596 100644 --- a/xfa/fgas/font/fgas_stdfontmgr.h +++ b/xfa/fgas/font/fgas_stdfontmgr.h @@ -9,7 +9,6 @@ #include "core/fxcrt/include/fx_ext.h" #include "core/fxge/include/fx_freetype.h" -#include "core/fxge/include/fx_ge.h" #include "third_party/freetype/include/freetype/fttypes.h" #include "xfa/fgas/font/fgas_font.h" @@ -21,36 +20,39 @@ FX_FONTDESCRIPTOR const* FX_DefFontMatcher(FX_LPFONTMATCHPARAMS pParams, class CFX_StdFontMgrImp : public IFX_FontMgr { public: - CFX_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator); - ~CFX_StdFontMgrImp(); - virtual void Release() { delete this; } - virtual IFX_Font* GetDefFontByCodePage(uint16_t wCodePage, - uint32_t dwFontStyles, - const FX_WCHAR* pszFontFamily = NULL); - virtual IFX_Font* GetDefFontByCharset(uint8_t nCharset, - uint32_t dwFontStyles, - const FX_WCHAR* pszFontFamily = NULL); - virtual IFX_Font* GetDefFontByUnicode(FX_WCHAR wUnicode, - uint32_t dwFontStyles, - const FX_WCHAR* pszFontFamily = NULL); - virtual IFX_Font* GetDefFontByLanguage(uint16_t wLanguage, - uint32_t dwFontStyles, - const FX_WCHAR* pszFontFamily = NULL); - virtual IFX_Font* LoadFont(const FX_WCHAR* pszFontFamily, - uint32_t dwFontStyles, - uint16_t wCodePage = 0xFFFF); - virtual IFX_Font* LoadFont(const uint8_t* pBuffer, int32_t iLength); - virtual IFX_Font* LoadFont(const FX_WCHAR* pszFileName); - virtual IFX_Font* LoadFont(IFX_Stream* pFontStream, - const FX_WCHAR* pszFontAlias = NULL, - uint32_t dwFontStyles = 0, - uint16_t wCodePage = 0, - FX_BOOL bSaveStream = FALSE); - virtual IFX_Font* LoadFont(IFX_Font* pSrcFont, - uint32_t dwFontStyles, - uint16_t wCodePage = 0xFFFF); - virtual void ClearFontCache(); - virtual void RemoveFont(IFX_Font* pFont); + explicit CFX_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator); + ~CFX_StdFontMgrImp() override; + + // IFX_FontMgr: + void Release() override { delete this; } + IFX_Font* GetDefFontByCodePage(uint16_t wCodePage, + uint32_t dwFontStyles, + const FX_WCHAR* pszFontFamily = NULL) override; + IFX_Font* GetDefFontByCharset(uint8_t nCharset, + uint32_t dwFontStyles, + const FX_WCHAR* pszFontFamily = NULL) override; + IFX_Font* GetDefFontByUnicode(FX_WCHAR wUnicode, + uint32_t dwFontStyles, + const FX_WCHAR* pszFontFamily = NULL) override; + IFX_Font* GetDefFontByLanguage(uint16_t wLanguage, + uint32_t dwFontStyles, + const FX_WCHAR* pszFontFamily = NULL) override; + IFX_Font* LoadFont(const FX_WCHAR* pszFontFamily, + uint32_t dwFontStyles, + uint16_t wCodePage = 0xFFFF) override; + IFX_Font* LoadFont(const uint8_t* pBuffer, int32_t iLength) override; + IFX_Font* LoadFont(const FX_WCHAR* pszFileName) override; + IFX_Font* LoadFont(IFX_Stream* pFontStream, + const FX_WCHAR* pszFontAlias = NULL, + uint32_t dwFontStyles = 0, + uint16_t wCodePage = 0, + FX_BOOL bSaveStream = FALSE) override; + IFX_Font* LoadFont(IFX_Font* pSrcFont, + uint32_t dwFontStyles, + uint16_t wCodePage = 0xFFFF) override; + + void ClearFontCache(); + void RemoveFont(IFX_Font* pFont); protected: void RemoveFont(CFX_MapPtrToPtr& fontMap, IFX_Font* pFont); @@ -144,49 +146,52 @@ class CFX_FontSourceEnum_File { class CFX_FontMgrImp : public IFX_FontMgr { public: - CFX_FontMgrImp(CFX_FontSourceEnum_File* pFontEnum); - - virtual void Release(); - virtual IFX_Font* GetDefFontByCodePage(uint16_t wCodePage, - uint32_t dwFontStyles, - const FX_WCHAR* pszFontFamily = NULL); - virtual IFX_Font* GetDefFontByCharset(uint8_t nCharset, - uint32_t dwFontStyles, - const FX_WCHAR* pszFontFamily = NULL); - virtual IFX_Font* GetDefFontByUnicode(FX_WCHAR wUnicode, - uint32_t dwFontStyles, - const FX_WCHAR* pszFontFamily = NULL); - virtual IFX_Font* GetDefFontByLanguage(uint16_t wLanguage, - uint32_t dwFontStyles, - const FX_WCHAR* pszFontFamily = NULL); - virtual IFX_Font* GetFontByCodePage(uint16_t wCodePage, - uint32_t dwFontStyles, - const FX_WCHAR* pszFontFamily = NULL); - virtual IFX_Font* GetFontByCharset(uint8_t nCharset, - uint32_t dwFontStyles, - const FX_WCHAR* pszFontFamily = NULL); - virtual IFX_Font* GetFontByUnicode(FX_WCHAR wUnicode, - uint32_t dwFontStyles, - const FX_WCHAR* pszFontFamily = NULL); - virtual IFX_Font* GetFontByLanguage(uint16_t wLanguage, - uint32_t dwFontStyles, - const FX_WCHAR* pszFontFamily = NULL); - virtual IFX_Font* LoadFont(const uint8_t* pBuffer, - int32_t iLength, - int32_t iFaceIndex, - int32_t* pFaceCount); - virtual IFX_Font* LoadFont(const FX_WCHAR* pszFileName, - int32_t iFaceIndex, - int32_t* pFaceCount); - virtual IFX_Font* LoadFont(IFX_Stream* pFontStream, - int32_t iFaceIndex, - int32_t* pFaceCount, - FX_BOOL bSaveStream = FALSE); - virtual IFX_Font* LoadFont(const CFX_WideString& wsFaceName, - int32_t iFaceIndex, - int32_t* pFaceCount); - virtual void ClearFontCache(); - virtual void RemoveFont(IFX_Font* pFont); + explicit CFX_FontMgrImp(CFX_FontSourceEnum_File* pFontEnum); + ~CFX_FontMgrImp() override; + + // IFX_FontMgr: + void Release() override; + IFX_Font* GetDefFontByCodePage(uint16_t wCodePage, + uint32_t dwFontStyles, + const FX_WCHAR* pszFontFamily = NULL) override; + IFX_Font* GetDefFontByCharset(uint8_t nCharset, + uint32_t dwFontStyles, + const FX_WCHAR* pszFontFamily = NULL) override; + IFX_Font* GetDefFontByUnicode(FX_WCHAR wUnicode, + uint32_t dwFontStyles, + const FX_WCHAR* pszFontFamily = NULL) override; + IFX_Font* GetDefFontByLanguage(uint16_t wLanguage, + uint32_t dwFontStyles, + const FX_WCHAR* pszFontFamily = NULL) override; + IFX_Font* GetFontByCodePage(uint16_t wCodePage, + uint32_t dwFontStyles, + const FX_WCHAR* pszFontFamily = NULL) override; + IFX_Font* GetFontByCharset(uint8_t nCharset, + uint32_t dwFontStyles, + const FX_WCHAR* pszFontFamily = NULL) override; + IFX_Font* GetFontByUnicode(FX_WCHAR wUnicode, + uint32_t dwFontStyles, + const FX_WCHAR* pszFontFamily = NULL) override; + IFX_Font* GetFontByLanguage(uint16_t wLanguage, + uint32_t dwFontStyles, + const FX_WCHAR* pszFontFamily = NULL) override; + IFX_Font* LoadFont(const uint8_t* pBuffer, + int32_t iLength, + int32_t iFaceIndex, + int32_t* pFaceCount) override; + IFX_Font* LoadFont(const FX_WCHAR* pszFileName, + int32_t iFaceIndex, + int32_t* pFaceCount) override; + IFX_Font* LoadFont(IFX_Stream* pFontStream, + int32_t iFaceIndex, + int32_t* pFaceCount, + FX_BOOL bSaveStream = FALSE) override; + void ClearFontCache() override; + void RemoveFont(IFX_Font* pFont) override; + + IFX_Font* LoadFont(const CFX_WideString& wsFaceName, + int32_t iFaceIndex, + int32_t* pFaceCount); FX_BOOL EnumFonts(); FX_BOOL EnumFontsFromFontMapper(); FX_BOOL EnumFontsFromFiles(); @@ -232,7 +237,7 @@ class CFX_FontMgrImp : public IFX_FontMgr { CFX_MapPtrTemplate m_FileAccess2IFXFont; CFX_MapPtrTemplate m_IFXFont2FileRead; CFX_MapPtrTemplate m_FailedUnicodes2NULL; - CFX_FontSourceEnum_File* m_pFontSource; + CFX_FontSourceEnum_File* const m_pFontSource; }; #endif -- cgit v1.2.3