Home | History | Annotate | Download | only in fpdfapi
      1 // Copyright 2014 PDFium Authors. All rights reserved.
      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/cpdf_modulemgr.h"
      8 
      9 #include "core/fpdfapi/page/cpdf_pagemodule.h"
     10 #include "core/fxcodec/fx_codec.h"
     11 #include "third_party/base/ptr_util.h"
     12 
     13 #ifdef PDF_ENABLE_XFA_BMP
     14 #include "core/fxcodec/codec/ccodec_bmpmodule.h"
     15 #endif
     16 
     17 #ifdef PDF_ENABLE_XFA_GIF
     18 #include "core/fxcodec/codec/ccodec_gifmodule.h"
     19 #endif
     20 
     21 #ifdef PDF_ENABLE_XFA_PNG
     22 #include "core/fxcodec/codec/ccodec_pngmodule.h"
     23 #endif
     24 
     25 #ifdef PDF_ENABLE_XFA_TIFF
     26 #include "core/fxcodec/codec/ccodec_tiffmodule.h"
     27 #endif
     28 
     29 namespace {
     30 
     31 CPDF_ModuleMgr* g_pDefaultMgr = nullptr;
     32 
     33 }  // namespace
     34 
     35 // static
     36 CPDF_ModuleMgr* CPDF_ModuleMgr::Get() {
     37   if (!g_pDefaultMgr)
     38     g_pDefaultMgr = new CPDF_ModuleMgr;
     39   return g_pDefaultMgr;
     40 }
     41 
     42 // static
     43 void CPDF_ModuleMgr::Destroy() {
     44   delete g_pDefaultMgr;
     45   g_pDefaultMgr = nullptr;
     46 }
     47 
     48 CPDF_ModuleMgr::CPDF_ModuleMgr() {}
     49 
     50 CPDF_ModuleMgr::~CPDF_ModuleMgr() {}
     51 
     52 void CPDF_ModuleMgr::Init() {
     53   InitCodecModule();
     54   InitPageModule();
     55   LoadEmbeddedMaps();
     56   LoadCodecModules();
     57 }
     58 
     59 void CPDF_ModuleMgr::LoadEmbeddedMaps() {
     60   LoadEmbeddedGB1CMaps();
     61   LoadEmbeddedJapan1CMaps();
     62   LoadEmbeddedCNS1CMaps();
     63   LoadEmbeddedKorea1CMaps();
     64 }
     65 
     66 void CPDF_ModuleMgr::LoadCodecModules() {
     67 #ifdef PDF_ENABLE_XFA_BMP
     68   m_pCodecModule->SetBmpModule(pdfium::MakeUnique<CCodec_BmpModule>());
     69 #endif
     70 
     71 #ifdef PDF_ENABLE_XFA_GIF
     72   m_pCodecModule->SetGifModule(pdfium::MakeUnique<CCodec_GifModule>());
     73 #endif
     74 
     75 #ifdef PDF_ENABLE_XFA_PNG
     76   m_pCodecModule->SetPngModule(pdfium::MakeUnique<CCodec_PngModule>());
     77 #endif
     78 
     79 #ifdef PDF_ENABLE_XFA_TIFF
     80   m_pCodecModule->SetTiffModule(pdfium::MakeUnique<CCodec_TiffModule>());
     81 #endif
     82 }
     83 
     84 void CPDF_ModuleMgr::InitCodecModule() {
     85   m_pCodecModule = pdfium::MakeUnique<CCodec_ModuleMgr>();
     86 }
     87 
     88 void CPDF_ModuleMgr::InitPageModule() {
     89   m_pPageModule = pdfium::MakeUnique<CPDF_PageModule>();
     90 }
     91 
     92 CCodec_FaxModule* CPDF_ModuleMgr::GetFaxModule() {
     93   return m_pCodecModule->GetFaxModule();
     94 }
     95 
     96 CCodec_JpegModule* CPDF_ModuleMgr::GetJpegModule() {
     97   return m_pCodecModule->GetJpegModule();
     98 }
     99 
    100 CCodec_JpxModule* CPDF_ModuleMgr::GetJpxModule() {
    101   return m_pCodecModule->GetJpxModule();
    102 }
    103 
    104 CCodec_Jbig2Module* CPDF_ModuleMgr::GetJbig2Module() {
    105   return m_pCodecModule->GetJbig2Module();
    106 }
    107 
    108 CCodec_IccModule* CPDF_ModuleMgr::GetIccModule() {
    109   return m_pCodecModule->GetIccModule();
    110 }
    111 
    112 CCodec_FlateModule* CPDF_ModuleMgr::GetFlateModule() {
    113   return m_pCodecModule->GetFlateModule();
    114 }
    115