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 #ifndef CORE_FPDFAPI_RENDER_CPDF_RENDERSTATUS_H_ 8 #define CORE_FPDFAPI_RENDER_CPDF_RENDERSTATUS_H_ 9 10 #include <memory> 11 #include <utility> 12 #include <vector> 13 14 #include "core/fpdfapi/page/cpdf_clippath.h" 15 #include "core/fpdfapi/page/cpdf_colorspace.h" 16 #include "core/fpdfapi/page/cpdf_graphicstates.h" 17 #include "core/fpdfapi/page/cpdf_transparency.h" 18 #include "core/fpdfapi/parser/cpdf_dictionary.h" 19 #include "core/fpdfapi/render/cpdf_renderoptions.h" 20 #include "core/fxcrt/retain_ptr.h" 21 #include "core/fxcrt/unowned_ptr.h" 22 #include "core/fxge/dib/fx_dib.h" 23 24 class CFX_DIBitmap; 25 class CFX_Path; 26 class CFX_RenderDevice; 27 class CPDF_Color; 28 class CPDF_Font; 29 class CPDF_FormObject; 30 class CPDF_ImageObject; 31 class CPDF_ImageRenderer; 32 class CPDF_Object; 33 class CPDF_PageObject; 34 class CPDF_PageObjectHolder; 35 class CPDF_PathObject; 36 class CPDF_RenderContext; 37 class CPDF_ShadingObject; 38 class CPDF_ShadingPattern; 39 class CPDF_TilingPattern; 40 class CPDF_TransferFunc; 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(RetainPtr<const CPDF_Dictionary> pRes)54 void SetFormResource(RetainPtr<const CPDF_Dictionary> pRes) { 55 m_pFormResource = std::move(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(CPDF_ColorSpace::Family family)62 void SetGroupFamily(CPDF_ColorSpace::Family family) { 63 m_GroupFamily = family; 64 } SetTransparency(const CPDF_Transparency & transparency)65 void SetTransparency(const CPDF_Transparency& transparency) { 66 m_Transparency = transparency; 67 } 68 69 void Initialize(const CPDF_RenderStatus* pParentStatus, 70 const CPDF_GraphicStates* pInitialStates); 71 72 void RenderObjectList(const CPDF_PageObjectHolder* pObjectHolder, 73 const CFX_Matrix& mtObj2Device); 74 void RenderSingleObject(CPDF_PageObject* pObj, 75 const CFX_Matrix& mtObj2Device); 76 bool ContinueSingleObject(CPDF_PageObject* pObj, 77 const CFX_Matrix& mtObj2Device, 78 PauseIndicatorIface* pPause); 79 void ProcessClipPath(const CPDF_ClipPath& ClipPath, 80 const CFX_Matrix& mtObj2Device); 81 GetGroupFamily()82 CPDF_ColorSpace::Family GetGroupFamily() const { return m_GroupFamily; } GetLoadMask()83 bool GetLoadMask() const { return m_bLoadMask; } GetDropObjects()84 bool GetDropObjects() const { return m_bDropObjects; } IsPrint()85 bool IsPrint() const { return m_bPrint; } IsStopped()86 bool IsStopped() const { return m_bStopped; } GetContext()87 CPDF_RenderContext* GetContext() const { return m_pContext; } GetFormResource()88 const CPDF_Dictionary* GetFormResource() const { 89 return m_pFormResource.Get(); 90 } GetPageResource()91 const CPDF_Dictionary* GetPageResource() const { 92 return m_pPageResource.Get(); 93 } GetRenderDevice()94 CFX_RenderDevice* GetRenderDevice() const { return m_pDevice; } GetRenderOptions()95 const CPDF_RenderOptions& GetRenderOptions() const { return m_Options; } 96 97 #if defined(_SKIA_SUPPORT_) 98 void DebugVerifyDeviceIsPreMultiplied() const; 99 #endif 100 101 RetainPtr<CPDF_TransferFunc> GetTransferFunc( 102 RetainPtr<const CPDF_Object> pObject) const; 103 104 FX_ARGB GetFillArgb(CPDF_PageObject* pObj) const; 105 FX_ARGB GetFillArgbForType3(CPDF_PageObject* pObj) const; 106 107 void DrawTilingPattern(CPDF_TilingPattern* pattern, 108 CPDF_PageObject* pPageObj, 109 const CFX_Matrix& mtObj2Device, 110 bool stroke); 111 void DrawShadingPattern(CPDF_ShadingPattern* pattern, 112 const CPDF_PageObject* pPageObj, 113 const CFX_Matrix& mtObj2Device, 114 bool stroke); 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 static std::unique_ptr<CPDF_GraphicStates> CloneObjStates( 124 const CPDF_GraphicStates* pSrcStates, 125 bool stroke); 126 127 private: 128 bool ProcessTransparency(CPDF_PageObject* PageObj, 129 const CFX_Matrix& mtObj2Device); 130 void ProcessObjectNoClip(CPDF_PageObject* pObj, 131 const CFX_Matrix& mtObj2Device); 132 void DrawObjWithBackground(CPDF_PageObject* pObj, 133 const CFX_Matrix& mtObj2Device); 134 bool DrawObjWithBlend(CPDF_PageObject* pObj, const CFX_Matrix& mtObj2Device); 135 bool ProcessPath(CPDF_PathObject* path_obj, const CFX_Matrix& mtObj2Device); 136 void ProcessPathPattern(CPDF_PathObject* path_obj, 137 const CFX_Matrix& mtObj2Device, 138 CFX_FillRenderOptions::FillType* fill_type, 139 bool* stroke); 140 void DrawPathWithPattern(CPDF_PathObject* path_obj, 141 const CFX_Matrix& mtObj2Device, 142 const CPDF_Color* pColor, 143 bool stroke); 144 bool ClipPattern(const CPDF_PageObject* page_obj, 145 const CFX_Matrix& mtObj2Device, 146 bool stroke); 147 bool SelectClipPath(const CPDF_PathObject* path_obj, 148 const CFX_Matrix& mtObj2Device, 149 bool stroke); 150 bool ProcessImage(CPDF_ImageObject* pImageObj, 151 const CFX_Matrix& mtObj2Device); 152 void ProcessShading(const CPDF_ShadingObject* pShadingObj, 153 const CFX_Matrix& mtObj2Device); 154 bool ProcessType3Text(CPDF_TextObject* textobj, 155 const CFX_Matrix& mtObj2Device); 156 bool ProcessText(CPDF_TextObject* textobj, 157 const CFX_Matrix& mtObj2Device, 158 CFX_Path* clipping_path); 159 void DrawTextPathWithPattern(const CPDF_TextObject* textobj, 160 const CFX_Matrix& mtObj2Device, 161 CPDF_Font* pFont, 162 float font_size, 163 const CFX_Matrix& mtTextMatrix, 164 bool fill, 165 bool stroke); 166 bool ProcessForm(const CPDF_FormObject* pFormObj, 167 const CFX_Matrix& mtObj2Device); 168 FX_RECT GetClippedBBox(const FX_RECT& rect) const; 169 RetainPtr<CFX_DIBitmap> GetBackdrop(const CPDF_PageObject* pObj, 170 const FX_RECT& bbox, 171 bool bBackAlphaRequired); 172 RetainPtr<CFX_DIBitmap> LoadSMask(CPDF_Dictionary* pSMaskDict, 173 FX_RECT* pClipRect, 174 const CFX_Matrix& mtMatrix); 175 // Optionally write the colorspace family value into |pCSFamily|. 176 FX_ARGB GetBackColor(const CPDF_Dictionary* pSMaskDict, 177 const CPDF_Dictionary* pGroupDict, 178 CPDF_ColorSpace::Family* pCSFamily); 179 FX_ARGB GetStrokeArgb(CPDF_PageObject* pObj) const; 180 FX_RECT GetObjectClippedRect(const CPDF_PageObject* pObj, 181 const CFX_Matrix& mtObj2Device) const; 182 183 CPDF_RenderOptions m_Options; 184 RetainPtr<const CPDF_Dictionary> m_pFormResource; 185 RetainPtr<const CPDF_Dictionary> m_pPageResource; 186 std::vector<UnownedPtr<const CPDF_Type3Font>> m_Type3FontCache; 187 UnownedPtr<CPDF_RenderContext> const m_pContext; 188 UnownedPtr<CFX_RenderDevice> const m_pDevice; 189 CFX_Matrix m_DeviceMatrix; 190 CPDF_ClipPath m_LastClipPath; 191 UnownedPtr<const CPDF_PageObject> m_pCurObj; 192 UnownedPtr<const CPDF_PageObject> m_pStopObj; 193 CPDF_GraphicStates m_InitialStates; 194 std::unique_ptr<CPDF_ImageRenderer> m_pImageRenderer; 195 UnownedPtr<const CPDF_Type3Char> m_pType3Char; 196 CPDF_Transparency m_Transparency; 197 bool m_bStopped = false; 198 bool m_bPrint = false; 199 bool m_bDropObjects = false; 200 bool m_bStdCS = false; 201 bool m_bLoadMask = false; 202 CPDF_ColorSpace::Family m_GroupFamily = CPDF_ColorSpace::Family::kUnknown; 203 FX_ARGB m_T3FillColor = 0; 204 BlendMode m_curBlend = BlendMode::kNormal; 205 }; 206 207 #endif // CORE_FPDFAPI_RENDER_CPDF_RENDERSTATUS_H_ 208