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

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

Issue 2207093005: Use smart pointers for class owned pointers (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: one more change Created 4 years, 4 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/layout/fgas_textbreak.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/fgas_gefont.h" 7 #include "xfa/fgas/font/fgas_gefont.h"
8 8
9 #include "xfa/fgas/crt/fgas_codepage.h" 9 #include "xfa/fgas/crt/fgas_codepage.h"
10 #include "xfa/fgas/font/fgas_fontutils.h" 10 #include "xfa/fgas/font/fgas_fontutils.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 CFGAS_GEFont::CFGAS_GEFont(IFGAS_FontMgr* pFontMgr) 70 CFGAS_GEFont::CFGAS_GEFont(IFGAS_FontMgr* pFontMgr)
71 : 71 :
72 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ 72 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
73 m_bUseLogFontStyle(FALSE), 73 m_bUseLogFontStyle(FALSE),
74 m_dwLogFontStyle(0), 74 m_dwLogFontStyle(0),
75 #endif 75 #endif
76 m_pFont(nullptr), 76 m_pFont(nullptr),
77 m_pFontMgr(pFontMgr), 77 m_pFontMgr(pFontMgr),
78 m_iRefCount(1), 78 m_iRefCount(1),
79 m_bExtFont(FALSE), 79 m_bExtFont(FALSE),
80 m_pStream(nullptr),
81 m_pFileRead(nullptr),
82 m_pFontEncoding(nullptr),
83 m_pCharWidthMap(nullptr),
84 m_pRectArray(nullptr),
85 m_pBBoxMap(nullptr),
86 m_pProvider(nullptr) { 80 m_pProvider(nullptr) {
87 } 81 }
88 82
89 CFGAS_GEFont::CFGAS_GEFont(const CFGAS_GEFont& src, uint32_t dwFontStyles) 83 CFGAS_GEFont::CFGAS_GEFont(const CFGAS_GEFont& src, uint32_t dwFontStyles)
90 : 84 :
91 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ 85 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
92 m_bUseLogFontStyle(FALSE), 86 m_bUseLogFontStyle(FALSE),
93 m_dwLogFontStyle(0), 87 m_dwLogFontStyle(0),
94 #endif 88 #endif
95 m_pFont(nullptr), 89 m_pFont(nullptr),
96 m_pFontMgr(src.m_pFontMgr), 90 m_pFontMgr(src.m_pFontMgr),
97 m_iRefCount(1), 91 m_iRefCount(1),
98 m_bExtFont(FALSE), 92 m_bExtFont(FALSE),
99 m_pStream(nullptr),
100 m_pFileRead(nullptr),
101 m_pFontEncoding(nullptr),
102 m_pCharWidthMap(nullptr),
103 m_pRectArray(nullptr),
104 m_pBBoxMap(nullptr),
105 m_pProvider(nullptr) { 93 m_pProvider(nullptr) {
106 ASSERT(src.m_pFont); 94 ASSERT(src.m_pFont);
107 m_pFont = new CFX_Font; 95 m_pFont = new CFX_Font;
108 m_pFont->LoadClone(src.m_pFont); 96 m_pFont->LoadClone(src.m_pFont);
109 CFX_SubstFont* pSubst = m_pFont->GetSubstFont(); 97 CFX_SubstFont* pSubst = m_pFont->GetSubstFont();
110 if (!pSubst) { 98 if (!pSubst) {
111 pSubst = new CFX_SubstFont; 99 pSubst = new CFX_SubstFont;
112 m_pFont->SetSubstFont(std::unique_ptr<CFX_SubstFont>(pSubst)); 100 m_pFont->SetSubstFont(std::unique_ptr<CFX_SubstFont>(pSubst));
113 } 101 }
114 pSubst->m_Weight = 102 pSubst->m_Weight =
115 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; 103 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL;
116 if (dwFontStyles & FX_FONTSTYLE_Italic) { 104 if (dwFontStyles & FX_FONTSTYLE_Italic) {
117 pSubst->m_SubstFlags |= FXFONT_SUBST_ITALIC; 105 pSubst->m_SubstFlags |= FXFONT_SUBST_ITALIC;
118 } 106 }
119 InitFont(); 107 InitFont();
120 } 108 }
121 109
122 CFGAS_GEFont::~CFGAS_GEFont() { 110 CFGAS_GEFont::~CFGAS_GEFont() {
123 for (int32_t i = 0; i < m_SubstFonts.GetSize(); i++) 111 for (int32_t i = 0; i < m_SubstFonts.GetSize(); i++)
124 m_SubstFonts[i]->Release(); 112 m_SubstFonts[i]->Release();
125 113
126 m_SubstFonts.RemoveAll(); 114 m_SubstFonts.RemoveAll();
127 m_FontMapper.clear(); 115 m_FontMapper.clear();
128 if (m_pFileRead)
129 m_pFileRead->Release();
130 116
131 if (m_pStream)
132 m_pStream->Release();
133
134 delete m_pFontEncoding;
135 delete m_pCharWidthMap;
136 delete m_pRectArray;
137 delete m_pBBoxMap;
138 if (!m_bExtFont) 117 if (!m_bExtFont)
139 delete m_pFont; 118 delete m_pFont;
140 } 119 }
141 120
142 void CFGAS_GEFont::Release() { 121 void CFGAS_GEFont::Release() {
143 if (--m_iRefCount < 1) { 122 if (--m_iRefCount < 1) {
144 if (m_pFontMgr) { 123 if (m_pFontMgr) {
145 m_pFontMgr->RemoveFont(this); 124 m_pFontMgr->RemoveFont(this);
146 } 125 }
147 delete this; 126 delete this;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 return FALSE; 185 return FALSE;
207 186
208 m_pFont = new CFX_Font; 187 m_pFont = new CFX_Font;
209 if (!m_pFont->LoadEmbedded(pBuffer, length)) 188 if (!m_pFont->LoadEmbedded(pBuffer, length))
210 return FALSE; 189 return FALSE;
211 return InitFont(); 190 return InitFont();
212 } 191 }
213 192
214 FX_BOOL CFGAS_GEFont::LoadFontInternal(IFX_Stream* pFontStream, 193 FX_BOOL CFGAS_GEFont::LoadFontInternal(IFX_Stream* pFontStream,
215 FX_BOOL bSaveStream) { 194 FX_BOOL bSaveStream) {
216 if (m_pFont || m_pFileRead || !pFontStream || pFontStream->GetLength() < 1) { 195 if (m_pFont || m_pFileRead || !pFontStream || pFontStream->GetLength() < 1)
217 return FALSE; 196 return FALSE;
218 } 197 if (bSaveStream)
219 if (bSaveStream) { 198 m_pStream.reset(pFontStream);
220 m_pStream = pFontStream; 199
221 } 200 m_pFileRead.reset(FX_CreateFileRead(pFontStream, FALSE));
222 m_pFileRead = FX_CreateFileRead(pFontStream, FALSE);
223 m_pFont = new CFX_Font; 201 m_pFont = new CFX_Font;
224 FX_BOOL bRet = m_pFont->LoadFile(m_pFileRead); 202 if (m_pFont->LoadFile(m_pFileRead.get()))
225 if (bRet) { 203 return InitFont();
226 bRet = InitFont(); 204 m_pFileRead.reset();
227 } else { 205 return FALSE;
228 m_pFileRead->Release();
229 m_pFileRead = nullptr;
230 }
231 return bRet;
232 } 206 }
233 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 207 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
234 208
235 FX_BOOL CFGAS_GEFont::LoadFontInternal(CFX_Font* pExtFont) { 209 FX_BOOL CFGAS_GEFont::LoadFontInternal(CFX_Font* pExtFont) {
236 if (m_pFont || !pExtFont) { 210 if (m_pFont || !pExtFont) {
237 return FALSE; 211 return FALSE;
238 } 212 }
239 m_pFont = pExtFont; 213 m_pFont = pExtFont;
240 m_bExtFont = TRUE; 214 m_bExtFont = TRUE;
241 return InitFont(); 215 return InitFont();
242 } 216 }
243 217
244 FX_BOOL CFGAS_GEFont::InitFont() { 218 FX_BOOL CFGAS_GEFont::InitFont() {
245 if (!m_pFont) 219 if (!m_pFont)
246 return FALSE; 220 return FALSE;
247 if (!m_pFontEncoding) { 221 if (!m_pFontEncoding) {
248 m_pFontEncoding = FX_CreateFontEncodingEx(m_pFont); 222 m_pFontEncoding.reset(FX_CreateFontEncodingEx(m_pFont));
249 if (!m_pFontEncoding) 223 if (!m_pFontEncoding)
250 return FALSE; 224 return FALSE;
251 } 225 }
252 if (!m_pCharWidthMap) 226 if (!m_pCharWidthMap)
253 m_pCharWidthMap = new CFX_DiscreteArrayTemplate<uint16_t>(1024); 227 m_pCharWidthMap.reset(new CFX_DiscreteArrayTemplate<uint16_t>(1024));
254 if (!m_pRectArray) 228 if (!m_pRectArray)
255 m_pRectArray = new CFX_MassArrayTemplate<CFX_Rect>(16); 229 m_pRectArray.reset(new CFX_MassArrayTemplate<CFX_Rect>(16));
256 if (!m_pBBoxMap) 230 if (!m_pBBoxMap)
257 m_pBBoxMap = new CFX_MapPtrToPtr(16); 231 m_pBBoxMap.reset(new CFX_MapPtrToPtr(16));
258 232
259 return TRUE; 233 return TRUE;
260 } 234 }
261 235
262 CFGAS_GEFont* CFGAS_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) { 236 CFGAS_GEFont* CFGAS_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) {
263 if (GetFontStyles() == dwFontStyles) 237 if (GetFontStyles() == dwFontStyles)
264 return Retain(); 238 return Retain();
265 return new CFGAS_GEFont(*this, dwFontStyles); 239 return new CFGAS_GEFont(*this, dwFontStyles);
266 } 240 }
267 241
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 } 448 }
475 if (m_pRectArray) { 449 if (m_pRectArray) {
476 m_pRectArray->RemoveAll(FALSE); 450 m_pRectArray->RemoveAll(FALSE);
477 } 451 }
478 } 452 }
479 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const { 453 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const {
480 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; 454 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24;
481 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this) 455 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this)
482 : m_SubstFonts[iGlyphIndex - 1]; 456 : m_SubstFonts[iGlyphIndex - 1];
483 } 457 }
OLDNEW
« no previous file with comments | « xfa/fgas/font/fgas_gefont.h ('k') | xfa/fgas/layout/fgas_textbreak.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698