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

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

Issue 2559763002: Refcount IFGAS_ streams all the time, too (Closed)
Patch Set: more Created 4 years 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/parser/cxfa_dataexporter.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>
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 CFGAS_FontMgr* pFontMgr) { 65 CFGAS_FontMgr* pFontMgr) {
66 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); 66 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr);
67 if (!pFont->LoadFontInternal(pBuffer, iLength)) { 67 if (!pFont->LoadFontInternal(pBuffer, iLength)) {
68 pFont->Release(); 68 pFont->Release();
69 return nullptr; 69 return nullptr;
70 } 70 }
71 return pFont; 71 return pFont;
72 } 72 }
73 73
74 // static 74 // static
75 CFGAS_GEFont* CFGAS_GEFont::LoadFont(IFGAS_Stream* pFontStream, 75 CFGAS_GEFont* CFGAS_GEFont::LoadFont(
76 CFGAS_FontMgr* pFontMgr, 76 const CFX_RetainPtr<IFGAS_Stream>& pFontStream,
77 bool bSaveStream) { 77 CFGAS_FontMgr* pFontMgr,
78 bool bSaveStream) {
78 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); 79 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr);
79 if (!pFont->LoadFontInternal(pFontStream, bSaveStream)) { 80 if (!pFont->LoadFontInternal(pFontStream, bSaveStream)) {
80 pFont->Release(); 81 pFont->Release();
81 return nullptr; 82 return nullptr;
82 } 83 }
83 return pFont; 84 return pFont;
84 } 85 }
85 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 86 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
86 87
87 CFGAS_GEFont::CFGAS_GEFont(CFGAS_FontMgr* pFontMgr) 88 CFGAS_GEFont::CFGAS_GEFont(CFGAS_FontMgr* pFontMgr)
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 bool CFGAS_GEFont::LoadFontInternal(const uint8_t* pBuffer, int32_t length) { 197 bool CFGAS_GEFont::LoadFontInternal(const uint8_t* pBuffer, int32_t length) {
197 if (m_pFont) 198 if (m_pFont)
198 return false; 199 return false;
199 200
200 m_pFont = new CFX_Font; 201 m_pFont = new CFX_Font;
201 if (!m_pFont->LoadEmbedded(pBuffer, length)) 202 if (!m_pFont->LoadEmbedded(pBuffer, length))
202 return false; 203 return false;
203 return InitFont(); 204 return InitFont();
204 } 205 }
205 206
206 bool CFGAS_GEFont::LoadFontInternal(IFGAS_Stream* pFontStream, 207 bool CFGAS_GEFont::LoadFontInternal(
207 bool bSaveStream) { 208 const CFX_RetainPtr<IFGAS_Stream>& pFontStream,
209 bool bSaveStream) {
208 if (m_pFont || m_pFileRead || !pFontStream || pFontStream->GetLength() < 1) 210 if (m_pFont || m_pFileRead || !pFontStream || pFontStream->GetLength() < 1)
209 return false; 211 return false;
210 if (bSaveStream) 212 if (bSaveStream)
211 m_pStream.reset(pFontStream); 213 m_pStream = pFontStream;
212 214
213 m_pFileRead = pFontStream->MakeSeekableReadStream(); 215 m_pFileRead = pFontStream->MakeSeekableReadStream();
214 m_pFont = new CFX_Font; 216 m_pFont = new CFX_Font;
215 if (!m_pFont->LoadFile(m_pFileRead)) { 217 if (!m_pFont->LoadFile(m_pFileRead)) {
216 m_pFileRead.Reset(); 218 m_pFileRead.Reset();
217 return false; 219 return false;
218 } 220 }
219 return InitFont(); 221 return InitFont();
220 } 222 }
221 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 223 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 456
455 int32_t CFGAS_GEFont::GetDescent() const { 457 int32_t CFGAS_GEFont::GetDescent() const {
456 return m_pFont->GetDescent(); 458 return m_pFont->GetDescent();
457 } 459 }
458 460
459 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const { 461 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const {
460 iGlyphIndex = static_cast<uint32_t>(iGlyphIndex) >> 24; 462 iGlyphIndex = static_cast<uint32_t>(iGlyphIndex) >> 24;
461 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this) 463 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this)
462 : m_SubstFonts[iGlyphIndex - 1]; 464 : m_SubstFonts[iGlyphIndex - 1];
463 } 465 }
OLDNEW
« no previous file with comments | « xfa/fgas/font/cfgas_gefont.h ('k') | xfa/fxfa/parser/cxfa_dataexporter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698