• 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/render/cpdf_renderoptions.h"
16 #include "core/fxcrt/unowned_ptr.h"
17 #include "core/fxge/cfx_renderdevice.h"
18 
19 class CFX_PathData;
20 class CPDF_Color;
21 class CPDF_Dictionary;
22 class CPDF_Font;
23 class CPDF_FormObject;
24 class CPDF_ImageCacheEntry;
25 class CPDF_ImageObject;
26 class CPDF_ImageRenderer;
27 class CPDF_Object;
28 class CPDF_PageObject;
29 class CPDF_PageObjectHolder;
30 class CPDF_PathObject;
31 class CPDF_ShadingObject;
32 class CPDF_ShadingPattern;
33 class CPDF_TilingPattern;
34 class CPDF_TransferFunc;
35 class CPDF_Type3Cache;
36 class CPDF_Type3Char;
37 class CPDF_Type3Font;
38 
39 class CPDF_RenderStatus {
40  public:
41   CPDF_RenderStatus();
42   ~CPDF_RenderStatus();
43 
44   bool Initialize(class CPDF_RenderContext* pContext,
45                   CFX_RenderDevice* pDevice,
46                   const CFX_Matrix* pDeviceMatrix,
47                   const CPDF_PageObject* pStopObj,
48                   const CPDF_RenderStatus* pParentStatus,
49                   const CPDF_GraphicStates* pInitialStates,
50                   const CPDF_RenderOptions* pOptions,
51                   int transparency,
52                   bool bDropObjects,
53                   CPDF_Dictionary* pFormResource = nullptr,
54                   bool bStdCS = false,
55                   CPDF_Type3Char* pType3Char = nullptr,
56                   FX_ARGB fill_color = 0,
57                   uint32_t GroupFamily = 0,
58                   bool bLoadMask = false);
59   void RenderObjectList(const CPDF_PageObjectHolder* pObjectHolder,
60                         const CFX_Matrix* pObj2Device);
61   void RenderSingleObject(CPDF_PageObject* pObj, const CFX_Matrix* pObj2Device);
62   bool ContinueSingleObject(CPDF_PageObject* pObj,
63                             const CFX_Matrix* pObj2Device,
64                             IFX_PauseIndicator* pPause);
65   void ProcessClipPath(const CPDF_ClipPath& ClipPath,
66                        const CFX_Matrix* pObj2Device);
67 
GetGroupFamily()68   uint32_t GetGroupFamily() const { return m_GroupFamily; }
GetLoadMask()69   bool GetLoadMask() const { return m_bLoadMask; }
GetDropObjects()70   bool GetDropObjects() const { return m_bDropObjects; }
IsPrint()71   bool IsPrint() const { return m_bPrint; }
IsStopped()72   bool IsStopped() const { return m_bStopped; }
GetContext()73   CPDF_RenderContext* GetContext() const { return m_pContext.Get(); }
GetFormResource()74   CPDF_Dictionary* GetFormResource() const { return m_pFormResource.Get(); }
GetPageResource()75   CPDF_Dictionary* GetPageResource() const { return m_pPageResource.Get(); }
GetRenderDevice()76   CFX_RenderDevice* GetRenderDevice() const { return m_pDevice; }
GetRenderOptions()77   const CPDF_RenderOptions* GetRenderOptions() const { return &m_Options; }
78 
79 #if defined _SKIA_SUPPORT_
80   void DebugVerifyDeviceIsPreMultiplied() const;
81 #endif
82 
83   RetainPtr<CPDF_TransferFunc> GetTransferFunc(CPDF_Object* pObject) const;
84   FX_ARGB GetFillArgb(CPDF_PageObject* pObj, bool bType3 = false) const;
85   void DrawTilingPattern(CPDF_TilingPattern* pPattern,
86                          CPDF_PageObject* pPageObj,
87                          const CFX_Matrix* pObj2Device,
88                          bool bStroke);
89   void DrawShadingPattern(CPDF_ShadingPattern* pPattern,
90                           const CPDF_PageObject* pPageObj,
91                           const CFX_Matrix* pObj2Device,
92                           bool bStroke);
93   void CompositeDIBitmap(const RetainPtr<CFX_DIBitmap>& pDIBitmap,
94                          int left,
95                          int top,
96                          FX_ARGB mask_argb,
97                          int bitmap_alpha,
98                          int blend_mode,
99                          int iTransparency);
100 
101  private:
102   bool ProcessTransparency(CPDF_PageObject* PageObj,
103                            const CFX_Matrix* pObj2Device);
104   void ProcessObjectNoClip(CPDF_PageObject* PageObj,
105                            const CFX_Matrix* pObj2Device);
106   void DrawObjWithBackground(CPDF_PageObject* pObj,
107                              const CFX_Matrix* pObj2Device);
108   bool DrawObjWithBlend(CPDF_PageObject* pObj, const CFX_Matrix* pObj2Device);
109   bool ProcessPath(CPDF_PathObject* pPathObj, const CFX_Matrix* pObj2Device);
110   void ProcessPathPattern(CPDF_PathObject* pPathObj,
111                           const CFX_Matrix* pObj2Device,
112                           int& filltype,
113                           bool& bStroke);
114   void DrawPathWithPattern(CPDF_PathObject* pPathObj,
115                            const CFX_Matrix* pObj2Device,
116                            const CPDF_Color* pColor,
117                            bool bStroke);
118   bool SelectClipPath(const CPDF_PathObject* pPathObj,
119                       const CFX_Matrix* pObj2Device,
120                       bool bStroke);
121   bool ProcessImage(CPDF_ImageObject* pImageObj, const CFX_Matrix* pObj2Device);
122   void ProcessShading(const CPDF_ShadingObject* pShadingObj,
123                       const CFX_Matrix* pObj2Device);
124   void DrawShading(const CPDF_ShadingPattern* pPattern,
125                    CFX_Matrix* pMatrix,
126                    FX_RECT& clip_rect,
127                    int alpha,
128                    bool bAlphaMode);
129   bool ProcessType3Text(CPDF_TextObject* textobj,
130                         const CFX_Matrix* pObj2Device);
131   bool ProcessText(CPDF_TextObject* textobj,
132                    const CFX_Matrix* pObj2Device,
133                    CFX_PathData* pClippingPath);
134   void DrawTextPathWithPattern(const CPDF_TextObject* textobj,
135                                const CFX_Matrix* pObj2Device,
136                                CPDF_Font* pFont,
137                                float font_size,
138                                const CFX_Matrix* pTextMatrix,
139                                bool bFill,
140                                bool bStroke);
141   bool ProcessForm(const CPDF_FormObject* pFormObj,
142                    const CFX_Matrix* pObj2Device);
143   RetainPtr<CFX_DIBitmap> GetBackdrop(const CPDF_PageObject* pObj,
144                                       const FX_RECT& rect,
145                                       bool bBackAlphaRequired,
146                                       int* left,
147                                       int* top);
148   RetainPtr<CFX_DIBitmap> LoadSMask(CPDF_Dictionary* pSMaskDict,
149                                     FX_RECT* pClipRect,
150                                     const CFX_Matrix* pMatrix);
151   static RetainPtr<CPDF_Type3Cache> GetCachedType3(CPDF_Type3Font* pFont);
152   static std::unique_ptr<CPDF_GraphicStates> CloneObjStates(
153       const CPDF_GraphicStates* pPathObj,
154       bool bStroke);
155   FX_ARGB GetStrokeArgb(CPDF_PageObject* pObj) const;
156   bool GetObjectClippedRect(const CPDF_PageObject* pObj,
157                             const CFX_Matrix* pObj2Device,
158                             bool bLogical,
159                             FX_RECT& rect) const;
160   void GetScaledMatrix(CFX_Matrix& matrix) const;
161 
162   static const int kRenderMaxRecursionDepth = 64;
163   static int s_CurrentRecursionDepth;
164 
165   CPDF_RenderOptions m_Options;
166   UnownedPtr<CPDF_Dictionary> m_pFormResource;
167   UnownedPtr<CPDF_Dictionary> m_pPageResource;
168   std::vector<CPDF_Type3Font*> m_Type3FontCache;
169   UnownedPtr<CPDF_RenderContext> m_pContext;
170   bool m_bStopped;
171   CFX_RenderDevice* m_pDevice;
172   CFX_Matrix m_DeviceMatrix;
173   CPDF_ClipPath m_LastClipPath;
174   const CPDF_PageObject* m_pCurObj;
175   const CPDF_PageObject* m_pStopObj;
176   CPDF_GraphicStates m_InitialStates;
177   std::unique_ptr<CPDF_ImageRenderer> m_pImageRenderer;
178   bool m_bPrint;
179   int m_iTransparency;
180   bool m_bDropObjects;
181   bool m_bStdCS;
182   uint32_t m_GroupFamily;
183   bool m_bLoadMask;
184   UnownedPtr<CPDF_Type3Char> m_pType3Char;
185   FX_ARGB m_T3FillColor;
186   int m_curBlend;
187 };
188 
189 #endif  // CORE_FPDFAPI_RENDER_CPDF_RENDERSTATUS_H_
190