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