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

Side by Side Diff: core/fpdfapi/font/fpdf_font.cpp

Issue 2571913002: Avoid the ptr.reset(new XXX()) anti-pattern (Closed)
Patch Set: rebase 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 | « core/fpdfapi/font/cpdf_font.cpp ('k') | core/fpdfapi/page/cpdf_contentparser.cpp » ('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 "core/fpdfapi/font/font_int.h" 7 #include "core/fpdfapi/font/font_int.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
11 11
12 #include "core/fpdfapi/cpdf_modulemgr.h" 12 #include "core/fpdfapi/cpdf_modulemgr.h"
13 #include "core/fpdfapi/page/cpdf_form.h" 13 #include "core/fpdfapi/page/cpdf_form.h"
14 #include "core/fpdfapi/page/cpdf_pagemodule.h" 14 #include "core/fpdfapi/page/cpdf_pagemodule.h"
15 #include "core/fpdfapi/page/pageint.h" 15 #include "core/fpdfapi/page/pageint.h"
16 #include "core/fpdfapi/parser/cpdf_array.h" 16 #include "core/fpdfapi/parser/cpdf_array.h"
17 #include "core/fpdfapi/parser/cpdf_dictionary.h" 17 #include "core/fpdfapi/parser/cpdf_dictionary.h"
18 #include "core/fpdfapi/parser/cpdf_document.h" 18 #include "core/fpdfapi/parser/cpdf_document.h"
19 #include "core/fpdfapi/parser/cpdf_name.h" 19 #include "core/fpdfapi/parser/cpdf_name.h"
20 #include "core/fpdfapi/parser/cpdf_number.h" 20 #include "core/fpdfapi/parser/cpdf_number.h"
21 #include "core/fpdfapi/parser/cpdf_simple_parser.h" 21 #include "core/fpdfapi/parser/cpdf_simple_parser.h"
22 #include "core/fpdfapi/parser/cpdf_stream_acc.h" 22 #include "core/fpdfapi/parser/cpdf_stream_acc.h"
23 #include "core/fxcrt/fx_ext.h" 23 #include "core/fxcrt/fx_ext.h"
24 #include "core/fxcrt/fx_safe_types.h" 24 #include "core/fxcrt/fx_safe_types.h"
25 #include "core/fxge/fx_freetype.h" 25 #include "core/fxge/fx_freetype.h"
26 #include "third_party/base/numerics/safe_conversions.h" 26 #include "third_party/base/numerics/safe_conversions.h"
27 #include "third_party/base/ptr_util.h"
27 #include "third_party/base/stl_util.h" 28 #include "third_party/base/stl_util.h"
28 29
29 int TT2PDF(int m, FXFT_Face face) { 30 int TT2PDF(int m, FXFT_Face face) {
30 int upm = FXFT_Get_Face_UnitsPerEM(face); 31 int upm = FXFT_Get_Face_UnitsPerEM(face);
31 if (upm == 0) 32 if (upm == 0)
32 return m; 33 return m;
33 return pdfium::base::checked_cast<int>( 34 return pdfium::base::checked_cast<int>(
34 (static_cast<double>(m) * 1000 + upm / 2) / upm); 35 (static_cast<double>(m) * 1000 + upm / 2) / upm);
35 } 36 }
36 37
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 auto it = m_StockMap.find(pDoc); 81 auto it = m_StockMap.find(pDoc);
81 if (it == m_StockMap.end()) 82 if (it == m_StockMap.end())
82 return nullptr; 83 return nullptr;
83 return it->second ? it->second->GetFont(index) : nullptr; 84 return it->second ? it->second->GetFont(index) : nullptr;
84 } 85 }
85 86
86 CPDF_Font* CPDF_FontGlobals::Set(CPDF_Document* pDoc, 87 CPDF_Font* CPDF_FontGlobals::Set(CPDF_Document* pDoc,
87 uint32_t index, 88 uint32_t index,
88 std::unique_ptr<CPDF_Font> pFont) { 89 std::unique_ptr<CPDF_Font> pFont) {
89 if (!pdfium::ContainsKey(m_StockMap, pDoc)) 90 if (!pdfium::ContainsKey(m_StockMap, pDoc))
90 m_StockMap[pDoc].reset(new CFX_StockFontArray); 91 m_StockMap[pDoc] = pdfium::MakeUnique<CFX_StockFontArray>();
91 return m_StockMap[pDoc]->SetFont(index, std::move(pFont)); 92 return m_StockMap[pDoc]->SetFont(index, std::move(pFont));
92 } 93 }
93 94
94 void CPDF_FontGlobals::Clear(CPDF_Document* pDoc) { 95 void CPDF_FontGlobals::Clear(CPDF_Document* pDoc) {
95 m_StockMap.erase(pDoc); 96 m_StockMap.erase(pDoc);
96 } 97 }
97 98
98 CFX_WideString CPDF_ToUnicodeMap::Lookup(uint32_t charcode) const { 99 CFX_WideString CPDF_ToUnicodeMap::Lookup(uint32_t charcode) const {
99 auto it = m_Map.find(charcode); 100 auto it = m_Map.find(charcode);
100 if (it != m_Map.end()) { 101 if (it != m_Map.end()) {
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 } 306 }
306 if (cid_set) { 307 if (cid_set) {
307 m_pBaseMap = CPDF_ModuleMgr::Get() 308 m_pBaseMap = CPDF_ModuleMgr::Get()
308 ->GetPageModule() 309 ->GetPageModule()
309 ->GetFontGlobals() 310 ->GetFontGlobals()
310 ->m_CMapManager.GetCID2UnicodeMap(cid_set, false); 311 ->m_CMapManager.GetCID2UnicodeMap(cid_set, false);
311 } else { 312 } else {
312 m_pBaseMap = nullptr; 313 m_pBaseMap = nullptr;
313 } 314 }
314 } 315 }
OLDNEW
« no previous file with comments | « core/fpdfapi/font/cpdf_font.cpp ('k') | core/fpdfapi/page/cpdf_contentparser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698