summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fpdfapi/cpdf_modulemgr.cpp41
-rw-r--r--core/fpdfapi/cpdf_modulemgr.h11
-rw-r--r--core/fxge/cfx_gemodule.h8
-rw-r--r--core/fxge/ge/cfx_gemodule.cpp10
-rw-r--r--fpdfsdk/fpdfview.cpp61
5 files changed, 66 insertions, 65 deletions
diff --git a/core/fpdfapi/cpdf_modulemgr.cpp b/core/fpdfapi/cpdf_modulemgr.cpp
index ac28b36663..8e39bdd587 100644
--- a/core/fpdfapi/cpdf_modulemgr.cpp
+++ b/core/fpdfapi/cpdf_modulemgr.cpp
@@ -10,6 +10,22 @@
#include "core/fxcodec/fx_codec.h"
#include "third_party/base/ptr_util.h"
+#ifdef PDF_ENABLE_XFA_BMP
+#include "core/fxcodec/codec/ccodec_bmpmodule.h"
+#endif
+
+#ifdef PDF_ENABLE_XFA_GIF
+#include "core/fxcodec/codec/ccodec_gifmodule.h"
+#endif
+
+#ifdef PDF_ENABLE_XFA_PNG
+#include "core/fxcodec/codec/ccodec_pngmodule.h"
+#endif
+
+#ifdef PDF_ENABLE_XFA_TIFF
+#include "core/fxcodec/codec/ccodec_tiffmodule.h"
+#endif
+
namespace {
CPDF_ModuleMgr* g_pDefaultMgr = nullptr;
@@ -33,6 +49,31 @@ CPDF_ModuleMgr::CPDF_ModuleMgr() : m_pCodecModule(nullptr) {}
CPDF_ModuleMgr::~CPDF_ModuleMgr() {}
+void CPDF_ModuleMgr::LoadEmbeddedMaps() {
+ LoadEmbeddedGB1CMaps();
+ LoadEmbeddedJapan1CMaps();
+ LoadEmbeddedCNS1CMaps();
+ LoadEmbeddedKorea1CMaps();
+}
+
+void CPDF_ModuleMgr::LoadCodecModules() {
+#ifdef PDF_ENABLE_XFA_BMP
+ m_pCodecModule->SetBmpModule(pdfium::MakeUnique<CCodec_BmpModule>());
+#endif
+
+#ifdef PDF_ENABLE_XFA_GIF
+ m_pCodecModule->SetGifModule(pdfium::MakeUnique<CCodec_GifModule>());
+#endif
+
+#ifdef PDF_ENABLE_XFA_PNG
+ m_pCodecModule->SetPngModule(pdfium::MakeUnique<CCodec_PngModule>());
+#endif
+
+#ifdef PDF_ENABLE_XFA_TIFF
+ m_pCodecModule->SetTiffModule(pdfium::MakeUnique<CCodec_TiffModule>());
+#endif
+}
+
void CPDF_ModuleMgr::InitPageModule() {
m_pPageModule = pdfium::MakeUnique<CPDF_PageModule>();
}
diff --git a/core/fpdfapi/cpdf_modulemgr.h b/core/fpdfapi/cpdf_modulemgr.h
index d31ffd5256..898b6ea0bc 100644
--- a/core/fpdfapi/cpdf_modulemgr.h
+++ b/core/fpdfapi/cpdf_modulemgr.h
@@ -52,10 +52,8 @@ class CPDF_ModuleMgr {
return m_pUnsupportInfoAdapter.get();
}
- void LoadEmbeddedGB1CMaps();
- void LoadEmbeddedCNS1CMaps();
- void LoadEmbeddedJapan1CMaps();
- void LoadEmbeddedKorea1CMaps();
+ void LoadEmbeddedMaps();
+ void LoadCodecModules();
CCodec_FaxModule* GetFaxModule();
CCodec_JpegModule* GetJpegModule();
@@ -68,6 +66,11 @@ class CPDF_ModuleMgr {
CPDF_ModuleMgr();
~CPDF_ModuleMgr();
+ void LoadEmbeddedGB1CMaps();
+ void LoadEmbeddedCNS1CMaps();
+ void LoadEmbeddedJapan1CMaps();
+ void LoadEmbeddedKorea1CMaps();
+
CCodec_ModuleMgr* m_pCodecModule;
std::unique_ptr<CPDF_PageModule> m_pPageModule;
std::unique_ptr<CFSDK_UnsupportInfo_Adapter> m_pUnsupportInfoAdapter;
diff --git a/core/fxge/cfx_gemodule.h b/core/fxge/cfx_gemodule.h
index 4dfa413437..e51ddde967 100644
--- a/core/fxge/cfx_gemodule.h
+++ b/core/fxge/cfx_gemodule.h
@@ -21,17 +21,15 @@ class CFX_GEModule {
static CFX_GEModule* Get();
static void Destroy();
- void Init(const char** pUserFontPaths, CCodec_ModuleMgr* pCodecModule);
+ void Init(const char** pUserFontPaths);
CFX_FontCache* GetFontCache();
CFX_FontMgr* GetFontMgr() { return m_pFontMgr.get(); }
void SetTextGamma(float gammaValue);
const uint8_t* GetTextGammaTable() const;
- CCodec_ModuleMgr* GetCodecModule() { return m_pCodecModule; }
+ CCodec_ModuleMgr* GetCodecModule() { return m_pCodecModule.get(); }
void* GetPlatformData() { return m_pPlatformData; }
- FXFT_Library m_FTLibrary;
-
private:
CFX_GEModule();
~CFX_GEModule();
@@ -42,7 +40,7 @@ class CFX_GEModule {
uint8_t m_GammaValue[256];
std::unique_ptr<CFX_FontCache> m_pFontCache;
std::unique_ptr<CFX_FontMgr> m_pFontMgr;
- CCodec_ModuleMgr* m_pCodecModule;
+ std::unique_ptr<CCodec_ModuleMgr> m_pCodecModule;
void* m_pPlatformData;
const char** m_pUserFontPaths;
};
diff --git a/core/fxge/ge/cfx_gemodule.cpp b/core/fxge/ge/cfx_gemodule.cpp
index 125758b6ad..2cd1e31144 100644
--- a/core/fxge/ge/cfx_gemodule.cpp
+++ b/core/fxge/ge/cfx_gemodule.cpp
@@ -6,6 +6,7 @@
#include "core/fxge/cfx_gemodule.h"
+#include "core/fxcodec/fx_codec.h"
#include "core/fxge/cfx_fontcache.h"
#include "core/fxge/cfx_fontmgr.h"
#include "core/fxge/ge/cfx_folderfontinfo.h"
@@ -19,9 +20,8 @@ CFX_GEModule* g_pGEModule = nullptr;
} // namespace
CFX_GEModule::CFX_GEModule()
- : m_FTLibrary(nullptr),
- m_pFontMgr(new CFX_FontMgr),
- m_pCodecModule(nullptr),
+ : m_pFontMgr(pdfium::MakeUnique<CFX_FontMgr>()),
+ m_pCodecModule(pdfium::MakeUnique<CCodec_ModuleMgr>()),
m_pPlatformData(nullptr),
m_pUserFontPaths(nullptr) {}
@@ -43,10 +43,8 @@ void CFX_GEModule::Destroy() {
g_pGEModule = nullptr;
}
-void CFX_GEModule::Init(const char** userFontPaths,
- CCodec_ModuleMgr* pCodecModule) {
+void CFX_GEModule::Init(const char** userFontPaths) {
ASSERT(g_pGEModule);
- m_pCodecModule = pCodecModule;
m_pUserFontPaths = userFontPaths;
InitPlatform();
SetTextGamma(2.2f);
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
index 616402e564..fea1aba8de 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -49,30 +49,13 @@
#include "public/fpdf_formfill.h"
#endif // PDF_ENABLE_XFA
-#ifdef PDF_ENABLE_XFA_BMP
-#include "core/fxcodec/codec/ccodec_bmpmodule.h"
-#endif
-
-#ifdef PDF_ENABLE_XFA_GIF
-#include "core/fxcodec/codec/ccodec_gifmodule.h"
-#endif
-
-#ifdef PDF_ENABLE_XFA_PNG
-#include "core/fxcodec/codec/ccodec_pngmodule.h"
-#endif
-
-#ifdef PDF_ENABLE_XFA_TIFF
-#include "core/fxcodec/codec/ccodec_tiffmodule.h"
-#endif
-
#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
#include "core/fxge/cfx_windowsdevice.h"
#endif
namespace {
-// Also indicates whether library is currently initialized.
-CCodec_ModuleMgr* g_pCodecModule = nullptr;
+bool g_bLibraryInitialized = false;
void RenderPageImpl(CPDF_PageRenderContext* pContext,
CPDF_Page* pPage,
@@ -368,42 +351,19 @@ DLLEXPORT void STDCALL FPDF_InitLibrary() {
DLLEXPORT void STDCALL
FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG* cfg) {
- if (g_pCodecModule)
+ if (g_bLibraryInitialized)
return;
FXMEM_InitializePartitionAlloc();
- g_pCodecModule = new CCodec_ModuleMgr();
CFX_GEModule* pModule = CFX_GEModule::Get();
- pModule->Init(cfg ? cfg->m_pUserFontPaths : nullptr, g_pCodecModule);
+ pModule->Init(cfg ? cfg->m_pUserFontPaths : nullptr);
CPDF_ModuleMgr* pModuleMgr = CPDF_ModuleMgr::Get();
- pModuleMgr->SetCodecModule(g_pCodecModule);
+ pModuleMgr->SetCodecModule(pModule->GetCodecModule());
pModuleMgr->InitPageModule();
- pModuleMgr->LoadEmbeddedGB1CMaps();
- pModuleMgr->LoadEmbeddedJapan1CMaps();
- pModuleMgr->LoadEmbeddedCNS1CMaps();
- pModuleMgr->LoadEmbeddedKorea1CMaps();
-
-#ifdef PDF_ENABLE_XFA_BMP
- pModuleMgr->GetCodecModule()->SetBmpModule(
- pdfium::MakeUnique<CCodec_BmpModule>());
-#endif
-
-#ifdef PDF_ENABLE_XFA_GIF
- pModuleMgr->GetCodecModule()->SetGifModule(
- pdfium::MakeUnique<CCodec_GifModule>());
-#endif
-
-#ifdef PDF_ENABLE_XFA_PNG
- pModuleMgr->GetCodecModule()->SetPngModule(
- pdfium::MakeUnique<CCodec_PngModule>());
-#endif
-
-#ifdef PDF_ENABLE_XFA_TIFF
- pModuleMgr->GetCodecModule()->SetTiffModule(
- pdfium::MakeUnique<CCodec_TiffModule>());
-#endif
+ pModuleMgr->LoadEmbeddedMaps();
+ pModuleMgr->LoadCodecModules();
#ifdef PDF_ENABLE_XFA
FXJSE_Initialize();
@@ -411,10 +371,12 @@ FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG* cfg) {
#endif // PDF_ENABLE_XFA
if (cfg && cfg->version >= 2)
IJS_Runtime::Initialize(cfg->m_v8EmbedderSlot, cfg->m_pIsolate);
+
+ g_bLibraryInitialized = true;
}
DLLEXPORT void STDCALL FPDF_DestroyLibrary() {
- if (!g_pCodecModule)
+ if (!g_bLibraryInitialized)
return;
#ifdef PDF_ENABLE_XFA
@@ -425,10 +387,9 @@ DLLEXPORT void STDCALL FPDF_DestroyLibrary() {
CPDF_ModuleMgr::Destroy();
CFX_GEModule::Destroy();
- delete g_pCodecModule;
- g_pCodecModule = nullptr;
-
IJS_Runtime::Destroy();
+
+ g_bLibraryInitialized = false;
}
#ifndef _WIN32