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

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

Issue 2631703003: Avoid endless loop deleting CFGAS_GEFont. (Closed)
Patch Set: rebase Created 3 years, 11 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/cfgas_gefont.h ('k') | xfa/fxfa/app/cxfa_pieceline.h » ('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/cfgas_gefont.h" 7 #include "xfa/fgas/font/cfgas_gefont.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
11 11
12 #include "core/fxge/cfx_substfont.h" 12 #include "core/fxge/cfx_substfont.h"
13 #include "core/fxge/cfx_unicodeencoding.h" 13 #include "core/fxge/cfx_unicodeencoding.h"
14 #include "core/fxge/cfx_unicodeencodingex.h" 14 #include "core/fxge/cfx_unicodeencodingex.h"
15 #include "third_party/base/ptr_util.h" 15 #include "third_party/base/ptr_util.h"
16 #include "xfa/fgas/crt/fgas_codepage.h" 16 #include "xfa/fgas/crt/fgas_codepage.h"
17 #include "xfa/fgas/font/fgas_fontutils.h" 17 #include "xfa/fgas/font/fgas_fontutils.h"
18 #include "xfa/fxfa/xfa_fontmgr.h" 18 #include "xfa/fxfa/xfa_fontmgr.h"
19 19
20 // static 20 // static
21 CFX_RetainPtr<CFGAS_GEFont> CFGAS_GEFont::LoadFont( 21 CFX_RetainPtr<CFGAS_GEFont> CFGAS_GEFont::LoadFont(
22 const FX_WCHAR* pszFontFamily, 22 const FX_WCHAR* pszFontFamily,
23 uint32_t dwFontStyles, 23 uint32_t dwFontStyles,
24 uint16_t wCodePage, 24 uint16_t wCodePage,
25 CFGAS_FontMgr* pFontMgr) { 25 CFGAS_FontMgr* pFontMgr) {
26 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ 26 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
27 if (!pFontMgr) 27 if (!pFontMgr)
28 return nullptr; 28 return nullptr;
29 29
30 return CFX_RetainPtr<CFGAS_GEFont>( 30 return pFontMgr->GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily);
31 pFontMgr->GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily));
32 #else 31 #else
33 auto pFont = pdfium::MakeRetain<CFGAS_GEFont>(pFontMgr); 32 auto pFont = pdfium::MakeRetain<CFGAS_GEFont>(pFontMgr);
34 if (!pFont->LoadFontInternal(pszFontFamily, dwFontStyles, wCodePage)) 33 if (!pFont->LoadFontInternal(pszFontFamily, dwFontStyles, wCodePage))
35 return nullptr; 34 return nullptr;
36 return pFont; 35 return pFont;
37 #endif 36 #endif
38 } 37 }
39 38
40 // static 39 // static
41 CFX_RetainPtr<CFGAS_GEFont> CFGAS_GEFont::LoadFont(CFX_Font* pExternalFont, 40 CFX_RetainPtr<CFGAS_GEFont> CFGAS_GEFont::LoadFont(CFX_Font* pExternalFont,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 m_pFont->SetSubstFont(std::unique_ptr<CFX_SubstFont>(pSubst)); 111 m_pFont->SetSubstFont(std::unique_ptr<CFX_SubstFont>(pSubst));
113 } 112 }
114 pSubst->m_Weight = 113 pSubst->m_Weight =
115 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; 114 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL;
116 if (dwFontStyles & FX_FONTSTYLE_Italic) 115 if (dwFontStyles & FX_FONTSTYLE_Italic)
117 pSubst->m_SubstFlags |= FXFONT_SUBST_ITALIC; 116 pSubst->m_SubstFlags |= FXFONT_SUBST_ITALIC;
118 InitFont(); 117 InitFont();
119 } 118 }
120 119
121 CFGAS_GEFont::~CFGAS_GEFont() { 120 CFGAS_GEFont::~CFGAS_GEFont() {
122 if (m_pFontMgr)
123 m_pFontMgr->RemoveFont(CFX_RetainPtr<CFGAS_GEFont>(this));
124
125 if (!m_bExternalFont) 121 if (!m_bExternalFont)
126 delete m_pFont; 122 delete m_pFont;
127 } 123 }
128 124
129 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 125 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
130 bool CFGAS_GEFont::LoadFontInternal(const FX_WCHAR* pszFontFamily, 126 bool CFGAS_GEFont::LoadFontInternal(const FX_WCHAR* pszFontFamily,
131 uint32_t dwFontStyles, 127 uint32_t dwFontStyles,
132 uint16_t wCodePage) { 128 uint16_t wCodePage) {
133 if (m_pFont) 129 if (m_pFont)
134 return false; 130 return false;
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 } 418 }
423 419
424 int32_t CFGAS_GEFont::GetAscent() const { 420 int32_t CFGAS_GEFont::GetAscent() const {
425 return m_pFont->GetAscent(); 421 return m_pFont->GetAscent();
426 } 422 }
427 423
428 int32_t CFGAS_GEFont::GetDescent() const { 424 int32_t CFGAS_GEFont::GetDescent() const {
429 return m_pFont->GetDescent(); 425 return m_pFont->GetDescent();
430 } 426 }
431 427
432 CFX_RetainPtr<CFGAS_GEFont> CFGAS_GEFont::GetSubstFont( 428 CFX_RetainPtr<CFGAS_GEFont> CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) {
433 int32_t iGlyphIndex) const {
434 iGlyphIndex = static_cast<uint32_t>(iGlyphIndex) >> 24; 429 iGlyphIndex = static_cast<uint32_t>(iGlyphIndex) >> 24;
435 if (iGlyphIndex == 0) 430 if (iGlyphIndex == 0)
436 return CFX_RetainPtr<CFGAS_GEFont>(const_cast<CFGAS_GEFont*>(this)); 431 return CFX_RetainPtr<CFGAS_GEFont>(this);
437 return m_SubstFonts[iGlyphIndex - 1]; 432 return m_SubstFonts[iGlyphIndex - 1];
438 } 433 }
OLDNEW
« no previous file with comments | « xfa/fgas/font/cfgas_gefont.h ('k') | xfa/fxfa/app/cxfa_pieceline.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698