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: [email protected] 13 // [email protected] 14 // http://www.antigrain.com 15 //---------------------------------------------------------------------------- 16 // 17 // class renderer_base 18 // 19 //---------------------------------------------------------------------------- 20 #ifndef AGG_RENDERER_BASE_INCLUDED 21 #define AGG_RENDERER_BASE_INCLUDED 22 #include "agg_basics.h" 23 #include "agg_rendering_buffer.h" 24 namespace pdfium 25 { 26 namespace agg 27 { 28 template<class PixelFormat> class renderer_base 29 { 30 public: 31 typedef PixelFormat pixfmt_type; 32 typedef typename pixfmt_type::color_type color_type; 33 typedef typename pixfmt_type::row_data row_data; 34 typedef typename pixfmt_type::span_data span_data; renderer_base()35 renderer_base() : m_ren(0), m_clip_box(1, 1, 0, 0) {} renderer_base(pixfmt_type & ren)36 renderer_base(pixfmt_type& ren) : 37 m_ren(&ren), 38 m_clip_box(0, 0, ren.width() - 1, ren.height() - 1) 39 {} attach(pixfmt_type & ren)40 void attach(pixfmt_type& ren) 41 { 42 m_ren = &ren; 43 m_clip_box = rect(0, 0, ren.width() - 1, ren.height() - 1); 44 } ren()45 const pixfmt_type& ren() const 46 { 47 return *m_ren; 48 } ren()49 pixfmt_type& ren() 50 { 51 return *m_ren; 52 } width()53 unsigned width() const 54 { 55 return m_ren->width(); 56 } height()57 unsigned height() const 58 { 59 return m_ren->height(); 60 } first_clip_box()61 void first_clip_box() {} next_clip_box()62 bool next_clip_box() 63 { 64 return false; 65 } clip_box()66 const rect& clip_box() const 67 { 68 return m_clip_box; 69 } xmin()70 int xmin() const 71 { 72 return m_clip_box.x1; 73 } ymin()74 int ymin() const 75 { 76 return m_clip_box.y1; 77 } xmax()78 int xmax() const 79 { 80 return m_clip_box.x2; 81 } ymax()82 int ymax() const 83 { 84 return m_clip_box.y2; 85 } bounding_clip_box()86 const rect& bounding_clip_box() const 87 { 88 return m_clip_box; 89 } bounding_xmin()90 int bounding_xmin() const 91 { 92 return m_clip_box.x1; 93 } bounding_ymin()94 int bounding_ymin() const 95 { 96 return m_clip_box.y1; 97 } bounding_xmax()98 int bounding_xmax() const 99 { 100 return m_clip_box.x2; 101 } bounding_ymax()102 int bounding_ymax() const 103 { 104 return m_clip_box.y2; 105 } blend_hline(int x1,int y,int x2,const color_type & c,cover_type cover)106 void blend_hline(int x1, int y, int x2, 107 const color_type& c, cover_type cover) 108 { 109 if(x1 > x2) { 110 int t = x2; 111 x2 = x1; 112 x1 = t; 113 } 114 if(y > ymax()) { 115 return; 116 } 117 if(y < ymin()) { 118 return; 119 } 120 if(x1 > xmax()) { 121 return; 122 } 123 if(x2 < xmin()) { 124 return; 125 } 126 if(x1 < xmin()) { 127 x1 = xmin(); 128 } 129 if(x2 > xmax()) { 130 x2 = xmax(); 131 } 132 m_ren->blend_hline(x1, y, x2 - x1 + 1, c, cover); 133 } blend_solid_hspan(int x,int y,int len,const color_type & c,const cover_type * covers)134 void blend_solid_hspan(int x, int y, int len, 135 const color_type& c, 136 const cover_type* covers) 137 { 138 if(y > ymax()) { 139 return; 140 } 141 if(y < ymin()) { 142 return; 143 } 144 if(x < xmin()) { 145 len -= xmin() - x; 146 if(len <= 0) { 147 return; 148 } 149 covers += xmin() - x; 150 x = xmin(); 151 } 152 if(x + len > xmax()) { 153 len = xmax() - x + 1; 154 if(len <= 0) { 155 return; 156 } 157 } 158 m_ren->blend_solid_hspan(x, y, len, c, covers); 159 } 160 private: 161 pixfmt_type* m_ren; 162 rect m_clip_box; 163 }; 164 } 165 } // namespace pdfium 166 #endif 167