Merge to XFA: Use stdint.h types throughout PDFium.
[pdfium.git] / fpdfsdk / src / fpdfview.cpp
index 7852670..fa6bb2e 100644 (file)
@@ -4,16 +4,17 @@
  
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
+
+#include "../../core/include/fxcrt/fx_safe_types.h"
 #include "../../public/fpdf_ext.h"
 #include "../../public/fpdf_formfill.h"
 #include "../../public/fpdf_progressive.h"
 #include "../../public/fpdfview.h"
+#include "../../third_party/base/nonstd_unique_ptr.h"
+#include "../../third_party/base/numerics/safe_conversions_impl.h"
 #include "../include/fsdk_define.h"
 #include "../include/fsdk_mgr.h"
 #include "../include/fsdk_rendercontext.h"
-#include "../../../core/src/fxcrt/fx_safe_types.h"
-#include "../../third_party/base/nonstd_unique_ptr.h"
-#include "../../third_party/base/numerics/safe_conversions_impl.h"
 #include "../include/fpdfxfa/fpdfxfa_doc.h"
 #include "../include/fpdfxfa/fpdfxfa_app.h"
 #include "../include/fpdfxfa/fpdfxfa_page.h"
@@ -103,7 +104,7 @@ CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess)
        m_BufferOffset = (FX_DWORD)-1;
 }
 
-FX_BOOL CPDF_CustomAccess::GetByte(FX_DWORD pos, FX_BYTE& ch)
+FX_BOOL CPDF_CustomAccess::GetByte(FX_DWORD pos, uint8_t& ch)
 {
        if (pos >= m_FileAccess.m_FileLen) return FALSE;
        if (m_BufferOffset == (FX_DWORD)-1 || pos < m_BufferOffset || pos >= m_BufferOffset + 512) {
@@ -176,36 +177,29 @@ FPDF_BOOL FSDK_IsSandBoxPolicyEnabled(FPDF_DWORD policy)
        return FALSE;
 }
 
-
-#ifndef _T
-#define _T(x) x
-#endif
-
 CCodec_ModuleMgr*      g_pCodecModule = NULL;
 
 DLLEXPORT void STDCALL FPDF_InitLibrary()
 {
-       g_pCodecModule = CCodec_ModuleMgr::Create();
-       
-       CFX_GEModule::Create();
-       CFX_GEModule::Get()->SetCodecModule(g_pCodecModule);
-       
-       CPDF_ModuleMgr::Create();
-       CPDF_ModuleMgr::Get()->SetCodecModule(g_pCodecModule);
-       CPDF_ModuleMgr::Get()->InitPageModule();
-       CPDF_ModuleMgr::Get()->InitRenderModule();
+    g_pCodecModule = CCodec_ModuleMgr::Create();
 
-       CPDFXFA_App* pAppProvider = FPDFXFA_GetApp();
-       pAppProvider->Initialize();
-}
+    CFX_GEModule::Create();
+    CFX_GEModule::Get()->SetCodecModule(g_pCodecModule);
 
+    CPDF_ModuleMgr::Create();
+    CPDF_ModuleMgr::Get()->SetCodecModule(g_pCodecModule);
+    CPDF_ModuleMgr::Get()->InitPageModule();
+    CPDF_ModuleMgr::Get()->InitRenderModule();
+
+    CPDFXFA_App::GetInstance()->Initialize();
+}
 
 DLLEXPORT void STDCALL FPDF_DestroyLibrary()
 {
-       FPDFXFA_ReleaseApp();
-       CPDF_ModuleMgr::Destroy();
-       CFX_GEModule::Destroy();
-       g_pCodecModule->Destroy();
+    CPDFXFA_App::ReleaseInstance();
+    CPDF_ModuleMgr::Destroy();
+    CFX_GEModule::Destroy();
+    g_pCodecModule->Destroy();
 }
 
 #ifndef _WIN32
@@ -261,12 +255,12 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path, FPDF_BY
        if (!pPDFDoc)
                return NULL;
 
