• 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 XFA_FXGRAPHICS_CXFA_GRAPHICS_H_
8 #define XFA_FXGRAPHICS_CXFA_GRAPHICS_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "core/fxcrt/fx_system.h"
14 #include "core/fxge/cfx_defaultrenderdevice.h"
15 #include "core/fxge/cfx_graphstatedata.h"
16 #include "core/fxge/cfx_renderdevice.h"
17 #include "core/fxge/fx_dib.h"
18 #include "xfa/fxgraphics/cxfa_gecolor.h"
19 
20 class CXFA_GEPath;
21 
22 using FX_FillMode = int32_t;
23 
24 enum class FX_HatchStyle {
25   Horizontal = 0,
26   Vertical = 1,
27   ForwardDiagonal = 2,
28   BackwardDiagonal = 3,
29   Cross = 4,
30   DiagonalCross = 5
31 };
32 
33 class CFX_RenderDevice;
34 
35 class CXFA_Graphics {
36  public:
37   explicit CXFA_Graphics(CFX_RenderDevice* renderDevice);
38   ~CXFA_Graphics();
39 
40   void SaveGraphState();
41   void RestoreGraphState();
42 
43   CFX_RectF GetClipRect() const;
44   const CFX_Matrix* GetMatrix() const;
45   CFX_RenderDevice* GetRenderDevice();
46 
47   void SetLineCap(CFX_GraphStateData::LineCap lineCap);
48   void SetLineDash(float dashPhase, float* dashArray, int32_t dashCount);
49   void SetSolidLineDash();
50   void SetLineWidth(float lineWidth);
51   void EnableActOnDash();
52   void SetStrokeColor(const CXFA_GEColor& color);
53   void SetFillColor(const CXFA_GEColor& color);
54   void SetClipRect(const CFX_RectF& rect);
55   void StrokePath(CXFA_GEPath* path, const CFX_Matrix* matrix);
56   void FillPath(CXFA_GEPath* path,
57                 FX_FillMode fillMode,
58                 const CFX_Matrix* matrix);
59   void ConcatMatrix(const CFX_Matrix* matrix);
60 
61  protected:
62   int32_t m_type;
63 
64  private:
65   struct TInfo {
66     TInfo();
67     explicit TInfo(const TInfo& info);
68     TInfo& operator=(const TInfo& other);
69 
70     CFX_GraphStateData graphState;
71     CFX_Matrix CTM;
72     bool isActOnDash;
73     CXFA_GEColor strokeColor;
74     CXFA_GEColor fillColor;
75   } m_info;
76 
77   void RenderDeviceStrokePath(const CXFA_GEPath* path,
78                               const CFX_Matrix* matrix);
79   void RenderDeviceFillPath(const CXFA_GEPath* path,
80                             FX_FillMode fillMode,
81                             const CFX_Matrix* matrix);
82 
83   void FillPathWithPattern(const CXFA_GEPath* path,
84                            FX_FillMode fillMode,
85                            const CFX_Matrix& matrix);
86   void FillPathWithShading(const CXFA_GEPath* path,
87                            FX_FillMode fillMode,
88                            const CFX_Matrix& matrix);
89 
90   void SetDIBitsWithMatrix(const RetainPtr<CFX_DIBSource>& source,
91                            const CFX_Matrix& matrix);
92 
93   CFX_RenderDevice* const m_renderDevice;  // Not owned.
94   std::vector<std::unique_ptr<TInfo>> m_infoStack;
95 };
96 
97 #endif  // XFA_FXGRAPHICS_CXFA_GRAPHICS_H_
98