From fe06d5109cd575c1e53b9b1cc3cc4ec3c5d7364f Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 1 May 2018 17:25:25 +0000 Subject: Make FPDF_Document always be CPDF_Document. Greatly minimize the impact between going back and forth from XFA being on/off, so that XFA case is just an extension beyond the non-XFA data structures we've shipped for years, instead of being a complete replacement of them. Change-Id: I6c98206e0ec99ea443547a4931eba912b1764d54 Reviewed-on: https://pdfium-review.googlesource.com/31690 Reviewed-by: dsinclair Commit-Queue: Tom Sepez --- fpdfsdk/fpdf_view.cpp | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'fpdfsdk/fpdf_view.cpp') diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp index 0015716d98..00c59bbda5 100644 --- a/fpdfsdk/fpdf_view.cpp +++ b/fpdfsdk/fpdf_view.cpp @@ -256,7 +256,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDF_GetFormType(FPDF_DOCUMENT document) { #ifdef PDF_ENABLE_XFA FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_LoadXFA(FPDF_DOCUMENT document) { - return document && static_cast(document)->LoadXFADoc(); + auto* pDoc = CPDFDocumentFromFPDFDocument(document); + return pDoc && + static_cast(pDoc->GetExtension())->LoadXFADoc(); } #endif // PDF_ENABLE_XFA @@ -320,21 +322,30 @@ FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) { } FPDF_EXPORT int FPDF_CALLCONV FPDF_GetPageCount(FPDF_DOCUMENT document) { - UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); - return pDoc ? pDoc->GetPageCount() : 0; + auto* pDoc = CPDFDocumentFromFPDFDocument(document); + if (!pDoc) + return 0; +#ifdef PDF_ENABLE_XFA + auto* pContext = static_cast(pDoc->GetExtension()); + return pContext ? pContext->GetPageCount() : 0; +#else + return pDoc->GetPageCount(); +#endif } FPDF_EXPORT FPDF_PAGE FPDF_CALLCONV FPDF_LoadPage(FPDF_DOCUMENT document, int page_index) { - UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); + auto* pDoc = CPDFDocumentFromFPDFDocument(document); if (!pDoc) return nullptr; - if (page_index < 0 || page_index >= pDoc->GetPageCount()) + if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) return nullptr; #ifdef PDF_ENABLE_XFA - return pDoc->GetXFAPage(page_index).Leak(); + return static_cast(pDoc->GetExtension()) + ->GetXFAPage(page_index) + .Leak(); #else // PDF_ENABLE_XFA CPDF_Dictionary* pDict = pDoc->GetPage(page_index); if (!pDict) @@ -740,7 +751,14 @@ FPDF_EXPORT void FPDF_CALLCONV FPDF_ClosePage(FPDF_PAGE page) { } FPDF_EXPORT void FPDF_CALLCONV FPDF_CloseDocument(FPDF_DOCUMENT document) { - delete UnderlyingFromFPDFDocument(document); + auto* pDoc = CPDFDocumentFromFPDFDocument(document); +#if PDF_ENABLE_XFA + // Deleting the extension will delete the document + if (pDoc) + delete pDoc->GetExtension(); +#else + delete pDoc; +#endif } FPDF_EXPORT unsigned long FPDF_CALLCONV FPDF_GetLastError() { @@ -918,15 +936,16 @@ FPDF_EXPORT int FPDF_CALLCONV FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, int page_index, double* width, double* height) { - UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); + auto* pDoc = CPDFDocumentFromFPDFDocument(document); if (!pDoc) return false; #ifdef PDF_ENABLE_XFA - int count = pDoc->GetPageCount(); - if (page_index < 0 || page_index >= count) + if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) return false; - RetainPtr pPage = pDoc->GetXFAPage(page_index); + RetainPtr pPage = + static_cast(pDoc->GetExtension()) + ->GetXFAPage(page_index); if (!pPage) return false; *width = pPage->GetPageWidth(); -- cgit v1.2.3