1 
2 //----------------------------------------------------------------------------
3 // Anti-Grain Geometry - Version 2.3
4 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
5 //
6 // Permission to copy, use, modify, sell and distribute this software
7 // is granted provided this copyright notice appears in all copies.
8 // This software is provided "as is" without express or implied
9 // warranty, and with no claim as to its suitability for any purpose.
10 //
11 //----------------------------------------------------------------------------
12 // Contact: mcseem@antigrain.com
13 //          mcseemagg@yahoo.com
14 //          http://www.antigrain.com
15 //----------------------------------------------------------------------------
16 #ifndef AGG_BASICS_INCLUDED
17 #define AGG_BASICS_INCLUDED
18 #ifndef AGG_INT8
19 #define AGG_INT8 signed char
20 #endif
21 #ifndef AGG_INT8U
22 #define AGG_INT8U unsigned char
23 #endif
24 #ifndef AGG_INT16
25 #define AGG_INT16 short
26 #endif
27 #ifndef AGG_INT16U
28 #define AGG_INT16U unsigned short
29 #endif
30 #ifndef AGG_INT32
31 #define AGG_INT32 int
32 #endif
33 #ifndef AGG_INT32U
34 #define AGG_INT32U unsigned
35 #endif
36 #ifndef AGG_INT64
37 #define AGG_INT64 signed long long
38 #endif
39 #ifndef AGG_INT64U
40 #define AGG_INT64U unsigned long long
41 #endif
42 #define AGG_INLINE inline
43 
44 #include "core/fxcrt/fx_system.h"
45 
46 namespace pdfium
47 {
48 namespace agg
49 {
50 typedef AGG_INT8   int8;
51 typedef AGG_INT8U  int8u;
52 typedef AGG_INT16  int16;
53 typedef AGG_INT16U int16u;
54 typedef AGG_INT32  int32;
55 typedef AGG_INT32U int32u;
56 typedef AGG_INT64  int64;
57 typedef AGG_INT64U int64u;
58 typedef unsigned char cover_type;
59 enum cover_scale_e {
60     cover_shift = 8,
61     cover_size  = 1 << cover_shift,
62     cover_mask  = cover_size - 1,
63     cover_none  = 0,
64     cover_full  = cover_mask
65 };
66 template<class T> struct rect_base  {
67     typedef rect_base<T> self_type;
68     T x1;
69     T y1;
70     T x2;
71     T y2;
rect_baserect_base72     rect_base() {}
rect_baserect_base73     rect_base(T x1_, T y1_, T x2_, T y2_) :
74         x1(x1_), y1(y1_), x2(x2_), y2(y2_) {}
normalizerect_base75     const self_type& normalize()
76     {
77         T t;
78         if(x1 > x2) {
79             t = x1;
80             x1 = x2;
81             x2 = t;
82         }
83         if(y1 > y2) {
84             t = y1;
85             y1 = y2;
86             y2 = t;
87         }
88         return *this;
89     }
cliprect_base90     bool clip(const self_type& r)
91     {
92         if(x2 > r.x2) {
93             x2 = r.x2;
94         }
95         if(y2 > r.y2) {
96             y2 = r.y2;
97         }
98         if(x1 < r.x1) {
99             x1 = r.x1;
100         }
101         if(y1 < r.y1) {
102             y1 = r.y1;
103         }
104         return x1 <= x2 && y1 <= y2;
105     }
is_validrect_base106     bool is_valid() const
107     {
108         return x1 <= x2 && y1 <= y2;
109     }
110 };
111 template<class Rect>
intersect_rectangles(const Rect & r1,const Rect & r2)112 inline Rect intersect_rectangles(const Rect& r1, const Rect& r2)
113 {
114     Rect r = r1;
115     if(r.x2 > r2.x2) {
116         r.x2 = r2.x2;
117     }
118     if(r.y2 > r2.y2) {
119         r.y2 = r2.y2;
120     }
121     if(r.x1 < r2.x1) {
122         r.x1 = r2.x1;
123     }
124     if(r.y1 < r2.y1) {
125         r.y1 = r2.y1;
126     }
127     return r;
128 }
129 template<class Rect>
unite_rectangles(const Rect & r1,const Rect & r2)130 inline Rect unite_rectangles(const Rect& r1, const Rect& r2)
131 {
132     Rect r = r1;
133     if(r.x2 < r2.x2) {
134         r.x2 = r2.x2;
135     }
136     if(r.y2 < r2.y2) {
137         r.y2 = r2.y2;
138     }
139     if(r.x1 > r2.x1) {
140         r.x1 = r2.x1;
141     }
142     if(r.y1 > r2.y1) {
143         r.y1 = r2.y1;
144     }
145     return r;
146 }
147 typedef rect_base<int>    rect;
148 typedef rect_base<float> rect_d;
149 enum path_commands_e {
150     path_cmd_stop     = 0,
151     path_cmd_move_to  = 1,
152     path_cmd_line_to  = 2,
153     path_cmd_curve3   = 3,
154     path_cmd_curve4   = 4,
155     path_cmd_curveN   = 5,
156     path_cmd_catrom   = 6,
157     path_cmd_ubspline = 7,
158     path_cmd_end_poly = 0x0F,
159     path_cmd_mask     = 0x0F
160 };
161 enum path_flags_e {
162     path_flags_none  = 0,
163     path_flags_ccw   = 0x10,
164     path_flags_cw    = 0x20,
165     path_flags_close = 0x40,
166     path_flags_jr	 = 0x80,
167     path_flags_mask  = 0xF0
168 };
is_vertex(unsigned c)169 inline bool is_vertex(unsigned c)
170 {
171     c &= ~path_flags_jr;
172     return c >= path_cmd_move_to && c < path_cmd_end_poly;
173 }
is_drawing(unsigned c)174 inline bool is_drawing(unsigned c)
175 {
176     c &= ~path_flags_jr;
177     return c >= path_cmd_line_to && c < path_cmd_end_poly;
178 }
is_stop(unsigned c)179 inline bool is_stop(unsigned c)
180 {
181     c &= ~path_flags_jr;
182     return c == path_cmd_stop;
183 }
is_move_to(unsigned c)184 inline bool is_move_to(unsigned c)
185 {
186     c &= ~path_flags_jr;
187     return c == path_cmd_move_to;
188 }
is_line_to(unsigned c)189 inline bool is_line_to(unsigned c)
190 {
191     c &= ~path_flags_jr;
192     return c == path_cmd_line_to;
193 }
is_curve(unsigned c)194 inline bool is_curve(unsigned c)
195 {
196     c &= ~path_flags_jr;
197     return c == path_cmd_curve3 || c == path_cmd_curve4;
198 }
is_curve3(unsigned c)199 inline bool is_curve3(unsigned c)
200 {
201     c &= ~path_flags_jr;
202     return c == path_cmd_curve3;
203 }
is_curve4(unsigned c)204 inline bool is_curve4(unsigned c)
205 {
206     c &= ~path_flags_jr;
207     return c == path_cmd_curve4;
208 }
is_end_poly(unsigned c)209 inline bool is_end_poly(unsigned c)
210 {
211     c &= ~path_flags_jr;
212     return (c & path_cmd_mask) == path_cmd_end_poly;
213 }
is_close(unsigned c)214 inline bool is_close(unsigned c)
215 {
216     c &= ~path_flags_jr;
217     return (c & ~(path_flags_cw | path_flags_ccw)) ==
218            (path_cmd_end_poly | path_flags_close);
219 }
is_next_poly(unsigned c)220 inline bool is_next_poly(unsigned c)
221 {
222     c &= ~path_flags_jr;
223     return is_stop(c) || is_move_to(c) || is_end_poly(c);
224 }
is_cw(unsigned c)225 inline bool is_cw(unsigned c)
226 {
227     c &= ~path_flags_jr;
228     return (c & path_flags_cw) != 0;
229 }
is_ccw(unsigned c)230 inline bool is_ccw(unsigned c)
231 {
232     c &= ~path_flags_jr;
233     return (c & path_flags_ccw) != 0;
234 }
is_oriented(unsigned c)235 inline bool is_oriented(unsigned c)
236 {
237     c &= ~path_flags_jr;
238     return (c & (path_flags_cw | path_flags_ccw)) != 0;
239 }
is_closed(unsigned c)240 inline bool is_closed(unsigned c)
241 {
242     c &= ~path_flags_jr;
243     return (c & path_flags_close) != 0;
244 }
get_close_flag(unsigned c)245 inline unsigned get_close_flag(unsigned c)
246 {
247     c &= ~path_flags_jr;
248     return c & path_flags_close;
249 }
clear_orientation(unsigned c)250 inline unsigned clear_orientation(unsigned c)
251 {
252     c &= ~path_flags_jr;
253     return c & ~(path_flags_cw | path_flags_ccw);
254 }
get_orientation(unsigned c)255 inline unsigned get_orientation(unsigned c)
256 {
257     c &= ~path_flags_jr;
258     return c & (path_flags_cw | path_flags_ccw);
259 }
set_orientation(unsigned c,unsigned o)260 inline unsigned set_orientation(unsigned c, unsigned o)
261 {
262     c &= ~path_flags_jr;
263     return clear_orientation(c) | o;
264 }
265 struct point_type  {
266     float x, y;
267     unsigned flag;
point_typepoint_type268     point_type() {}
xpoint_type269     point_type(float x_, float y_, unsigned flag_ = 0) : x(x_), y(y_), flag(flag_) {}
270 };
271 struct vertex_type  {
272     float   x, y;
273     unsigned cmd;
vertex_typevertex_type274     vertex_type() {}
vertex_typevertex_type275     vertex_type(float x_, float y_, unsigned cmd_) :
276         x(x_), y(y_), cmd(cmd_) {}
277 };
278 }
279 }  // namespace pdfium
280 #endif
281