Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdf_progressiverenderer.cpp
Go to the documentation of this file.
1// Copyright 2016 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "core/fpdfapi/render/cpdf_progressiverenderer.h"
8
9#include "core/fpdfapi/page/cpdf_image.h"
10#include "core/fpdfapi/page/cpdf_imageobject.h"
11#include "core/fpdfapi/page/cpdf_pageimagecache.h"
12#include "core/fpdfapi/page/cpdf_pageobject.h"
13#include "core/fpdfapi/page/cpdf_pageobjectholder.h"
14#include "core/fpdfapi/render/cpdf_renderoptions.h"
15#include "core/fpdfapi/render/cpdf_renderstatus.h"
16#include "core/fxcrt/pauseindicator_iface.h"
17#include "core/fxge/cfx_renderdevice.h"
18
24
26 if (m_pRenderStatus) {
27 m_pRenderStatus.reset(); // Release first.
28 m_pDevice->RestoreState(false);
29 }
30}
31
33 if (!m_pContext || !m_pDevice || m_Status != kReady) {
34 m_Status = kFailed;
35 return;
36 }
37 m_Status = kToBeContinued;
38 Continue(pPause);
39}
40
42 while (m_Status == kToBeContinued) {
43 if (!m_pCurrentLayer) {
44 if (m_LayerIndex >= m_pContext->CountLayers()) {
45 m_Status = kDone;
46 return;
47 }
48 m_pCurrentLayer = m_pContext->GetLayer(m_LayerIndex);
49 m_LastObjectRendered = m_pCurrentLayer->GetObjectHolder()->end();
50 m_pRenderStatus =
51 std::make_unique<CPDF_RenderStatus>(m_pContext, m_pDevice);
52 if (m_pOptions)
53 m_pRenderStatus->SetOptions(*m_pOptions);
54 m_pRenderStatus->SetTransparency(
55 m_pCurrentLayer->GetObjectHolder()->GetTransparency());
56 m_pRenderStatus->Initialize(nullptr, nullptr);
57 m_pDevice->SaveState();
58 m_ClipRect = m_pCurrentLayer->GetMatrix().GetInverse().TransformRect(
59 CFX_FloatRect(m_pDevice->GetClipBox()));
60 }
61 CPDF_PageObjectHolder::const_iterator iter;
62 CPDF_PageObjectHolder::const_iterator iterEnd =
63 m_pCurrentLayer->GetObjectHolder()->end();
64 if (m_LastObjectRendered != iterEnd) {
65 iter = m_LastObjectRendered;
66 ++iter;
67 } else {
68 iter = m_pCurrentLayer->GetObjectHolder()->begin();
69 }
70 int nObjsToGo = kStepLimit;
71 bool is_mask = false;
72 while (iter != iterEnd) {
73 CPDF_PageObject* pCurObj = iter->get();
74 if (pCurObj && pCurObj->GetRect().left <= m_ClipRect.right &&
75 pCurObj->GetRect().right >= m_ClipRect.left &&
76 pCurObj->GetRect().bottom <= m_ClipRect.top &&
77 pCurObj->GetRect().top >= m_ClipRect.bottom) {
78 if (m_pOptions->GetOptions().bBreakForMasks && pCurObj->IsImage() &&
79 pCurObj->AsImage()->GetImage()->IsMask()) {
80 if (m_pDevice->GetDeviceType() == DeviceType::kPrinter) {
81 m_LastObjectRendered = iter;
82 m_pRenderStatus->ProcessClipPath(pCurObj->clip_path(),
83 m_pCurrentLayer->GetMatrix());
84 return;
85 }
86 is_mask = true;
87 }
88 if (m_pRenderStatus->ContinueSingleObject(
89 pCurObj, m_pCurrentLayer->GetMatrix(), pPause)) {
90 return;
91 }
92 if (pCurObj->IsImage() && m_pRenderStatus->GetRenderOptions()
93 .GetOptions()
94 .bLimitedImageCache) {
95 m_pContext->GetPageCache()->CacheOptimization(
96 m_pRenderStatus->GetRenderOptions().GetCacheSizeLimit());
97 }
98 if (pCurObj->IsForm() || pCurObj->IsShading())
99 nObjsToGo = 0;
100 else
101 --nObjsToGo;
102 }
103 m_LastObjectRendered = iter;
104 if (nObjsToGo == 0) {
105 if (pPause && pPause->NeedToPauseNow())
106 return;
107 nObjsToGo = kStepLimit;
108 }
109 ++iter;
110 if (is_mask && iter != iterEnd)
111 return;
112 }
113 if (m_pCurrentLayer->GetObjectHolder()->GetParseState() ==
114 CPDF_PageObjectHolder::ParseState::kParsed) {
115 m_pRenderStatus.reset();
116 m_pDevice->RestoreState(false);
117 m_pCurrentLayer = nullptr;
118 m_LayerIndex++;
119 if (is_mask || (pPause && pPause->NeedToPauseNow()))
120 return;
121 } else if (is_mask) {
122 return;
123 } else {
124 m_pCurrentLayer->GetObjectHolder()->ContinueParse(pPause);
125 if (m_pCurrentLayer->GetObjectHolder()->GetParseState() !=
126 CPDF_PageObjectHolder::ParseState::kParsed) {
127 return;
128 }
129 }
130 }
131}
const CFX_FloatRect & GetRect() const
virtual bool IsForm() const
virtual bool IsShading() const
void Start(PauseIndicatorIface *pPause)
void Continue(PauseIndicatorIface *pPause)
CPDF_ProgressiveRenderer(CPDF_RenderContext *pContext, CFX_RenderDevice *pDevice, const CPDF_RenderOptions *pOptions)
virtual bool NeedToPauseNow()=0