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