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

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: small fix 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
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)
196 return FALSE;
197 if (bSaveStream)
198 m_pStream.reset(pFontStream);
199
200 m_pFileRead.reset(FX_CreateFileRead(pFontStream, FALSE));
201 m_pFont = new CFX_Font;
202 if (m_pFont->LoadFile(m_pFileRead.get())) {
203 return InitFont();
204 } else {
Lei Zhang 2016/08/04 18:49:31 no else after return
Wei Li 2016/08/04 22:16:04 Done.
205 m_pFileRead.reset();
217 return FALSE; 206 return FALSE;
218 } 207 }
219 if (bSaveStream) {
220 m_pStream = pFontStream;
221 }
222 m_pFileRead = FX_CreateFileRead(pFontStream, FALSE);
223 m_pFont = new CFX_Font;
224 FX_BOOL bRet = m_pFont->LoadFile(m_pFileRead);
225 if (bRet) {
226 bRet = InitFont();
227 } else {
228 m_pFileRead->Release();
229 m_pFileRead = nullptr;
230 }
231 return bRet;
232 } 208 }
233 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 209 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
234 210
235 FX_BOOL CFGAS_GEFont::LoadFontInternal(CFX_Font* pExtFont) { 211 FX_BOOL CFGAS_GEFont::LoadFontInternal(CFX_Font* pExtFont) {
236 if (m_pFont || !pExtFont) { 212 if (m_pFont || !pExtFont) {
237 return FALSE; 213 return FALSE;
238 } 214 }
239 m_pFont = pExtFont; 215 m_pFont = pExtFont;
240 m_bExtFont = TRUE; 216 m_bExtFont = TRUE;
241 return InitFont(); 217 return InitFont();
242 } 218 }
243 219
244 FX_BOOL CFGAS_GEFont::InitFont() { 220 FX_BOOL CFGAS_GEFont::InitFont() {
245 if (!m_pFont) 221 if (!m_pFont)
246 return FALSE; 222 return FALSE;
247 if (!m_pFontEncoding) { 223 if (!m_pFontEncoding) {
248 m_pFontEncoding = FX_CreateFontEncodingEx(m_pFont); 224 m_pFontEncoding.reset(FX_CreateFontEncodingEx(m_pFont));
249 if (!m_pFontEncoding) 225 if (!m_pFontEncoding)
250 return FALSE; 226 return FALSE;
251 } 227 }
252 if (!m_pCharWidthMap) 228 if (!m_pCharWidthMap)
253 m_pCharWidthMap = new CFX_DiscreteArrayTemplate<uint16_t>(1024); 229 m_pCharWidthMap.reset(new CFX_DiscreteArrayTemplate<uint16_t>(1024));
254 if (!m_pRectArray) 230 if (!m_pRectArray)
255 m_pRectArray = new CFX_MassArrayTemplate<CFX_Rect>(16); 231 m_pRectArray.reset(new CFX_MassArrayTemplate<CFX_Rect>(16));
256 if (!m_pBBoxMap) 232 if (!m_pBBoxMap)
257 m_pBBoxMap = new CFX_MapPtrToPtr(16); 233 m_pBBoxMap.reset(new CFX_MapPtrToPtr(16));
258 234
259 return TRUE; 235 return TRUE;
260 } 236 }
261 237
262 CFGAS_GEFont* CFGAS_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) { 238 CFGAS_GEFont* CFGAS_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) {
263 if (GetFontStyles() == dwFontStyles) 239 if (GetFontStyles() == dwFontStyles)
264 return Retain(); 240 return Retain();
265 return new CFGAS_GEFont(*this, dwFontStyles); 241 return new CFGAS_GEFont(*this, dwFontStyles);
266 } 242 }
267 243
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 } 450 }
475 if (m_pRectArray) { 451 if (m_pRectArray) {
476 m_pRectArray->RemoveAll(FALSE); 452 m_pRectArray->RemoveAll(FALSE);
477 } 453 }
478 } 454 }
479 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const { 455 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const {
480 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; 456 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24;
481 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this) 457 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this)
482 : m_SubstFonts[iGlyphIndex - 1]; 458 : m_SubstFonts[iGlyphIndex - 1];
483 } 459 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698