• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 PDFium Authors. All rights reserved.
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_rendercontext.h"
8 
9 #include "core/fpdfapi/page/cpdf_page.h"
10 #include "core/fpdfapi/page/cpdf_pageobject.h"
11 #include "core/fpdfapi/page/cpdf_pageobjectholder.h"
12 #include "core/fpdfapi/parser/cpdf_dictionary.h"
13 #include "core/fpdfapi/parser/cpdf_document.h"
14 #include "core/fpdfapi/render/cpdf_pagerendercache.h"
15 #include "core/fpdfapi/render/cpdf_progressiverenderer.h"
16 #include "core/fpdfapi/render/cpdf_renderoptions.h"
17 #include "core/fpdfapi/render/cpdf_renderstatus.h"
18 #include "core/fpdfapi/render/cpdf_textrenderer.h"
19 #include "core/fxge/cfx_renderdevice.h"
20 #include "core/fxge/dib/cfx_dibitmap.h"
21 #include "core/fxge/fx_dib.h"
22 
CPDF_RenderContext(CPDF_Page * pPage)23 CPDF_RenderContext::CPDF_RenderContext(CPDF_Page* pPage)
24     : m_pDocument(pPage->m_pDocument.Get()),
25       m_pPageResources(pPage->m_pPageResources.Get()),
26       m_pPageCache(pPage->GetRenderCache()) {}
27 
CPDF_RenderContext(CPDF_Document * pDoc,CPDF_PageRenderCache * pPageCache)28 CPDF_RenderContext::CPDF_RenderContext(CPDF_Document* pDoc,
29                                        CPDF_PageRenderCache* pPageCache)
30     : m_pDocument(pDoc), m_pPageResources(nullptr), m_pPageCache(pPageCache) {}
31 
~CPDF_RenderContext()32 CPDF_RenderContext::~CPDF_RenderContext() {}
33 
GetBackground(const RetainPtr<CFX_DIBitmap> & pBuffer,const CPDF_PageObject * pObj,const CPDF_RenderOptions * pOptions,CFX_Matrix * pFinalMatrix)34 void CPDF_RenderContext::GetBackground(const RetainPtr<CFX_DIBitmap>& pBuffer,
35                                        const CPDF_PageObject* pObj,
36                                        const CPDF_RenderOptions* pOptions,
37                                        CFX_Matrix* pFinalMatrix) {
38   CFX_DefaultRenderDevice device;
39   device.Attach(pBuffer, false, nullptr, false);
40 
41   FX_RECT rect(0, 0, device.GetWidth(), device.GetHeight());
42   device.FillRect(&rect, 0xffffffff);
43   Render(&device, pObj, pOptions, pFinalMatrix);
44 }
45 
AppendLayer(CPDF_PageObjectHolder * pObjectHolder,const CFX_Matrix * pObject2Device)46 void CPDF_RenderContext::AppendLayer(CPDF_PageObjectHolder* pObjectHolder,
47                                      const CFX_Matrix* pObject2Device) {
48   m_Layers.emplace_back();
49   m_Layers.back().m_pObjectHolder = pObjectHolder;
50   if (pObject2Device)
51     m_Layers.back().m_Matrix = *pObject2Device;
52   else
53     m_Layers.back().m_Matrix.SetIdentity();
54 }
55 
Render(CFX_RenderDevice * pDevice,const CPDF_RenderOptions * pOptions,const CFX_Matrix * pLastMatrix)56 void CPDF_RenderContext::Render(CFX_RenderDevice* pDevice,
57                                 const CPDF_RenderOptions* pOptions,
58                                 const CFX_Matrix* pLastMatrix) {
59   Render(pDevice, nullptr, pOptions, pLastMatrix);
60 }
61 
Render(CFX_RenderDevice * pDevice,const CPDF_PageObject * pStopObj,const CPDF_RenderOptions * pOptions,const CFX_Matrix * pLastMatrix)62 void CPDF_RenderContext::Render(CFX_RenderDevice* pDevice,
63                                 const CPDF_PageObject* pStopObj,
64                                 const CPDF_RenderOptions* pOptions,
65                                 const CFX_Matrix* pLastMatrix) {
66   for (auto& layer : m_Layers) {
67     CFX_RenderDevice::StateRestorer restorer(pDevice);
68     CPDF_RenderStatus status;
69     if (pLastMatrix) {
70       CFX_Matrix FinalMatrix = layer.m_Matrix;
71       FinalMatrix.Concat(*pLastMatrix);
72       status.Initialize(this, pDevice, pLastMatrix, pStopObj, nullptr, nullptr,
73                         pOptions, layer.m_pObjectHolder->m_iTransparency, false,
74                         nullptr);
75       status.RenderObjectList(layer.m_pObjectHolder.Get(), &FinalMatrix);
76     } else {
77       status.Initialize(this, pDevice, nullptr, pStopObj, nullptr, nullptr,
78                         pOptions, layer.m_pObjectHolder->m_iTransparency, false,
79                         nullptr);
80       status.RenderObjectList(layer.m_pObjectHolder.Get(), &layer.m_Matrix);
81     }
82     if (status.GetRenderOptions()->HasFlag(RENDER_LIMITEDIMAGECACHE)) {
83       m_pPageCache->CacheOptimization(
84           status.GetRenderOptions()->GetCacheSizeLimit());
85     }
86     if (status.IsStopped())
87       break;
88   }
89 }
90 
Layer()91 CPDF_RenderContext::Layer::Layer() {}
92 
93 CPDF_RenderContext::Layer::Layer(const Layer& that) = default;
94 
~Layer()95 CPDF_RenderContext::Layer::~Layer() {}
96