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

Side by Side Diff: core/fpdfapi/fpdf_page/fpdf_page_doc.cpp

Issue 2364643003: Make CPDF_Font::Create() return a std::unique_ptr. (Closed)
Patch Set: Stray file Created 4 years, 2 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 | « core/fpdfapi/fpdf_font/include/cpdf_font.h ('k') | no next file » | 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 "core/fpdfapi/fpdf_page/pageint.h" 7 #include "core/fpdfapi/fpdf_page/pageint.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 if (it != m_FontMap.end()) { 138 if (it != m_FontMap.end()) {
139 pFontData = it->second; 139 pFontData = it->second;
140 if (pFontData->get()) { 140 if (pFontData->get()) {
141 return pFontData->AddRef(); 141 return pFontData->AddRef();
142 } 142 }
143 } 143 }
144 144
145 if (findOnly) 145 if (findOnly)
146 return nullptr; 146 return nullptr;
147 147
148 CPDF_Font* pFont = CPDF_Font::CreateFontF(m_pPDFDoc, pFontDict); 148 std::unique_ptr<CPDF_Font> pFont = CPDF_Font::Create(m_pPDFDoc, pFontDict);
149 if (!pFont) 149 if (!pFont)
150 return nullptr; 150 return nullptr;
151 151
152 if (pFontData) { 152 if (pFontData) {
153 pFontData->reset(pFont); 153 pFontData->reset(pFont.release());
154 } else { 154 } else {
155 pFontData = new CPDF_CountedFont(pFont); 155 pFontData = new CPDF_CountedFont(pFont.release());
156 m_FontMap[pFontDict] = pFontData; 156 m_FontMap[pFontDict] = pFontData;
157 } 157 }
158 return pFontData->AddRef(); 158 return pFontData->AddRef();
159 } 159 }
160 160
161 CPDF_Font* CPDF_DocPageData::GetStandardFont(const CFX_ByteString& fontName, 161 CPDF_Font* CPDF_DocPageData::GetStandardFont(const CFX_ByteString& fontName,
162 CPDF_FontEncoding* pEncoding) { 162 CPDF_FontEncoding* pEncoding) {
163 if (fontName.IsEmpty()) 163 if (fontName.IsEmpty())
164 return nullptr; 164 return nullptr;
165 165
(...skipping 19 matching lines...) Expand all
185 } 185 }
186 186
187 CPDF_Dictionary* pDict = new CPDF_Dictionary; 187 CPDF_Dictionary* pDict = new CPDF_Dictionary;
188 pDict->SetNameFor("Type", "Font"); 188 pDict->SetNameFor("Type", "Font");
189 pDict->SetNameFor("Subtype", "Type1"); 189 pDict->SetNameFor("Subtype", "Type1");
190 pDict->SetNameFor("BaseFont", fontName); 190 pDict->SetNameFor("BaseFont", fontName);
191 if (pEncoding) { 191 if (pEncoding) {
192 pDict->SetFor("Encoding", pEncoding->Realize()); 192 pDict->SetFor("Encoding", pEncoding->Realize());
193 } 193 }
194 m_pPDFDoc->AddIndirectObject(pDict); 194 m_pPDFDoc->AddIndirectObject(pDict);
195 CPDF_Font* pFont = CPDF_Font::CreateFontF(m_pPDFDoc, pDict); 195 std::unique_ptr<CPDF_Font> pFont = CPDF_Font::Create(m_pPDFDoc, pDict);
196 if (!pFont) { 196 if (!pFont)
197 return nullptr; 197 return nullptr;
198 } 198
199 CPDF_CountedFont* fontData = new CPDF_CountedFont(pFont); 199 CPDF_CountedFont* fontData = new CPDF_CountedFont(pFont.release());
200 m_FontMap[pDict] = fontData; 200 m_FontMap[pDict] = fontData;
201 return fontData->AddRef(); 201 return fontData->AddRef();
202 } 202 }
203 203
204 void CPDF_DocPageData::ReleaseFont(const CPDF_Dictionary* pFontDict) { 204 void CPDF_DocPageData::ReleaseFont(const CPDF_Dictionary* pFontDict) {
205 if (!pFontDict) 205 if (!pFontDict)
206 return; 206 return;
207 207
208 auto it = m_FontMap.find(pFontDict); 208 auto it = m_FontMap.find(pFontDict);
209 if (it == m_FontMap.end()) 209 if (it == m_FontMap.end())
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 } 544 }
545 545
546 CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr( 546 CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr(
547 CPDF_Object* pPatternObj) const { 547 CPDF_Object* pPatternObj) const {
548 if (!pPatternObj) 548 if (!pPatternObj)
549 return nullptr; 549 return nullptr;
550 550
551 auto it = m_PatternMap.find(pPatternObj); 551 auto it = m_PatternMap.find(pPatternObj);
552 return it != m_PatternMap.end() ? it->second : nullptr; 552 return it != m_PatternMap.end() ? it->second : nullptr;
553 } 553 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_font/include/cpdf_font.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698