1 2 //---------------------------------------------------------------------------- 3 // Anti-Grain Geometry - Version 2.3 4 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) 5 // Copyright (C) 2005 Tony Juricic (tonygeek@yahoo.com) 6 // 7 // Permission to copy, use, modify, sell and distribute this software 8 // is granted provided this copyright notice appears in all copies. 9 // This software is provided "as is" without express or implied 10 // warranty, and with no claim as to its suitability for any purpose. 11 // 12 //---------------------------------------------------------------------------- 13 // Contact: mcseem@antigrain.com 14 // mcseemagg@yahoo.com 15 // http://www.antigrain.com 16 //---------------------------------------------------------------------------- 17 #ifndef AGG_CURVES_INCLUDED 18 #define AGG_CURVES_INCLUDED 19 #include "agg_array.h" 20 namespace pdfium 21 { 22 namespace agg 23 { 24 struct curve4_points { 25 float cp[8]; curve4_pointscurve4_points26 curve4_points() {} curve4_pointscurve4_points27 curve4_points(float x1, float y1, 28 float x2, float y2, 29 float x3, float y3, 30 float x4, float y4) 31 { 32 cp[0] = x1; 33 cp[1] = y1; 34 cp[2] = x2; 35 cp[3] = y2; 36 cp[4] = x3; 37 cp[5] = y3; 38 cp[6] = x4; 39 cp[7] = y4; 40 } initcurve4_points41 void init(float x1, float y1, 42 float x2, float y2, 43 float x3, float y3, 44 float x4, float y4) 45 { 46 cp[0] = x1; 47 cp[1] = y1; 48 cp[2] = x2; 49 cp[3] = y2; 50 cp[4] = x3; 51 cp[5] = y3; 52 cp[6] = x4; 53 cp[7] = y4; 54 } 55 float operator [] (unsigned i) const 56 { 57 return cp[i]; 58 } 59 float& operator [] (unsigned i) 60 { 61 return cp[i]; 62 } 63 }; 64 class curve4_div 65 { 66 public: curve4_div()67 curve4_div() : 68 m_count(0) 69 {} curve4_div(float x1,float y1,float x2,float y2,float x3,float y3,float x4,float y4)70 curve4_div(float x1, float y1, 71 float x2, float y2, 72 float x3, float y3, 73 float x4, float y4) : 74 m_count(0) 75 { 76 init(x1, y1, x2, y2, x3, y3, x4, y4); 77 } curve4_div(const curve4_points & cp)78 curve4_div(const curve4_points& cp) : 79 m_count(0) 80 { 81 init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]); 82 } reset()83 void reset() 84 { 85 m_points.remove_all(); 86 m_count = 0; 87 } 88 void init(float x1, float y1, 89 float x2, float y2, 90 float x3, float y3, 91 float x4, float y4); init(const curve4_points & cp)92 void init(const curve4_points& cp) 93 { 94 init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]); 95 } rewind(unsigned)96 void rewind(unsigned) 97 { 98 m_count = 0; 99 } vertex(float * x,float * y)100 unsigned vertex(float* x, float* y) 101 { 102 if(m_count >= m_points.size()) { 103 return path_cmd_stop; 104 } 105 const point_type& p = m_points[m_count++]; 106 *x = p.x; 107 *y = p.y; 108 return (m_count == 1) ? path_cmd_move_to : path_cmd_line_to; 109 } 110 private: 111 void bezier(float x1, float y1, 112 float x2, float y2, 113 float x3, float y3, 114 float x4, float y4); 115 void recursive_bezier(float x1, float y1, 116 float x2, float y2, 117 float x3, float y3, 118 float x4, float y4, 119 unsigned level); 120 float m_distance_tolerance_square; 121 float m_distance_tolerance_manhattan; 122 unsigned m_count; 123 pod_deque<point_type> m_points; 124 }; 125 class curve4 126 { 127 public: curve4()128 curve4() {} curve4(float x1,float y1,float x2,float y2,float x3,float y3,float x4,float y4)129 curve4(float x1, float y1, 130 float x2, float y2, 131 float x3, float y3, 132 float x4, float y4) 133 { 134 init(x1, y1, x2, y2, x3, y3, x4, y4); 135 } curve4(const curve4_points & cp)136 curve4(const curve4_points& cp) 137 { 138 init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]); 139 } reset()140 void reset() 141 { 142 m_curve_div.reset(); 143 } init(float x1,float y1,float x2,float y2,float x3,float y3,float x4,float y4)144 void init(float x1, float y1, 145 float x2, float y2, 146 float x3, float y3, 147 float x4, float y4) 148 { 149 m_curve_div.init(x1, y1, x2, y2, x3, y3, x4, y4); 150 } init(const curve4_points & cp)151 void init(const curve4_points& cp) 152 { 153 init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]); 154 } rewind(unsigned path_id)155 void rewind(unsigned path_id) 156 { 157 m_curve_div.rewind(path_id); 158 } vertex(float * x,float * y)159 unsigned vertex(float* x, float* y) 160 { 161 return m_curve_div.vertex(x, y); 162 } 163 private: 164 curve4_div m_curve_div; 165 }; 166 } 167 } // namespace pdfium 168 #endif 169