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 #ifndef AGG_RENDERER_SCANLINE_INCLUDED 17 #define AGG_RENDERER_SCANLINE_INCLUDED 18 #include "agg_basics.h" 19 #include "agg_renderer_base.h" 20 #include "agg_render_scanlines.h" 21 namespace pdfium 22 { 23 namespace agg 24 { 25 template<class BaseRenderer, class SpanGenerator> class renderer_scanline_aa 26 { 27 public: 28 typedef BaseRenderer base_ren_type; 29 typedef SpanGenerator span_gen_type; renderer_scanline_aa()30 renderer_scanline_aa() : m_ren(0), m_span_gen(0) {} renderer_scanline_aa(base_ren_type & ren,span_gen_type & span_gen)31 renderer_scanline_aa(base_ren_type& ren, span_gen_type& span_gen) : 32 m_ren(&ren), 33 m_span_gen(&span_gen) 34 {} attach(base_ren_type & ren,span_gen_type & span_gen)35 void attach(base_ren_type& ren, span_gen_type& span_gen) 36 { 37 m_ren = &ren; 38 m_span_gen = &span_gen; 39 } prepare(unsigned max_span_len)40 void prepare(unsigned max_span_len) 41 { 42 m_span_gen->prepare(max_span_len); 43 } render(const Scanline & sl)44 template<class Scanline> void render(const Scanline& sl) 45 { 46 int y = sl.y(); 47 m_ren->first_clip_box(); 48 do { 49 int xmin = m_ren->xmin(); 50 int xmax = m_ren->xmax(); 51 if(y >= m_ren->ymin() && y <= m_ren->ymax()) { 52 unsigned num_spans = sl.num_spans(); 53 typename Scanline::const_iterator span = sl.begin(); 54 for(;;) { 55 int x = span->x; 56 int len = span->len; 57 bool solid = false; 58 const typename Scanline::cover_type* covers = span->covers; 59 if(len < 0) { 60 solid = true; 61 len = -len; 62 } 63 if(x < xmin) { 64 len -= xmin - x; 65 if(!solid) { 66 covers += xmin - x; 67 } 68 x = xmin; 69 } 70 if(len > 0) { 71 if(x + len > xmax) { 72 len = xmax - x + 1; 73 } 74 if(len > 0) { 75 m_ren->blend_color_hspan_no_clip( 76 x, y, len, 77 m_span_gen->generate(x, y, len), 78 solid ? 0 : covers, 79 *covers); 80 } 81 } 82 if(--num_spans == 0) { 83 break; 84 } 85 ++span; 86 } 87 } 88 } while(m_ren->next_clip_box()); 89 } 90 private: 91 base_ren_type* m_ren; 92 SpanGenerator* m_span_gen; 93 }; 94 } 95 } // namespace pdfium 96 #endif 97