From 24508dff1636d80be01497e30fccd21533fc0bde Mon Sep 17 00:00:00 2001 From: thestig Date: Fri, 27 May 2016 15:14:20 -0700 Subject: Clean up some Android/Windows code. Review-Url: https://codereview.chromium.org/2004313007 --- fpdfsdk/fpdf_sysfontinfo.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/fpdf_sysfontinfo.cpp b/fpdfsdk/fpdf_sysfontinfo.cpp index 18b01341ee..9d05903a61 100644 --- a/fpdfsdk/fpdf_sysfontinfo.cpp +++ b/fpdfsdk/fpdf_sysfontinfo.cpp @@ -14,11 +14,9 @@ class CFX_ExternalFontInfo final : public IFX_SystemFontInfo { public: explicit CFX_ExternalFontInfo(FPDF_SYSFONTINFO* pInfo) : m_pInfo(pInfo) {} - - void Release() override { + ~CFX_ExternalFontInfo() override { if (m_pInfo->Release) m_pInfo->Release(m_pInfo); - delete this; } FX_BOOL EnumFontList(CFX_FontMapper* pMapper) override { @@ -83,8 +81,6 @@ class CFX_ExternalFontInfo final : public IFX_SystemFontInfo { } private: - ~CFX_ExternalFontInfo() override {} - FPDF_SYSFONTINFO* const m_pInfo; }; @@ -99,7 +95,8 @@ DLLEXPORT void STDCALL FPDF_SetSystemFontInfo(FPDF_SYSFONTINFO* pFontInfoExt) { return; CFX_GEModule::Get()->GetFontMgr()->SetSystemFontInfo( - new CFX_ExternalFontInfo(pFontInfoExt)); + std::unique_ptr( + new CFX_ExternalFontInfo(pFontInfoExt))); } DLLEXPORT const FPDF_CharsetFontMap* STDCALL FPDF_GetDefaultTTFMap() { @@ -111,7 +108,9 @@ struct FPDF_SYSFONTINFO_DEFAULT : public FPDF_SYSFONTINFO { }; static void DefaultRelease(struct _FPDF_SYSFONTINFO* pThis) { - ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->Release(); + auto* pDefault = static_cast(pThis); + // TODO(thestig): Should this be set to nullptr too? + delete pDefault->m_pFontInfo; } static void DefaultEnumFonts(struct _FPDF_SYSFONTINFO* pThis, void* pMapper) { @@ -171,9 +170,10 @@ static void DefaultDeleteFont(struct _FPDF_SYSFONTINFO* pThis, void* hFont) { } DLLEXPORT FPDF_SYSFONTINFO* STDCALL FPDF_GetDefaultSystemFontInfo() { - IFX_SystemFontInfo* pFontInfo = IFX_SystemFontInfo::CreateDefault(nullptr); + std::unique_ptr pFontInfo = + IFX_SystemFontInfo::CreateDefault(nullptr); if (!pFontInfo) - return NULL; + return nullptr; FPDF_SYSFONTINFO_DEFAULT* pFontInfoExt = FX_Alloc(FPDF_SYSFONTINFO_DEFAULT, 1); @@ -186,6 +186,6 @@ DLLEXPORT FPDF_SYSFONTINFO* STDCALL FPDF_GetDefaultSystemFontInfo() { pFontInfoExt->MapFont = DefaultMapFont; pFontInfoExt->Release = DefaultRelease; pFontInfoExt->version = 1; - pFontInfoExt->m_pFontInfo = pFontInfo; + pFontInfoExt->m_pFontInfo = pFontInfo.release(); return pFontInfoExt; } -- cgit v1.2.3