summaryrefslogtreecommitdiff
path: root/xfa/fgas/font
diff options
context:
space:
mode:
authorweili <weili@chromium.org>2016-08-10 14:50:48 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-10 14:50:48 -0700
commitb4d1b576bccb5ca6cebe29288af014bd0f512af1 (patch)
tree2d60839a8323eb6780c782aba4ae1123243c7355 /xfa/fgas/font
parent1194561d5d83869edecf6a1f402122a59955f0b7 (diff)
downloadpdfium-b4d1b576bccb5ca6cebe29288af014bd0f512af1.tar.xz
Use smart pointers for class owned pointers in xfa/fxfa
Use smart pointers instead of raw pointer to make memory management easier for classes mainly under xfa/fxfa. Also change the return type of IFGAS_FontMgr::Create() to smart pointer type. BUG=pdfium:518 Review-Url: https://codereview.chromium.org/2227883002
Diffstat (limited to 'xfa/fgas/font')
-rw-r--r--xfa/fgas/font/fgas_font.h68
-rw-r--r--xfa/fgas/font/fgas_stdfontmgr.cpp71
-rw-r--r--xfa/fgas/font/fgas_stdfontmgr.h59
3 files changed, 89 insertions, 109 deletions
diff --git a/xfa/fgas/font/fgas_font.h b/xfa/fgas/font/fgas_font.h
index 7fcfbd715b..f91c015dae 100644
--- a/xfa/fgas/font/fgas_font.h
+++ b/xfa/fgas/font/fgas_font.h
@@ -80,11 +80,13 @@ typedef FX_FONTDESCRIPTOR const* (*FX_LPMatchFont)(
FX_LPFONTMATCHPARAMS pParams,
const CFX_FontDescriptors& fonts);
FX_LPMatchFont FX_GetDefFontMatchor();
+
class IFGAS_FontMgr {
public:
- static IFGAS_FontMgr* Create(FX_LPEnumAllFonts pEnumerator);
virtual ~IFGAS_FontMgr() {}
- virtual void Release() = 0;
+
+ static std::unique_ptr<IFGAS_FontMgr> Create(FX_LPEnumAllFonts pEnumerator);
+
virtual CFGAS_GEFont* GetDefFontByCodePage(
uint16_t wCodePage,
uint32_t dwFontStyles,
@@ -121,46 +123,40 @@ class IFGAS_FontMgr {
class IFGAS_FontMgr {
public:
- static IFGAS_FontMgr* Create(CFX_FontSourceEnum_File* pFontEnum);
virtual ~IFGAS_FontMgr() {}
- virtual void Release() = 0;
- virtual CFGAS_GEFont* GetDefFontByCodePage(
- uint16_t wCodePage,
- uint32_t dwFontStyles,
- const FX_WCHAR* pszFontFamily = nullptr) = 0;
- virtual CFGAS_GEFont* GetDefFontByCharset(
- uint8_t nCharset,
- uint32_t dwFontStyles,
- const FX_WCHAR* pszFontFamily = nullptr) = 0;
- virtual CFGAS_GEFont* GetDefFontByUnicode(
- FX_WCHAR wUnicode,
- uint32_t dwFontStyles,
- const FX_WCHAR* pszFontFamily = nullptr) = 0;
- virtual CFGAS_GEFont* GetDefFontByLanguage(
- uint16_t wLanguage,
- uint32_t dwFontStyles,
- const FX_WCHAR* pszFontFamily = nullptr) = 0;
- virtual CFGAS_GEFont* GetFontByCodePage(
- uint16_t wCodePage,
- uint32_t dwFontStyles,
- const FX_WCHAR* pszFontFamily = nullptr) = 0;
+
+ static std::unique_ptr<IFGAS_FontMgr> Create(
+ CFX_FontSourceEnum_File* pFontEnum);
+
+ virtual CFGAS_GEFont* GetDefFontByCodePage(uint16_t wCodePage,
+ uint32_t dwFontStyles,
+ const FX_WCHAR* pszFontFamily) = 0;
+ virtual CFGAS_GEFont* GetDefFontByCharset(uint8_t nCharset,
+ uint32_t dwFontStyles,
+ const FX_WCHAR* pszFontFamily) = 0;
+ virtual CFGAS_GEFont* GetDefFontByUnicode(FX_WCHAR wUnicode,
+ uint32_t dwFontStyles,
+ const FX_WCHAR* pszFontFamily) = 0;
+ virtual CFGAS_GEFont* GetDefFontByLanguage(uint16_t wLanguage,
+ uint32_t dwFontStyles,
+ const FX_WCHAR* pszFontFamily) = 0;
+ virtual CFGAS_GEFont* GetFontByCodePage(uint16_t wCodePage,
+ uint32_t dwFontStyles,
+ const FX_WCHAR* pszFontFamily) = 0;
inline CFGAS_GEFont* LoadFont(const FX_WCHAR* pszFontFamily,
uint32_t dwFontStyles,
uint16_t wCodePage) {
return GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily);
}
- virtual CFGAS_GEFont* GetFontByCharset(
- uint8_t nCharset,
- uint32_t dwFontStyles,
- const FX_WCHAR* pszFontFamily = nullptr) = 0;
- virtual CFGAS_GEFont* GetFontByUnicode(
- FX_WCHAR wUnicode,
- uint32_t dwFontStyles,
- const FX_WCHAR* pszFontFamily = nullptr) = 0;
- virtual CFGAS_GEFont* GetFontByLanguage(
- uint16_t wLanguage,
- uint32_t dwFontStyles,
- const FX_WCHAR* pszFontFamily = nullptr) = 0;
+ virtual CFGAS_GEFont* GetFontByCharset(uint8_t nCharset,
+ uint32_t dwFontStyles,
+ const FX_WCHAR* pszFontFamily) = 0;
+ virtual CFGAS_GEFont* GetFontByUnicode(FX_WCHAR wUnicode,
+ uint32_t dwFontStyles,
+ const FX_WCHAR* pszFontFamily) = 0;
+ virtual CFGAS_GEFont* GetFontByLanguage(uint16_t wLanguage,
+ uint32_t dwFontStyles,
+ const FX_WCHAR* pszFontFamily) = 0;
virtual void ClearFontCache() = 0;
virtual void RemoveFont(CFGAS_GEFont* pFont) = 0;
};
diff --git a/xfa/fgas/font/fgas_stdfontmgr.cpp b/xfa/fgas/font/fgas_stdfontmgr.cpp
index 20a520414c..ab7852e310 100644
--- a/xfa/fgas/font/fgas_stdfontmgr.cpp
+++ b/xfa/fgas/font/fgas_stdfontmgr.cpp
@@ -17,8 +17,9 @@
#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
-IFGAS_FontMgr* IFGAS_FontMgr::Create(FX_LPEnumAllFonts pEnumerator) {
- return new CFGAS_StdFontMgrImp(pEnumerator);
+std::unique_ptr<IFGAS_FontMgr> IFGAS_FontMgr::Create(
+ FX_LPEnumAllFonts pEnumerator) {
+ return std::unique_ptr<IFGAS_FontMgr>(new CFGAS_StdFontMgrImp(pEnumerator));
}
CFGAS_StdFontMgrImp::CFGAS_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator)
@@ -47,10 +48,6 @@ CFGAS_StdFontMgrImp::~CFGAS_StdFontMgrImp() {
m_Fonts[i]->Release();
}
-void CFGAS_StdFontMgrImp::Release() {
- delete this;
-}
-
CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByCodePage(
uint16_t wCodePage,
uint32_t dwFontStyles,
@@ -564,20 +561,47 @@ IFX_FileAccess* CFX_FontSourceEnum_File::GetNext(FX_POSITION& pos) {
return pAccess;
}
-IFGAS_FontMgr* IFGAS_FontMgr::Create(CFX_FontSourceEnum_File* pFontEnum) {
+std::unique_ptr<IFGAS_FontMgr> IFGAS_FontMgr::Create(
+ CFX_FontSourceEnum_File* pFontEnum) {
if (!pFontEnum)
return nullptr;
std::unique_ptr<CFGAS_FontMgrImp> pFontMgr(new CFGAS_FontMgrImp(pFontEnum));
if (!pFontMgr->EnumFonts())
return nullptr;
- return pFontMgr.release();
+ return std::move(pFontMgr);
}
CFGAS_FontMgrImp::CFGAS_FontMgrImp(CFX_FontSourceEnum_File* pFontEnum)
: m_pFontSource(pFontEnum) {}
-CFGAS_FontMgrImp::~CFGAS_FontMgrImp() {}
+CFGAS_FontMgrImp::~CFGAS_FontMgrImp() {
+ for (int32_t i = 0; i < m_InstalledFonts.GetSize(); i++) {
+ delete m_InstalledFonts[i];
+ }
+ FX_POSITION pos = m_Hash2CandidateList.GetStartPosition();
+ while (pos) {
+ uint32_t dwHash;
+ CFX_FontDescriptorInfos* pDescs;
+ m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs);
+ delete pDescs;
+ }
+ pos = m_Hash2Fonts.GetStartPosition();
+ while (pos) {
+ uint32_t dwHash;
+ CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts;
+ m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts);
+ delete pFonts;
+ }
+ m_Hash2Fonts.RemoveAll();
+ pos = m_IFXFont2FileRead.GetStartPosition();
+ while (pos) {
+ CFGAS_GEFont* pFont;
+ IFX_FileRead* pFileRead;
+ m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead);
+ pFileRead->Release();
+ }
+}
FX_BOOL CFGAS_FontMgrImp::EnumFontsFromFontMapper() {
CFX_FontMapper* pFontMapper =
@@ -634,35 +658,6 @@ FX_BOOL CFGAS_FontMgrImp::EnumFonts() {
return EnumFontsFromFiles();
}
-void CFGAS_FontMgrImp::Release() {
- for (int32_t i = 0; i < m_InstalledFonts.GetSize(); i++) {
- delete m_InstalledFonts[i];
- }
- FX_POSITION pos = m_Hash2CandidateList.GetStartPosition();
- while (pos) {
- uint32_t dwHash;
- CFX_FontDescriptorInfos* pDescs;
- m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs);
- delete pDescs;
- }
- pos = m_Hash2Fonts.GetStartPosition();
- while (pos) {
- uint32_t dwHash;
- CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts;
- m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts);
- delete pFonts;
- }
- m_Hash2Fonts.RemoveAll();
- pos = m_IFXFont2FileRead.GetStartPosition();
- while (pos) {
- CFGAS_GEFont* pFont;
- IFX_FileRead* pFileRead;
- m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead);
- pFileRead->Release();
- }
- delete this;
-}
-
CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByCodePage(
uint16_t wCodePage,
uint32_t dwFontStyles,
diff --git a/xfa/fgas/font/fgas_stdfontmgr.h b/xfa/fgas/font/fgas_stdfontmgr.h
index 4de6971738..65f260c54c 100644
--- a/xfa/fgas/font/fgas_stdfontmgr.h
+++ b/xfa/fgas/font/fgas_stdfontmgr.h
@@ -28,7 +28,6 @@ class CFGAS_StdFontMgrImp : public IFGAS_FontMgr {
~CFGAS_StdFontMgrImp() override;
// IFGAS_FontMgr:
- void Release() override;
CFGAS_GEFont* GetDefFontByCodePage(
uint16_t wCodePage,
uint32_t dwFontStyles,
@@ -132,7 +131,6 @@ class CFX_FontSourceEnum_File {
CFX_FontSourceEnum_File();
~CFX_FontSourceEnum_File();
- void Release() { delete this; }
FX_POSITION GetStartPosition();
IFX_FileAccess* GetNext(FX_POSITION& pos);
@@ -150,39 +148,30 @@ class CFGAS_FontMgrImp : public IFGAS_FontMgr {
~CFGAS_FontMgrImp() override;
// IFGAS_FontMgr:
- void Release() override;
- CFGAS_GEFont* GetDefFontByCodePage(
- uint16_t wCodePage,
- uint32_t dwFontStyles,
- const FX_WCHAR* pszFontFamily = nullptr) override;
- CFGAS_GEFont* GetDefFontByCharset(
- uint8_t nCharset,
- uint32_t dwFontStyles,
- const FX_WCHAR* pszFontFamily = nullptr) override;
- CFGAS_GEFont* GetDefFontByUnicode(
- FX_WCHAR wUnicode,
- uint32_t dwFontStyles,
- const FX_WCHAR* pszFontFamily = nullptr) override;
- CFGAS_GEFont* GetDefFontByLanguage(
- uint16_t wLanguage,
- uint32_t dwFontStyles,
- const FX_WCHAR* pszFontFamily = nullptr) override;
- CFGAS_GEFont* GetFontByCodePage(
- uint16_t wCodePage,
- uint32_t dwFontStyles,
- const FX_WCHAR* pszFontFamily = nullptr) override;
- CFGAS_GEFont* GetFontByCharset(
- uint8_t nCharset,
- uint32_t dwFontStyles,
- const FX_WCHAR* pszFontFamily = nullptr) override;
- CFGAS_GEFont* GetFontByUnicode(
- FX_WCHAR wUnicode,
- uint32_t dwFontStyles,
- const FX_WCHAR* pszFontFamily = nullptr) override;
- CFGAS_GEFont* GetFontByLanguage(
- uint16_t wLanguage,
- uint32_t dwFontStyles,
- const FX_WCHAR* pszFontFamily = nullptr) override;
+ CFGAS_GEFont* GetDefFontByCodePage(uint16_t wCodePage,
+ uint32_t dwFontStyles,
+ const FX_WCHAR* pszFontFamily) override;
+ CFGAS_GEFont* GetDefFontByCharset(uint8_t nCharset,
+ uint32_t dwFontStyles,
+ const FX_WCHAR* pszFontFamily) override;
+ CFGAS_GEFont* GetDefFontByUnicode(FX_WCHAR wUnicode,
+ uint32_t dwFontStyles,
+ const FX_WCHAR* pszFontFamily) override;
+ CFGAS_GEFont* GetDefFontByLanguage(uint16_t wLanguage,
+ uint32_t dwFontStyles,
+ const FX_WCHAR* pszFontFamily) override;
+ CFGAS_GEFont* GetFontByCodePage(uint16_t wCodePage,
+ uint32_t dwFontStyles,
+ const FX_WCHAR* pszFontFamily) override;
+ CFGAS_GEFont* GetFontByCharset(uint8_t nCharset,
+ uint32_t dwFontStyles,
+ const FX_WCHAR* pszFontFamily) override;
+ CFGAS_GEFont* GetFontByUnicode(FX_WCHAR wUnicode,
+ uint32_t dwFontStyles,
+ const FX_WCHAR* pszFontFamily) override;
+ CFGAS_GEFont* GetFontByLanguage(uint16_t wLanguage,
+ uint32_t dwFontStyles,
+ const FX_WCHAR* pszFontFamily) override;
void ClearFontCache() override;
void RemoveFont(CFGAS_GEFont* pFont) override;