• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "core/fpdfapi/font/cpdf_cmapmanager.h"
8 
9 #include <utility>
10 
11 #include "core/fpdfapi/font/cpdf_cid2unicodemap.h"
12 #include "core/fpdfapi/font/cpdf_cmap.h"
13 #include "third_party/base/stl_util.h"
14 
CPDF_CMapManager()15 CPDF_CMapManager::CPDF_CMapManager() {}
16 
~CPDF_CMapManager()17 CPDF_CMapManager::~CPDF_CMapManager() {}
18 
GetPredefinedCMap(const ByteString & name,bool bPromptCJK)19 RetainPtr<CPDF_CMap> CPDF_CMapManager::GetPredefinedCMap(const ByteString& name,
20                                                          bool bPromptCJK) {
21   auto it = m_CMaps.find(name);
22   if (it != m_CMaps.end())
23     return it->second;
24 
25   RetainPtr<CPDF_CMap> pCMap = LoadPredefinedCMap(name, bPromptCJK);
26   if (!name.IsEmpty())
27     m_CMaps[name] = pCMap;
28 
29   return pCMap;
30 }
31 
LoadPredefinedCMap(const ByteString & name,bool bPromptCJK)32 RetainPtr<CPDF_CMap> CPDF_CMapManager::LoadPredefinedCMap(
33     const ByteString& name,
34     bool bPromptCJK) {
35   const char* pname = name.c_str();
36   if (*pname == '/')
37     pname++;
38 
39   auto pCMap = pdfium::MakeRetain<CPDF_CMap>();
40   pCMap->LoadPredefined(this, pname, bPromptCJK);
41   return pCMap;
42 }
43 
GetCID2UnicodeMap(CIDSet charset,bool bPromptCJK)44 CPDF_CID2UnicodeMap* CPDF_CMapManager::GetCID2UnicodeMap(CIDSet charset,
45                                                          bool bPromptCJK) {
46   if (!m_CID2UnicodeMaps[charset])
47     m_CID2UnicodeMaps[charset] = LoadCID2UnicodeMap(charset, bPromptCJK);
48 
49   return m_CID2UnicodeMaps[charset].get();
50 }
51 
LoadCID2UnicodeMap(CIDSet charset,bool bPromptCJK)52 std::unique_ptr<CPDF_CID2UnicodeMap> CPDF_CMapManager::LoadCID2UnicodeMap(
53     CIDSet charset,
54     bool bPromptCJK) {
55   auto pMap = pdfium::MakeUnique<CPDF_CID2UnicodeMap>();
56   pMap->Load(this, charset, bPromptCJK);
57   return pMap;
58 }
59