diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-06-04 18:26:07 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-06-04 18:26:07 +0000 |
commit | f06ed6d3578fff9e1d2990e5757dc460e60e5dd3 (patch) | |
tree | 80a0b51c34053bcce961d43905afaef33b33c4da | |
parent | 168c763539e70bea450701470c47a8991f578336 (diff) | |
download | pdfium-f06ed6d3578fff9e1d2990e5757dc460e60e5dd3.tar.xz |
Revert "Make CPDF_Document cache CPDF_Pages"
This reverts commit f0d9d28a034fe3650c3c2d662090c1e8687ddb16.
Reason for revert: avoid parsing page.
Change-Id: Id3478f7e38f1cbe95d098e00158b1d7d9dc6f76e
Reviewed-on: https://pdfium-review.googlesource.com/33750
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
-rw-r--r-- | core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp | 6 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_page.cpp | 4 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_page.h | 7 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_document.cpp | 13 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_document.h | 10 | ||||
-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 | ||||
-rw-r--r-- | fxjs/cjs_document.cpp | 6 |
12 files changed, 32 insertions, 43 deletions
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp index 859f5b3991..1244b12331 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp @@ -129,7 +129,7 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessGraphics) { auto pDoc = pdfium::MakeUnique<CPDF_Document>(nullptr); pDoc->CreateNewDoc(); CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(0); - RetainPtr<CPDF_Page> pTestPage = pDoc->GetOrCreatePDFPage(pPageDict); + auto pTestPage = pdfium::MakeRetain<CPDF_Page>(pDoc.get(), pPageDict, false); CPDF_PageContentGenerator generator(pTestPage.Get()); std::ostringstream buf; TestProcessPath(&generator, &buf, pPathObj.get()); @@ -168,7 +168,7 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessStandardText) { auto pDoc = pdfium::MakeUnique<CPDF_Document>(nullptr); pDoc->CreateNewDoc(); CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(0); - RetainPtr<CPDF_Page> pTestPage = pDoc->GetOrCreatePDFPage(pPageDict); + auto pTestPage = pdfium::MakeRetain<CPDF_Page>(pDoc.get(), pPageDict, false); CPDF_PageContentGenerator generator(pTestPage.Get()); auto pTextObj = pdfium::MakeUnique<CPDF_TextObject>(); CPDF_Font* pFont = CPDF_Font::GetStockFont(pDoc.get(), "Times-Roman"); @@ -231,7 +231,7 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessText) { auto pDoc = pdfium::MakeUnique<CPDF_Document>(nullptr); pDoc->CreateNewDoc(); CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(0); - RetainPtr<CPDF_Page> pTestPage = pDoc->GetOrCreatePDFPage(pPageDict); + auto pTestPage = pdfium::MakeRetain<CPDF_Page>(pDoc.get(), pPageDict, false); CPDF_PageContentGenerator generator(pTestPage.Get()); std::ostringstream buf; diff --git a/core/fpdfapi/page/cpdf_page.cpp b/core/fpdfapi/page/cpdf_page.cpp index c5c85635b2..7c0a3234c9 100644 --- a/core/fpdfapi/page/cpdf_page.cpp +++ b/core/fpdfapi/page/cpdf_page.cpp @@ -21,11 +21,11 @@ CPDF_Page::CPDF_Page(CPDF_Document* pDocument, CPDF_Dictionary* pPageDict, - bool bUseRenderCache) + bool bPageCache) : CPDF_PageObjectHolder(pDocument, pPageDict), m_PageSize(100, 100), m_pPDFDocument(pDocument) { - if (bUseRenderCache) + if (bPageCache) m_pPageRender = pdfium::MakeUnique<CPDF_PageRenderCache>(this); if (!pPageDict) return; diff --git a/core/fpdfapi/page/cpdf_page.h b/core/fpdfapi/page/cpdf_page.h index b94326e47b..0bb99b73f1 100644 --- a/core/fpdfapi/page/cpdf_page.h +++ b/core/fpdfapi/page/cpdf_page.h @@ -12,7 +12,6 @@ #include "core/fpdfapi/page/cpdf_pageobjectholder.h" #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_system.h" -#include "core/fxcrt/observable.h" #include "core/fxcrt/retain_ptr.h" #include "core/fxcrt/unowned_ptr.h" #include "third_party/base/optional.h" @@ -23,9 +22,7 @@ class CPDF_Object; class CPDF_PageRenderCache; class CPDF_PageRenderContext; -class CPDF_Page : public Retainable, - public Observable<CPDF_Page>, - public CPDF_PageObjectHolder { +class CPDF_Page : public Retainable, public CPDF_PageObjectHolder { public: class View {}; // Caller implements as desired, empty here due to layering. class Extension : public Retainable {}; // XFA page parent class, layering. @@ -69,7 +66,7 @@ class CPDF_Page : public Retainable, private: CPDF_Page(CPDF_Document* pDocument, CPDF_Dictionary* pPageDict, - bool bUseRenderCache); + bool bPageCache); ~CPDF_Page() override; void StartParse(); diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp index 412f726eca..995d7edaf9 100644 --- a/core/fpdfapi/parser/cpdf_document.cpp +++ b/core/fpdfapi/parser/cpdf_document.cpp @@ -602,19 +602,6 @@ bool CPDF_Document::InsertNewPage(int iPage, CPDF_Dictionary* pPageDict) { return true; } -RetainPtr<CPDF_Page> CPDF_Document::GetOrCreatePDFPage( - CPDF_Dictionary* pPageDict) { - std::pair<uint32_t, uint32_t> key = {pPageDict->GetObjNum(), - pPageDict->GetGenNum()}; - if (m_PageMap[key]) - return RetainPtr<CPDF_Page>(m_PageMap[key].Get()); - - auto pPage = pdfium::MakeRetain<CPDF_Page>(this, pPageDict, true); - pPage->ParseContent(); - m_PageMap[key].Reset(pPage.Get()); - return pPage; -} - void CPDF_Document::DeletePage(int iPage) { CPDF_Dictionary* pPages = GetPagesDict(); if (!pPages) diff --git a/core/fpdfapi/parser/cpdf_document.h b/core/fpdfapi/parser/cpdf_document.h index c096e89e28..fe3f170114 100644 --- a/core/fpdfapi/parser/cpdf_document.h +++ b/core/fpdfapi/parser/cpdf_document.h @@ -8,7 +8,6 @@ #define CORE_FPDFAPI_PARSER_CPDF_DOCUMENT_H_ #include <functional> -#include <map> #include <memory> #include <set> #include <utility> @@ -67,7 +66,6 @@ class CPDF_Document : public CPDF_IndirectObjectHolder { const CPDF_Dictionary* GetInfo() const { return m_pInfoDict.Get(); } CPDF_Dictionary* GetInfo() { return m_pInfoDict.Get(); } - RetainPtr<CPDF_Page> GetOrCreatePDFPage(CPDF_Dictionary* pPageDict); void DeletePage(int iPage); int GetPageCount() const; bool IsPageLoaded(int iPage) const; @@ -171,13 +169,7 @@ class CPDF_Document : public CPDF_IndirectObjectHolder { std::unique_ptr<CPDF_DocRenderData> m_pDocRender; std::unique_ptr<JBig2_DocumentContext> m_pCodecContext; std::unique_ptr<CPDF_LinkList> m_pLinksContext; - - // Page number (index) to page's dict objnum. - std::vector<uint32_t> m_PageList; - - // Dict {objnum, gennum} to page mapping. - std::map<std::pair<uint32_t, uint32_t>, CPDF_Page::ObservedPtr> m_PageMap; - + std::vector<uint32_t> m_PageList; // Page number to page's dict objnum. std::unique_ptr<Extension> m_pExtension; }; diff --git a/fpdfsdk/fpdf_doc_embeddertest.cpp b/fpdfsdk/fpdf_doc_embeddertest.cpp index a9e4701e1d..c1f5e02ed6 100644 --- a/fpdfsdk/fpdf_doc_embeddertest.cpp +++ b/fpdfsdk/fpdf_doc_embeddertest.cpp @@ -27,7 +27,11 @@ 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 b8ceea5724..094349f694 100644 --- a/fpdfsdk/fpdf_editpage.cpp +++ b/fpdfsdk/fpdf_editpage.cpp @@ -200,7 +200,8 @@ 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 - RetainPtr<CPDF_Page> pPage = pDoc->GetOrCreatePDFPage(pPageDict); + auto pPage = pdfium::MakeRetain<CPDF_Page>(pDoc, pPageDict, true); + pPage->ParseContent(); return FPDFPageFromUnderlying(pPage.Leak()); // Caller takes ownership. #endif // PDF_ENABLE_XFA } diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp index 2d81f1230e..720fa9ff55 100644 --- a/fpdfsdk/fpdf_flatten.cpp +++ b/fpdfsdk/fpdf_flatten.cpp @@ -47,7 +47,9 @@ bool IsValidRect(const CFX_FloatRect& rect, const CFX_FloatRect& rcPage) { void GetContentsRect(CPDF_Document* pDoc, CPDF_Dictionary* pDict, std::vector<CFX_FloatRect>* pRectArray) { - RetainPtr<CPDF_Page> pPDFPage = pDoc->GetOrCreatePDFPage(pDict); + auto pPDFPage = pdfium::MakeRetain<CPDF_Page>(pDoc, pDict, false); + pPDFPage->ParseContent(); + 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 4ea3334b65..b73042466b 100644 --- a/fpdfsdk/fpdf_ppo.cpp +++ b/fpdfsdk/fpdf_ppo.cpp @@ -618,7 +618,7 @@ bool CPDF_NPageToOneExporter::ExportNPagesToOne( if (!pSrcPageDict) return false; - RetainPtr<CPDF_Page> srcPage = src()->GetOrCreatePDFPage(pSrcPageDict); + auto srcPage = pdfium::MakeRetain<CPDF_Page>(src(), pSrcPageDict, true); NupPageSettings settings = nupState.CalculateNewPagePosition(srcPage->GetPageSize()); AddSubPage(pSrcPageDict, settings, &objectNumberMap, &pageXObjectMap, diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp index e38c651cbe..1b33952204 100644 --- a/fpdfsdk/fpdf_view.cpp +++ b/fpdfsdk/fpdf_view.cpp @@ -360,7 +360,8 @@ FPDF_EXPORT FPDF_PAGE FPDF_CALLCONV FPDF_LoadPage(FPDF_DOCUMENT document, if (!pDict) return nullptr; - RetainPtr<CPDF_Page> pPage = pDoc->GetOrCreatePDFPage(pDict); + auto pPage = pdfium::MakeRetain<CPDF_Page>(pDoc, pDict, true); + pPage->ParseContent(); return FPDFPageFromUnderlying(pPage.Leak()); #endif // PDF_ENABLE_XFA } @@ -958,7 +959,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, if (!pDict) return false; - RetainPtr<CPDF_Page> page = pDoc->GetOrCreatePDFPage(pDict); + auto page = pdfium::MakeRetain<CPDF_Page>(pDoc, pDict, true); *width = page->GetPageWidth(); *height = page->GetPageHeight(); return true; diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp index f4120896a8..4d7e3bc222 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp @@ -34,9 +34,10 @@ bool CPDFXFA_Page::LoadPDFPage() { if (!pDict) return false; - if (!m_pPDFPage || m_pPDFPage->GetFormDict() != pDict) - m_pPDFPage = pPDFDoc->GetOrCreatePDFPage(pDict); - + if (!m_pPDFPage || m_pPDFPage->GetFormDict() != pDict) { + m_pPDFPage = pdfium::MakeRetain<CPDF_Page>(pPDFDoc, pDict, true); + m_pPDFPage->ParseContent(); + } return true; } @@ -79,7 +80,9 @@ bool CPDFXFA_Page::LoadPDFPage(CPDF_Dictionary* pageDict) { if (!m_pContext || m_iPageIndex < 0 || !pageDict) return false; - m_pPDFPage = m_pContext->GetPDFDoc()->GetOrCreatePDFPage(pageDict); + m_pPDFPage = + pdfium::MakeRetain<CPDF_Page>(m_pContext->GetPDFDoc(), pageDict, true); + m_pPDFPage->ParseContent(); return true; } diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp index b2cc1eb72c..533decf1dc 100644 --- a/fxjs/cjs_document.cpp +++ b/fxjs/cjs_document.cpp @@ -1256,7 +1256,8 @@ CJS_Return CJS_Document::getPageNthWord( if (!pPageDict) return CJS_Return(false); - RetainPtr<CPDF_Page> page = pDocument->GetOrCreatePDFPage(pPageDict); + auto page = pdfium::MakeRetain<CPDF_Page>(pDocument, pPageDict, true); + page->ParseContent(); int nWords = 0; WideString swRet; @@ -1304,7 +1305,8 @@ CJS_Return CJS_Document::getPageNumWords( if (!pPageDict) return CJS_Return(false); - RetainPtr<CPDF_Page> page = pDocument->GetOrCreatePDFPage(pPageDict); + auto page = pdfium::MakeRetain<CPDF_Page>(pDocument, pPageDict, true); + page->ParseContent(); int nWords = 0; for (auto& pPageObj : *page->GetPageObjectList()) { |