summaryrefslogtreecommitdiff
path: root/xfa/fxgraphics/cfx_graphics.h
blob: 8785a387d68a7b7118d1d90f80e1c45f3af56243 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2016 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef XFA_FXGRAPHICS_CFX_GRAPHICS_H_
#define XFA_FXGRAPHICS_CFX_GRAPHICS_H_

#include <memory>
#include <vector>

#include "core/fxcrt/fx_system.h"
#include "core/fxge/cfx_defaultrenderdevice.h"
#include "core/fxge/cfx_graphstatedata.h"
#include "core/fxge/cfx_renderdevice.h"
#include "core/fxge/fx_dib.h"
#include "core/fxge/fx_font.h"

class CFX_Color;
class CFX_Path;

using FX_FillMode = int32_t;

enum FX_DashStyle {
  FX_DASHSTYLE_Solid = 0,
  FX_DASHSTYLE_Dash = 1,
  FX_DASHSTYLE_Dot = 2,
  FX_DASHSTYLE_DashDot = 3,
  FX_DASHSTYLE_DashDotDot = 4
};

enum class FX_HatchStyle {
  Horizontal = 0,
  Vertical = 1,
  ForwardDiagonal = 2,
  BackwardDiagonal = 3,
  Cross = 4,
  DiagonalCross = 5
};

class CFX_RenderDevice;

class CFX_Graphics {
 public:
  explicit CFX_Graphics(CFX_RenderDevice* renderDevice);
  ~CFX_Graphics();

  void SaveGraphState();
  void RestoreGraphState();

  CFX_RectF GetClipRect() const;
  CFX_Matrix* GetMatrix();
  CFX_RenderDevice* GetRenderDevice();

  void SetLineCap(CFX_GraphStateData::LineCap lineCap);
  void SetLineDash(float dashPhase, float* dashArray, int32_t dashCount);
  void SetLineDash(FX_DashStyle dashStyle);
  void SetLineWidth(float lineWidth, bool isActOnDash = false);
  void SetStrokeColor(CFX_Color* color);
  void SetFillColor(CFX_Color* color);
  void SetClipRect(const CFX_RectF& rect);
  void StrokePath(CFX_Path* path, CFX_Matrix* matrix = nullptr);
  void FillPath(CFX_Path* path,
                FX_FillMode fillMode = FXFILL_WINDING,
                CFX_Matrix* matrix = nullptr);
  void StretchImage(const CFX_RetainPtr<CFX_DIBSource>& source,
                    const CFX_RectF& rect,
                    CFX_Matrix* matrix = nullptr);
  void ConcatMatrix(const CFX_Matrix* matrix);

 protected:
  int32_t m_type;

 private:
  struct TInfo {
    TInfo();
    explicit TInfo(const TInfo& info);
    TInfo& operator=(const TInfo& other);

    CFX_GraphStateData graphState;
    CFX_Matrix CTM;
    bool isActOnDash;
    CFX_Color* strokeColor;
    CFX_Color* fillColor;
  } m_info;

  void RenderDeviceSetLineDash(FX_DashStyle dashStyle);
  void RenderDeviceStrokePath(CFX_Path* path, CFX_Matrix* matrix);
  void RenderDeviceFillPath(CFX_Path* path,
                            FX_FillMode fillMode,
                            CFX_Matrix* matrix);
  void RenderDeviceStretchImage(const CFX_RetainPtr<CFX_DIBSource>& source,
                                const CFX_RectF& rect,
                                CFX_Matrix* matrix);

  void FillPathWithPattern(CFX_Path* path,
                           FX_FillMode fillMode,
                           CFX_Matrix* matrix);
  void FillPathWithShading(CFX_Path* path,
                           FX_FillMode fillMode,
                           CFX_Matrix* matrix);

  void SetDIBitsWithMatrix(const CFX_RetainPtr<CFX_DIBSource>& source,
                           CFX_Matrix* matrix);

  CFX_RenderDevice* const m_renderDevice;  // Not owned.
  std::vector<std::unique_ptr<TInfo>> m_infoStack;
};

#endif  // XFA_FXGRAPHICS_CFX_GRAPHICS_H_