summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fpdfapi/cmaps/CNS1/cmaps_cns1.cpp11
-rw-r--r--core/fpdfapi/cmaps/GB1/cmaps_gb1.cpp10
-rw-r--r--core/fpdfapi/cmaps/Japan1/cmaps_japan1.cpp11
-rw-r--r--core/fpdfapi/cmaps/Korea1/cmaps_korea1.cpp11
-rw-r--r--core/fpdfapi/cmaps/fpdf_cmaps.cpp9
-rw-r--r--core/fpdfapi/font/cpdf_cid2unicodemap.cpp4
-rw-r--r--core/fpdfapi/font/cpdf_cidfont.cpp41
-rw-r--r--core/fpdfapi/font/cpdf_fontglobals.h22
-rw-r--r--core/fpdfapi/font/cpdf_tounicodemap.cpp3
9 files changed, 70 insertions, 52 deletions
diff --git a/core/fpdfapi/cmaps/CNS1/cmaps_cns1.cpp b/core/fpdfapi/cmaps/CNS1/cmaps_cns1.cpp
index 101c316c3b..bb57381400 100644
--- a/core/fpdfapi/cmaps/CNS1/cmaps_cns1.cpp
+++ b/core/fpdfapi/cmaps/CNS1/cmaps_cns1.cpp
@@ -45,11 +45,8 @@ static const FXCMAP_CMap g_FXCMAP_CNS1_cmaps[] = {
void CPDF_ModuleMgr::LoadEmbeddedCNS1CMaps() {
CPDF_FontGlobals* pFontGlobals =
CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
- pFontGlobals->m_EmbeddedCharsets[CIDSET_CNS1].m_pMapList =
- g_FXCMAP_CNS1_cmaps;
- pFontGlobals->m_EmbeddedCharsets[CIDSET_CNS1].m_Count =
- FX_ArraySize(g_FXCMAP_CNS1_cmaps);
- pFontGlobals->m_EmbeddedToUnicodes[CIDSET_CNS1].m_pMap =
- g_FXCMAP_CNS1CID2Unicode_5;
- pFontGlobals->m_EmbeddedToUnicodes[CIDSET_CNS1].m_Count = 19088;
+ pFontGlobals->SetEmbeddedCharset(CIDSET_CNS1, g_FXCMAP_CNS1_cmaps,
+ FX_ArraySize(g_FXCMAP_CNS1_cmaps));
+ pFontGlobals->SetEmbeddedToUnicode(CIDSET_CNS1, g_FXCMAP_CNS1CID2Unicode_5,
+ 19088);
}
diff --git a/core/fpdfapi/cmaps/GB1/cmaps_gb1.cpp b/core/fpdfapi/cmaps/GB1/cmaps_gb1.cpp
index 5776b18c0e..a91da32369 100644
--- a/core/fpdfapi/cmaps/GB1/cmaps_gb1.cpp
+++ b/core/fpdfapi/cmaps/GB1/cmaps_gb1.cpp
@@ -45,10 +45,8 @@ static const FXCMAP_CMap g_FXCMAP_GB1_cmaps[] = {
void CPDF_ModuleMgr::LoadEmbeddedGB1CMaps() {
CPDF_FontGlobals* pFontGlobals =
CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
- pFontGlobals->m_EmbeddedCharsets[CIDSET_GB1].m_pMapList = g_FXCMAP_GB1_cmaps;
- pFontGlobals->m_EmbeddedCharsets[CIDSET_GB1].m_Count =
- FX_ArraySize(g_FXCMAP_GB1_cmaps);
- pFontGlobals->m_EmbeddedToUnicodes[CIDSET_GB1].m_pMap =
- g_FXCMAP_GB1CID2Unicode_5;
- pFontGlobals->m_EmbeddedToUnicodes[CIDSET_GB1].m_Count = 30284;
+ pFontGlobals->SetEmbeddedCharset(CIDSET_GB1, g_FXCMAP_GB1_cmaps,
+ FX_ArraySize(g_FXCMAP_GB1_cmaps));
+ pFontGlobals->SetEmbeddedToUnicode(CIDSET_GB1, g_FXCMAP_GB1CID2Unicode_5,
+ 30284);
}
diff --git a/core/fpdfapi/cmaps/Japan1/cmaps_japan1.cpp b/core/fpdfapi/cmaps/Japan1/cmaps_japan1.cpp
index ba8f02dcdf..17611e774b 100644
--- a/core/fpdfapi/cmaps/Japan1/cmaps_japan1.cpp
+++ b/core/fpdfapi/cmaps/Japan1/cmaps_japan1.cpp
@@ -57,11 +57,8 @@ static const FXCMAP_CMap g_FXCMAP_Japan1_cmaps[] = {
void CPDF_ModuleMgr::LoadEmbeddedJapan1CMaps() {
CPDF_FontGlobals* pFontGlobals =
CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
- pFontGlobals->m_EmbeddedCharsets[CIDSET_JAPAN1].m_pMapList =
- g_FXCMAP_Japan1_cmaps;
- pFontGlobals->m_EmbeddedCharsets[CIDSET_JAPAN1].m_Count =
- FX_ArraySize(g_FXCMAP_Japan1_cmaps);
- pFontGlobals->m_EmbeddedToUnicodes[CIDSET_JAPAN1].m_pMap =
- g_FXCMAP_Japan1CID2Unicode_4;
- pFontGlobals->m_EmbeddedToUnicodes[CIDSET_JAPAN1].m_Count = 15444;
+ pFontGlobals->SetEmbeddedCharset(CIDSET_JAPAN1, g_FXCMAP_Japan1_cmaps,
+ FX_ArraySize(g_FXCMAP_Japan1_cmaps));
+ pFontGlobals->SetEmbeddedToUnicode(CIDSET_JAPAN1,
+ g_FXCMAP_Japan1CID2Unicode_4, 15444);
}
diff --git a/core/fpdfapi/cmaps/Korea1/cmaps_korea1.cpp b/core/fpdfapi/cmaps/Korea1/cmaps_korea1.cpp
index 12dbec6a74..690ce2a4ea 100644
--- a/core/fpdfapi/cmaps/Korea1/cmaps_korea1.cpp
+++ b/core/fpdfapi/cmaps/Korea1/cmaps_korea1.cpp
@@ -39,11 +39,8 @@ static const FXCMAP_CMap g_FXCMAP_Korea1_cmaps[] = {
void CPDF_ModuleMgr::LoadEmbeddedKorea1CMaps() {
CPDF_FontGlobals* pFontGlobals =
CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
- pFontGlobals->m_EmbeddedCharsets[CIDSET_KOREA1].m_pMapList =
- g_FXCMAP_Korea1_cmaps;
- pFontGlobals->m_EmbeddedCharsets[CIDSET_KOREA1].m_Count =
- FX_ArraySize(g_FXCMAP_Korea1_cmaps);
- pFontGlobals->m_EmbeddedToUnicodes[CIDSET_KOREA1].m_pMap =
- g_FXCMAP_Korea1CID2Unicode_2;
- pFontGlobals->m_EmbeddedToUnicodes[CIDSET_KOREA1].m_Count = 18352;
+ pFontGlobals->SetEmbeddedCharset(CIDSET_KOREA1, g_FXCMAP_Korea1_cmaps,
+ FX_ArraySize(g_FXCMAP_Korea1_cmaps));
+ pFontGlobals->SetEmbeddedToUnicode(CIDSET_KOREA1,
+ g_FXCMAP_Korea1CID2Unicode_2, 18352);
}
diff --git a/core/fpdfapi/cmaps/fpdf_cmaps.cpp b/core/fpdfapi/cmaps/fpdf_cmaps.cpp
index 01c8da9691..ac8456dc69 100644
--- a/core/fpdfapi/cmaps/fpdf_cmaps.cpp
+++ b/core/fpdfapi/cmaps/fpdf_cmaps.cpp
@@ -60,10 +60,11 @@ void FPDFAPI_FindEmbeddedCMap(const ByteString& bsName,
pMap = nullptr;
CPDF_FontGlobals* pFontGlobals =
CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
- const FXCMAP_CMap* pCMaps =
- pFontGlobals->m_EmbeddedCharsets[charset].m_pMapList.Get();
- for (uint32_t i = 0; i < pFontGlobals->m_EmbeddedCharsets[charset].m_Count;
- i++) {
+
+ const FXCMAP_CMap* pCMaps;
+ uint32_t count;
+ std::tie(count, pCMaps) = pFontGlobals->GetEmbeddedCharset(charset);
+ for (uint32_t i = 0; i < count; i++) {
if (bsName == pCMaps[i].m_Name) {
pMap = &pCMaps[i];
break;
diff --git a/core/fpdfapi/font/cpdf_cid2unicodemap.cpp b/core/fpdfapi/font/cpdf_cid2unicodemap.cpp
index cb378aa9d6..650856419a 100644
--- a/core/fpdfapi/font/cpdf_cid2unicodemap.cpp
+++ b/core/fpdfapi/font/cpdf_cid2unicodemap.cpp
@@ -37,6 +37,6 @@ void CPDF_CID2UnicodeMap::Load(CPDF_CMapManager* pMgr,
CPDF_FontGlobals* pFontGlobals =
CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
- m_pEmbeddedMap = pFontGlobals->m_EmbeddedToUnicodes[charset].m_pMap;
- m_EmbeddedCount = pFontGlobals->m_EmbeddedToUnicodes[charset].m_Count;
+ std::tie(m_EmbeddedCount, m_pEmbeddedMap) =
+ pFontGlobals->GetEmbeddedToUnicode(charset);
}
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp
index 0140cc8a23..be0f7b7cba 100644
--- a/core/fpdfapi/font/cpdf_cidfont.cpp
+++ b/core/fpdfapi/font/cpdf_cidfont.cpp
@@ -147,9 +147,14 @@ wchar_t EmbeddedUnicodeFromCharcode(const FXCMAP_CMap* pEmbedMap,
return 0;
uint16_t cid = FPDFAPI_CIDFromCharCode(pEmbedMap, charcode);
- const auto& codes = GetFontGlobals()->m_EmbeddedToUnicodes[charset];
- if (codes.m_pMap && cid && cid < codes.m_Count)
- return codes.m_pMap[cid];
+ if (!cid)
+ return 0;
+
+ const uint16_t* map;
+ uint32_t count;
+ std::tie(count, map) = GetFontGlobals()->GetEmbeddedToUnicode(charset);
+ if (map && cid < count)
+ return map[cid];
return 0;
}
@@ -159,16 +164,17 @@ uint32_t EmbeddedCharcodeFromUnicode(const FXCMAP_CMap* pEmbedMap,
if (!IsValidEmbeddedCharcodeFromUnicodeCharset(charset))
return 0;
- const auto& codes = GetFontGlobals()->m_EmbeddedToUnicodes[charset];
- const uint16_t* pCodes = codes.m_pMap;
- if (!pCodes)
+ const uint16_t* map;
+ uint32_t count;
+ std::tie(count, map) = GetFontGlobals()->GetEmbeddedToUnicode(charset);
+ if (!map)
return 0;
- for (uint32_t i = 0; i < codes.m_Count; ++i) {
- if (pCodes[i] == unicode) {
- uint32_t CharCode = FPDFAPI_CharCodeFromCID(pEmbedMap, i);
- if (CharCode)
- return CharCode;
+ for (uint32_t i = 0; i < count; ++i) {
+ if (map[i] == unicode) {
+ uint32_t charCode = FPDFAPI_CharCodeFromCID(pEmbedMap, i);
+ if (charCode)
+ return charCode;
}
}
return 0;
@@ -359,11 +365,11 @@ bool CPDF_CIDFont::Load() {
ByteString subtype = pCIDFontDict->GetStringFor("Subtype");
m_bType1 = (subtype == "CIDFontType0");
- CPDF_CMapManager& manager = GetFontGlobals()->m_CMapManager;
+ CPDF_CMapManager* manager = GetFontGlobals()->GetCMapManager();
if (pEncoding->IsName()) {
ByteString cmap = pEncoding->GetString();
bool bPromptCJK = m_pFontFile && m_bType1;
- m_pCMap = manager.GetPredefinedCMap(cmap, bPromptCJK);
+ m_pCMap = manager->GetPredefinedCMap(cmap, bPromptCJK);
if (!m_pCMap)
return false;
} else if (CPDF_Stream* pStream = pEncoding->AsStream()) {
@@ -386,7 +392,7 @@ bool CPDF_CIDFont::Load() {
if (m_Charset != CIDSET_UNKNOWN) {
bool bPromptCJK = !m_pFontFile && (m_pCMap->m_Coding == CIDCODING_CID ||
pCIDFontDict->KeyExist("W"));
- m_pCID2UnicodeMap = manager.GetCID2UnicodeMap(m_Charset, bPromptCJK);
+ m_pCID2UnicodeMap = manager->GetCID2UnicodeMap(m_Charset, bPromptCJK);
}
if (m_Font.GetFace()) {
if (m_bType1)
@@ -841,9 +847,10 @@ void CPDF_CIDFont::LoadGB2312() {
m_Charset = CIDSET_GB1;
m_bType1 = false;
- CPDF_CMapManager& manager = GetFontGlobals()->m_CMapManager;
- m_pCMap = manager.GetPredefinedCMap("GBK-EUC-H", false);
- m_pCID2UnicodeMap = manager.GetCID2UnicodeMap(m_Charset, false);
+
+ CPDF_CMapManager* manager = GetFontGlobals()->GetCMapManager();
+ m_pCMap = manager->GetPredefinedCMap("GBK-EUC-H", false);
+ m_pCID2UnicodeMap = manager->GetCID2UnicodeMap(m_Charset, false);
if (!IsEmbedded())
LoadSubstFont();
diff --git a/core/fpdfapi/font/cpdf_fontglobals.h b/core/fpdfapi/font/cpdf_fontglobals.h
index 239a757528..a47dfa13d0 100644
--- a/core/fpdfapi/font/cpdf_fontglobals.h
+++ b/core/fpdfapi/font/cpdf_fontglobals.h
@@ -9,6 +9,7 @@
#include <map>
#include <memory>
+#include <utility>
#include "core/fpdfapi/cmaps/cmap_int.h"
#include "core/fpdfapi/font/cfx_stockfontarray.h"
@@ -27,6 +28,26 @@ class CPDF_FontGlobals {
uint32_t index,
std::unique_ptr<CPDF_Font> pFont);
+ void SetEmbeddedCharset(size_t idx, const FXCMAP_CMap* map, uint32_t count) {
+ m_EmbeddedCharsets[idx].m_pMapList = map;
+ m_EmbeddedCharsets[idx].m_Count = count;
+ }
+ std::pair<uint32_t, const FXCMAP_CMap*> GetEmbeddedCharset(size_t idx) const {
+ return {m_EmbeddedCharsets[idx].m_Count,
+ m_EmbeddedCharsets[idx].m_pMapList.Get()};
+ }
+ void SetEmbeddedToUnicode(size_t idx, const uint16_t* map, uint32_t count) {
+ m_EmbeddedToUnicodes[idx].m_pMap = map;
+ m_EmbeddedToUnicodes[idx].m_Count = count;
+ }
+ std::pair<uint32_t, const uint16_t*> GetEmbeddedToUnicode(size_t idx) {
+ return {m_EmbeddedToUnicodes[idx].m_Count,
+ m_EmbeddedToUnicodes[idx].m_pMap};
+ }
+
+ CPDF_CMapManager* GetCMapManager() { return &m_CMapManager; }
+
+ private:
CPDF_CMapManager m_CMapManager;
struct {
UnownedPtr<const FXCMAP_CMap> m_pMapList;
@@ -37,7 +58,6 @@ class CPDF_FontGlobals {
uint32_t m_Count;
} m_EmbeddedToUnicodes[CIDSET_NUM_SETS];
- private:
std::map<CPDF_Document*, std::unique_ptr<CFX_StockFontArray>> m_StockMap;
};
diff --git a/core/fpdfapi/font/cpdf_tounicodemap.cpp b/core/fpdfapi/font/cpdf_tounicodemap.cpp
index 354f5061c3..0ddaa34e13 100644
--- a/core/fpdfapi/font/cpdf_tounicodemap.cpp
+++ b/core/fpdfapi/font/cpdf_tounicodemap.cpp
@@ -224,7 +224,8 @@ void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) {
m_pBaseMap = CPDF_ModuleMgr::Get()
->GetPageModule()
->GetFontGlobals()
- ->m_CMapManager.GetCID2UnicodeMap(cid_set, false);
+ ->GetCMapManager()
+ ->GetCID2UnicodeMap(cid_set, false);
} else {
m_pBaseMap = nullptr;
}