From 1f5f2fff688f4075a62c87a032c9a9070bde89fc Mon Sep 17 00:00:00 2001 From: dsinclair Date: Mon, 25 Apr 2016 14:14:56 -0700 Subject: Fixup page removal for XFA documents. Currently when you call DelegePage on a CPDFXFA_Document the page will not be correctly removed. The page is left in the underlying document and, if GetPage was never called for that page index nothing will happen. This CL updates the code to always remove the page_index from the underlying CPDF_Document then, if needed, the original code runs to clear out the XFA page list for that page. BUG=chromium:596373 Review URL: https://codereview.chromium.org/1921033003 --- fpdfsdk/fpdfdoc_embeddertest.cpp | 8 ++++++++ fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/fpdfsdk/fpdfdoc_embeddertest.cpp b/fpdfsdk/fpdfdoc_embeddertest.cpp index 855235858b..2450b6aea6 100644 --- a/fpdfsdk/fpdfdoc_embeddertest.cpp +++ b/fpdfsdk/fpdfdoc_embeddertest.cpp @@ -6,6 +6,7 @@ #include "core/fxcrt/include/fx_string.h" #include "public/fpdf_doc.h" +#include "public/fpdf_edit.h" #include "public/fpdfview.h" #include "testing/embedder_test.h" #include "testing/fx_string_testhelpers.h" @@ -138,3 +139,10 @@ TEST_F(FPDFDocEmbeddertest, FindBookmarks_bug420) { GetFPDFWideString(L"anything"); EXPECT_EQ(nullptr, FPDFBookmark_Find(document(), title.get())); } + +TEST_F(FPDFDocEmbeddertest, DeletePage) { + EXPECT_TRUE(OpenDocument("hello_world.pdf")); + EXPECT_EQ(1, FPDF_GetPageCount(document())); + FPDFPage_Delete(document(), 0); + EXPECT_EQ(0, FPDF_GetPageCount(document())); +} diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp index d55183751e..72f67dd271 100644 --- a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp +++ b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp @@ -154,6 +154,7 @@ int CPDFXFA_Document::GetPageCount() { CPDFXFA_Page* CPDFXFA_Document::GetPage(int page_index) { if (page_index < 0) return nullptr; + CPDFXFA_Page* pPage = nullptr; int nCount = m_XFAPageList.GetSize(); if (nCount > 0 && page_index < nCount) { @@ -166,6 +167,7 @@ CPDFXFA_Page* CPDFXFA_Document::GetPage(int page_index) { } if (pPage) return pPage; + pPage = new CPDFXFA_Page(this, page_index); if (!pPage->LoadPage()) { pPage->Release(); @@ -177,13 +179,13 @@ CPDFXFA_Page* CPDFXFA_Document::GetPage(int page_index) { CPDFXFA_Page* CPDFXFA_Document::GetPage(CXFA_FFPageView* pPage) { if (!pPage) - return NULL; + return nullptr; if (!m_pXFADoc) - return NULL; + return nullptr; if (m_iDocType != DOCTYPE_DYNAMIC_XFA) - return NULL; + return nullptr; int nSize = m_XFAPageList.GetSize(); for (int i = 0; i < nSize; i++) { @@ -194,10 +196,16 @@ CPDFXFA_Page* CPDFXFA_Document::GetPage(CXFA_FFPageView* pPage) { return pTempPage; } - return NULL; + return nullptr; } void CPDFXFA_Document::DeletePage(int page_index) { + // Delete from the document first because, if GetPage was never called for + // this |page_index| then |m_XFAPageList| may have size < |page_index| even + // if it's a valid page in the document. + if (m_pPDFDoc) + m_pPDFDoc->DeletePage(page_index); + if (page_index < 0 || page_index >= m_XFAPageList.GetSize()) return; -- cgit v1.2.3