diff options
author | Lei Zhang <thestig@chromium.org> | 2015-06-19 17:17:54 -0700 |
---|---|---|
committer | Lei Zhang <thestig@chromium.org> | 2015-06-19 17:17:54 -0700 |
commit | fa6eb28e08d924271d91758f945ce48a1c2dbf0c (patch) | |
tree | 6d4e627b18c5ac50cca976709ae5fb2c01b525c6 /core | |
parent | e5b0bd1a79f90b7758246655e18ef965a87bcd0b (diff) | |
download | pdfium-fa6eb28e08d924271d91758f945ce48a1c2dbf0c.tar.xz |
Merge to XFA: Make CPDF_PageModuleDef and CPDF_RenderModuleDef pure virtual.
Get rid of the dummy implementations, which are never used when
the modules have been initialized.
R=tsepez@chromium.org
Review URL: https://codereview.chromium.org/1177383003.
(cherry picked from commit 5fef754bc09e971f1bf1ba79da98c0a7ee1e1c8d)
Review URL: https://codereview.chromium.org/1189413006.
Diffstat (limited to 'core')
-rw-r--r-- | core/include/fpdfapi/fpdf_module.h | 181 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_basic_module.cpp | 52 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page.cpp | 2 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp | 25 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp | 2 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_render/fpdf_render.cpp | 43 |
6 files changed, 130 insertions, 175 deletions
diff --git a/core/include/fpdfapi/fpdf_module.h b/core/include/fpdfapi/fpdf_module.h index 65e4117a54..5877e11372 100644 --- a/core/include/fpdfapi/fpdf_module.h +++ b/core/include/fpdfapi/fpdf_module.h @@ -7,6 +7,7 @@ #ifndef CORE_INCLUDE_FPDFAPI_FPDF_MODULE_H_ #define CORE_INCLUDE_FPDFAPI_FPDF_MODULE_H_ +#include "../../../third_party/base/nonstd_unique_ptr.h" #include "../fxcrt/fx_coordinates.h" #include "../fxcrt/fx_system.h" @@ -21,13 +22,10 @@ class CPDF_DocRenderData; class CPDF_Document; class CPDF_FontGlobals; class CPDF_Image; -class CPDF_ModuleMgr; class CPDF_Page; -class CPDF_PageModuleDef; class CPDF_PageObjects; class CPDF_PageRenderCache; class CPDF_RenderConfig; -class CPDF_RenderModuleDef; class CPDF_RenderOptions; class CPDF_SecurityHandler; class CPDF_Stream; @@ -38,162 +36,113 @@ class ICodec_Jbig2Module; class ICodec_JpegModule; class ICodec_JpxModule; class IPDF_FontMapper; - -#define ADDIN_NAME_CJK "Eastern Asian Language Support" -#define ADDIN_NAME_DECODER "JPEG2000 and JBIG2 Image Decoders" +class IPDF_PageModule; +class IPDF_RenderModule; class CPDF_ModuleMgr { public: + static CPDF_ModuleMgr* Get(); + static void Create(); + static void Destroy(); + static const int kFileBufSize = 512; - static void Create(); - - static CPDF_ModuleMgr* Get(); - - static void Destroy(); - - - - void SetCodecModule(CCodec_ModuleMgr* pModule) + void SetCodecModule(CCodec_ModuleMgr* pModule) { m_pCodecModule = pModule; } - CCodec_ModuleMgr* GetCodecModule() + CCodec_ModuleMgr* GetCodecModule() { return m_pCodecModule; } - void InitPageModule(); - - void InitRenderModule(); + void InitPageModule(); - void SetDownloadCallback(FX_BOOL (*callback)(const FX_CHAR* module_name)); + void InitRenderModule(); - FX_BOOL DownloadModule(const FX_CHAR* module_name); + void SetDownloadCallback(FX_BOOL (*callback)(const FX_CHAR* module_name)); - void NotifyModuleAvailable(const FX_CHAR* module_name); + FX_BOOL DownloadModule(const FX_CHAR* module_name); + void NotifyModuleAvailable(const FX_CHAR* module_name); - - CPDF_RenderModuleDef* GetRenderModule() const + IPDF_RenderModule* GetRenderModule() const { - return m_pRenderModule; + return m_pRenderModule.get(); } - CPDF_PageModuleDef* GetPageModule() const + IPDF_PageModule* GetPageModule() const { - return m_pPageModule; + return m_pPageModule.get(); } + void LoadEmbeddedGB1CMaps(); + void LoadEmbeddedCNS1CMaps(); + void LoadEmbeddedJapan1CMaps(); + void LoadEmbeddedKorea1CMaps(); + ICodec_FaxModule* GetFaxModule(); + ICodec_JpegModule* GetJpegModule(); + ICodec_JpxModule* GetJpxModule(); + ICodec_Jbig2Module* GetJbig2Module(); + ICodec_IccModule* GetIccModule(); + ICodec_FlateModule* GetFlateModule(); + void RegisterSecurityHandler( + const FX_CHAR* name, + CPDF_SecurityHandler* (*CreateHandler)(void* param), + void* param); - void LoadEmbeddedGB1CMaps(); - - void LoadEmbeddedCNS1CMaps(); - - void LoadEmbeddedJapan1CMaps(); - - void LoadEmbeddedKorea1CMaps(); - - ICodec_FaxModule* GetFaxModule(); - ICodec_JpegModule* GetJpegModule(); - ICodec_JpxModule* GetJpxModule(); - ICodec_Jbig2Module* GetJbig2Module(); - ICodec_IccModule* GetIccModule(); - ICodec_FlateModule* GetFlateModule(); - - void RegisterSecurityHandler(const FX_CHAR* name, CPDF_SecurityHandler * (*CreateHandler)(void* param), void* param); + CPDF_SecurityHandler* CreateSecurityHandler(const FX_CHAR* name); - CPDF_SecurityHandler* CreateSecurityHandler(const FX_CHAR* name); + void SetPrivateData(void* module_id, + void* pData, + PD_CALLBACK_FREEDATA callback); - void SetPrivateData(void* module_id, void* pData, PD_CALLBACK_FREEDATA callback); - - void* GetPrivateData(void* module_id); - - int m_FileBufSize; -protected: + void* GetPrivateData(void* module_id); +private: CPDF_ModuleMgr(); - ~CPDF_ModuleMgr(); - void Initialize(); - - void InitModules(); - - - CCodec_ModuleMgr* m_pCodecModule; - - CPDF_RenderModuleDef* m_pRenderModule; - - CPDF_PageModuleDef* m_pPageModule; + CCodec_ModuleMgr* m_pCodecModule; + nonstd::unique_ptr<IPDF_RenderModule> m_pRenderModule; + nonstd::unique_ptr<IPDF_PageModule> m_pPageModule; FX_BOOL (*m_pDownloadCallback)(const FX_CHAR* module_name); - CFX_MapByteStringToPtr m_SecurityHandlerMap; + CFX_MapByteStringToPtr m_SecurityHandlerMap; - CFX_PrivateData m_privateData; + CFX_PrivateData m_privateData; }; -class CPDF_PageModuleDef + +class IPDF_PageModule { public: - virtual ~CPDF_PageModuleDef() {} - - virtual CPDF_DocPageData* CreateDocData(CPDF_Document* pDoc) - { - return NULL; - } - - virtual void ReleaseDoc(CPDF_Document*) {} - virtual void ClearDoc(CPDF_Document*) {} - - virtual CPDF_FontGlobals* GetFontGlobals() - { - return NULL; - } - - virtual void ClearStockFont(CPDF_Document* pDoc) {} - - virtual void NotifyCJKAvailable() {} - - virtual CPDF_ColorSpace* GetStockCS(int family) - { - return NULL; - } + virtual ~IPDF_PageModule() {} + + virtual CPDF_DocPageData* CreateDocData(CPDF_Document* pDoc) = 0; + virtual void ReleaseDoc(CPDF_Document*) = 0; + virtual void ClearDoc(CPDF_Document*) = 0; + virtual CPDF_FontGlobals* GetFontGlobals() = 0; + virtual void ClearStockFont(CPDF_Document* pDoc) = 0; + virtual void NotifyCJKAvailable() = 0; + virtual CPDF_ColorSpace* GetStockCS(int family) = 0; }; -class CPDF_RenderModuleDef + +class IPDF_RenderModule { public: - virtual ~CPDF_RenderModuleDef() {} - - virtual CPDF_DocRenderData* CreateDocData(CPDF_Document* pDoc) - { - return NULL; - } - - virtual void DestroyDocData(CPDF_DocRenderData*) {} - virtual void ClearDocData(CPDF_DocRenderData*) {} - - virtual CPDF_DocRenderData* GetRenderData() - { - return NULL; - } - - virtual CPDF_PageRenderCache* CreatePageCache(CPDF_Page* pPage) - { - return NULL; - } - - virtual void DestroyPageCache(CPDF_PageRenderCache*) {} - - virtual void NotifyDecoderAvailable() {} - - virtual CPDF_RenderConfig* GetConfig() - { - return NULL; - } + virtual ~IPDF_RenderModule() {} + + virtual CPDF_DocRenderData* CreateDocData(CPDF_Document* pDoc) = 0; + virtual void DestroyDocData(CPDF_DocRenderData*) = 0; + virtual void ClearDocData(CPDF_DocRenderData*) = 0; + virtual CPDF_DocRenderData* GetRenderData() = 0; + virtual CPDF_PageRenderCache* CreatePageCache(CPDF_Page* pPage) = 0; + virtual void DestroyPageCache(CPDF_PageRenderCache*) = 0; + virtual CPDF_RenderConfig* GetConfig() = 0; }; #endif // CORE_INCLUDE_FPDFAPI_FPDF_MODULE_H_ diff --git a/core/src/fpdfapi/fpdf_basic_module.cpp b/core/src/fpdfapi/fpdf_basic_module.cpp index 62be616d3d..03cfd66afb 100644 --- a/core/src/fpdfapi/fpdf_basic_module.cpp +++ b/core/src/fpdfapi/fpdf_basic_module.cpp @@ -6,50 +6,44 @@ #include "../../include/fxcodec/fx_codec.h" #include "../../include/fpdfapi/fpdf_module.h" -static CPDF_ModuleMgr* g_FPDFAPI_pDefaultMgr = NULL; + +namespace { + +CPDF_ModuleMgr* g_FPDFAPI_pDefaultMgr = nullptr; + +const char kAddinNameCJK[] = "Eastern Asian Language Support"; + +} // namespace + +// static CPDF_ModuleMgr* CPDF_ModuleMgr::Get() { return g_FPDFAPI_pDefaultMgr; } + +// static void CPDF_ModuleMgr::Create() { + ASSERT(!g_FPDFAPI_pDefaultMgr); g_FPDFAPI_pDefaultMgr = new CPDF_ModuleMgr; - g_FPDFAPI_pDefaultMgr->Initialize(); } + +// static void CPDF_ModuleMgr::Destroy() { - if (g_FPDFAPI_pDefaultMgr) { - delete g_FPDFAPI_pDefaultMgr; - } - g_FPDFAPI_pDefaultMgr = NULL; + delete g_FPDFAPI_pDefaultMgr; + g_FPDFAPI_pDefaultMgr = nullptr; } + CPDF_ModuleMgr::CPDF_ModuleMgr() + : m_pCodecModule(nullptr) { - m_pCodecModule = NULL; - m_pPageModule = NULL; - m_pRenderModule = NULL; - m_FileBufSize = 512; -} -void CPDF_ModuleMgr::Initialize() -{ - InitModules(); - m_FileBufSize = 512; -} -void CPDF_ModuleMgr::InitModules() -{ - m_pCodecModule = NULL; - m_pPageModule = new CPDF_PageModuleDef; - m_pRenderModule = new CPDF_RenderModuleDef; } + CPDF_ModuleMgr::~CPDF_ModuleMgr() { - if (m_pPageModule) { - delete m_pPageModule; - } - if (m_pRenderModule) { - delete m_pRenderModule; - } } + void CPDF_ModuleMgr::SetDownloadCallback(FX_BOOL (*callback)(const FX_CHAR* module_name)) { m_pDownloadCallback = callback; @@ -63,10 +57,8 @@ FX_BOOL CPDF_ModuleMgr::DownloadModule(const FX_CHAR* module_name) } void CPDF_ModuleMgr::NotifyModuleAvailable(const FX_CHAR* module_name) { - if (FXSYS_strcmp(module_name, ADDIN_NAME_CJK) == 0) { + if (FXSYS_strcmp(module_name, kAddinNameCJK) == 0) { m_pPageModule->NotifyCJKAvailable(); - } else if (FXSYS_strcmp(module_name, ADDIN_NAME_DECODER) == 0) { - m_pRenderModule->NotifyDecoderAvailable(); } } void CPDF_ModuleMgr::RegisterSecurityHandler(const FX_CHAR* filter, CPDF_SecurityHandler * (*CreateHandler)(void* param), void* param) diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp index 984baedf16..97b28574fc 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp @@ -898,7 +898,7 @@ void CPDF_Page::ParseContent(CPDF_ParseOptions* pOptions, FX_BOOL bReParse) CPDF_Page::~CPDF_Page() { if (m_pPageRender) { - CPDF_RenderModuleDef* pModule = CPDF_ModuleMgr::Get()->GetRenderModule(); + IPDF_RenderModule* pModule = CPDF_ModuleMgr::Get()->GetRenderModule(); pModule->DestroyPageCache(m_pPageRender); } } diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp index 49c158c52f..05233a12a4 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp @@ -10,7 +10,7 @@ #include "../fpdf_font/font_int.h" #include "pageint.h" -class CPDF_PageModule : public CPDF_PageModuleDef +class CPDF_PageModule : public IPDF_PageModule { public: CPDF_PageModule() @@ -26,24 +26,30 @@ private: { return new CPDF_DocPageData(pDoc); } - virtual void ReleaseDoc(CPDF_Document* pDoc); - virtual void ClearDoc(CPDF_Document* pDoc); - virtual CPDF_FontGlobals* GetFontGlobals() + + void ReleaseDoc(CPDF_Document* pDoc) override; + void ClearDoc(CPDF_Document* pDoc) override; + + CPDF_FontGlobals* GetFontGlobals() override { return &m_FontGlobals; } - virtual void ClearStockFont(CPDF_Document* pDoc) + + void ClearStockFont(CPDF_Document* pDoc) override { m_FontGlobals.Clear(pDoc); } - virtual CPDF_ColorSpace* GetStockCS(int family); - virtual void NotifyCJKAvailable(); + + CPDF_ColorSpace* GetStockCS(int family) override; + void NotifyCJKAvailable() override; + CPDF_FontGlobals m_FontGlobals; CPDF_DeviceCS m_StockGrayCS; CPDF_DeviceCS m_StockRGBCS; CPDF_DeviceCS m_StockCMYKCS; CPDF_PatternCS m_StockPatternCS; }; + CPDF_ColorSpace* CPDF_PageModule::GetStockCS(int family) { if (family == PDFCS_DEVICEGRAY) { @@ -60,11 +66,12 @@ CPDF_ColorSpace* CPDF_PageModule::GetStockCS(int family) } return NULL; } + void CPDF_ModuleMgr::InitPageModule() { - delete m_pPageModule; - m_pPageModule = new CPDF_PageModule; + m_pPageModule.reset(new CPDF_PageModule); } + void CPDF_PageModule::ReleaseDoc(CPDF_Document* pDoc) { delete pDoc->GetPageData(); diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp index 4362735d72..9f5acb5257 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp @@ -1690,7 +1690,7 @@ CPDF_SyntaxParser::CPDF_SyntaxParser() m_pFileAccess = NULL; m_pCryptoHandler = NULL; m_pFileBuf = NULL; - m_BufSize = CPDF_ModuleMgr::Get()->m_FileBufSize; + m_BufSize = CPDF_ModuleMgr::kFileBufSize; m_pFileBuf = NULL; m_MetadataObjnum = 0; m_dwWordPos = 0; diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp index 608e124118..06c9ea614f 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp @@ -78,34 +78,40 @@ void CPDF_DocRenderData::ReleaseCachedType3(CPDF_Type3Font* pFont) if (m_Type3FaceMap.Lookup(pFont, pCache)) pCache->RemoveRef(); } -class CPDF_RenderModule : public CPDF_RenderModuleDef + +class CPDF_RenderModule : public IPDF_RenderModule { public: - virtual ~CPDF_RenderModule() {} - virtual FX_BOOL Installed() - { - return TRUE; - } - virtual CPDF_DocRenderData* CreateDocData(CPDF_Document* pDoc); - virtual void DestroyDocData(CPDF_DocRenderData* p); - virtual void ClearDocData(CPDF_DocRenderData* p); - virtual CPDF_DocRenderData* GetRenderData() + CPDF_RenderModule() {} + +private: + ~CPDF_RenderModule() override {} + + CPDF_DocRenderData* CreateDocData(CPDF_Document* pDoc) override; + void DestroyDocData(CPDF_DocRenderData* p) override; + void ClearDocData(CPDF_DocRenderData* p) override; + + CPDF_DocRenderData* GetRenderData() override { return &m_RenderData; } - virtual CPDF_PageRenderCache* CreatePageCache(CPDF_Page* pPage) + + CPDF_PageRenderCache* CreatePageCache(CPDF_Page* pPage) override { return new CPDF_PageRenderCache(pPage); } - virtual void DestroyPageCache(CPDF_PageRenderCache* pCache); - virtual CPDF_RenderConfig* GetConfig() + + void DestroyPageCache(CPDF_PageRenderCache* pCache) override; + + CPDF_RenderConfig* GetConfig() override { return &m_RenderConfig; } -private: - CPDF_DocRenderData m_RenderData; - CPDF_RenderConfig m_RenderConfig; + + CPDF_DocRenderData m_RenderData; + CPDF_RenderConfig m_RenderConfig; }; + CPDF_DocRenderData* CPDF_RenderModule::CreateDocData(CPDF_Document* pDoc) { CPDF_DocRenderData* pData = new CPDF_DocRenderData(pDoc); @@ -126,11 +132,12 @@ void CPDF_RenderModule::DestroyPageCache(CPDF_PageRenderCache* pCache) { delete pCache; } + void CPDF_ModuleMgr::InitRenderModule() { - delete m_pRenderModule; - m_pRenderModule = new CPDF_RenderModule; + m_pRenderModule.reset(new CPDF_RenderModule); } + CPDF_RenderOptions::CPDF_RenderOptions() : m_ColorMode(RENDER_COLOR_NORMAL) , m_Flags(RENDER_CLEARTYPE) |