1 #ifndef MPL_BACKEND_AGG_BASIC_TYPES_H
2 #define MPL_BACKEND_AGG_BASIC_TYPES_H
3 
4 /* Contains some simple types from the Agg backend that are also used
5    by other modules */
6 
7 #include <vector>
8 
9 #include "agg_color_rgba.h"
10 #include "agg_math_stroke.h"
11 #include "path_converters.h"
12 
13 #include "py_adaptors.h"
14 
15 struct ClipPath
16 {
17     py::PathIterator path;
18     agg::trans_affine trans;
19 };
20 
21 struct SketchParams
22 {
23     double scale;
24     double length;
25     double randomness;
26 };
27 
28 class Dashes
29 {
30     typedef std::vector<std::pair<double, double> > dash_t;
31     double dash_offset;
32     dash_t dashes;
33 
34   public:
get_dash_offset()35     double get_dash_offset() const
36     {
37         return dash_offset;
38     }
set_dash_offset(double x)39     void set_dash_offset(double x)
40     {
41         dash_offset = x;
42     }
add_dash_pair(double length,double skip)43     void add_dash_pair(double length, double skip)
44     {
45         dashes.push_back(std::make_pair(length, skip));
46     }
size()47     size_t size() const
48     {
49         return dashes.size();
50     }
51 
52     template <class T>
dash_to_stroke(T & stroke,double dpi,bool isaa)53     void dash_to_stroke(T &stroke, double dpi, bool isaa)
54     {
55         for (dash_t::const_iterator i = dashes.begin(); i != dashes.end(); ++i) {
56             double val0 = i->first;
57             double val1 = i->second;
58             val0 = val0 * dpi / 72.0;
59             val1 = val1 * dpi / 72.0;
60             if (!isaa) {
61                 val0 = (int)val0 + 0.5;
62                 val1 = (int)val1 + 0.5;
63             }
64             stroke.add_dash(val0, val1);
65         }
66         stroke.dash_start(get_dash_offset() * dpi / 72.0);
67     }
68 };
69 
70 typedef std::vector<Dashes> DashesVector;
71 
72 enum e_offset_position {
73     OFFSET_POSITION_FIGURE,
74     OFFSET_POSITION_DATA
75 };
76 
77 class GCAgg
78 {
79   public:
GCAgg()80     GCAgg()
81         : linewidth(1.0),
82           alpha(1.0),
83           cap(agg::butt_cap),
84           join(agg::round_join),
85           snap_mode(SNAP_FALSE)
86     {
87     }
88 
~GCAgg()89     ~GCAgg()
90     {
91     }
92 
93     double linewidth;
94     double alpha;
95     bool forced_alpha;
96     agg::rgba color;
97     bool isaa;
98 
99     agg::line_cap_e cap;
100     agg::line_join_e join;
101 
102     agg::rect_d cliprect;
103 
104     ClipPath clippath;
105 
106     Dashes dashes;
107 
108     e_snap_mode snap_mode;
109 
110     py::PathIterator hatchpath;
111     agg::rgba hatch_color;
112     double hatch_linewidth;
113 
114     SketchParams sketch;
115 
has_hatchpath()116     bool has_hatchpath()
117     {
118         return hatchpath.total_vertices() != 0;
119     }
120 
121   private:
122     // prevent copying
123     GCAgg(const GCAgg &);
124     GCAgg &operator=(const GCAgg &);
125 };
126 
127 #endif
128