1 //---------------------------------------------------------------------------- 2 // Anti-Grain Geometry (AGG) - Version 2.5 3 // A high quality rendering engine for C++ 4 // Copyright (C) 2002-2006 Maxim Shemanarev 5 // Contact: mcseem@antigrain.com 6 // mcseemagg@yahoo.com 7 // http://antigrain.com 8 // 9 // AGG is free software; you can redistribute it and/or 10 // modify it under the terms of the GNU General Public License 11 // as published by the Free Software Foundation; either version 2 12 // of the License, or (at your option) any later version. 13 // 14 // AGG is distributed in the hope that it will be useful, 15 // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 // GNU General Public License for more details. 18 // 19 // You should have received a copy of the GNU General Public License 20 // along with AGG; if not, write to the Free Software 21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 22 // MA 02110-1301, USA. 23 //---------------------------------------------------------------------------- 24 25 #ifndef AGG_RENDERER_RASTER_TEXT_INCLUDED 26 #define AGG_RENDERER_RASTER_TEXT_INCLUDED 27 28 #include "agg_basics.h" 29 30 namespace agg 31 { 32 33 //==============================================renderer_raster_htext_solid 34 template<class BaseRenderer, class GlyphGenerator> 35 class renderer_raster_htext_solid 36 { 37 public: 38 typedef BaseRenderer ren_type; 39 typedef GlyphGenerator glyph_gen_type; 40 typedef typename glyph_gen_type::glyph_rect glyph_rect; 41 typedef typename ren_type::color_type color_type; 42 renderer_raster_htext_solid(ren_type & ren,glyph_gen_type & glyph)43 renderer_raster_htext_solid(ren_type& ren, glyph_gen_type& glyph) : 44 m_ren(&ren), 45 m_glyph(&glyph) 46 {} attach(ren_type & ren)47 void attach(ren_type& ren) { m_ren = &ren; } 48 49 //-------------------------------------------------------------------- color(const color_type & c)50 void color(const color_type& c) { m_color = c; } color()51 const color_type& color() const { return m_color; } 52 53 //-------------------------------------------------------------------- 54 template<class CharT> 55 void render_text(double x, double y, const CharT* str, bool flip=false) 56 { 57 glyph_rect r; 58 while(*str) 59 { 60 m_glyph->prepare(&r, x, y, *str, flip); 61 if(r.x2 >= r.x1) 62 { 63 int i; 64 if(flip) 65 { 66 for(i = r.y1; i <= r.y2; i++) 67 { 68 m_ren->blend_solid_hspan(r.x1, i, (r.x2 - r.x1 + 1), 69 m_color, 70 m_glyph->span(r.y2 - i)); 71 } 72 } 73 else 74 { 75 for(i = r.y1; i <= r.y2; i++) 76 { 77 m_ren->blend_solid_hspan(r.x1, i, (r.x2 - r.x1 + 1), 78 m_color, 79 m_glyph->span(i - r.y1)); 80 } 81 } 82 } 83 x += r.dx; 84 y += r.dy; 85 ++str; 86 } 87 } 88 89 private: 90 ren_type* m_ren; 91 glyph_gen_type* m_glyph; 92 color_type m_color; 93 }; 94 95 96 97 //=============================================renderer_raster_vtext_solid 98 template<class BaseRenderer, class GlyphGenerator> 99 class renderer_raster_vtext_solid 100 { 101 public: 102 typedef BaseRenderer ren_type; 103 typedef GlyphGenerator glyph_gen_type; 104 typedef typename glyph_gen_type::glyph_rect glyph_rect; 105 typedef typename ren_type::color_type color_type; 106 renderer_raster_vtext_solid(ren_type & ren,glyph_gen_type & glyph)107 renderer_raster_vtext_solid(ren_type& ren, glyph_gen_type& glyph) : 108 m_ren(&ren), 109 m_glyph(&glyph) 110 { 111 } 112 113 //-------------------------------------------------------------------- color(const color_type & c)114 void color(const color_type& c) { m_color = c; } color()115 const color_type& color() const { return m_color; } 116 117 //-------------------------------------------------------------------- 118 template<class CharT> 119 void render_text(double x, double y, const CharT* str, bool flip=false) 120 { 121 glyph_rect r; 122 while(*str) 123 { 124 m_glyph->prepare(&r, x, y, *str, !flip); 125 if(r.x2 >= r.x1) 126 { 127 int i; 128 if(flip) 129 { 130 for(i = r.y1; i <= r.y2; i++) 131 { 132 m_ren->blend_solid_vspan(i, r.x1, (r.x2 - r.x1 + 1), 133 m_color, 134 m_glyph->span(i - r.y1)); 135 } 136 } 137 else 138 { 139 for(i = r.y1; i <= r.y2; i++) 140 { 141 m_ren->blend_solid_vspan(i, r.x1, (r.x2 - r.x1 + 1), 142 m_color, 143 m_glyph->span(r.y2 - i)); 144 } 145 } 146 } 147 x += r.dx; 148 y += r.dy; 149 ++str; 150 } 151 } 152 153 private: 154 ren_type* m_ren; 155 glyph_gen_type* m_glyph; 156 color_type m_color; 157 }; 158 159 160 161 162 163 164 //===================================================renderer_raster_htext 165 template<class ScanlineRenderer, class GlyphGenerator> 166 class renderer_raster_htext 167 { 168 public: 169 typedef ScanlineRenderer ren_type; 170 typedef GlyphGenerator glyph_gen_type; 171 typedef typename glyph_gen_type::glyph_rect glyph_rect; 172 173 class scanline_single_span 174 { 175 public: 176 typedef agg::cover_type cover_type; 177 178 //---------------------------------------------------------------- 179 struct const_span 180 { 181 int x; 182 unsigned len; 183 const cover_type* covers; 184 const_spanconst_span185 const_span() {} const_spanconst_span186 const_span(int x_, unsigned len_, const cover_type* covers_) : 187 x(x_), len(len_), covers(covers_) 188 {} 189 }; 190 191 typedef const const_span* const_iterator; 192 193 //---------------------------------------------------------------- scanline_single_span(int x,int y,unsigned len,const cover_type * covers)194 scanline_single_span(int x, int y, unsigned len, 195 const cover_type* covers) : 196 m_y(y), 197 m_span(x, len, covers) 198 {} 199 200 //---------------------------------------------------------------- y()201 int y() const { return m_y; } num_spans()202 unsigned num_spans() const { return 1; } begin()203 const_iterator begin() const { return &m_span; } 204 205 private: 206 //---------------------------------------------------------------- 207 int m_y; 208 const_span m_span; 209 }; 210 211 212 213 //-------------------------------------------------------------------- renderer_raster_htext(ren_type & ren,glyph_gen_type & glyph)214 renderer_raster_htext(ren_type& ren, glyph_gen_type& glyph) : 215 m_ren(&ren), 216 m_glyph(&glyph) 217 { 218 } 219 220 221 //-------------------------------------------------------------------- 222 template<class CharT> 223 void render_text(double x, double y, const CharT* str, bool flip=false) 224 { 225 glyph_rect r; 226 while(*str) 227 { 228 m_glyph->prepare(&r, x, y, *str, flip); 229 if(r.x2 >= r.x1) 230 { 231 m_ren->prepare(); 232 int i; 233 if(flip) 234 { 235 for(i = r.y1; i <= r.y2; i++) 236 { 237 m_ren->render( 238 scanline_single_span(r.x1, 239 i, 240 (r.x2 - r.x1 + 1), 241 m_glyph->span(r.y2 - i))); 242 } 243 } 244 else 245 { 246 for(i = r.y1; i <= r.y2; i++) 247 { 248 m_ren->render( 249 scanline_single_span(r.x1, 250 i, 251 (r.x2 - r.x1 + 1), 252 m_glyph->span(i - r.y1))); 253 } 254 } 255 } 256 x += r.dx; 257 y += r.dy; 258 ++str; 259 } 260 } 261 262 private: 263 ren_type* m_ren; 264 glyph_gen_type* m_glyph; 265 }; 266 267 268 269 270 } 271 272 #endif 273 274