From 22eb7ae54e4351f70a5a01b0130c8b0dc713586c Mon Sep 17 00:00:00 2001 From: Jane Liu Date: Mon, 26 Jun 2017 13:24:23 -0400 Subject: Modified CPDF_PageContentGenerator to work with both Form and Page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CPDF_PageContentGenerator currently only works for CPDF_Page objects. However, CPDF_Form is also a CPDF_PageObjectHolder like CPDF_Page, and content streams can be generated for form objects too. This CL modifies the content generator to work with both forms and pages. The content generator will later be used on annotation objects' CPDF_Form to simplify the code for annotation AP stream generation. Change-Id: I1c50bdf0329d1f5788db23286ac72750355a10ed Reviewed-on: https://pdfium-review.googlesource.com/6837 Commit-Queue: Nicolás Peña Reviewed-by: dsinclair Reviewed-by: Nicolás Peña --- core/fpdfapi/page/cpdf_page.cpp | 4 ++++ core/fpdfapi/page/cpdf_page.h | 22 +++------------------- core/fpdfapi/page/cpdf_pageobjectholder.cpp | 4 ++++ core/fpdfapi/page/cpdf_pageobjectholder.h | 20 ++++++++++++++++++++ 4 files changed, 31 insertions(+), 19 deletions(-) (limited to 'core/fpdfapi/page') diff --git a/core/fpdfapi/page/cpdf_page.cpp b/core/fpdfapi/page/cpdf_page.cpp index 075aa9023d..dfbd342f13 100644 --- a/core/fpdfapi/page/cpdf_page.cpp +++ b/core/fpdfapi/page/cpdf_page.cpp @@ -74,6 +74,10 @@ CPDF_Page::CPDF_Page(CPDF_Document* pDocument, CPDF_Page::~CPDF_Page() {} +bool CPDF_Page::IsPage() const { + return true; +} + void CPDF_Page::StartParse() { if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) return; diff --git a/core/fpdfapi/page/cpdf_page.h b/core/fpdfapi/page/cpdf_page.h index 0a080a58ae..82df60ce9f 100644 --- a/core/fpdfapi/page/cpdf_page.h +++ b/core/fpdfapi/page/cpdf_page.h @@ -7,7 +7,6 @@ #ifndef CORE_FPDFAPI_PAGE_CPDF_PAGE_H_ #define CORE_FPDFAPI_PAGE_CPDF_PAGE_H_ -#include #include #include "core/fpdfapi/page/cpdf_pageobjectholder.h" @@ -21,21 +20,6 @@ class CPDF_Object; class CPDF_PageRenderCache; class CPDF_PageRenderContext; -// These structs are used to keep track of resources that have already been -// generated in the page. -struct GraphicsData { - float fillAlpha; - float strokeAlpha; - int blendType; - bool operator<(const GraphicsData& other) const; -}; - -struct FontData { - CFX_ByteString baseFont; - CFX_ByteString type; - bool operator<(const FontData& other) const; -}; - class CPDF_Page : public CPDF_PageObjectHolder { public: class View {}; // Caller implements as desired, empty here due to layering. @@ -45,6 +29,9 @@ class CPDF_Page : public CPDF_PageObjectHolder { bool bPageCache); ~CPDF_Page() override; + // CPDF_PageObjectHolder + bool IsPage() const override; + void ParseContent(); CFX_Matrix GetDisplayMatrix(int xPos, @@ -68,9 +55,6 @@ class CPDF_Page : public CPDF_PageObjectHolder { View* GetView() const { return m_pView; } void SetView(View* pView) { m_pView = pView; } - std::map m_GraphicsMap; - std::map m_FontsMap; - private: void StartParse(); diff --git a/core/fpdfapi/page/cpdf_pageobjectholder.cpp b/core/fpdfapi/page/cpdf_pageobjectholder.cpp index 53dfd75d5d..50ef780396 100644 --- a/core/fpdfapi/page/cpdf_pageobjectholder.cpp +++ b/core/fpdfapi/page/cpdf_pageobjectholder.cpp @@ -25,6 +25,10 @@ CPDF_PageObjectHolder::CPDF_PageObjectHolder(CPDF_Document* pDoc, CPDF_PageObjectHolder::~CPDF_PageObjectHolder() {} +bool CPDF_PageObjectHolder::IsPage() const { + return false; +} + void CPDF_PageObjectHolder::ContinueParse(IFX_Pause* pPause) { if (!m_pParser) return; diff --git a/core/fpdfapi/page/cpdf_pageobjectholder.h b/core/fpdfapi/page/cpdf_pageobjectholder.h index c95ae50520..4733e06b2c 100644 --- a/core/fpdfapi/page/cpdf_pageobjectholder.h +++ b/core/fpdfapi/page/cpdf_pageobjectholder.h @@ -7,6 +7,7 @@ #ifndef CORE_FPDFAPI_PAGE_CPDF_PAGEOBJECTHOLDER_H_ #define CORE_FPDFAPI_PAGE_CPDF_PAGEOBJECTHOLDER_H_ +#include #include #include @@ -25,11 +26,28 @@ class CPDF_ContentParser; #define PDFTRANS_ISOLATED 0x0200 #define PDFTRANS_KNOCKOUT 0x0400 +// These structs are used to keep track of resources that have already been +// generated in the page object holder. +struct GraphicsData { + float fillAlpha; + float strokeAlpha; + int blendType; + bool operator<(const GraphicsData& other) const; +}; + +struct FontData { + CFX_ByteString baseFont; + CFX_ByteString type; + bool operator<(const FontData& other) const; +}; + class CPDF_PageObjectHolder { public: CPDF_PageObjectHolder(CPDF_Document* pDoc, CPDF_Dictionary* pFormDict); virtual ~CPDF_PageObjectHolder(); + virtual bool IsPage() const; + void ContinueParse(IFX_Pause* pPause); bool IsParsed() const { return m_ParseState == CONTENT_PARSED; } @@ -56,6 +74,8 @@ class CPDF_PageObjectHolder { CFX_UnownedPtr m_pDocument; CFX_UnownedPtr m_pPageResources; CFX_UnownedPtr m_pResources; + std::map m_GraphicsMap; + std::map m_FontsMap; CFX_FloatRect m_BBox; int m_Transparency; -- cgit v1.2.3