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 <math.h>
45 #include "core/fxcrt/fx_system.h"
46
47 namespace pdfium
48 {
49 namespace agg
50 {
51 typedef AGG_INT8 int8;
52 typedef AGG_INT8U int8u;
53 typedef AGG_INT16 int16;
54 typedef AGG_INT16U int16u;
55 typedef AGG_INT32 int32;
56 typedef AGG_INT32U int32u;
57 typedef AGG_INT64 int64;
58 typedef AGG_INT64U int64u;
59 typedef unsigned char cover_type;
60 enum cover_scale_e {
61 cover_shift = 8,
62 cover_size = 1 << cover_shift,
63 cover_mask = cover_size - 1,
64 cover_none = 0,
65 cover_full = cover_mask
66 };
67 template<class T> struct rect_base {
68 typedef rect_base<T> self_type;
69 T x1;
70 T y1;
71 T x2;
72 T y2;
rect_baserect_base73 rect_base() {}
rect_baserect_base74 rect_base(T x1_, T y1_, T x2_, T y2_) :
75 x1(x1_), y1(y1_), x2(x2_), y2(y2_) {}
normalizerect_base76 const self_type& normalize()
77 {
78 T t;
79 if(x1 > x2) {
80 t = x1;
81 x1 = x2;
82 x2 = t;
83 }
84 if(y1 > y2) {
85 t = y1;
86 y1 = y2;
87 y2 = t;
88 }
89 return *this;
90 }
cliprect_base91 bool clip(const self_type& r)
92 {
93 if(x2 > r.x2) {
94 x2 = r.x2;
95 }
96 if(y2 > r.y2) {
97 y2 = r.y2;
98 }
99 if(x1 < r.x1) {
100 x1 = r.x1;
101 }
102 if(y1 < r.y1) {
103 y1 = r.y1;
104 }
105 return x1 <= x2 && y1 <= y2;
106 }
is_validrect_base107 bool is_valid() const
108 {
109 return x1 <= x2 && y1 <= y2;
110 }
111 };
112 template<class Rect>
intersect_rectangles(const Rect & r1,const Rect & r2)113 inline Rect intersect_rectangles(const Rect& r1, const Rect& r2)
114 {
115 Rect r = r1;
116 if(r.x2 > r2.x2) {
117 r.x2 = r2.x2;
118 }
119 if(r.y2 > r2.y2) {
120 r.y2 = r2.y2;
121 }
122 if(r.x1 < r2.x1) {
123 r.x1 = r2.x1;
124 }
125 if(r.y1 < r2.y1) {
126 r.y1 = r2.y1;
127 }
128 return r;
129 }
130 template<class Rect>
unite_rectangles(const Rect & r1,const Rect & r2)131 inline Rect unite_rectangles(const Rect& r1, const Rect& r2)
132 {
133 Rect r = r1;
134 if(r.x2 < r2.x2) {
135 r.x2 = r2.x2;
136 }
137 if(r.y2 < r2.y2) {
138 r.y2 = r2.y2;
139 }
140 if(r.x1 > r2.x1) {
141 r.x1 = r2.x1;
142 }
143 if(r.y1 > r2.y1) {
144 r.y1 = r2.y1;
145 }
146 return r;
147 }
148 typedef rect_base<int> rect;
149 typedef rect_base<float> rect_d;
150 enum path_commands_e {
151 path_cmd_stop = 0,
152 path_cmd_move_to = 1,
153 path_cmd_line_to = 2,
154 path_cmd_curve3 = 3,
155 path_cmd_curve4 = 4,
156 path_cmd_curveN = 5,
157 path_cmd_catrom = 6,
158 path_cmd_ubspline = 7,
159 path_cmd_end_poly = 0x0F,
160 path_cmd_mask = 0x0F
161 };
162 enum path_flags_e {
163 path_flags_none = 0,
164 path_flags_ccw = 0x10,
165 path_flags_cw = 0x20,
166 path_flags_close = 0x40,
167 path_flags_jr = 0x80,
168 path_flags_mask = 0xF0
169 };
is_vertex(unsigned c)170 inline bool is_vertex(unsigned c)
171 {
172 c &= ~path_flags_jr;
173 return c >= path_cmd_move_to && c < path_cmd_end_poly;
174 }
is_drawing(unsigned c)175 inline bool is_drawing(unsigned c)
176 {
177 c &= ~path_flags_jr;
178 return c >= path_cmd_line_to && c < path_cmd_end_poly;
179 }
is_stop(unsigned c)180 inline bool is_stop(unsigned c)
181 {
182 c &= ~path_flags_jr;
183 return c == path_cmd_stop;
184 }
is_move_to(unsigned c)185 inline bool is_move_to(unsigned c)
186 {
187 c &= ~path_flags_jr;
188 return c == path_cmd_move_to;
189 }
is_line_to(unsigned c)190 inline bool is_line_to(unsigned c)
191 {
192 c &= ~path_flags_jr;
193 return c == path_cmd_line_to;
194 }
is_curve(unsigned c)195 inline bool is_curve(unsigned c)
196 {
197 c &= ~path_flags_jr;
198 return c == path_cmd_curve3 || c == path_cmd_curve4;
199 }
is_curve3(unsigned c)200 inline bool is_curve3(unsigned c)
201 {
202 c &= ~path_flags_jr;
203 return c == path_cmd_curve3;
204 }
is_curve4(unsigned c)205 inline bool is_curve4(unsigned c)
206 {
207 c &= ~path_flags_jr;
208 return c == path_cmd_curve4;
209 }
is_end_poly(unsigned c)210 inline bool is_end_poly(unsigned c)
211 {
212 c &= ~path_flags_jr;
213 return (c & path_cmd_mask) == path_cmd_end_poly;
214 }
is_close(unsigned c)215 inline bool is_close(unsigned c)
216 {
217 c &= ~path_flags_jr;
218 return (c & ~(path_flags_cw | path_flags_ccw)) ==
219 (unsigned{path_cmd_end_poly} | path_flags_close);
220 }
is_next_poly(unsigned c)221 inline bool is_next_poly(unsigned c)
222 {
223 c &= ~path_flags_jr;
224 return is_stop(c) || is_move_to(c) || is_end_poly(c);
225 }
is_cw(unsigned c)226 inline bool is_cw(unsigned c)
227 {
228 c &= ~path_flags_jr;
229 return (c & path_flags_cw) != 0;
230 }
is_ccw(unsigned c)231 inline bool is_ccw(unsigned c)
232 {
233 c &= ~path_flags_jr;
234 return (c & path_flags_ccw) != 0;
235 }
is_oriented(unsigned c)236 inline bool is_oriented(unsigned c)
237 {
238 c &= ~path_flags_jr;
239 return (c & (path_flags_cw | path_flags_ccw)) != 0;
240 }
is_closed(unsigned c)241 inline bool is_closed(unsigned c)
242 {
243 c &= ~path_flags_jr;
244 return (c & path_flags_close) != 0;
245 }
get_close_flag(unsigned c)246 inline unsigned get_close_flag(unsigned c)
247 {
248 c &= ~path_flags_jr;
249 return c & path_flags_close;
250 }
clear_orientation(unsigned c)251 inline unsigned clear_orientation(unsigned c)
252 {
253 c &= ~path_flags_jr;
254 return c & ~(path_flags_cw | path_flags_ccw);
255 }
get_orientation(unsigned c)256 inline unsigned get_orientation(unsigned c)
257 {
258 c &= ~path_flags_jr;
259 return c & (path_flags_cw | path_flags_ccw);
260 }
set_orientation(unsigned c,unsigned o)261 inline unsigned set_orientation(unsigned c, unsigned o)
262 {
263 c &= ~path_flags_jr;
264 return clear_orientation(c) | o;
265 }
266 struct point_type {
267 float x, y;
268 unsigned flag;
point_typepoint_type269 point_type() {}
xpoint_type270 point_type(float x_, float y_, unsigned flag_ = 0) : x(x_), y(y_), flag(flag_) {}
271 };
272 struct vertex_type {
273 float x, y;
274 unsigned cmd;
vertex_typevertex_type275 vertex_type() {}
vertex_typevertex_type276 vertex_type(float x_, float y_, unsigned cmd_) :
277 x(x_), y(y_), cmd(cmd_) {}
278 };
279 }
280 } // namespace pdfium
281 #endif
282