From 9b671ace8aec906683b05399cf8a2882ed8ef7b6 Mon Sep 17 00:00:00 2001 From: weili Date: Mon, 25 Jul 2016 07:40:27 -0700 Subject: Use smart pointers for CFX_Font and CFX_Type3Font classes For the class owned member variables, use std::unique_ptr or std::vector for memory management. BUG=pdfium:518 Review-Url: https://codereview.chromium.org/2169793002 --- xfa/fde/fde_gedevice.cpp | 14 ++++++-------- xfa/fgas/font/fgas_gefont.cpp | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) (limited to 'xfa') diff --git a/xfa/fde/fde_gedevice.cpp b/xfa/fde/fde_gedevice.cpp index e78ab8da4c..56f845c35b 100644 --- a/xfa/fde/fde_gedevice.cpp +++ b/xfa/fde/fde_gedevice.cpp @@ -134,12 +134,12 @@ FX_BOOL CFDE_RenderDevice::DrawString(CFDE_Brush* pBrush, #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ uint32_t dwFontStyle = pFont->GetFontStyles(); CFX_Font FxFont; - CFX_SubstFont SubstFxFont; - FxFont.SetSubstFont(&SubstFxFont); - SubstFxFont.m_Weight = dwFontStyle & FX_FONTSTYLE_Bold ? 700 : 400; - SubstFxFont.m_ItalicAngle = dwFontStyle & FX_FONTSTYLE_Italic ? -12 : 0; - SubstFxFont.m_WeightCJK = SubstFxFont.m_Weight; - SubstFxFont.m_bItalicCJK = !!(dwFontStyle & FX_FONTSTYLE_Italic); + CFX_SubstFont* SubstFxFont = new CFX_SubstFont(); + FxFont.SetSubstFont(std::unique_ptr(SubstFxFont)); + SubstFxFont->m_Weight = dwFontStyle & FX_FONTSTYLE_Bold ? 700 : 400; + SubstFxFont->m_ItalicAngle = dwFontStyle & FX_FONTSTYLE_Italic ? -12 : 0; + SubstFxFont->m_WeightCJK = SubstFxFont->m_Weight; + SubstFxFont->m_bItalicCJK = !!(dwFontStyle & FX_FONTSTYLE_Italic); #endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ for (int32_t i = 0; i < iCount; ++i) { @@ -175,7 +175,6 @@ FX_BOOL CFDE_RenderDevice::DrawString(CFDE_Brush* pBrush, FX_BOOL bRet = m_pDevice->DrawNormalText( iCurCount, pCurCP, &FxFont, pCache, -fFontSize, (const CFX_Matrix*)pMatrix, argb, FXTEXT_CLEARTYPE); - FxFont.SetSubstFont(nullptr); FxFont.SetFace(nullptr); return bRet; #else @@ -186,7 +185,6 @@ FX_BOOL CFDE_RenderDevice::DrawString(CFDE_Brush* pBrush, } #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ - FxFont.SetSubstFont(nullptr); FxFont.SetFace(nullptr); #endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ diff --git a/xfa/fgas/font/fgas_gefont.cpp b/xfa/fgas/font/fgas_gefont.cpp index 576f482df2..48635cabf7 100644 --- a/xfa/fgas/font/fgas_gefont.cpp +++ b/xfa/fgas/font/fgas_gefont.cpp @@ -109,7 +109,7 @@ CFGAS_GEFont::CFGAS_GEFont(const CFGAS_GEFont& src, uint32_t dwFontStyles) CFX_SubstFont* pSubst = m_pFont->GetSubstFont(); if (!pSubst) { pSubst = new CFX_SubstFont; - m_pFont->SetSubstFont(pSubst); + m_pFont->SetSubstFont(std::unique_ptr(pSubst)); } pSubst->m_Weight = (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; -- cgit v1.2.3