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 "third_party/base/check.h"
20#include "third_party/base/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() {
93 fxcmap::kGB1_cmaps_size));
95}
96
97void CPDF_FontGlobals::LoadEmbeddedCNS1CMaps() {
99 fxcmap::kCNS1_cmaps_size));
101}
102
103void CPDF_FontGlobals::LoadEmbeddedJapan1CMaps() {
106 pdfium::make_span(fxcmap::kJapan1_cmaps, fxcmap::kJapan1_cmaps_size));
108}
109
110void CPDF_FontGlobals::LoadEmbeddedKorea1CMaps() {
113 pdfium::make_span(fxcmap::kKorea1_cmaps, fxcmap::kKorea1_cmaps_size));
115}
116
118 const ByteString& name) {
119 auto it = m_CMaps.find(name);
120 if (it != m_CMaps.end())
121 return it->second;
122
123 RetainPtr<const CPDF_CMap> pCMap = LoadPredefinedCMap(name.AsStringView());
124 if (!name.IsEmpty())
125 m_CMaps[name] = pCMap;
126
127 return pCMap;
128}
129
131 if (!m_CID2UnicodeMaps[charset]) {
132 m_CID2UnicodeMaps[charset] = std::make_unique<CPDF_CID2UnicodeMap>(charset);
133 }
134 return m_CID2UnicodeMaps[charset].get();
135}
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)
void SetEmbeddedCharset(CIDSet idx, pdfium::span< const fxcmap::CMap > map)
CPDF_CID2UnicodeMap * GetCID2UnicodeMap(CIDSet charset)
void SetEmbeddedToUnicode(CIDSet idx, pdfium::span< const uint16_t > map)
CIDSet
@ CIDSET_KOREA1
@ CIDSET_JAPAN1
@ CIDSET_GB1
@ CIDSET_CNS1
const CMap kJapan1_cmaps[]
const CMap kKorea1_cmaps[]
const uint16_t kJapan1CID2Unicode_4[15444]
const uint16_t kGB1CID2Unicode_5[30284]
const uint16_t kKorea1CID2Unicode_2[18352]
const uint16_t kCNS1CID2Unicode_5[19088]
const CMap kCNS1_cmaps[]
const CMap kGB1_cmaps[]
Definition cmaps_gb1.cpp:13