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

Side by Side Diff: core/fpdfapi/fpdf_font/fpdf_font.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/font_int.h ('k') | core/fpdfapi/fpdf_font/include/cpdf_font.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 "core/fpdfapi/fpdf_font/font_int.h" 7 #include "core/fpdfapi/fpdf_font/font_int.h"
8 8
9 #include "core/fpdfapi/fpdf_page/cpdf_pagemodule.h" 9 #include "core/fpdfapi/fpdf_page/cpdf_pagemodule.h"
10 #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" 10 #include "core/fpdfapi/fpdf_page/include/cpdf_form.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 pFontDict->Release(); 53 pFontDict->Release();
54 } 54 }
55 } 55 }
56 56
57 CPDF_Font* CFX_StockFontArray::GetFont(uint32_t index) const { 57 CPDF_Font* CFX_StockFontArray::GetFont(uint32_t index) const {
58 if (index >= FX_ArraySize(m_StockFonts)) 58 if (index >= FX_ArraySize(m_StockFonts))
59 return nullptr; 59 return nullptr;
60 return m_StockFonts[index].get(); 60 return m_StockFonts[index].get();
61 } 61 }
62 62
63 void CFX_StockFontArray::SetFont(uint32_t index, CPDF_Font* font) { 63 CPDF_Font* CFX_StockFontArray::SetFont(uint32_t index,
64 if (index >= FX_ArraySize(m_StockFonts)) 64 std::unique_ptr<CPDF_Font> pFont) {
65 return; 65 CPDF_Font* result = pFont.get();
66 m_StockFonts[index].reset(font); 66 if (index < FX_ArraySize(m_StockFonts))
67 m_StockFonts[index] = std::move(pFont);
68 return result;
67 } 69 }
68 70
69 CPDF_FontGlobals::CPDF_FontGlobals() { 71 CPDF_FontGlobals::CPDF_FontGlobals() {
70 FXSYS_memset(m_EmbeddedCharsets, 0, sizeof(m_EmbeddedCharsets)); 72 FXSYS_memset(m_EmbeddedCharsets, 0, sizeof(m_EmbeddedCharsets));
71 FXSYS_memset(m_EmbeddedToUnicodes, 0, sizeof(m_EmbeddedToUnicodes)); 73 FXSYS_memset(m_EmbeddedToUnicodes, 0, sizeof(m_EmbeddedToUnicodes));
72 } 74 }
73 75
74 CPDF_FontGlobals::~CPDF_FontGlobals() {} 76 CPDF_FontGlobals::~CPDF_FontGlobals() {}
75 77
76 CPDF_Font* CPDF_FontGlobals::Find(CPDF_Document* pDoc, uint32_t index) { 78 CPDF_Font* CPDF_FontGlobals::Find(CPDF_Document* pDoc, uint32_t index) {
77 auto it = m_StockMap.find(pDoc); 79 auto it = m_StockMap.find(pDoc);
78 if (it == m_StockMap.end()) 80 if (it == m_StockMap.end())
79 return nullptr; 81 return nullptr;
80 return it->second ? it->second->GetFont(index) : nullptr; 82 return it->second ? it->second->GetFont(index) : nullptr;
81 } 83 }
82 84
83 void CPDF_FontGlobals::Set(CPDF_Document* pDoc, 85 CPDF_Font* CPDF_FontGlobals::Set(CPDF_Document* pDoc,
84 uint32_t index, 86 uint32_t index,
85 CPDF_Font* pFont) { 87 std::unique_ptr<CPDF_Font> pFont) {
86 if (!pdfium::ContainsKey(m_StockMap, pDoc)) 88 if (!pdfium::ContainsKey(m_StockMap, pDoc))
87 m_StockMap[pDoc].reset(new CFX_StockFontArray); 89 m_StockMap[pDoc].reset(new CFX_StockFontArray);
88 m_StockMap[pDoc]->SetFont(index, pFont); 90 return m_StockMap[pDoc]->SetFont(index, std::move(pFont));
89 } 91 }
90 92
91 void CPDF_FontGlobals::Clear(CPDF_Document* pDoc) { 93 void CPDF_FontGlobals::Clear(CPDF_Document* pDoc) {
92 m_StockMap.erase(pDoc); 94 m_StockMap.erase(pDoc);
93 } 95 }
94 96
95 CFX_WideString CPDF_ToUnicodeMap::Lookup(uint32_t charcode) const { 97 CFX_WideString CPDF_ToUnicodeMap::Lookup(uint32_t charcode) const {
96 auto it = m_Map.find(charcode); 98 auto it = m_Map.find(charcode);
97 if (it != m_Map.end()) { 99 if (it != m_Map.end()) {
98 uint32_t value = it->second; 100 uint32_t value = it->second;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 } 298 }
297 if (cid_set) { 299 if (cid_set) {
298 m_pBaseMap = CPDF_ModuleMgr::Get() 300 m_pBaseMap = CPDF_ModuleMgr::Get()
299 ->GetPageModule() 301 ->GetPageModule()
300 ->GetFontGlobals() 302 ->GetFontGlobals()
301 ->m_CMapManager.GetCID2UnicodeMap(cid_set, FALSE); 303 ->m_CMapManager.GetCID2UnicodeMap(cid_set, FALSE);
302 } else { 304 } else {
303 m_pBaseMap = nullptr; 305 m_pBaseMap = nullptr;
304 } 306 }
305 } 307 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_font/font_int.h ('k') | core/fpdfapi/fpdf_font/include/cpdf_font.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698