From e647799f6a2f7f747c9f55d9f0ce08dcdfbd53f4 Mon Sep 17 00:00:00 2001 From: tsepez Date: Thu, 5 Jan 2017 12:57:00 -0800 Subject: Properly ref-count CFGAS_GEFont with CFX_RetainPtr. We worry about cyclical references, but no leaks found. Review-Url: https://codereview.chromium.org/2609423003 --- xfa/fgas/font/cfgas_gefont.h | 58 ++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 26 deletions(-) (limited to 'xfa/fgas/font/cfgas_gefont.h') diff --git a/xfa/fgas/font/cfgas_gefont.h b/xfa/fgas/font/cfgas_gefont.h index 86e5e4c955..962b93fbb5 100644 --- a/xfa/fgas/font/cfgas_gefont.h +++ b/xfa/fgas/font/cfgas_gefont.h @@ -9,40 +9,47 @@ #include #include +#include +#include "core/fxcrt/cfx_retain_ptr.h" #include "core/fxcrt/fx_memory.h" #include "xfa/fgas/crt/fgas_utils.h" #include "xfa/fgas/font/cfgas_fontmgr.h" #define FXFONT_SUBST_ITALIC 0x02 +class CFGAS_FontMgr; class CFX_UnicodeEncoding; class CXFA_PDFFontMgr; -class CFGAS_GEFont { +class CFGAS_GEFont : public CFX_Retainable { public: - static CFGAS_GEFont* LoadFont(const FX_WCHAR* pszFontFamily, - uint32_t dwFontStyles, - uint16_t wCodePage, - CFGAS_FontMgr* pFontMgr); - static CFGAS_GEFont* LoadFont(CFX_Font* pExternalFont, - CFGAS_FontMgr* pFontMgr); - static CFGAS_GEFont* LoadFont(std::unique_ptr pInternalFont, - CFGAS_FontMgr* pFontMgr); + template + friend CFX_RetainPtr pdfium::MakeRetain(Args&&... args); + + static CFX_RetainPtr LoadFont(const FX_WCHAR* pszFontFamily, + uint32_t dwFontStyles, + uint16_t wCodePage, + CFGAS_FontMgr* pFontMgr); + static CFX_RetainPtr LoadFont(CFX_Font* pExternalFont, + CFGAS_FontMgr* pFontMgr); + static CFX_RetainPtr LoadFont( + std::unique_ptr pInternalFont, + CFGAS_FontMgr* pFontMgr); #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - static CFGAS_GEFont* LoadFont(const uint8_t* pBuffer, - int32_t iLength, - CFGAS_FontMgr* pFontMgr); - static CFGAS_GEFont* LoadFont(const CFX_RetainPtr& pFontStream, - CFGAS_FontMgr* pFontMgr, - bool bSaveStream); + static CFX_RetainPtr LoadFont(const uint8_t* pBuffer, + int32_t iLength, + CFGAS_FontMgr* pFontMgr); + static CFX_RetainPtr LoadFont( + const CFX_RetainPtr& pFontStream, + CFGAS_FontMgr* pFontMgr, + bool bSaveStream); #endif - ~CFGAS_GEFont(); + ~CFGAS_GEFont() override; - void Release(); - CFGAS_GEFont* Retain(); - CFGAS_GEFont* Derive(uint32_t dwFontStyles, uint16_t wCodePage = 0); + CFX_RetainPtr Derive(uint32_t dwFontStyles, + uint16_t wCodePage = 0); uint32_t GetFontStyles() const; bool GetCharWidth(FX_WCHAR wUnicode, int32_t& iWidth, bool bCharCode); int32_t GetGlyphIndex(FX_WCHAR wUnicode, bool bCharCode = false); @@ -50,7 +57,7 @@ class CFGAS_GEFont { int32_t GetDescent() const; bool GetCharBBox(FX_WCHAR wUnicode, CFX_Rect& bbox, bool bCharCode = false); bool GetBBox(CFX_Rect& bbox); - CFGAS_GEFont* GetSubstFont(int32_t iGlyphIndex) const; + CFX_RetainPtr GetSubstFont(int32_t iGlyphIndex) const; CFX_Font* GetDevFont() const { return m_pFont; } void SetFontProvider(CXFA_PDFFontMgr* pProvider) { m_pProvider = pProvider; } #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ @@ -62,7 +69,7 @@ class CFGAS_GEFont { private: explicit CFGAS_GEFont(CFGAS_FontMgr* pFontMgr); - CFGAS_GEFont(CFGAS_GEFont* src, uint32_t dwFontStyles); + CFGAS_GEFont(const CFX_RetainPtr& src, uint32_t dwFontStyles); #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ bool LoadFontInternal(const FX_WCHAR* pszFontFamily, @@ -85,7 +92,7 @@ class CFGAS_GEFont { bool bCharCode); int32_t GetGlyphIndex(FX_WCHAR wUnicode, bool bRecursive, - CFGAS_GEFont** ppFont, + CFX_RetainPtr* ppFont, bool bCharCode = false); CFX_WideString GetFamilyName() const; @@ -94,9 +101,8 @@ class CFGAS_GEFont { uint32_t m_dwLogFontStyle; #endif CFX_Font* m_pFont; - CFGAS_GEFont* const m_pSrcFont; + CFX_RetainPtr m_pSrcFont; // Only set by ctor, so no cycles. CFGAS_FontMgr* const m_pFontMgr; - int32_t m_iRefCount; bool m_bExternalFont; CFX_RetainPtr m_pStream; CFX_RetainPtr m_pFileRead; @@ -105,8 +111,8 @@ class CFGAS_GEFont { std::unique_ptr> m_pRectArray; std::unique_ptr m_pBBoxMap; CXFA_PDFFontMgr* m_pProvider; // not owned. - CFX_ArrayTemplate m_SubstFonts; - std::map m_FontMapper; + std::vector> m_SubstFonts; + std::map> m_FontMapper; }; #endif // XFA_FGAS_FONT_CFGAS_GEFONT_H_ -- cgit v1.2.3