• 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_graphstatedata.h"
15 #include "xfa/fxgraphics/cxfa_gecolor.h"
16 
17 using FX_FillMode = int32_t;
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 CFX_DIBBase;
29 class CFX_RenderDevice;
30 class CXFA_GEPath;
31 
32 class CXFA_Graphics {
33  public:
34   explicit CXFA_Graphics(CFX_RenderDevice* renderDevice);
35   ~CXFA_Graphics();
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, const float* dashArray, size_t dashCount);
46   void SetSolidLineDash();
47   void SetLineWidth(float lineWidth);
48   void EnableActOnDash();
49   void SetStrokeColor(const CXFA_GEColor& color);
50   void SetFillColor(const CXFA_GEColor& color);
51   void SetClipRect(const CFX_RectF& rect);
52   void StrokePath(CXFA_GEPath* path, const CFX_Matrix* matrix);
53   void FillPath(CXFA_GEPath* path,
54                 FX_FillMode fillMode,
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;
67     CXFA_GEColor strokeColor;
68     CXFA_GEColor fillColor;
69   };
70 
71   void RenderDeviceStrokePath(const CXFA_GEPath* path,
72                               const CFX_Matrix* matrix);
73   void RenderDeviceFillPath(const CXFA_GEPath* path,
74                             FX_FillMode fillMode,
75                             const CFX_Matrix* matrix);
76   void FillPathWithPattern(const CXFA_GEPath* path,
77                            FX_FillMode fillMode,
78                            const CFX_Matrix& matrix);
79   void FillPathWithShading(const CXFA_GEPath* path,
80                            FX_FillMode fillMode,
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_FXGRAPHICS_CXFA_GRAPHICS_H_
91