AGG学习之十一----font_cache_manager使用(FreeType在Rasterizer层应用)
2012-01-09 13:46
459 查看
font_cache_manager
1. 定义: template<class FontEngine> class font_cache_manager;可以对FreeType与win32两种font Engine进行包装.
2.
typedef path_adaptor_type | 把字体数据包装成顶点源的类 |
typedef gray8_adaptor_type | 把字体数据包装成Scanline Rasterizer的类 |
typedef mono_adaptor_type | 把字体数据包装成Scanline Rasterizer的类,但无AA效果 |
3.
字体高度,单位为Point
字体宽度,单位为Point*2.4. 0表示规则大小(height/2.4)
样例代码
#pragma comment(lib, "freetype.lib") #include <agg_pixfmt_rgba.h> #include <agg_rasterizer_scanline_aa.h> #include <agg_scanline_p.h> #include <agg_font_freetype.h> #include <agg_rendering_buffer.h> #include <agg_basics.h> #include <platform/agg_platform_support.h> #include "agg_font_cache_manager.h" #include <vector> using namespace std; typedef agg::font_engine_freetype_int32 fe_type; typedef fe_type::path_adaptor_type vs_type; class the_application : public agg::platform_support { public: the_application(agg::pix_format_e format, bool flip_y): agg::platform_support(format,flip_y) {} virtual ~the_application() { } virtual void on_init(){} virtual void on_draw() { agg::rasterizer_scanline_aa<> ras; agg::scanline_p8 sl; agg::rendering_buffer rbuf = this->rbuf_window(); agg::pixfmt_rgba32 pixf(rbuf); agg::renderer_base<agg::pixfmt_rgba32> renb(pixf); // 屏幕清空为白色 renb.clear(agg::rgba(1, 1, 1, 0)); fe_type fe; agg::font_cache_manager<fe_type> font_manager(fe); if( !fe.load_font( "./微软雅黑.ttf", 0, agg::glyph_ren_agg_gray8) ) // 第三个参数描述包装字体数据方式不同 return; fe.height(50); fe.width(25.5); fe.flip_y(false); fe.hinting(true); // 画所有字符 vector<agg::rect_i> bounds; const agg::glyph_cache *glyph; wchar_t *text = L"测 试FreeType+Raster\0"; int x=50, y=100; for( ; *text; ++text ) { //取字模 glyph = font_manager.glyph( *text ); if(glyph) { font_manager.init_embedded_adaptors(glyph, x, y); agg::render_scanlines_aa_solid( font_manager.gray8_adaptor(), font_manager.gray8_scanline(), renb, agg::rgba(0, 0, 0) ); x += glyph->advance_x; y += glyph->advance_y; } } // 红色十字定位,中心坐标为 (50,50) renb.copy_hline( 40, 100, 60, agg::rgba(1, 0, 0, 0) ); renb.copy_vline( 50, 90, 110, agg::rgba(1, 0, 0, 0) ); } }; int agg_main(int argc, char* argv[]) { the_application app(agg::pix_format_rgba32, true); app.caption("My AGG Demo"); if(app.init(320, 200, agg::window_resize )) { app.run(); } return 1; }
效果图
注
1. 红色十字中心为绘制起始点。 绘制起始点不是文字的外包的角点.2. 显示效果不够精细,似乎有"毛刺",反锯齿效果不理想.
3. 可调节字体width,使字体横纵比可不一致.
4. 未找到将所有文字graph都取得后,一次性绘制的方法。只能每一个字符调用一次绘制。
相关文章推荐
- AGG学习之十二----font_cache_manager使用(FreeType在vertex source层应用)
- 使用Cache-Control和gzip提升tomcat应用性能(整理)
- JAVA学习笔记(十一):enum的使用
- Symbian学习笔记(4):在GUI应用中使用图像
- Oracle学习(十一)之使用RMAN对数据库做在线完全备份
- SpringMVC的学习应用:使用IntelliJ IDEA开发SpringMVC网站
- android应用开发学习纪实(4)(火箭一般的android模拟器genymotion的使用)
- flume学习(十一):如何使用Spooling Directory Source
- Cache-control使用Cache-control:private学习笔记
- 【深度学习框架Caffe学习与应用】第三课 使用训练好的模型
- Hadoop-2.4.1学习之使用Quorum Journal Manager的HDFS的高可用性(二)
- 学习笔记 --- LINUX应用调试之使用GDB
- Android应用开发学习—Toast使用方法
- Android应用开发学习笔记04--使用布局
- Android应用开发学习—Toast的使用(位置变化及重新自定义)
- 从零开始学习Sencha Touch MVC应用之十一
- glib学习笔记三(续)——GLib核心应用支持:在Linux下使用IO通道(IO Channels)
- JSP学习笔记(一百二十三):使用axis1.4开发webservice应用(二)
- MVC学习十一:浅谈在ASP.NET MVC3中使用IClientValidatable接口实现客户端和服务器端同时验证