author | Francesco Abbate <francesco.bbt@gmail.com> | 2012年06月30日 23:43:40 +0200 |
---|---|---|
committer | unknown <Maria@abbate-95206d9a.(none)> | 2012年07月03日 16:14:56 +0200 |
commit | ff82ea90e8046da871fd3885588e1b0538257a9b (patch) | |
tree | 1cb280dedcf609042e9e0af7dec9160c1733abc8 | |
parent | 71d027c178756db13d44ae52ddd13bb010d4151d (diff) | |
download | gsl-shell-ff82ea90e8046da871fd3885588e1b0538257a9b.tar.gz |
-rw-r--r-- | agg-plot/canvas.h | 19 | ||||
-rw-r--r-- | agg-plot/font_renderer.h | 101 | ||||
-rw-r--r-- | agg-plot/sg_object.h | 11 | ||||
-rw-r--r-- | agg-plot/text.cpp | 38 | ||||
-rw-r--r-- | agg-plot/text.h | 10 |
diff --git a/agg-plot/canvas.h b/agg-plot/canvas.h index 2f0eedf2..27fe7725 100644 --- a/agg-plot/canvas.h +++ b/agg-plot/canvas.h @@ -18,12 +18,18 @@ template <class Pixel> class canvas_gen : private Pixel { + + enum { subpixel_scale = 3 }; + typedef agg::renderer_base<typename Pixel::fmt> renderer_base; typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_solid; renderer_base rb; renderer_solid rs; + agg::renderer_base<typename Pixel::lcd_fmt> rb_subpixel; + agg::renderer_scanline_aa_solid<agg::renderer_base<typename Pixel::lcd_fmt> > rs_subpixel; + agg::rasterizer_scanline_aa<> ras; agg::scanline_u8 sl; @@ -36,6 +42,7 @@ public: canvas_gen(agg::rendering_buffer& ren_buf, double width, double height, agg::rgba bgcol): Pixel(ren_buf), rb(Pixel::pixfmt), rs(rb), + rb_subpixel(Pixel::pixfmt_lcd), rs_subpixel(rb_subpixel), ras(), sl(), bg_color(bgcol), m_width(width), m_height(height) { @@ -61,9 +68,15 @@ public: void draw(sg_object& vs, agg::rgba8 c) { - bool direct_render = vs.render(this->pixfmt_lcd, this->ras, this->sl, c); - - if (!direct_render) + if (vs.use_subpixel()) + { + agg::trans_affine_scaling subpixel_mtx(double(subpixel_scale), 1.0); + agg::conv_transform<sg_object> trans(vs, subpixel_mtx); + this->ras.add_path(trans); + this->rs_subpixel.color(c); + agg::render_scanlines(this->ras, this->sl, this->rs_subpixel); + } + else { this->ras.add_path(vs); this->rs.color(c); diff --git a/agg-plot/font_renderer.h b/agg-plot/font_renderer.h deleted file mode 100644 index 7d4b183c..00000000 --- a/agg-plot/font_renderer.h +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef AGGPLOT_FONT_RENDERER_H -#define AGGPLOT_FONT_RENDERER_H - -#include "agg_renderer_scanline.h" -#include "agg_conv_transform.h" -#include "agg_font_freetype.h" -#include "agg_conv_curve.h" - - -class font_renderer { - typedef agg::font_engine_freetype_int32 font_engine_type; - typedef agg::font_cache_manager<font_engine_type> font_manager_type; - - enum { scale_x = 100, subpixel_scale = 3 }; - -public: - font_renderer(const char *font_name, double text_height): - m_font_eng(), m_font_man(m_font_eng) - { - agg::glyph_rendering gren = agg::glyph_ren_outline; - m_font_eng.load_font(font_name, 0, gren); - m_font_eng.hinting(true); - - m_font_eng.height(text_height); - m_font_eng.width(text_height * scale_x); - } - - template <class Rasterizer, class Scanline, class RenSolid> - void draw_text(Rasterizer& ras, Scanline& sl, RenSolid& ren_solid, - const agg::trans_affine& user_matrix, - double x, double y, const char* text, int text_length, - agg::rgba8 color) - { - typedef agg::conv_curve<font_manager_type::path_adaptor_type> curve_type; - - agg::trans_affine mtx = user_matrix; - agg::trans_affine_scaling scale_mtx(1.0 / double(scale_x), 1.0); - trans_affine_compose (mtx, scale_mtx); - - curve_type curves(m_font_man.path_adaptor()); - agg::conv_transform<curve_type> trans(curves, mtx); - - agg::trans_affine_scaling subpixel_mtx(subpixel_scale, 1.0); - agg::conv_transform<agg::conv_transform<curve_type> > subpixel_trans(trans, subpixel_mtx); - - const double start_x = x; - - for (const char* p = text; p < text + text_length; p++) - { - const agg::glyph_cache* glyph = m_font_man.glyph(*p); - - if (!glyph) continue; - - m_font_man.add_kerning(&x, &y); - - m_font_man.init_embedded_adaptors(glyph, 0, 0); - if(glyph->data_type == agg::glyph_data_outline) - { - mtx.tx = start_x + x / scale_x; - mtx.ty = floor(y + 0.5); - - user_matrix.transform(&mtx.tx, &mtx.ty); - - ras.add_path(subpixel_trans); - ren_solid.color(color); - agg::render_scanlines(ras, sl, ren_solid); - } - - // increment pen position - x += glyph->advance_x; - y += glyph->advance_y; - } - } - - double text_width(const char* text, int text_length) - { - double x = 0, y = 0; - - for (const char* p = text; p < text + text_length; p++) - { - const agg::glyph_cache* glyph = m_font_man.glyph(*p); - - if (glyph) - { - m_font_man.add_kerning(&x, &y); - /* We suppose that the embedded adaptors doesn't play to - determine the text width. */ - /* m_font_man.init_embedded_adaptors(glyph, 0, 0); */ - x += glyph->advance_x; - } - } - - return x / double(scale_x); - } - -private: - font_engine_type m_font_eng; - font_manager_type m_font_man; -}; - -#endif diff --git a/agg-plot/sg_object.h b/agg-plot/sg_object.h index 2aca06b4..e863e828 100644 --- a/agg-plot/sg_object.h +++ b/agg-plot/sg_object.h @@ -45,11 +45,7 @@ struct sg_object : public vertex_source { virtual void apply_transform(const agg::trans_affine& m, double as) = 0; virtual void bounding_box(double *x1, double *y1, double *x2, double *y2) = 0; - - virtual bool render(pixel_type::lcd_fmt& ren_buf, agg::rasterizer_scanline_aa<>& ras, agg::scanline_u8& sl, agg::rgba8 c) - { - return false; - } + virtual bool use_subpixel() { return false; } virtual bool affine_compose(agg::trans_affine& m) { return false; } @@ -208,10 +204,7 @@ public: virtual bool affine_compose(agg::trans_affine& m) { return this->m_source->affine_compose(m); } - virtual bool render(pixel_type::lcd_fmt& ren_buf, agg::rasterizer_scanline_aa<>& ras, agg::scanline_u8& sl, agg::rgba8 c) - { - return m_source->render(ren_buf, ras, sl, c); - } + virtual bool use_subpixel() { return m_source->use_subpixel(); } private: sg_object* m_source; diff --git a/agg-plot/text.cpp b/agg-plot/text.cpp index d23ecf25..82c05b8c 100644 --- a/agg-plot/text.cpp +++ b/agg-plot/text.cpp @@ -8,21 +8,6 @@ namespace draw { -#if 0 - void - text::rewind(unsigned path_id) - { - m_text.start_point (-m_hjustif * m_text_width, -m_vjustif * m_text_height); - m_stroke.rewind(path_id); - } - - unsigned - text::vertex(double* x, double* y) - { - return m_stroke.vertex(x, y); - } -#endif - void text::apply_transform(const agg::trans_affine& m, double as) { @@ -98,27 +83,4 @@ namespace draw { return s; } - -#if 0 - bool text::render(pixel_type::lcd_fmt& pixbuf, - agg::rasterizer_scanline_aa<>& ras, - agg::scanline_u8& sl, agg::rgba8 c) - { - typedef agg::renderer_base<pixel_type::lcd_fmt> renderer_type; - - renderer_type ren_base(pixbuf); - agg::renderer_scanline_aa_solid<renderer_type> ren_solid(ren_base); - - const char *text = m_text_buf.cstr(); - unsigned text_length = m_text_buf.len(); - double text_width = m_font_ren.text_width(text, text_length); - double x = -m_hjustif * text_width; - double y = -m_vjustif * m_text_height; - - m_font_ren.draw_text(ras, sl, ren_solid, m_matrix, x, y, - text, text_length, c); - - return true; - } -#endif } diff --git a/agg-plot/text.h b/agg-plot/text.h index ca5bf81f..9edafa30 100644 --- a/agg-plot/text.h +++ b/agg-plot/text.h @@ -15,7 +15,7 @@ namespace draw { class text : public sg_object { - enum { scale_x = 100, subpixel_scale = 3 }; + enum { scale_x = 100 }; typedef agg::font_engine_freetype_int32 font_engine_type; typedef agg::font_cache_manager<font_engine_type> font_manager_type; @@ -169,18 +169,12 @@ namespace draw { void hjustif(double hj) { m_hjustif = hj; } void vjustif(double vj) { m_vjustif = vj; } -// virtual void rewind(unsigned path_id); -// virtual unsigned vertex(double* x, double* y); virtual void apply_transform(const agg::trans_affine& m, double as); virtual void bounding_box(double *x1, double *y1, double *x2, double *y2); virtual str write_svg(int id, agg::rgba8 c, double h); -#if 0 - virtual bool render(pixel_type::lcd_fmt& ren_buf, - agg::rasterizer_scanline_aa<>& ras, - agg::scanline_u8& sl, agg::rgba8 c); -#endif + virtual bool use_subpixel() { return true; } const vs_text& self() const { return m_text; }; vs_text& self() { return m_text; }; |