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

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

Issue 2641853004: use unique_ptr in fpdf_font_cid.cpp (Closed)
Patch Set: iwyu, maybe owned Created 3 years, 11 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/font/font_int.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/font/font_int.h" 7 #include "core/fpdfapi/font/font_int.h"
8 8
9 #include <memory>
10 #include <utility>
11
9 #include "core/fpdfapi/cmaps/cmap_int.h" 12 #include "core/fpdfapi/cmaps/cmap_int.h"
10 #include "core/fpdfapi/cpdf_modulemgr.h" 13 #include "core/fpdfapi/cpdf_modulemgr.h"
11 #include "core/fpdfapi/font/ttgsubtable.h" 14 #include "core/fpdfapi/font/ttgsubtable.h"
12 #include "core/fpdfapi/page/cpdf_pagemodule.h" 15 #include "core/fpdfapi/page/cpdf_pagemodule.h"
13 #include "core/fpdfapi/parser/cpdf_array.h" 16 #include "core/fpdfapi/parser/cpdf_array.h"
14 #include "core/fpdfapi/parser/cpdf_dictionary.h" 17 #include "core/fpdfapi/parser/cpdf_dictionary.h"
15 #include "core/fpdfapi/parser/cpdf_simple_parser.h" 18 #include "core/fpdfapi/parser/cpdf_simple_parser.h"
16 #include "core/fxcrt/fx_ext.h" 19 #include "core/fxcrt/fx_ext.h"
17 #include "core/fxge/fx_freetype.h" 20 #include "core/fxge/fx_freetype.h"
18 #include "third_party/base/stl_util.h" 21 #include "third_party/base/stl_util.h"
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 --iSeg; 274 --iSeg;
272 } 275 }
273 --size; 276 --size;
274 ++offset; 277 ++offset;
275 } 278 }
276 return 1; 279 return 1;
277 } 280 }
278 281
279 } // namespace 282 } // namespace
280 283
281 CPDF_CMapManager::CPDF_CMapManager() { 284 CPDF_CMapManager::CPDF_CMapManager() {}
282 FXSYS_memset(m_CID2UnicodeMaps, 0, sizeof m_CID2UnicodeMaps); 285
286 CPDF_CMapManager::~CPDF_CMapManager() {}
287
288 CFX_MaybeOwned<CPDF_CMap> CPDF_CMapManager::GetPredefinedCMap(
289 const CFX_ByteString& name,
290 bool bPromptCJK) {
291 auto it = m_CMaps.find(name);
292 if (it != m_CMaps.end())
293 return CFX_MaybeOwned<CPDF_CMap>(it->second.get()); // Unowned.
294
295 std::unique_ptr<CPDF_CMap> pCMap = LoadPredefinedCMap(name, bPromptCJK);
296 if (name.IsEmpty())
297 return CFX_MaybeOwned<CPDF_CMap>(std::move(pCMap)); // Owned.
298
299 CPDF_CMap* pUnowned = pCMap.get();
300 m_CMaps[name] = std::move(pCMap);
301 return CFX_MaybeOwned<CPDF_CMap>(pUnowned); // Unowned.
283 } 302 }
284 CPDF_CMapManager::~CPDF_CMapManager() { 303
285 for (const auto& pair : m_CMaps) { 304 std::unique_ptr<CPDF_CMap> CPDF_CMapManager::LoadPredefinedCMap(
286 delete pair.second; 305 const CFX_ByteString& name,
287 } 306 bool bPromptCJK) {
288 m_CMaps.clear(); 307 auto pCMap = pdfium::MakeUnique<CPDF_CMap>();
289 for (size_t i = 0; i < FX_ArraySize(m_CID2UnicodeMaps); ++i) {
290 delete m_CID2UnicodeMaps[i];
291 }
292 }
293 CPDF_CMap* CPDF_CMapManager::GetPredefinedCMap(const CFX_ByteString& name,
294 bool bPromptCJK) {
295 auto it = m_CMaps.find(name);
296 if (it != m_CMaps.end()) {
297 return it->second;
298 }
299 CPDF_CMap* pCMap = LoadPredefinedCMap(name, bPromptCJK);
300 if (!name.IsEmpty()) {
Tom Sepez 2017/01/18 23:16:25 note: leak here if name is empty and we don't stic
301 m_CMaps[name] = pCMap;
302 }
303 return pCMap;
304 }
305 CPDF_CMap* CPDF_CMapManager::LoadPredefinedCMap(const CFX_ByteString& name,
306 bool bPromptCJK) {
307 CPDF_CMap* pCMap = new CPDF_CMap;
308 const FX_CHAR* pname = name.c_str(); 308 const FX_CHAR* pname = name.c_str();
309 if (*pname == '/') { 309 if (*pname == '/')
310 pname++; 310 pname++;
311 } 311
312 pCMap->LoadPredefined(this, pname, bPromptCJK); 312 pCMap->LoadPredefined(this, pname, bPromptCJK);
313 return pCMap; 313 return pCMap;
314 } 314 }
315 315
316 CPDF_CID2UnicodeMap* CPDF_CMapManager::GetCID2UnicodeMap(CIDSet charset, 316 CPDF_CID2UnicodeMap* CPDF_CMapManager::GetCID2UnicodeMap(CIDSet charset,
317 bool bPromptCJK) { 317 bool bPromptCJK) {
318 if (!m_CID2UnicodeMaps[charset]) 318 if (!m_CID2UnicodeMaps[charset])
319 m_CID2UnicodeMaps[charset] = LoadCID2UnicodeMap(charset, bPromptCJK); 319 m_CID2UnicodeMaps[charset] = LoadCID2UnicodeMap(charset, bPromptCJK);
320 return m_CID2UnicodeMaps[charset]; 320
321 return m_CID2UnicodeMaps[charset].get();
321 } 322 }
322 CPDF_CID2UnicodeMap* CPDF_CMapManager::LoadCID2UnicodeMap(CIDSet charset, 323
323 bool bPromptCJK) { 324 std::unique_ptr<CPDF_CID2UnicodeMap> CPDF_CMapManager::LoadCID2UnicodeMap(
324 CPDF_CID2UnicodeMap* pMap = new CPDF_CID2UnicodeMap(); 325 CIDSet charset,
326 bool bPromptCJK) {
327 auto pMap = pdfium::MakeUnique<CPDF_CID2UnicodeMap>();
325 pMap->Load(this, charset, bPromptCJK); 328 pMap->Load(this, charset, bPromptCJK);
326 return pMap; 329 return pMap;
327 } 330 }
328 331
329 CPDF_CMapParser::CPDF_CMapParser() 332 CPDF_CMapParser::CPDF_CMapParser()
330 : m_pCMap(nullptr), m_Status(0), m_CodeSeq(0) {} 333 : m_pCMap(nullptr), m_Status(0), m_CodeSeq(0) {}
331 334
332 CPDF_CMapParser::~CPDF_CMapParser() {} 335 CPDF_CMapParser::~CPDF_CMapParser() {}
333 336
334 void CPDF_CMapParser::Initialize(CPDF_CMap* pCMap) { 337 void CPDF_CMapParser::Initialize(CPDF_CMap* pCMap) {
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 m_EmbeddedCount = pFontGlobals->m_EmbeddedToUnicodes[charset].m_Count; 777 m_EmbeddedCount = pFontGlobals->m_EmbeddedToUnicodes[charset].m_Count;
775 } 778 }
776 779
777 CIDSet CharsetFromOrdering(const CFX_ByteStringC& ordering) { 780 CIDSet CharsetFromOrdering(const CFX_ByteStringC& ordering) {
778 for (size_t charset = 1; charset < FX_ArraySize(g_CharsetNames); ++charset) { 781 for (size_t charset = 1; charset < FX_ArraySize(g_CharsetNames); ++charset) {
779 if (ordering == g_CharsetNames[charset]) 782 if (ordering == g_CharsetNames[charset])
780 return CIDSetFromSizeT(charset); 783 return CIDSetFromSizeT(charset);
781 } 784 }
782 return CIDSET_UNKNOWN; 785 return CIDSET_UNKNOWN;
783 } 786 }
OLDNEW
« no previous file with comments | « core/fpdfapi/font/font_int.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698