diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-05-30 16:40:00 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-05-30 16:40:00 +0000 |
commit | f0d9d28a034fe3650c3c2d662090c1e8687ddb16 (patch) | |
tree | 6f25857014a0c76445cab264db99f355a4446e3d /fpdfsdk | |
parent | 163b4a4117bcc0b2bd1866d32205fbfb9cc01e02 (diff) | |
download | pdfium-f0d9d28a034fe3650c3c2d662090c1e8687ddb16.tar.xz |
Make CPDF_Document cache CPDF_Pages
We cache pages not by page number, which can bounce around as pages
are inserted or removed, but by page dictionary's object number.
Since the page may be created under one function and used under
another, we can't take the shortcut of not instantiating a render
cache nor not parsing the page.
Change-Id: I9a325cda8b3141153544ac53e78a51a44e6b411a
Reviewed-on: https://pdfium-review.googlesource.com/32830
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/fpdf_doc_embeddertest.cpp | 4 | ||||
-rw-r--r-- | fpdfsdk/fpdf_editpage.cpp | 3 | ||||
-rw-r--r-- | fpdfsdk/fpdf_flatten.cpp | 4 | ||||
-rw-r--r-- | fpdfsdk/fpdf_ppo.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/fpdf_view.cpp | 5 | ||||
-rw-r--r-- | fpdfsdk/fpdfxfa/cpdfxfa_page.cpp | 11 |
6 files changed, 9 insertions, 20 deletions
diff --git a/fpdfsdk/fpdf_doc_embeddertest.cpp b/fpdfsdk/fpdf_doc_embeddertest.cpp index c1f5e02ed6..a9e4701e1d 100644 --- a/fpdfsdk/fpdf_doc_embeddertest.cpp +++ b/fpdfsdk/fpdf_doc_embeddertest.cpp @@ -27,11 +27,7 @@ TEST_F(FPDFDocEmbeddertest, MultipleSamePage) { ref.reset(FPDF_LoadPage(document(), 0)); unique_pages.insert(ref.get()); } -#ifdef PDF_ENABLE_XFA EXPECT_EQ(1u, unique_pages.size()); -#else // PDF_ENABLE_XFA - EXPECT_EQ(4u, unique_pages.size()); -#endif // PDF_ENABLE_XFA } TEST_F(FPDFDocEmbeddertest, DestGetPageIndex) { diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp index 39cf85fb95..9fb6c1fedf 100644 --- a/fpdfsdk/fpdf_editpage.cpp +++ b/fpdfsdk/fpdf_editpage.cpp @@ -196,8 +196,7 @@ FPDF_EXPORT FPDF_PAGE FPDF_CALLCONV FPDFPage_New(FPDF_DOCUMENT document, // Eventually, fallthru into non-XFA case once page type is consistent. return nullptr; #else // PDF_ENABLE_XFA - auto pPage = pdfium::MakeRetain<CPDF_Page>(pDoc, pPageDict, true); - pPage->ParseContent(); + RetainPtr<CPDF_Page> pPage = pDoc->GetOrCreatePDFPage(pPageDict); return FPDFPageFromUnderlying(pPage.Leak()); // Caller takes ownership. #endif // PDF_ENABLE_XFA } diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp index 720fa9ff55..2d81f1230e 100644 --- a/fpdfsdk/fpdf_flatten.cpp +++ b/fpdfsdk/fpdf_flatten.cpp @@ -47,9 +47,7 @@ bool IsValidRect(const CFX_FloatRect& rect, const CFX_FloatRect& rcPage) { void GetContentsRect(CPDF_Document* pDoc, CPDF_Dictionary* pDict, std::vector<CFX_FloatRect>* pRectArray) { - auto pPDFPage = pdfium::MakeRetain<CPDF_Page>(pDoc, pDict, false); - pPDFPage->ParseContent(); - + RetainPtr<CPDF_Page> pPDFPage = pDoc->GetOrCreatePDFPage(pDict); for (const auto& pPageObject : *pPDFPage->GetPageObjectList()) { CFX_FloatRect rc; rc.left = pPageObject->m_Left; diff --git a/fpdfsdk/fpdf_ppo.cpp b/fpdfsdk/fpdf_ppo.cpp index b73042466b..4ea3334b65 100644 --- a/fpdfsdk/fpdf_ppo.cpp +++ b/fpdfsdk/fpdf_ppo.cpp @@ -618,7 +618,7 @@ bool CPDF_NPageToOneExporter::ExportNPagesToOne( if (!pSrcPageDict) return false; - auto srcPage = pdfium::MakeRetain<CPDF_Page>(src(), pSrcPageDict, true); + RetainPtr<CPDF_Page> srcPage = src()->GetOrCreatePDFPage(pSrcPageDict); NupPageSettings settings = nupState.CalculateNewPagePosition(srcPage->GetPageSize()); AddSubPage(pSrcPageDict, settings, &objectNumberMap, &pageXObjectMap, diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp index af9117579d..9af0ca4755 100644 --- a/fpdfsdk/fpdf_view.cpp +++ b/fpdfsdk/fpdf_view.cpp @@ -354,8 +354,7 @@ FPDF_EXPORT FPDF_PAGE FPDF_CALLCONV FPDF_LoadPage(FPDF_DOCUMENT document, if (!pDict) return nullptr; - auto pPage = pdfium::MakeRetain<CPDF_Page>(pDoc, pDict, true); - pPage->ParseContent(); + RetainPtr<CPDF_Page> pPage = pDoc->GetOrCreatePDFPage(pDict); return FPDFPageFromUnderlying(pPage.Leak()); #endif // PDF_ENABLE_XFA } @@ -962,7 +961,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, if (!pDict) return false; - auto page = pdfium::MakeRetain<CPDF_Page>(pDoc, pDict, true); + RetainPtr<CPDF_Page> page = pDoc->GetOrCreatePDFPage(pDict); *width = page->GetPageWidth(); *height = page->GetPageHeight(); return true; diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp index 4d7e3bc222..f4120896a8 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp @@ -34,10 +34,9 @@ bool CPDFXFA_Page::LoadPDFPage() { if (!pDict) return false; - if (!m_pPDFPage || m_pPDFPage->GetFormDict() != pDict) { - m_pPDFPage = pdfium::MakeRetain<CPDF_Page>(pPDFDoc, pDict, true); - m_pPDFPage->ParseContent(); - } + if (!m_pPDFPage || m_pPDFPage->GetFormDict() != pDict) + m_pPDFPage = pPDFDoc->GetOrCreatePDFPage(pDict); + return true; } @@ -80,9 +79,7 @@ bool CPDFXFA_Page::LoadPDFPage(CPDF_Dictionary* pageDict) { if (!m_pContext || m_iPageIndex < 0 || !pageDict) return false; - m_pPDFPage = - pdfium::MakeRetain<CPDF_Page>(m_pContext->GetPDFDoc(), pageDict, true); - m_pPDFPage->ParseContent(); + m_pPDFPage = m_pContext->GetPDFDoc()->GetOrCreatePDFPage(pageDict); return true; } |