Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: xfa/fgas/font/fgas_gefont.cpp

Issue 2297303004: Fix leaked internal font (Closed)
Patch Set: address comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fgas/font/fgas_gefont.h ('k') | xfa/fgas/font/fgas_stdfontmgr.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fgas/font/fgas_gefont.h" 7 #include "xfa/fgas/font/fgas_gefont.h"
8 8
9 #include "core/fxge/include/cfx_substfont.h" 9 #include "core/fxge/include/cfx_substfont.h"
10 #include "core/fxge/include/cfx_unicodeencoding.h" 10 #include "core/fxge/include/cfx_unicodeencoding.h"
(...skipping 16 matching lines...) Expand all
27 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); 27 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr);
28 if (!pFont->LoadFontInternal(pszFontFamily, dwFontStyles, wCodePage)) { 28 if (!pFont->LoadFontInternal(pszFontFamily, dwFontStyles, wCodePage)) {
29 pFont->Release(); 29 pFont->Release();
30 return nullptr; 30 return nullptr;
31 } 31 }
32 return pFont; 32 return pFont;
33 #endif 33 #endif
34 } 34 }
35 35
36 // static 36 // static
37 CFGAS_GEFont* CFGAS_GEFont::LoadFont(CFX_Font* pExtFont, 37 CFGAS_GEFont* CFGAS_GEFont::LoadFont(CFX_Font* pExternalFont,
38 IFGAS_FontMgr* pFontMgr) { 38 IFGAS_FontMgr* pFontMgr) {
39 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); 39 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr);
40 if (!pFont->LoadFontInternal(pExtFont)) { 40 if (!pFont->LoadFontInternal(pExternalFont)) {
41 pFont->Release(); 41 pFont->Release();
42 return nullptr; 42 return nullptr;
43 } 43 }
44 return pFont;
45 }
46
47 // static
48 CFGAS_GEFont* CFGAS_GEFont::LoadFont(std::unique_ptr<CFX_Font> pInternalFont,
49 IFGAS_FontMgr* pFontMgr) {
50 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr);
51 if (!pFont->LoadFontInternal(std::move(pInternalFont))) {
52 pFont->Release();
53 return nullptr;
54 }
44 return pFont; 55 return pFont;
45 } 56 }
46 57
47 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 58 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
48 // static 59 // static
49 CFGAS_GEFont* CFGAS_GEFont::LoadFont(const uint8_t* pBuffer, 60 CFGAS_GEFont* CFGAS_GEFont::LoadFont(const uint8_t* pBuffer,
50 int32_t iLength, 61 int32_t iLength,
51 IFGAS_FontMgr* pFontMgr) { 62 IFGAS_FontMgr* pFontMgr) {
52 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); 63 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr);
53 if (!pFont->LoadFontInternal(pBuffer, iLength)) { 64 if (!pFont->LoadFontInternal(pBuffer, iLength)) {
(...skipping 18 matching lines...) Expand all
72 83
73 CFGAS_GEFont::CFGAS_GEFont(IFGAS_FontMgr* pFontMgr) 84 CFGAS_GEFont::CFGAS_GEFont(IFGAS_FontMgr* pFontMgr)
74 : 85 :
75 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ 86 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
76 m_bUseLogFontStyle(FALSE), 87 m_bUseLogFontStyle(FALSE),
77 m_dwLogFontStyle(0), 88 m_dwLogFontStyle(0),
78 #endif 89 #endif
79 m_pFont(nullptr), 90 m_pFont(nullptr),
80 m_pFontMgr(pFontMgr), 91 m_pFontMgr(pFontMgr),
81 m_iRefCount(1), 92 m_iRefCount(1),
82 m_bExtFont(FALSE), 93 m_bExternalFont(false),
83 m_pProvider(nullptr) { 94 m_pProvider(nullptr) {
84 } 95 }
85 96
86 CFGAS_GEFont::CFGAS_GEFont(const CFGAS_GEFont& src, uint32_t dwFontStyles) 97 CFGAS_GEFont::CFGAS_GEFont(const CFGAS_GEFont& src, uint32_t dwFontStyles)
87 : 98 :
88 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ 99 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
89 m_bUseLogFontStyle(FALSE), 100 m_bUseLogFontStyle(FALSE),
90 m_dwLogFontStyle(0), 101 m_dwLogFontStyle(0),
91 #endif 102 #endif
92 m_pFont(nullptr), 103 m_pFont(nullptr),
93 m_pFontMgr(src.m_pFontMgr), 104 m_pFontMgr(src.m_pFontMgr),
94 m_iRefCount(1), 105 m_iRefCount(1),
95 m_bExtFont(FALSE), 106 m_bExternalFont(false),
96 m_pProvider(nullptr) { 107 m_pProvider(nullptr) {
97 ASSERT(src.m_pFont); 108 ASSERT(src.m_pFont);
98 m_pFont = new CFX_Font; 109 m_pFont = new CFX_Font;
99 m_pFont->LoadClone(src.m_pFont); 110 m_pFont->LoadClone(src.m_pFont);
100 CFX_SubstFont* pSubst = m_pFont->GetSubstFont(); 111 CFX_SubstFont* pSubst = m_pFont->GetSubstFont();
101 if (!pSubst) { 112 if (!pSubst) {
102 pSubst = new CFX_SubstFont; 113 pSubst = new CFX_SubstFont;
103 m_pFont->SetSubstFont(std::unique_ptr<CFX_SubstFont>(pSubst)); 114 m_pFont->SetSubstFont(std::unique_ptr<CFX_SubstFont>(pSubst));
104 } 115 }
105 pSubst->m_Weight = 116 pSubst->m_Weight =
106 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; 117 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL;
107 if (dwFontStyles & FX_FONTSTYLE_Italic) { 118 if (dwFontStyles & FX_FONTSTYLE_Italic) {
108 pSubst->m_SubstFlags |= FXFONT_SUBST_ITALIC; 119 pSubst->m_SubstFlags |= FXFONT_SUBST_ITALIC;
109 } 120 }
110 InitFont(); 121 InitFont();
111 } 122 }
112 123
113 CFGAS_GEFont::~CFGAS_GEFont() { 124 CFGAS_GEFont::~CFGAS_GEFont() {
114 for (int32_t i = 0; i < m_SubstFonts.GetSize(); i++) 125 for (int32_t i = 0; i < m_SubstFonts.GetSize(); i++)
115 m_SubstFonts[i]->Release(); 126 m_SubstFonts[i]->Release();
116 127
117 m_SubstFonts.RemoveAll(); 128 m_SubstFonts.RemoveAll();
118 m_FontMapper.clear(); 129 m_FontMapper.clear();
119 130
120 if (!m_bExtFont) 131 if (!m_bExternalFont)
121 delete m_pFont; 132 delete m_pFont;
122 } 133 }
123 134
124 void CFGAS_GEFont::Release() { 135 void CFGAS_GEFont::Release() {
125 if (--m_iRefCount < 1) { 136 if (--m_iRefCount < 1) {
126 if (m_pFontMgr) { 137 if (m_pFontMgr) {
127 m_pFontMgr->RemoveFont(this); 138 m_pFontMgr->RemoveFont(this);
128 } 139 }
129 delete this; 140 delete this;
130 } 141 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 213
203 m_pFileRead.reset(FX_CreateFileRead(pFontStream, FALSE)); 214 m_pFileRead.reset(FX_CreateFileRead(pFontStream, FALSE));
204 m_pFont = new CFX_Font; 215 m_pFont = new CFX_Font;
205 if (m_pFont->LoadFile(m_pFileRead.get())) 216 if (m_pFont->LoadFile(m_pFileRead.get()))
206 return InitFont(); 217 return InitFont();
207 m_pFileRead.reset(); 218 m_pFileRead.reset();
208 return FALSE; 219 return FALSE;
209 } 220 }
210 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 221 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
211 222
212 FX_BOOL CFGAS_GEFont::LoadFontInternal(CFX_Font* pExtFont) { 223 FX_BOOL CFGAS_GEFont::LoadFontInternal(CFX_Font* pExternalFont) {
213 if (m_pFont || !pExtFont) { 224 if (m_pFont || !pExternalFont)
214 return FALSE; 225 return FALSE;
215 } 226
216 m_pFont = pExtFont; 227 m_pFont = pExternalFont;
217 m_bExtFont = TRUE; 228 m_bExternalFont = true;
218 return InitFont(); 229 return InitFont();
219 } 230 }
220 231
232 FX_BOOL CFGAS_GEFont::LoadFontInternal(
233 std::unique_ptr<CFX_Font> pInternalFont) {
234 if (m_pFont || !pInternalFont)
235 return FALSE;
236
237 m_pFont = pInternalFont.release();
238 m_bExternalFont = false;
239 return InitFont();
240 }
241
221 FX_BOOL CFGAS_GEFont::InitFont() { 242 FX_BOOL CFGAS_GEFont::InitFont() {
222 if (!m_pFont) 243 if (!m_pFont)
223 return FALSE; 244 return FALSE;
224 if (!m_pFontEncoding) { 245 if (!m_pFontEncoding) {
225 m_pFontEncoding.reset(FX_CreateFontEncodingEx(m_pFont)); 246 m_pFontEncoding.reset(FX_CreateFontEncodingEx(m_pFont));
226 if (!m_pFontEncoding) 247 if (!m_pFontEncoding)
227 return FALSE; 248 return FALSE;
228 } 249 }
229 if (!m_pCharWidthMap) 250 if (!m_pCharWidthMap)
230 m_pCharWidthMap.reset(new CFX_DiscreteArrayTemplate<uint16_t>(1024)); 251 m_pCharWidthMap.reset(new CFX_DiscreteArrayTemplate<uint16_t>(1024));
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 } 472 }
452 if (m_pRectArray) { 473 if (m_pRectArray) {
453 m_pRectArray->RemoveAll(FALSE); 474 m_pRectArray->RemoveAll(FALSE);
454 } 475 }
455 } 476 }
456 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const { 477 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const {
457 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; 478 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24;
458 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this) 479 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this)
459 : m_SubstFonts[iGlyphIndex - 1]; 480 : m_SubstFonts[iGlyphIndex - 1];
460 } 481 }
OLDNEW
« no previous file with comments | « xfa/fgas/font/fgas_gefont.h ('k') | xfa/fgas/font/fgas_stdfontmgr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698