-       CPDFXFA_App* pProvider = FPDFXFA_GetApp();
+       CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance();
        CPDFXFA_Document* pDocument = FX_NEW CPDFXFA_Document(pPDFDoc, pProvider);
        return pDocument;
 }
 
-DLLEXPORT FX_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document, int& docType)
+DLLEXPORT FX_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document, int* docType)
 {
        if (!document)
                return FALSE;
@@ -290,9 +284,9 @@ DLLEXPORT FX_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document, int& docType)
        FX_BOOL bDynamicXFA = pRoot->GetBoolean("NeedsRendering", FALSE);
 
        if (bDynamicXFA)
-               docType = DOCTYPE_DYNIMIC_XFA;
+               *docType = DOCTYPE_DYNIMIC_XFA;
        else
-               docType = DOCTYPE_STATIC_XFA;
+               *docType = DOCTYPE_STATIC_XFA;
 
        return TRUE;
 }
@@ -305,10 +299,10 @@ DLLEXPORT  FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document)
 
 extern void CheckUnSupportError(CPDF_Document * pDoc, FX_DWORD err_code);
 
-class CMemFile FX_FINAL: public IFX_FileRead
+class CMemFile final : public IFX_FileRead
 {
 public:
-       CMemFile(FX_BYTE* pBuf, FX_FILESIZE size):m_pBuf(pBuf),m_size(size) {}
+       CMemFile(uint8_t* pBuf, FX_FILESIZE size):m_pBuf(pBuf),m_size(size) {}
 
        virtual void                    Release() {delete this;}
        virtual FX_FILESIZE             GetSize() {return m_size;}
@@ -326,14 +320,14 @@ public:
            return TRUE;
        }
 private:
-       FX_BYTE* m_pBuf;
+       uint8_t* m_pBuf;
        FX_FILESIZE m_size;
 };
 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, int size, FPDF_BYTESTRING password)
 {
        CPDF_Parser* pParser = FX_NEW CPDF_Parser;
        pParser->SetPassword(password);
-       CMemFile* pMemFile = FX_NEW CMemFile((FX_BYTE*)data_buf, size);
+       CMemFile* pMemFile = new CMemFile((uint8_t*)data_buf, size);
        FX_DWORD err_code = pParser->StartParse(pMemFile);
        if (err_code) {
                delete pParser;
@@ -347,10 +341,8 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, int s
        if (!pPDFDoc)
                return NULL;
 
-       CPDFXFA_App* pProvider = FPDFXFA_GetApp();
+       CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance();
        CPDFXFA_Document* pDocument = FX_NEW CPDFXFA_Document(pPDFDoc, pProvider);
-       //pDocument->LoadXFADoc();
-
        return pDocument;
 }
 
@@ -372,10 +364,8 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAc
        if (!pPDFDoc)
                return NULL;
 
-       CPDFXFA_App* pProvider = FPDFXFA_GetApp();
+       CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance();
        CPDFXFA_Document* pDocument = FX_NEW CPDFXFA_Document(pPDFDoc, pProvider);
-       //pDocument->LoadXFADoc();
-
        return pDocument;
 }
 
@@ -1011,10 +1001,10 @@ FPDF_RESULT     FPDF_BStr_Clear(FPDF_BSTR* str)
        return 0;
 }
 
-DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, int index, void* buffer, long& buflen)
+DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, int index, void* buffer, long* buflen)
 {
     if (!buffer)
-        buflen = 0;
+        *buflen = 0;
     if (!document || index < 0) return NULL;
        CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
 
@@ -1051,12 +1041,12 @@ DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, int index,
     CFX_ByteString utf16Name = wsName.UTF16LE_Encode();
     unsigned int len = utf16Name.GetLength();
     if (!buffer) {
-        buflen = len;
-    } else if (buflen >= len) {
+        *buflen = len;
+    } else if (*buflen >= len) {
         memcpy(buffer, utf16Name.c_str(), len);
-        buflen = len;
+        *buflen = len;
     } else {
-        buflen = -1;
+        *buflen = -1;
     }
     return (FPDF_DEST)pDestObj;
 }