From cec01808e8b155f598b2a9ea527736ce774e76a2 Mon Sep 17 00:00:00 2001 From: rbpotter Date: Mon, 17 Apr 2017 09:10:21 -0700 Subject: Render image masks individually instead of rendering the entire page as a bitmap in order to reduce spool sizes. BUG=682156, 674771 Change-Id: Ic743ba729a7b9609be18fb620a5eb6bc440aed6a Reviewed-on: https://pdfium-review.googlesource.com/2916 Commit-Queue: Lei Zhang Reviewed-by: Lei Zhang --- core/fpdfapi/page/cpdf_pageobjectholder.cpp | 5 ++++- core/fpdfapi/page/cpdf_pageobjectholder.h | 11 +++++++---- core/fpdfapi/page/cpdf_streamcontentparser.cpp | 10 +++++++--- core/fpdfapi/render/cpdf_progressiverenderer.cpp | 6 ++++++ core/fpdfapi/render/cpdf_renderoptions.h | 1 + 5 files changed, 25 insertions(+), 8 deletions(-) (limited to 'core') diff --git a/core/fpdfapi/page/cpdf_pageobjectholder.cpp b/core/fpdfapi/page/cpdf_pageobjectholder.cpp index 974baa65a0..5f5597e5ac 100644 --- a/core/fpdfapi/page/cpdf_pageobjectholder.cpp +++ b/core/fpdfapi/page/cpdf_pageobjectholder.cpp @@ -21,7 +21,6 @@ CPDF_PageObjectHolder::CPDF_PageObjectHolder() m_pResources(nullptr), m_Transparency(0), m_bBackgroundAlphaNeeded(false), - m_bHasImageMask(false), m_ParseState(CONTENT_NOT_PARSED) {} CPDF_PageObjectHolder::~CPDF_PageObjectHolder() {} @@ -37,6 +36,10 @@ void CPDF_PageObjectHolder::ContinueParse(IFX_Pause* pPause) { } } +void CPDF_PageObjectHolder::AddImageMaskBoundingBox(const CFX_FloatRect& box) { + m_MaskBoundingBoxes.push_back(box); +} + void CPDF_PageObjectHolder::Transform(const CFX_Matrix& matrix) { for (auto& pObj : m_PageObjectList) pObj->Transform(matrix); diff --git a/core/fpdfapi/page/cpdf_pageobjectholder.h b/core/fpdfapi/page/cpdf_pageobjectholder.h index aee7617c1f..0b88a86518 100644 --- a/core/fpdfapi/page/cpdf_pageobjectholder.h +++ b/core/fpdfapi/page/cpdf_pageobjectholder.h @@ -8,6 +8,7 @@ #define CORE_FPDFAPI_PAGE_CPDF_PAGEOBJECTHOLDER_H_ #include +#include #include "core/fpdfapi/page/cpdf_pageobjectlist.h" #include "core/fxcrt/fx_coordinates.h" @@ -41,9 +42,11 @@ class CPDF_PageObjectHolder { m_bBackgroundAlphaNeeded = needed; } - bool HasImageMask() const { return m_bHasImageMask; } - void SetHasImageMask(bool value) { m_bHasImageMask = value; } - + bool HasImageMask() const { return !m_MaskBoundingBoxes.empty(); } + const std::vector& GetMaskBoundingBoxes() const { + return m_MaskBoundingBoxes; + } + void AddImageMaskBoundingBox(const CFX_FloatRect& box); void Transform(const CFX_Matrix& matrix); CFX_FloatRect CalcBoundingBox() const; @@ -61,7 +64,7 @@ class CPDF_PageObjectHolder { void LoadTransInfo(); bool m_bBackgroundAlphaNeeded; - bool m_bHasImageMask; + std::vector m_MaskBoundingBoxes; ParseState m_ParseState; std::unique_ptr m_pParser; CPDF_PageObjectList m_PageObjectList; diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp index 30686133c2..d9f12f121b 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp +++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp @@ -735,7 +735,11 @@ void CPDF_StreamContentParser::Handle_ExecuteXObject() { CFX_ByteString name = GetString(0); if (name == m_LastImageName && m_pLastImage && m_pLastImage->GetStream() && m_pLastImage->GetStream()->GetObjNum()) { - AddImage(m_pLastImage); + CPDF_ImageObject* pObj = AddImage(m_pLastImage); + // Record the bounding box of this image, so rendering code can draw it + // properly. + if (pObj->GetImage()->IsMask()) + m_pObjectHolder->AddImageMaskBoundingBox(pObj->GetRect()); return; } @@ -757,8 +761,8 @@ void CPDF_StreamContentParser::Handle_ExecuteXObject() { m_LastImageName = name; m_pLastImage = pObj->GetImage(); - if (!m_pObjectHolder->HasImageMask()) - m_pObjectHolder->SetHasImageMask(m_pLastImage->IsMask()); + if (m_pLastImage->IsMask()) + m_pObjectHolder->AddImageMaskBoundingBox(pObj->GetRect()); } else if (type == "Form") { AddForm(pXObject); } diff --git a/core/fpdfapi/render/cpdf_progressiverenderer.cpp b/core/fpdfapi/render/cpdf_progressiverenderer.cpp index 6aa3b8a309..c3cef1fc77 100644 --- a/core/fpdfapi/render/cpdf_progressiverenderer.cpp +++ b/core/fpdfapi/render/cpdf_progressiverenderer.cpp @@ -6,6 +6,8 @@ #include "core/fpdfapi/render/cpdf_progressiverenderer.h" +#include "core/fpdfapi/page/cpdf_image.h" +#include "core/fpdfapi/page/cpdf_imageobject.h" #include "core/fpdfapi/page/cpdf_pageobject.h" #include "core/fpdfapi/page/cpdf_pageobjectholder.h" #include "core/fpdfapi/render/cpdf_pagerendercache.h" @@ -95,6 +97,10 @@ void CPDF_ProgressiveRenderer::Continue(IFX_Pause* pPause) { return; nObjsToGo = kStepLimit; } + if (pCurObj->IsImage() && pCurObj->AsImage()->GetImage()->IsMask() && + (m_pOptions->m_Flags & RENDER_BREAKFORMASKS)) { + return; + } ++iter; } if (m_pCurrentLayer->m_pObjectHolder->IsParsed()) { diff --git a/core/fpdfapi/render/cpdf_renderoptions.h b/core/fpdfapi/render/cpdf_renderoptions.h index b934941d00..ee26ccbb07 100644 --- a/core/fpdfapi/render/cpdf_renderoptions.h +++ b/core/fpdfapi/render/cpdf_renderoptions.h @@ -28,6 +28,7 @@ #define RENDER_PRINTIMAGETEXT 0x00000200 #define RENDER_OVERPRINT 0x00000400 #define RENDER_THINLINE 0x00000800 +#define RENDER_BREAKFORMASKS 0x00001000 #define RENDER_NOTEXTSMOOTH 0x10000000 #define RENDER_NOPATHSMOOTH 0x20000000 #define RENDER_NOIMAGESMOOTH 0x40000000 -- cgit v1.2.3