summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp6
-rw-r--r--core/fpdfapi/page/cpdf_page.cpp4
-rw-r--r--core/fpdfapi/page/cpdf_page.h7
-rw-r--r--core/fpdfapi/parser/cpdf_document.cpp13
-rw-r--r--core/fpdfapi/parser/cpdf_document.h10
5 files changed, 32 insertions, 8 deletions
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
index 1244b12331..859f5b3991 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);
- auto pTestPage = pdfium::MakeRetain<CPDF_Page>(pDoc.get(), pPageDict, false);
+ RetainPtr<CPDF_Page> pTestPage = pDoc->GetOrCreatePDFPage(pPageDict);
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);
- auto pTestPage = pdfium::MakeRetain<CPDF_Page>(pDoc.get(), pPageDict, false);
+ RetainPtr<CPDF_Page> pTestPage = pDoc->GetOrCreatePDFPage(pPageDict);
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);
- auto pTestPage = pdfium::MakeRetain<CPDF_Page>(pDoc.get(), pPageDict, false);
+ RetainPtr<CPDF_Page> pTestPage = pDoc->GetOrCreatePDFPage(pPageDict);
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 7c0a3234c9..c5c85635b2 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 bPageCache)
+ bool bUseRenderCache)
: CPDF_PageObjectHolder(pDocument, pPageDict),
m_PageSize(100, 100),
m_pPDFDocument(pDocument) {
- if (bPageCache)
+ if (bUseRenderCache)
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 0bb99b73f1..b94326e47b 100644
--- a/core/fpdfapi/page/cpdf_page.h
+++ b/core/fpdfapi/page/cpdf_page.h
@@ -12,6 +12,7 @@
#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"
@@ -22,7 +23,9 @@ class CPDF_Object;
class CPDF_PageRenderCache;
class CPDF_PageRenderContext;
-class CPDF_Page : public Retainable, public CPDF_PageObjectHolder {
+class CPDF_Page : public Retainable,
+ public Observable<CPDF_Page>,
+ public CPDF_PageObjectHolder {
public:
class View {}; // Caller implements as desired, empty here due to layering.
class Extension : public Retainable {}; // XFA page parent class, layering.
@@ -66,7 +69,7 @@ class CPDF_Page : public Retainable, public CPDF_PageObjectHolder {
private:
CPDF_Page(CPDF_Document* pDocument,
CPDF_Dictionary* pPageDict,
- bool bPageCache);
+ bool bUseRenderCache);
~CPDF_Page() override;
void StartParse();
diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp
index 7968d1b019..2e4baabe91 100644
--- a/core/fpdfapi/parser/cpdf_document.cpp
+++ b/core/fpdfapi/parser/cpdf_document.cpp
@@ -602,6 +602,19 @@ 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 c2774b163a..c240e77567 100644
--- a/core/fpdfapi/parser/cpdf_document.h
+++ b/core/fpdfapi/parser/cpdf_document.h
@@ -8,6 +8,7 @@
#define CORE_FPDFAPI_PARSER_CPDF_DOCUMENT_H_
#include <functional>
+#include <map>
#include <memory>
#include <set>
#include <utility>
@@ -64,6 +65,7 @@ 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;
@@ -167,7 +169,13 @@ 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;
- std::vector<uint32_t> m_PageList; // Page number to page's dict objnum.
+
+ // 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;
+
UnownedPtr<Extension> m_pExtension;
};