• 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 #ifndef CORE_FPDFAPI_RENDER_CPDF_RENDERSTATUS_H_
8 #define CORE_FPDFAPI_RENDER_CPDF_RENDERSTATUS_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "core/fpdfapi/page/cpdf_clippath.h"
14 #include "core/fpdfapi/page/cpdf_graphicstates.h"
15 #include "core/fpdfapi/page/cpdf_transparency.h"
16 #include "core/fpdfapi/parser/cpdf_dictionary.h"
17 #include "core/fpdfapi/render/cpdf_renderoptions.h"
18 #include "core/fxcrt/retain_ptr.h"
19 #include "core/fxcrt/unowned_ptr.h"
20 #include "core/fxge/fx_dib.h"
21 
22 class CFX_DIBitmap;
23 class CFX_PathData;
24 class CFX_RenderDevice;
25 class CPDF_Color;
26 class CPDF_Font;
27 class CPDF_FormObject;
28 class CPDF_ImageCacheEntry;
29 class CPDF_ImageObject;
30 class CPDF_ImageRenderer;
31 class CPDF_Object;
32 class CPDF_PageObject;
33 class CPDF_PageObjectHolder;
34 class CPDF_PathObject;
35 class CPDF_RenderContext;
36 class CPDF_ShadingObject;
37 class CPDF_ShadingPattern;
38 class CPDF_TilingPattern;
39 class CPDF_TransferFunc;
40 class CPDF_Type3Cache;
41 class CPDF_Type3Char;
42 class CPDF_Type3Font;
43 class PauseIndicatorIface;
44 
45 class CPDF_RenderStatus {
46  public:
47   CPDF_RenderStatus(CPDF_RenderContext* pContext, CFX_RenderDevice* pDevice);
48   ~CPDF_RenderStatus();
49 
50   // Called prior to Initialize().
SetOptions(const CPDF_RenderOptions & options)51   void SetOptions(const CPDF_RenderOptions& options) { m_Options = options; }
SetDeviceMatrix(const CFX_Matrix & matrix)52   void SetDeviceMatrix(const CFX_Matrix& matrix) { m_DeviceMatrix = matrix; }
SetStopObject(const CPDF_PageObject * pStopObj)53   void SetStopObject(const CPDF_PageObject* pStopObj) { m_pStopObj = pStopObj; }
SetFormResource(const CPDF_Dictionary * pRes)54   void SetFormResource(const CPDF_Dictionary* pRes) {
55     m_pFormResource.Reset(pRes);
56   }
SetType3Char(CPDF_Type3Char * pType3Char)57   void SetType3Char(CPDF_Type3Char* pType3Char) { m_pType3Char = pType3Char; }
SetFillColor(FX_ARGB color)58   void SetFillColor(FX_ARGB color) { m_T3FillColor = color; }
SetDropObjects(bool bDropObjects)59   void SetDropObjects(bool bDropObjects) { m_bDropObjects = bDropObjects; }
SetLoadMask(bool bLoadMask)60   void SetLoadMask(bool bLoadMask) { m_bLoadMask = bLoadMask; }
SetStdCS(bool bStdCS)61   void SetStdCS(bool bStdCS) { m_bStdCS = bStdCS; }
SetGroupFamily(uint32_t family)62   void SetGroupFamily(uint32_t family) { m_GroupFamily = family; }
SetTransparency(const CPDF_Transparency & transparency)63   void SetTransparency(const CPDF_Transparency& transparency) {
64     m_Transparency = transparency;
65   }
66 
67   void Initialize(const CPDF_RenderStatus* pParentStatus,
68                   const CPDF_GraphicStates* pInitialStates);
69 
70   void RenderObjectList(const CPDF_PageObjectHolder* pObjectHolder,
71                         const CFX_Matrix& mtObj2Device);
72   void RenderSingleObject(CPDF_PageObject* pObj,
73                           const CFX_Matrix& mtObj2Device);
74   bool ContinueSingleObject(CPDF_PageObject* pObj,
75                             const CFX_Matrix& mtObj2Device,
76                             PauseIndicatorIface* pPause);
77   void ProcessClipPath(const CPDF_ClipPath& ClipPath,
78                        const CFX_Matrix& mtObj2Device);
79 
GetGroupFamily()80   uint32_t GetGroupFamily() const { return m_GroupFamily; }
GetLoadMask()81   bool GetLoadMask() const { return m_bLoadMask; }
GetDropObjects()82   bool GetDropObjects() const { return m_bDropObjects; }
IsPrint()83   bool IsPrint() const { return m_bPrint; }
IsStopped()84   bool IsStopped() const { return m_bStopped; }
GetContext()85   CPDF_RenderContext* GetContext() const { return m_pContext.Get(); }
GetFormResource()86   const CPDF_Dictionary* GetFormResource() const {
87     return m_pFormResource.Get();
88   }
GetPageResource()89   CPDF_Dictionary* GetPageResource() const { return m_pPageResource.Get(); }
GetRenderDevice()90   CFX_RenderDevice* GetRenderDevice() const { return m_pDevice; }
GetRenderOptions()91   const CPDF_RenderOptions& GetRenderOptions() const { return m_Options; }
92 
93 #if defined _SKIA_SUPPORT_
94   void DebugVerifyDeviceIsPreMultiplied() const;
95 #endif
96 
97   RetainPtr<CPDF_TransferFunc> GetTransferFunc(
98       const CPDF_Object* pObject) const;
99 
GetFillArgb(CPDF_PageObject * pObj)100   FX_ARGB GetFillArgb(CPDF_PageObject* pObj) const {
101     return GetFillArgbInternal(pObj, false);
102   }
GetFillArgbForType3(CPDF_PageObject * pObj)103   FX_ARGB GetFillArgbForType3(CPDF_PageObject* pObj) const {
104     return GetFillArgbInternal(pObj, true);
105   }
106 
107   void DrawTilingPattern(CPDF_TilingPattern* pPattern,
108                          CPDF_PageObject* pPageObj,
109                          const CFX_Matrix& mtObj2Device,
110                          bool bStroke);
111   void DrawShadingPattern(CPDF_ShadingPattern* pPattern,
112                           const CPDF_PageObject* pPageObj,
113                           const CFX_Matrix& mtObj2Device,
114                           bool bStroke);
115   void CompositeDIBitmap(const RetainPtr<CFX_DIBitmap>& pDIBitmap,
116                          int left,
117                          int top,
118                          FX_ARGB mask_argb,
119                          int bitmap_alpha,
120                          BlendMode blend_mode,
121                          const CPDF_Transparency& transparency);
122 
123  private:
124   static std::unique_ptr<CPDF_GraphicStates> CloneObjStates(
125       const CPDF_GraphicStates* pSrcStates,
126       bool bStroke);
127 
128   FX_ARGB GetFillArgbInternal(CPDF_PageObject* pObj, bool bType3) const;
129   bool ProcessTransparency(CPDF_PageObject* PageObj,
130                            const CFX_Matrix& mtObj2Device);
131   void ProcessObjectNoClip(CPDF_PageObject* pObj,
132                            const CFX_Matrix& mtObj2Device);
133   void DrawObjWithBackground(CPDF_PageObject* pObj,
134                              const CFX_Matrix& mtObj2Device);
135   bool DrawObjWithBlend(CPDF_PageObject* pObj, const CFX_Matrix& mtObj2Device);
136   bool ProcessPath(CPDF_PathObject* pPathObj, const CFX_Matrix& mtObj2Device);
137   void ProcessPathPattern(CPDF_PathObject* pPathObj,
138                           const CFX_Matrix& mtObj2Device,
139                           int* filltype,
140                           bool* bStroke);
141   void DrawPathWithPattern(CPDF_PathObject* pPathObj,
142                            const CFX_Matrix& mtObj2Device,
143                            const CPDF_Color* pColor,
144                            bool bStroke);
145   bool ClipPattern(const CPDF_PageObject* pPageObj,
146                    const CFX_Matrix& mtObj2Device,
147                    bool bStroke);
148   bool SelectClipPath(const CPDF_PathObject* pPathObj,
149                       const CFX_Matrix& mtObj2Device,
150                       bool bStroke);
151   bool ProcessImage(CPDF_ImageObject* pImageObj,
152                     const CFX_Matrix& mtObj2Device);
153   void ProcessShading(const CPDF_ShadingObject* pShadingObj,
154                       const CFX_Matrix& mtObj2Device);
155   bool ProcessType3Text(CPDF_TextObject* textobj,
156                         const CFX_Matrix& mtObj2Device);
157   bool ProcessText(CPDF_TextObject* textobj,
158                    const CFX_Matrix& mtObj2Device,
159                    CFX_PathData* pClippingPath);
160   void DrawTextPathWithPattern(const CPDF_TextObject* textobj,
161                                const CFX_Matrix& mtObj2Device,
162                                CPDF_Font* pFont,
163                                float font_size,
164                                const CFX_Matrix* pTextMatrix,
165                                bool bFill,
166                                bool bStroke);
167   bool ProcessForm(const CPDF_FormObject* pFormObj,
168                    const CFX_Matrix& mtObj2Device);
169   RetainPtr<CFX_DIBitmap> GetBackdrop(const CPDF_PageObject* pObj,
170                                       const FX_RECT& rect,
171                                       bool bBackAlphaRequired,
172                                       int* left,
173                                       int* top);
174   RetainPtr<CFX_DIBitmap> LoadSMask(CPDF_Dictionary* pSMaskDict,
175                                     FX_RECT* pClipRect,
176                                     const CFX_Matrix* pMatrix);
177   // Optionally write the colorspace family value into |pCSFamily|.
178   FX_ARGB GetBackColor(const CPDF_Dictionary* pSMaskDict,
179                        const CPDF_Dictionary* pGroupDict,
180                        int* pCSFamily);
181   FX_ARGB GetStrokeArgb(CPDF_PageObject* pObj) const;
182   FX_RECT GetObjectClippedRect(const CPDF_PageObject* pObj,
183                                const CFX_Matrix& mtObj2Device) const;
184 
185   CPDF_RenderOptions m_Options;
186   RetainPtr<const CPDF_Dictionary> m_pFormResource;
187   RetainPtr<CPDF_Dictionary> m_pPageResource;
188   std::vector<CPDF_Type3Font*> m_Type3FontCache;
189   UnownedPtr<CPDF_RenderContext> const m_pContext;
190   bool m_bStopped = false;
191   CFX_RenderDevice* const m_pDevice;
192   CFX_Matrix m_DeviceMatrix;
193   CPDF_ClipPath m_LastClipPath;
194   UnownedPtr<const CPDF_PageObject> m_pCurObj;
195   UnownedPtr<const CPDF_PageObject> m_pStopObj;
196   CPDF_GraphicStates m_InitialStates;
197   std::unique_ptr<CPDF_ImageRenderer> m_pImageRenderer;
198   CPDF_Transparency m_Transparency;
199   bool m_bPrint = false;
200   bool m_bDropObjects = false;
201   bool m_bStdCS = false;
202   bool m_bLoadMask = false;
203   uint32_t m_GroupFamily = 0;
204   UnownedPtr<CPDF_Type3Char> m_pType3Char;
205   FX_ARGB m_T3FillColor = 0;
206   BlendMode m_curBlend = BlendMode::kNormal;
207 };
208 
209 #endif  // CORE_FPDFAPI_RENDER_CPDF_RENDERSTATUS_H_
210