Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdf_fontglobals.cpp
Go to the documentation of this file.
1// Copyright 2017 The PDFium Authors
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_fontglobals.h"
8
9#include <utility>
10
11#include "core/fpdfapi/cmaps/CNS1/cmaps_cns1.h"
12#include "core/fpdfapi/cmaps/GB1/cmaps_gb1.h"
13#include "core/fpdfapi/cmaps/Japan1/cmaps_japan1.h"
14#include "core/fpdfapi/cmaps/Korea1/cmaps_korea1.h"
15#include "core/fpdfapi/font/cfx_stockfontarray.h"
16#include "core/fpdfapi/font/cpdf_cid2unicodemap.h"
17#include "core/fpdfapi/font/cpdf_cmap.h"
18#include "core/fpdfapi/parser/cpdf_document.h"
19#include "core/fxcrt/check.h"
20#include "core/fxcrt/containers/contains.h"
21
22namespace {
23
24CPDF_FontGlobals* g_FontGlobals = nullptr;
25
26RetainPtr<const CPDF_CMap> LoadPredefinedCMap(ByteStringView name) {
27 if (!name.IsEmpty() && name[0] == '/')
28 name = name.Last(name.GetLength() - 1);
29 return pdfium::MakeRetain<CPDF_CMap>(name);
30}
31
32} // namespace
33
34// static
36 DCHECK(!g_FontGlobals);
37 g_FontGlobals = new CPDF_FontGlobals();
38}
39
40// static
42 DCHECK(g_FontGlobals);
43 delete g_FontGlobals;
44 g_FontGlobals = nullptr;
45}
46
47// static
49 DCHECK(g_FontGlobals);
50 return g_FontGlobals;
51}
52
53CPDF_FontGlobals::CPDF_FontGlobals() = default;
54
55CPDF_FontGlobals::~CPDF_FontGlobals() = default;
56
58 LoadEmbeddedGB1CMaps();
59 LoadEmbeddedCNS1CMaps();
60 LoadEmbeddedJapan1CMaps();
61 LoadEmbeddedKorea1CMaps();
62}
63
65 CPDF_Document* pDoc,
67 auto it = m_StockMap.find(pDoc);
68 if (it == m_StockMap.end() || !it->second)
69 return nullptr;
70
71 return it->second->GetFont(index);
72}
73
76 RetainPtr<CPDF_Font> pFont) {
77 UnownedPtr<CPDF_Document> pKey(pDoc);
78 if (!pdfium::Contains(m_StockMap, pKey))
79 m_StockMap[pKey] = std::make_unique<CFX_StockFontArray>();
80 m_StockMap[pKey]->SetFont(index, std::move(pFont));
81}
82
84 // Avoid constructing smart-pointer key as erase() doesn't invoke
85 // transparent lookup in the same way find() does.
86 auto it = m_StockMap.find(pDoc);
87 if (it != m_StockMap.end())
88 m_StockMap.erase(it);
89}
90
91void CPDF_FontGlobals::LoadEmbeddedGB1CMaps() {
92 SetEmbeddedCharset(CIDSET_GB1, fxcmap::kGB1_cmaps_span);
93 SetEmbeddedToUnicode(CIDSET_GB1, fxcmap::kGB1CID2Unicode_5);
94}
95
96void CPDF_FontGlobals::LoadEmbeddedCNS1CMaps() {
97 SetEmbeddedCharset(CIDSET_CNS1, fxcmap::kCNS1_cmaps_span);
98 SetEmbeddedToUnicode(CIDSET_CNS1, fxcmap::kCNS1CID2Unicode_5);
99}
100
101void CPDF_FontGlobals::LoadEmbeddedJapan1CMaps() {
102 SetEmbeddedCharset(CIDSET_JAPAN1, fxcmap::kJapan1_cmaps_span);
103 SetEmbeddedToUnicode(CIDSET_JAPAN1, fxcmap::kJapan1CID2Unicode_4);
104}
105
106void CPDF_FontGlobals::LoadEmbeddedKorea1CMaps() {
107 SetEmbeddedCharset(CIDSET_KOREA1, fxcmap::kKorea1_cmaps_span);
108 SetEmbeddedToUnicode(CIDSET_KOREA1, fxcmap::kKorea1CID2Unicode_2);
109}
110
112 const ByteString& name) {
113 auto it = m_CMaps.find(name);
114 if (it != m_CMaps.end())
115 return it->second;
116
117 RetainPtr<const CPDF_CMap> pCMap = LoadPredefinedCMap(name.AsStringView());
118 if (!name.IsEmpty())
119 m_CMaps[name] = pCMap;
120
121 return pCMap;
122}
123
125 if (!m_CID2UnicodeMaps[charset]) {
126 m_CID2UnicodeMaps[charset] = std::make_unique<CPDF_CID2UnicodeMap>(charset);
127 }
128 return m_CID2UnicodeMaps[charset].get();
129}
fxcrt::ByteString ByteString
Definition bytestring.h:180
#define DCHECK
Definition check.h:33
void Set(CPDF_Document *pDoc, CFX_FontMapper::StandardFont index, RetainPtr< CPDF_Font > pFont)
static void Destroy()
RetainPtr< CPDF_Font > Find(CPDF_Document *pDoc, CFX_FontMapper::StandardFont index)
static CPDF_FontGlobals * GetInstance()
RetainPtr< const CPDF_CMap > GetPredefinedCMap(const ByteString &name)
void Clear(CPDF_Document *pDoc)
CPDF_CID2UnicodeMap * GetCID2UnicodeMap(CIDSet charset)
CIDSet
fxcrt::ByteStringView ByteStringView