update dev300-m58
[ooovba.git] / agg / inc / agg_renderer_raster_text.h
blobbe4d22e57a28b20cb3afb61ca8c5897fe36cfc20
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.3
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4 //
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all copies.
7 // This software is provided "as is" without express or implied
8 // warranty, and with no claim as to its suitability for any purpose.
9 //
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
16 #ifndef AGG_RENDERER_RASTER_TEXT_INCLUDED
17 #define AGG_RENDERER_RASTER_TEXT_INCLUDED
19 #include "agg_basics.h"
21 namespace agg
24 //==============================================renderer_raster_htext_solid
25 template<class BaseRenderer, class GlyphGenerator>
26 class renderer_raster_htext_solid
28 public:
29 typedef BaseRenderer ren_type;
30 typedef GlyphGenerator glyph_gen_type;
31 typedef typename glyph_gen_type::glyph_rect glyph_rect;
32 typedef typename ren_type::color_type color_type;
34 renderer_raster_htext_solid(ren_type& ren, glyph_gen_type& glyph) :
35 m_ren(&ren),
36 m_glyph(&glyph)
40 //--------------------------------------------------------------------
41 void color(const color_type& c) { m_color = c; }
42 const color_type& color() const { return m_color; }
44 //--------------------------------------------------------------------
45 template<class CharT>
46 void render_text(double x, double y, const CharT* str, bool flip=false)
48 glyph_rect r;
49 while(*str)
51 m_glyph->prepare(&r, x, y, *str, flip);
52 if(r.x2 >= r.x1)
54 int i;
55 if(flip)
57 for(i = r.y1; i <= r.y2; i++)
59 m_ren->blend_solid_hspan(r.x1, i, (r.x2 - r.x1 + 1),
60 m_color,
61 m_glyph->span(r.y2 - i));
64 else
66 for(i = r.y1; i <= r.y2; i++)
68 m_ren->blend_solid_hspan(r.x1, i, (r.x2 - r.x1 + 1),
69 m_color,
70 m_glyph->span(i - r.y1));
74 x += r.dx;
75 y += r.dy;
76 ++str;
80 private:
81 ren_type* m_ren;
82 glyph_gen_type* m_glyph;
83 color_type m_color;
88 //=============================================renderer_raster_vtext_solid
89 template<class BaseRenderer, class GlyphGenerator>
90 class renderer_raster_vtext_solid
92 public:
93 typedef BaseRenderer ren_type;
94 typedef GlyphGenerator glyph_gen_type;
95 typedef typename glyph_gen_type::glyph_rect glyph_rect;
96 typedef typename ren_type::color_type color_type;
98 renderer_raster_vtext_solid(ren_type& ren, glyph_gen_type& glyph) :
99 m_ren(&ren),
100 m_glyph(&glyph)
104 //--------------------------------------------------------------------
105 void color(const color_type& c) { m_color = c; }
106 const color_type& color() const { return m_color; }
108 //--------------------------------------------------------------------
109 template<class CharT>
110 void render_text(double x, double y, const CharT* str, bool flip=false)
112 glyph_rect r;
113 while(*str)
115 m_glyph->prepare(&r, x, y, *str, !flip);
116 if(r.x2 >= r.x1)
118 int i;
119 if(flip)
121 for(i = r.y1; i <= r.y2; i++)
123 m_ren->blend_solid_vspan(i, r.x1, (r.x2 - r.x1 + 1),
124 m_color,
125 m_glyph->span(i - r.y1));
128 else
130 for(i = r.y1; i <= r.y2; i++)
132 m_ren->blend_solid_vspan(i, r.x1, (r.x2 - r.x1 + 1),
133 m_color,
134 m_glyph->span(r.y2 - i));
138 x += r.dx;
139 y += r.dy;
140 ++str;
144 private:
145 ren_type* m_ren;
146 glyph_gen_type* m_glyph;
147 color_type m_color;
155 //===================================================renderer_raster_htext
156 template<class ScanlineRenderer, class GlyphGenerator>
157 class renderer_raster_htext
159 public:
160 typedef ScanlineRenderer ren_type;
161 typedef GlyphGenerator glyph_gen_type;
162 typedef typename glyph_gen_type::glyph_rect glyph_rect;
164 class scanline_single_span
166 public:
167 typedef agg::cover_type cover_type;
169 //----------------------------------------------------------------
170 struct const_span
172 int x;
173 unsigned len;
174 const cover_type* covers;
176 const_span() {}
177 const_span(int x_, unsigned len_, const cover_type* covers_) :
178 x(x_), len(len_), covers(covers_)
182 typedef const const_span* const_iterator;
184 //----------------------------------------------------------------
185 scanline_single_span(int x, int y, unsigned len,
186 const cover_type* covers) :
187 m_y(y),
188 m_span(x, len, covers)
191 //----------------------------------------------------------------
192 int y() const { return m_y; }
193 unsigned num_spans() const { return 1; }
194 const_iterator begin() const { return &m_span; }
196 private:
197 //----------------------------------------------------------------
198 int m_y;
199 const_span m_span;
204 //--------------------------------------------------------------------
205 renderer_raster_htext(ren_type& ren, glyph_gen_type& glyph) :
206 m_ren(&ren),
207 m_glyph(&glyph)
212 //--------------------------------------------------------------------
213 template<class CharT>
214 void render_text(double x, double y, const CharT* str, bool flip=false)
216 glyph_rect r;
217 while(*str)
219 m_glyph->prepare(&r, x, y, *str, flip);
220 if(r.x2 >= r.x1)
222 m_ren->prepare(r.x2 - r.x1 + 1);
223 int i;
224 if(flip)
226 for(i = r.y1; i <= r.y2; i++)
228 m_ren->render(
229 scanline_single_span(r.x1,
231 (r.x2 - r.x1 + 1),
232 m_glyph->span(r.y2 - i)));
235 else
237 for(i = r.y1; i <= r.y2; i++)
239 m_ren->render(
240 scanline_single_span(r.x1,
242 (r.x2 - r.x1 + 1),
243 m_glyph->span(i - r.y1)));
247 x += r.dx;
248 y += r.dy;
249 ++str;
253 private:
254 ren_type* m_ren;
255 glyph_gen_type* m_glyph;
263 #endif