| Index: fpdfsdk/src/fpdfview.cpp
|
| diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp
|
| index 99a3d90246df0ffdd04a8b029cecfb23f8dca470..d47e2b02da539ebbf00800c74d4ca3fad2dd3958 100644
|
| --- a/fpdfsdk/src/fpdfview.cpp
|
| +++ b/fpdfsdk/src/fpdfview.cpp
|
| @@ -6,6 +6,13 @@
|
|
|
| #include "public/fpdfview.h"
|
|
|
| +#ifdef PDF_ENABLE_XFA
|
| +#include "../include/fpdfxfa/fpdfxfa_app.h"
|
| +#include "../include/fpdfxfa/fpdfxfa_doc.h"
|
| +#include "../include/fpdfxfa/fpdfxfa_page.h"
|
| +#include "../include/fpdfxfa/fpdfxfa_util.h"
|
| +#include "core/include/fpdfapi/fpdf_module.h"
|
| +#endif
|
| #include "core/include/fxcodec/fx_codec.h"
|
| #include "core/include/fxcrt/fx_safe_types.h"
|
| #include "fpdfsdk/include/fsdk_define.h"
|
| @@ -13,6 +20,9 @@
|
| #include "fpdfsdk/include/fsdk_rendercontext.h"
|
| #include "fpdfsdk/include/javascript/IJavaScript.h"
|
| #include "public/fpdf_ext.h"
|
| +#ifdef PDF_ENABLE_XFA
|
| +#include "public/fpdf_formfill.h"
|
| +#endif
|
| #include "public/fpdf_progressive.h"
|
| #include "third_party/base/nonstd_unique_ptr.h"
|
| #include "third_party/base/numerics/safe_conversions_impl.h"
|
| @@ -30,19 +40,141 @@ UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page) {
|
| }
|
|
|
| CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) {
|
| +#ifndef PDF_ENABLE_XFA
|
| return UnderlyingFromFPDFDocument(doc);
|
| +#else
|
| + return doc ? UnderlyingFromFPDFDocument(doc)->GetPDFDoc() : nullptr;
|
| +#endif
|
| }
|
|
|
| FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) {
|
| +#ifndef PDF_ENABLE_XFA
|
| return FPDFDocumentFromUnderlying(doc);
|
| +#else
|
| + return doc ? FPDFDocumentFromUnderlying(
|
| + new CPDFXFA_Document(doc, CPDFXFA_App::GetInstance()))
|
| + : nullptr;
|
| +#endif
|
| }
|
|
|
| CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) {
|
| +#ifndef PDF_ENABLE_XFA
|
| return UnderlyingFromFPDFPage(page);
|
| +#else
|
| + return page ? UnderlyingFromFPDFPage(page)->GetPDFPage() : nullptr;
|
| +}
|
| +
|
| +CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) {
|
| + m_pFS = pFS;
|
| + m_nCurPos = 0;
|
| +}
|
| +
|
| +IFX_FileStream* CFPDF_FileStream::Retain() {
|
| + return this;
|
| +}
|
| +
|
| +void CFPDF_FileStream::Release() {
|
| + if (m_pFS && m_pFS->Release)
|
| + m_pFS->Release(m_pFS->clientData);
|
| + delete this;
|
| +}
|
| +
|
| +FX_FILESIZE CFPDF_FileStream::GetSize() {
|
| + if (m_pFS && m_pFS->GetSize)
|
| + return (FX_FILESIZE)m_pFS->GetSize(m_pFS->clientData);
|
| + return 0;
|
| +}
|
| +
|
| +FX_BOOL CFPDF_FileStream::IsEOF() {
|
| + return m_nCurPos >= GetSize();
|
| +}
|
| +
|
| +FX_BOOL CFPDF_FileStream::ReadBlock(void* buffer,
|
| + FX_FILESIZE offset,
|
| + size_t size) {
|
| + if (!buffer || !size || !m_pFS->ReadBlock)
|
| + return FALSE;
|
| +
|
| + if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer,
|
| + (FPDF_DWORD)size) == 0) {
|
| + m_nCurPos = offset + size;
|
| + return TRUE;
|
| + }
|
| + return FALSE;
|
| +}
|
| +
|
| +size_t CFPDF_FileStream::ReadBlock(void* buffer, size_t size) {
|
| + if (!buffer || !size || !m_pFS->ReadBlock)
|
| + return 0;
|
| +
|
| + FX_FILESIZE nSize = GetSize();
|
| + if (m_nCurPos >= nSize)
|
| + return 0;
|
| + FX_FILESIZE dwAvail = nSize - m_nCurPos;
|
| + if (dwAvail < (FX_FILESIZE)size)
|
| + size = (size_t)dwAvail;
|
| + if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)m_nCurPos, buffer,
|
| + (FPDF_DWORD)size) == 0) {
|
| + m_nCurPos += size;
|
| + return size;
|
| + }
|
| +
|
| + return 0;
|
| +}
|
| +
|
| +FX_BOOL CFPDF_FileStream::WriteBlock(const void* buffer,
|
| + FX_FILESIZE offset,
|
| + size_t size) {
|
| + if (!m_pFS || !m_pFS->WriteBlock)
|
| + return FALSE;
|
| +
|
| + if (m_pFS->WriteBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer,
|
| + (FPDF_DWORD)size) == 0) {
|
| + m_nCurPos = offset + size;
|
| + return TRUE;
|
| + }
|
| + return FALSE;
|
| +}
|
| +
|
| +FX_BOOL CFPDF_FileStream::Flush() {
|
| + if (!m_pFS || !m_pFS->Flush)
|
| + return TRUE;
|
| +
|
| + return m_pFS->Flush(m_pFS->clientData) == 0;
|
| +#endif
|
| }
|
|
|
| CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) {
|
| m_FileAccess = *pFileAccess;
|
| +#ifdef PDF_ENABLE_XFA
|
| + m_BufferOffset = (FX_DWORD)-1;
|
| +}
|
| +
|
| +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) {
|
| + // Need to read from file access
|
| + m_BufferOffset = pos;
|
| + int size = 512;
|
| + if (pos + 512 > m_FileAccess.m_FileLen)
|
| + size = m_FileAccess.m_FileLen - pos;
|
| + if (!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, m_BufferOffset, m_Buffer,
|
| + size))
|
| + return FALSE;
|
| + }
|
| + ch = m_Buffer[pos - m_BufferOffset];
|
| + return TRUE;
|
| +}
|
| +
|
| +FX_BOOL CPDF_CustomAccess::GetBlock(FX_DWORD pos,
|
| + uint8_t* pBuf,
|
| + FX_DWORD size) {
|
| + if (pos + size > m_FileAccess.m_FileLen)
|
| + return FALSE;
|
| + return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, pos, pBuf, size);
|
| +#endif
|
| }
|
|
|
| FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer,
|
| @@ -104,15 +236,22 @@ DLLEXPORT void STDCALL FPDF_InitLibraryWithConfig(
|
| pModuleMgr->SetCodecModule(g_pCodecModule);
|
| pModuleMgr->InitPageModule();
|
| pModuleMgr->InitRenderModule();
|
| +#ifndef PDF_ENABLE_XFA
|
| pModuleMgr->LoadEmbeddedGB1CMaps();
|
| pModuleMgr->LoadEmbeddedJapan1CMaps();
|
| pModuleMgr->LoadEmbeddedCNS1CMaps();
|
| pModuleMgr->LoadEmbeddedKorea1CMaps();
|
| +#else
|
| + CPDFXFA_App::GetInstance()->Initialize();
|
| +#endif
|
| if (cfg && cfg->version >= 2)
|
| IJS_Runtime::Initialize(cfg->m_v8EmbedderSlot, cfg->m_pIsolate);
|
| }
|
|
|
| DLLEXPORT void STDCALL FPDF_DestroyLibrary() {
|
| +#ifdef PDF_ENABLE_XFA
|
| + CPDFXFA_App::ReleaseInstance();
|
| +#endif
|
| CPDF_ModuleMgr::Destroy();
|
| CFX_GEModule::Destroy();
|
|
|
| @@ -173,7 +312,52 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path,
|
| ProcessParseError(err_code);
|
| return NULL;
|
| }
|
| +#ifndef PDF_ENABLE_XFA
|
| return pParser->GetDocument();
|
| +#else
|
| + CPDF_Document* pPDFDoc = pParser->GetDocument();
|
| + if (!pPDFDoc)
|
| + return NULL;
|
| +
|
| + CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance();
|
| + return new CPDFXFA_Document(pPDFDoc, pProvider);
|
| +}
|
| +
|
| +DLLEXPORT FPDF_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document,
|
| + int* docType) {
|
| + if (!document)
|
| + return FALSE;
|
| +
|
| + CPDF_Document* pdfDoc =
|
| + (static_cast<CPDFXFA_Document*>(document))->GetPDFDoc();
|
| + if (!pdfDoc)
|
| + return FALSE;
|
| +
|
| + CPDF_Dictionary* pRoot = pdfDoc->GetRoot();
|
| + if (!pRoot)
|
| + return FALSE;
|
| +
|
| + CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm");
|
| + if (!pAcroForm)
|
| + return FALSE;
|
| +
|
| + CPDF_Object* pXFA = pAcroForm->GetElement("XFA");
|
| + if (!pXFA)
|
| + return FALSE;
|
| +
|
| + FX_BOOL bDynamicXFA = pRoot->GetBoolean("NeedsRendering", FALSE);
|
| +
|
| + if (bDynamicXFA)
|
| + *docType = DOCTYPE_DYNAMIC_XFA;
|
| + else
|
| + *docType = DOCTYPE_STATIC_XFA;
|
| +
|
| + return TRUE;
|
| +}
|
| +
|
| +DLLEXPORT FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document) {
|
| + return document && (static_cast<CPDFXFA_Document*>(document))->LoadXFADoc();
|
| +#endif
|
| }
|
|
|
| class CMemFile final : public IFX_FileRead {
|
| @@ -262,7 +446,11 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc,
|
| DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) {
|
| CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
|
| if (!pDoc)
|
| +#ifndef PDF_ENABLE_XFA
|
| return 0;
|
| +#else
|
| + return (FX_DWORD)-1;
|
| +#endif
|
|
|
| CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict();
|
| return pDict ? pDict->GetInteger("P") : (FX_DWORD)-1;
|
| @@ -291,6 +479,7 @@ DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document,
|
| if (page_index < 0 || page_index >= pDoc->GetPageCount())
|
| return nullptr;
|
|
|
| +#ifndef PDF_ENABLE_XFA
|
| CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
|
| if (pDict == NULL)
|
| return NULL;
|
| @@ -298,6 +487,9 @@ DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document,
|
| pPage->Load(pDoc, pDict);
|
| pPage->ParseContent();
|
| return pPage;
|
| +#else
|
| + return pDoc->GetPage(page_index);
|
| +#endif
|
| }
|
|
|
| DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) {
|
| @@ -522,6 +714,7 @@ DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap,
|
| DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) {
|
| if (!page)
|
| return;
|
| +#ifndef PDF_ENABLE_XFA
|
| CPDFSDK_PageView* pPageView =
|
| (CPDFSDK_PageView*)(((CPDF_Page*)page))->GetPrivateData((void*)page);
|
| if (pPageView && pPageView->IsLocked()) {
|
| @@ -529,9 +722,15 @@ DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) {
|
| return;
|
| }
|
| delete (CPDF_Page*)page;
|
| +#else
|
| +
|
| + CPDFXFA_Page* pPage = (CPDFXFA_Page*)page;
|
| + pPage->Release();
|
| +#endif
|
| }
|
|
|
| DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) {
|
| +#ifndef PDF_ENABLE_XFA
|
| CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
|
| if (!pDoc)
|
| return;
|
| @@ -542,6 +741,9 @@ DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) {
|
| return;
|
| }
|
| delete pParser;
|
| +#else
|
| + delete CPDFDocumentFromFPDFDocument(document);
|
| +#endif
|
| }
|
|
|
| DLLEXPORT unsigned long STDCALL FPDF_GetLastError() {
|
| @@ -561,6 +763,7 @@ DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page,
|
| if (page == NULL || page_x == NULL || page_y == NULL)
|
| return;
|
| UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
|
| +#ifndef PDF_ENABLE_XFA
|
|
|
| CPDF_Matrix page2device;
|
| pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y,
|
| @@ -574,6 +777,10 @@ DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page,
|
|
|
| *page_x = (page_x_f);
|
| *page_y = (page_y_f);
|
| +#else
|
| + pPage->DeviceToPage(start_x, start_y, size_x, size_y, rotate, device_x,
|
| + device_y, page_x, page_y);
|
| +#endif
|
| }
|
|
|
| DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page,
|
| @@ -591,6 +798,7 @@ DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page,
|
| UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
|
| if (!pPage)
|
| return;
|
| +#ifndef PDF_ENABLE_XFA
|
| CPDF_Matrix page2device;
|
| pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y,
|
| rotate);
|
| @@ -601,6 +809,10 @@ DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page,
|
|
|
| *device_x = FXSYS_round(device_x_f);
|
| *device_y = FXSYS_round(device_y_f);
|
| +#else
|
| + pPage->PageToDevice(start_x, start_y, size_x, size_y, rotate, page_x, page_y,
|
| + device_x, device_y);
|
| +#endif
|
| }
|
|
|
| DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width,
|
| @@ -715,12 +927,14 @@ void FPDF_RenderPage_Retail(CRenderContext* pContext,
|
| pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE;
|
| if (flags & FPDF_RENDER_FORCEHALFTONE)
|
| pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE;
|
| +#ifndef PDF_ENABLE_XFA
|
| if (flags & FPDF_RENDER_NO_SMOOTHTEXT)
|
| pContext->m_pOptions->m_Flags |= RENDER_NOTEXTSMOOTH;
|
| if (flags & FPDF_RENDER_NO_SMOOTHIMAGE)
|
| pContext->m_pOptions->m_Flags |= RENDER_NOIMAGESMOOTH;
|
| if (flags & FPDF_RENDER_NO_SMOOTHPATH)
|
| pContext->m_pOptions->m_Flags |= RENDER_NOPATHSMOOTH;
|
| +#endif
|
| // Grayscale output
|
| if (flags & FPDF_GRAYSCALE) {
|
| pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY;
|
| @@ -770,14 +984,28 @@ DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document,
|
| if (!pDoc)
|
| return FALSE;
|
|
|
| +#ifndef PDF_ENABLE_XFA
|
| CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
|
| if (!pDict)
|
| +#else
|
| + int count = pDoc->GetPageCount();
|
| + if (page_index < 0 || page_index >= count)
|
| + return FALSE;
|
| +
|
| + CPDFXFA_Page* pPage = pDoc->GetPage(page_index);
|
| + if (!pPage)
|
| +#endif
|
| return FALSE;
|
|
|
| +#ifndef PDF_ENABLE_XFA
|
| CPDF_Page page;
|
| page.Load(pDoc, pDict);
|
| *width = page.GetPageWidth();
|
| *height = page.GetPageHeight();
|
| +#else
|
| + *width = pPage->GetPageWidth();
|
| + *height = pPage->GetPageHeight();
|
| +#endif
|
|
|
| return TRUE;
|
| }
|
| @@ -854,6 +1082,60 @@ DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,
|
| return name_tree.LookupNamedDest(pDoc, name);
|
| }
|
|
|
| +#ifdef PDF_ENABLE_XFA
|
| +FPDF_RESULT FPDF_BStr_Init(FPDF_BSTR* str) {
|
| + if (!str)
|
| + return -1;
|
| +
|
| + FXSYS_memset(str, 0, sizeof(FPDF_BSTR));
|
| + return 0;
|
| +}
|
| +
|
| +FPDF_RESULT FPDF_BStr_Set(FPDF_BSTR* str, FPDF_LPCSTR bstr, int length) {
|
| + if (!str)
|
| + return -1;
|
| + if (!bstr || !length)
|
| + return -1;
|
| + if (length == -1)
|
| + length = FXSYS_strlen(bstr);
|
| +
|
| + if (length == 0) {
|
| + if (str->str) {
|
| + FX_Free(str->str);
|
| + str->str = NULL;
|
| + }
|
| + str->len = 0;
|
| + return 0;
|
| + }
|
| +
|
| + if (str->str && str->len < length)
|
| + str->str = FX_Realloc(char, str->str, length + 1);
|
| + else if (!str->str)
|
| + str->str = FX_Alloc(char, length + 1);
|
| +
|
| + str->str[length] = 0;
|
| + if (str->str == NULL)
|
| + return -1;
|
| +
|
| + FXSYS_memcpy(str->str, bstr, length);
|
| + str->len = length;
|
| +
|
| + return 0;
|
| +}
|
| +
|
| +FPDF_RESULT FPDF_BStr_Clear(FPDF_BSTR* str) {
|
| + if (!str)
|
| + return -1;
|
| +
|
| + if (str->str) {
|
| + FX_Free(str->str);
|
| + str->str = NULL;
|
| + }
|
| + str->len = 0;
|
| + return 0;
|
| +}
|
| +
|
| +#endif
|
| DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document,
|
| int index,
|
| void* buffer,
|
|
|