From b174aa37b6a99461dc581c63a93a1d706705dd16 Mon Sep 17 00:00:00 2001 From: tsepez Date: Wed, 27 Apr 2016 15:28:25 -0700 Subject: Replace CFX_PtrArray with type-safe CFX_ArrayTemplate<>, Part 1. Ideally, these will become std::vector<>, but in the mean time this is quicker and allow us to remove casts. Doing so has already turned up one place where the wrong type of object was being used. Review-Url: https://codereview.chromium.org/1924073002 --- xfa/fgas/font/fgas_gefont.cpp | 45 ++++++++++++++++--------------------------- xfa/fgas/font/fgas_gefont.h | 2 +- 2 files changed, 18 insertions(+), 29 deletions(-) (limited to 'xfa/fgas') diff --git a/xfa/fgas/font/fgas_gefont.cpp b/xfa/fgas/font/fgas_gefont.cpp index 495ac7d69d..5dfdb70018 100644 --- a/xfa/fgas/font/fgas_gefont.cpp +++ b/xfa/fgas/font/fgas_gefont.cpp @@ -106,7 +106,6 @@ CFX_GEFont::CFX_GEFont(IFX_FontMgr* pFontMgr) m_pBBoxMap(NULL), m_pProvider(NULL), m_wCharSet(0xFFFF), - m_SubstFonts(), m_FontMapper(16) { } @@ -128,7 +127,6 @@ CFX_GEFont::CFX_GEFont(const CFX_GEFont& src, uint32_t dwFontStyles) m_pBBoxMap(NULL), m_pProvider(NULL), m_wCharSet(0xFFFF), - m_SubstFonts(), m_FontMapper(16) { m_pFont = new CFX_Font; ASSERT(m_pFont != NULL); @@ -146,36 +144,27 @@ CFX_GEFont::CFX_GEFont(const CFX_GEFont& src, uint32_t dwFontStyles) } InitFont(); } + CFX_GEFont::~CFX_GEFont() { - int32_t iCount = m_SubstFonts.GetSize(); - for (int32_t i = 0; i < iCount; i++) { - IFX_Font* pFont = (IFX_Font*)m_SubstFonts[i]; - pFont->Release(); - } + for (int32_t i = 0; i < m_SubstFonts.GetSize(); i++) + m_SubstFonts[i]->Release(); + m_SubstFonts.RemoveAll(); m_FontMapper.RemoveAll(); - if (m_pFileRead != NULL) { + if (m_pFileRead) m_pFileRead->Release(); - } - if (m_pStream != NULL) { + + if (m_pStream) m_pStream->Release(); - } - if (m_pFontEncoding != NULL) { - delete m_pFontEncoding; - } - if (m_pCharWidthMap != NULL) { - delete m_pCharWidthMap; - } - if (m_pRectArray != NULL) { - delete m_pRectArray; - } - if (m_pBBoxMap != NULL) { - delete m_pBBoxMap; - } - if (m_pFont != NULL && !m_bExtFont) { + + delete m_pFontEncoding; + delete m_pCharWidthMap; + delete m_pRectArray; + delete m_pBBoxMap; + if (!m_bExtFont) delete m_pFont; - } } + void CFX_GEFont::Release() { if (--m_iRefCount < 1) { if (m_pFontMgr != NULL) { @@ -554,7 +543,7 @@ int32_t CFX_GEFont::GetDescent() const { void CFX_GEFont::Reset() { int32_t iCount = m_SubstFonts.GetSize(); for (int32_t i = 0; i < iCount; i++) { - IFX_Font* pFont = (IFX_Font*)m_SubstFonts[i]; + IFX_Font* pFont = m_SubstFonts[i]; ((CFX_GEFont*)pFont)->Reset(); } if (m_pCharWidthMap != NULL) { @@ -569,6 +558,6 @@ void CFX_GEFont::Reset() { } IFX_Font* CFX_GEFont::GetSubstFont(int32_t iGlyphIndex) const { iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; - return iGlyphIndex == 0 ? (IFX_Font*)this - : (IFX_Font*)m_SubstFonts[iGlyphIndex - 1]; + return iGlyphIndex == 0 ? const_cast(this) + : m_SubstFonts[iGlyphIndex - 1]; } diff --git a/xfa/fgas/font/fgas_gefont.h b/xfa/fgas/font/fgas_gefont.h index 43b5c5876e..491f38bc89 100644 --- a/xfa/fgas/font/fgas_gefont.h +++ b/xfa/fgas/font/fgas_gefont.h @@ -74,7 +74,7 @@ class CFX_GEFont : public IFX_Font { CFX_MapPtrToPtr* m_pBBoxMap; CXFA_PDFFontMgr* m_pProvider; uint16_t m_wCharSet; - CFX_PtrArray m_SubstFonts; + CFX_ArrayTemplate m_SubstFonts; CFX_MapPtrToPtr m_FontMapper; FX_BOOL InitFont(); FX_BOOL GetCharBBox(FX_WCHAR wUnicode, -- cgit v1.2.3