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 XFA_FGAS_GRAPHICS_CFGAS_GEGRAPHICS_H_ 8 #define XFA_FGAS_GRAPHICS_CFGAS_GEGRAPHICS_H_ 9 10 #include <memory> 11 #include <vector> 12 13 #include "core/fxcrt/fx_coordinates.h" 14 #include "core/fxcrt/fx_memory.h" 15 #include "core/fxcrt/retain_ptr.h" 16 #include "core/fxcrt/unowned_ptr.h" 17 #include "core/fxge/cfx_fillrenderoptions.h" 18 #include "core/fxge/cfx_graphstatedata.h" 19 #include "third_party/base/span.h" 20 #include "xfa/fgas/graphics/cfgas_gecolor.h" 21 22 class CFGAS_GEPath; 23 class CFX_DIBBase; 24 class CFX_RenderDevice; 25 26 class CFGAS_GEGraphics { 27 public: 28 class StateRestorer { 29 public: 30 FX_STACK_ALLOCATED(); 31 32 explicit StateRestorer(CFGAS_GEGraphics* graphics); 33 ~StateRestorer(); 34 35 private: 36 UnownedPtr<CFGAS_GEGraphics> const graphics_; 37 }; 38 39 explicit CFGAS_GEGraphics(CFX_RenderDevice* renderDevice); 40 ~CFGAS_GEGraphics(); 41 42 CFX_RectF GetClipRect() const; 43 const CFX_Matrix* GetMatrix() const; 44 CFX_RenderDevice* GetRenderDevice(); 45 46 void SetLineCap(CFX_GraphStateData::LineCap lineCap); 47 void SetLineDash(float dashPhase, pdfium::span<const float> dashArray); 48 void SetSolidLineDash(); 49 void SetLineWidth(float lineWidth); 50 void EnableActOnDash(); 51 void SetStrokeColor(const CFGAS_GEColor& color); 52 void SetFillColor(const CFGAS_GEColor& color); 53 void SetClipRect(const CFX_RectF& rect); 54 void StrokePath(const CFGAS_GEPath& path, const CFX_Matrix& matrix); 55 void FillPath(const CFGAS_GEPath& path, 56 CFX_FillRenderOptions::FillType fill_type, 57 const CFX_Matrix& matrix); 58 void ConcatMatrix(const CFX_Matrix& matrix); 59 60 private: 61 struct TInfo { 62 TInfo(); 63 explicit TInfo(const TInfo& info); 64 TInfo& operator=(const TInfo& other); 65 66 CFX_GraphStateData graphState; 67 CFX_Matrix CTM; 68 bool isActOnDash = false; 69 CFGAS_GEColor strokeColor{nullptr}; 70 CFGAS_GEColor fillColor{nullptr}; 71 }; 72 73 void SaveGraphState(); 74 void RestoreGraphState(); 75 76 void RenderDeviceStrokePath(const CFGAS_GEPath& path, 77 const CFX_Matrix& matrix); 78 void RenderDeviceFillPath(const CFGAS_GEPath& path, 79 CFX_FillRenderOptions::FillType fill_type, 80 const CFX_Matrix& matrix); 81 void FillPathWithPattern(const CFGAS_GEPath& path, 82 const CFX_FillRenderOptions& fill_options, 83 const CFX_Matrix& matrix); 84 void FillPathWithShading(const CFGAS_GEPath& path, 85 const CFX_FillRenderOptions& fill_options, 86 const CFX_Matrix& matrix); 87 void SetDIBitsWithMatrix(RetainPtr<CFX_DIBBase> source, 88 const CFX_Matrix& matrix); 89 90 UnownedPtr<CFX_RenderDevice> const m_renderDevice; 91 TInfo m_info; 92 std::vector<std::unique_ptr<TInfo>> m_infoStack; 93 }; 94 95 #endif // XFA_FGAS_GRAPHICS_CFGAS_GEGRAPHICS_H_ 96