Break direct top-level fpdfapi to cmaps dependence.
Let the font/ layer manage the cmaps/ layer directly.
Change-Id: I7ef3227b44065a9c2b3714339790d353e0e7897d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/58510
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/BUILD.gn b/core/fpdfapi/BUILD.gn
index 3f947dd..e364e7c 100644
--- a/core/fpdfapi/BUILD.gn
+++ b/core/fpdfapi/BUILD.gn
@@ -15,7 +15,6 @@
"../fxcodec",
"../fxcrt",
"../fxge",
- "cmaps",
"edit",
"font",
"page",
diff --git a/core/fpdfapi/cpdf_modulemgr.cpp b/core/fpdfapi/cpdf_modulemgr.cpp
index 3987f69..3ab5cb5 100644
--- a/core/fpdfapi/cpdf_modulemgr.cpp
+++ b/core/fpdfapi/cpdf_modulemgr.cpp
@@ -6,10 +6,6 @@
#include "core/fpdfapi/cpdf_modulemgr.h"
-#include "core/fpdfapi/cmaps/CNS1/cmaps_cns1.h"
-#include "core/fpdfapi/cmaps/GB1/cmaps_gb1.h"
-#include "core/fpdfapi/cmaps/Japan1/cmaps_japan1.h"
-#include "core/fpdfapi/cmaps/Korea1/cmaps_korea1.h"
#include "core/fpdfapi/font/cpdf_fontglobals.h"
#include "core/fpdfapi/page/cpdf_pagemodule.h"
#include "core/fxcodec/fx_codec.h"
@@ -27,7 +23,7 @@
g_pDefaultMgr = new CPDF_ModuleMgr;
fxcodec::ModuleMgr::Create();
CPDF_PageModule::Create();
- g_pDefaultMgr->LoadEmbeddedMaps();
+ CPDF_FontGlobals::GetInstance()->LoadEmbeddedMaps();
}
// static
@@ -48,44 +44,3 @@
CPDF_ModuleMgr::CPDF_ModuleMgr() = default;
CPDF_ModuleMgr::~CPDF_ModuleMgr() = default;
-
-void CPDF_ModuleMgr::LoadEmbeddedMaps() {
- LoadEmbeddedGB1CMaps();
- LoadEmbeddedCNS1CMaps();
- LoadEmbeddedJapan1CMaps();
- LoadEmbeddedKorea1CMaps();
-}
-
-void CPDF_ModuleMgr::LoadEmbeddedGB1CMaps() {
- auto* pFontGlobals = CPDF_FontGlobals::GetInstance();
- pFontGlobals->SetEmbeddedCharset(
- CIDSET_GB1,
- pdfium::make_span(g_FXCMAP_GB1_cmaps, g_FXCMAP_GB1_cmaps_size));
- pFontGlobals->SetEmbeddedToUnicode(CIDSET_GB1, g_FXCMAP_GB1CID2Unicode_5);
-}
-
-void CPDF_ModuleMgr::LoadEmbeddedCNS1CMaps() {
- auto* pFontGlobals = CPDF_FontGlobals::GetInstance();
- pFontGlobals->SetEmbeddedCharset(
- CIDSET_CNS1,
- pdfium::make_span(g_FXCMAP_CNS1_cmaps, g_FXCMAP_CNS1_cmaps_size));
- pFontGlobals->SetEmbeddedToUnicode(CIDSET_CNS1, g_FXCMAP_CNS1CID2Unicode_5);
-}
-
-void CPDF_ModuleMgr::LoadEmbeddedJapan1CMaps() {
- auto* pFontGlobals = CPDF_FontGlobals::GetInstance();
- pFontGlobals->SetEmbeddedCharset(
- CIDSET_JAPAN1,
- pdfium::make_span(g_FXCMAP_Japan1_cmaps, g_FXCMAP_Japan1_cmaps_size));
- pFontGlobals->SetEmbeddedToUnicode(CIDSET_JAPAN1,
- g_FXCMAP_Japan1CID2Unicode_4);
-}
-
-void CPDF_ModuleMgr::LoadEmbeddedKorea1CMaps() {
- auto* pFontGlobals = CPDF_FontGlobals::GetInstance();
- pFontGlobals->SetEmbeddedCharset(
- CIDSET_KOREA1,
- pdfium::make_span(g_FXCMAP_Korea1_cmaps, g_FXCMAP_Korea1_cmaps_size));
- pFontGlobals->SetEmbeddedToUnicode(CIDSET_KOREA1,
- g_FXCMAP_Korea1CID2Unicode_2);
-}
diff --git a/core/fpdfapi/cpdf_modulemgr.h b/core/fpdfapi/cpdf_modulemgr.h
index 7bda93b..86fe988 100644
--- a/core/fpdfapi/cpdf_modulemgr.h
+++ b/core/fpdfapi/cpdf_modulemgr.h
@@ -43,11 +43,6 @@
~CPDF_ModuleMgr();
void InitPageModule();
- void LoadEmbeddedMaps();
- void LoadEmbeddedGB1CMaps();
- void LoadEmbeddedCNS1CMaps();
- void LoadEmbeddedJapan1CMaps();
- void LoadEmbeddedKorea1CMaps();
std::unique_ptr<fpdfapi::UnsupportedInfoAdapter> m_pUnsupportInfoAdapter;
};
diff --git a/core/fpdfapi/font/cpdf_fontglobals.cpp b/core/fpdfapi/font/cpdf_fontglobals.cpp
index e3b19e2..10b6c5e 100644
--- a/core/fpdfapi/font/cpdf_fontglobals.cpp
+++ b/core/fpdfapi/font/cpdf_fontglobals.cpp
@@ -6,6 +6,10 @@
#include "core/fpdfapi/font/cpdf_fontglobals.h"
+#include "core/fpdfapi/cmaps/CNS1/cmaps_cns1.h"
+#include "core/fpdfapi/cmaps/GB1/cmaps_gb1.h"
+#include "core/fpdfapi/cmaps/Japan1/cmaps_japan1.h"
+#include "core/fpdfapi/cmaps/Korea1/cmaps_korea1.h"
#include "core/fpdfapi/font/cfx_stockfontarray.h"
#include "core/fpdfapi/parser/cpdf_document.h"
#include "third_party/base/ptr_util.h"
@@ -43,6 +47,13 @@
CPDF_FontGlobals::~CPDF_FontGlobals() = default;
+void CPDF_FontGlobals::LoadEmbeddedMaps() {
+ LoadEmbeddedGB1CMaps();
+ LoadEmbeddedCNS1CMaps();
+ LoadEmbeddedJapan1CMaps();
+ LoadEmbeddedKorea1CMaps();
+}
+
RetainPtr<CPDF_Font> CPDF_FontGlobals::Find(
CPDF_Document* pDoc,
CFX_FontMapper::StandardFont index) {
@@ -64,3 +75,29 @@
void CPDF_FontGlobals::Clear(CPDF_Document* pDoc) {
m_StockMap.erase(pDoc);
}
+
+void CPDF_FontGlobals::LoadEmbeddedGB1CMaps() {
+ SetEmbeddedCharset(CIDSET_GB1, pdfium::make_span(g_FXCMAP_GB1_cmaps,
+ g_FXCMAP_GB1_cmaps_size));
+ SetEmbeddedToUnicode(CIDSET_GB1, g_FXCMAP_GB1CID2Unicode_5);
+}
+
+void CPDF_FontGlobals::LoadEmbeddedCNS1CMaps() {
+ SetEmbeddedCharset(CIDSET_CNS1, pdfium::make_span(g_FXCMAP_CNS1_cmaps,
+ g_FXCMAP_CNS1_cmaps_size));
+ SetEmbeddedToUnicode(CIDSET_CNS1, g_FXCMAP_CNS1CID2Unicode_5);
+}
+
+void CPDF_FontGlobals::LoadEmbeddedJapan1CMaps() {
+ SetEmbeddedCharset(
+ CIDSET_JAPAN1,
+ pdfium::make_span(g_FXCMAP_Japan1_cmaps, g_FXCMAP_Japan1_cmaps_size));
+ SetEmbeddedToUnicode(CIDSET_JAPAN1, g_FXCMAP_Japan1CID2Unicode_4);
+}
+
+void CPDF_FontGlobals::LoadEmbeddedKorea1CMaps() {
+ SetEmbeddedCharset(
+ CIDSET_KOREA1,
+ pdfium::make_span(g_FXCMAP_Korea1_cmaps, g_FXCMAP_Korea1_cmaps_size));
+ SetEmbeddedToUnicode(CIDSET_KOREA1, g_FXCMAP_Korea1CID2Unicode_2);
+}
diff --git a/core/fpdfapi/font/cpdf_fontglobals.h b/core/fpdfapi/font/cpdf_fontglobals.h
index ff3449e..8ef9687 100644
--- a/core/fpdfapi/font/cpdf_fontglobals.h
+++ b/core/fpdfapi/font/cpdf_fontglobals.h
@@ -25,6 +25,9 @@
static void Destroy();
static CPDF_FontGlobals* GetInstance();
+ // Caller must load the maps before using font globals.
+ void LoadEmbeddedMaps();
+
void Clear(CPDF_Document* pDoc);
RetainPtr<CPDF_Font> Find(CPDF_Document* pDoc,
CFX_FontMapper::StandardFont index);
@@ -51,6 +54,11 @@
CPDF_FontGlobals();
~CPDF_FontGlobals();
+ void LoadEmbeddedGB1CMaps();
+ void LoadEmbeddedCNS1CMaps();
+ void LoadEmbeddedJapan1CMaps();
+ void LoadEmbeddedKorea1CMaps();
+
CPDF_CMapManager m_CMapManager;
pdfium::span<const FXCMAP_CMap> m_EmbeddedCharsets[CIDSET_NUM_SETS];
pdfium::span<const uint16_t> m_EmbeddedToUnicodes[CIDSET_NUM_SETS];