Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Unified Diff: fpdfsdk/src/fpdfview.cpp

Issue 1477583002: Inflict PDF_ENABLE_XFA ifdefs on XFA fpdfsdk/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: fpdfsdk/src/fpdfview.cpp
diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp
index 1ff100488085b9335326eeeb099cd7d3dad5240b..1333c28756e09ff66fc979d63436040d2cca3b75 100644
--- a/fpdfsdk/src/fpdfview.cpp
+++ b/fpdfsdk/src/fpdfview.cpp
@@ -6,11 +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"
@@ -18,7 +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"
@@ -36,16 +40,27 @@ 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;
Lei Zhang 2015/11/25 00:34:30 #endif here, and another #if PDF_ENABLE_XFA for CF
Tom Sepez 2015/11/25 21:45:30 Yup, manual cleanup to follow. diff is too good a
}
@@ -126,10 +141,12 @@ FX_BOOL CFPDF_FileStream::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;
}
@@ -157,6 +174,7 @@ FX_BOOL CPDF_CustomAccess::GetBlock(FX_DWORD pos,
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,
@@ -217,13 +235,25 @@ DLLEXPORT void STDCALL FPDF_InitLibraryWithConfig(
CPDF_ModuleMgr::Get()->SetCodecModule(g_pCodecModule);
CPDF_ModuleMgr::Get()->InitPageModule();
CPDF_ModuleMgr::Get()->InitRenderModule();
+#ifndef PDF_ENABLE_XFA
+ CPDF_ModuleMgr* pModuleMgr = CPDF_ModuleMgr::Get();
+ if (pModuleMgr) {
Lei Zhang 2015/11/25 00:34:30 Always true, given the lines above.
Tom Sepez 2015/11/25 21:45:30 Done.
+ 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();
@@ -284,6 +314,9 @@ 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;
@@ -326,6 +359,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document,
DLLEXPORT FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document) {
return document && (static_cast<CPDFXFA_Document*>(document))->LoadXFADoc();
+#endif
}
class CMemFile final : public IFX_FileRead {
@@ -414,7 +448,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;
Lei Zhang 2015/11/25 00:34:30 This is a weird discrepancy.
Tom Sepez 2015/11/25 21:45:30 Sure is. It looks like its been this way since be
+#else
return (FX_DWORD)-1;
+#endif
CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict();
return pDict ? pDict->GetInteger("P") : (FX_DWORD)-1;
@@ -439,10 +477,23 @@ DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document,
UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document);
if (!pDoc)
return nullptr;
+#ifndef PDF_ENABLE_XFA
+
Lei Zhang 2015/11/25 00:34:30 blank
Tom Sepez 2015/11/25 21:45:30 Done.
+#endif
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;
+ CPDF_Page* pPage = new CPDF_Page;
+ pPage->Load(pDoc, pDict);
+ pPage->ParseContent();
+ return pPage;
+#else
return pDoc->GetPage(page_index);
+#endif
}
DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) {
@@ -667,13 +718,36 @@ 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()) {
+ pPageView->TakeOverPage();
+ 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;
+
+ CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
+ if (!pParser) {
+ delete pDoc;
+ return;
+ }
+ delete pParser;
+#else
delete CPDFDocumentFromFPDFDocument(document);
+#endif
}
DLLEXPORT unsigned long STDCALL FPDF_GetLastError() {
@@ -693,8 +767,24 @@ 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,
+ rotate);
+ CPDF_Matrix device2page;
+ device2page.SetReverse(page2device);
+
+ FX_FLOAT page_x_f, page_y_f;
+ device2page.Transform((FX_FLOAT)(device_x), (FX_FLOAT)(device_y), page_x_f,
+ page_y_f);
+
+ *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,
@@ -712,8 +802,21 @@ 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);
+
+ FX_FLOAT device_x_f, device_y_f;
+ page2device.Transform(((FX_FLOAT)page_x), ((FX_FLOAT)page_y), device_x_f,
+ device_y_f);
+
+ *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,
@@ -828,6 +931,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;
@@ -877,16 +988,28 @@ DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document,
if (!pDoc)
return FALSE;
+#ifndef PDF_ENABLE_XFA
+ CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
Lei Zhang 2015/11/25 00:34:30 More readable to combine all the XFA path into one
Tom Sepez 2015/11/25 21:45:30 Manual task for later. diff is too smart here.
+ if (!pDict)
+#else
int count = pDoc->GetPageCount();
if (page_index < 0 || page_index >= count)
+#endif
return FALSE;
+#ifndef PDF_ENABLE_XFA
+ CPDF_Page page;
+ page.Load(pDoc, pDict);
+ *width = page.GetPageWidth();
+ *height = page.GetPageHeight();
+#else
CPDFXFA_Page* pPage = pDoc->GetPage(page_index);
if (!pPage)
return FALSE;
*width = pPage->GetPageWidth();
*height = pPage->GetPageHeight();
+#endif
return TRUE;
}
@@ -963,6 +1086,7 @@ 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;
@@ -1015,6 +1139,7 @@ FPDF_RESULT FPDF_BStr_Clear(FPDF_BSTR* str) {
return 0;
}
+#endif
DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document,
int index,
void* buffer,

Powered by Google App Engine
This is Rietveld 408576698