AGG学习之九----自带gsv_text对象raster方式绘制字符
2012-01-06 10:14
239 查看
使用AGG绘制字符方式有很多种:
使用AGG自带的 gsv_text 对象;
使用 WinAPI 字体引擎;
使用 FreeType 字体引擎;
使用字体缓存管理器。
首先,我们使用自带的gsv_text对象,在rastser方式下绘制字符。样例代码如下:
#include <agg_pixfmt_rgba.h>
#include <agg_rasterizer_scanline_aa.h>
#include <agg_scanline_p.h>
#include <agg_gsv_text.h>
#include <agg_rendering_buffer.h>
#include <agg_basics.h>
#include <platform/agg_platform_support.h>
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));
// gsv_text类
agg::gsv_text txt;
agg::conv_stroke<agg::gsv_text> cstxt(txt);
txt.flip(false); // 设置是否反转
txt.size(30); // 高、宽
txt.line_space(10); // 行间距
txt.space(5); // 字符间距
// 设置位置和文字
txt.start_point(100,100);
txt.text("program\nC++");
cstxt.width(3); // 线宽
cstxt.line_cap(agg::butt_cap); // 线端样式
// 输出红色绿色文字
ras.add_path(cstxt);
agg::render_scanlines_aa_solid(ras,sl,renb,agg::rgba(0,1,0));
// 红色十字定位,中心坐标为(100,100)
renb.copy_hline( 90, 100, 110, agg::rgba(1, 0, 0, 0) );
renb.copy_vline( 100, 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;
}
显示效果:
注意:
红色十字中心点坐标为(100,100),是绘制字符传入的起始坐标。
绘制效果图显示,传入的绘制起始坐标点并非是字符实际绘制的外框左上角点或左下角点。
所以,如果需要在指定位置绘制字符,则需要预先精确计算绘制实际位置、传入绘制坐标之间的差值。
gsv_text对象,自动处理了换行。
gsv_text对象,虽然可以设定行间距,带行间距并未减除字符边线的宽度,需要开发者注意计算。
gsv_text仅能处理西文字符,无法处理中文。
使用AGG自带的 gsv_text 对象;
使用 WinAPI 字体引擎;
使用 FreeType 字体引擎;
使用字体缓存管理器。
首先,我们使用自带的gsv_text对象,在rastser方式下绘制字符。样例代码如下:
#include <agg_pixfmt_rgba.h>
#include <agg_rasterizer_scanline_aa.h>
#include <agg_scanline_p.h>
#include <agg_gsv_text.h>
#include <agg_rendering_buffer.h>
#include <agg_basics.h>
#include <platform/agg_platform_support.h>
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));
// gsv_text类
agg::gsv_text txt;
agg::conv_stroke<agg::gsv_text> cstxt(txt);
txt.flip(false); // 设置是否反转
txt.size(30); // 高、宽
txt.line_space(10); // 行间距
txt.space(5); // 字符间距
// 设置位置和文字
txt.start_point(100,100);
txt.text("program\nC++");
cstxt.width(3); // 线宽
cstxt.line_cap(agg::butt_cap); // 线端样式
// 输出红色绿色文字
ras.add_path(cstxt);
agg::render_scanlines_aa_solid(ras,sl,renb,agg::rgba(0,1,0));
// 红色十字定位,中心坐标为(100,100)
renb.copy_hline( 90, 100, 110, agg::rgba(1, 0, 0, 0) );
renb.copy_vline( 100, 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;
}
显示效果:
注意:
红色十字中心点坐标为(100,100),是绘制字符传入的起始坐标。
绘制效果图显示,传入的绘制起始坐标点并非是字符实际绘制的外框左上角点或左下角点。
所以,如果需要在指定位置绘制字符,则需要预先精确计算绘制实际位置、传入绘制坐标之间的差值。
gsv_text对象,自动处理了换行。
gsv_text对象,虽然可以设定行间距,带行间距并未减除字符边线的宽度,需要开发者注意计算。
gsv_text仅能处理西文字符,无法处理中文。
相关文章推荐
- AGG学习之十----FreeType库 raster方式绘制字符
- MVC3学习 七 JQuery方式和微软自带的AJAX请求
- 【OpenCV 学习】自带示例:随机数发生器&绘制文字 代码注释解析
- OpenGL ES(第一篇绘制方式) 学习
- OpenGL学习脚印: 基本图形绘制方式比较(glBegin,glCallList,glVertexPointer,VBO)
- Direct-X学习笔记--光照&材质&DX自带几何体绘制
- 学习数码相框1.2.0.0字符的编码方式_显示点阵文字_freetype_在PC上测试freetype
- 字符设备驱动学习笔记----查询方式取得按键值
- AGG第三十六课 gsv_text_outline 渲染环绕的字符
- 学习springmvc的第六天(@PathVariable 注解、Ant字符匹配、指定请求方式)
- 中英文数字字符等混合字符串精确测量字符大小并两种方式绘制比较
- 学习OpenGL(四)绘制直线
- OpenGLES入门笔记:Rajawali学习(3)模型绘制的基本流程
- Spring学习总结(三)——Spring实现AOP的多种方式
- SpringMVC学习(二)-RequestMapping修饰类&请求参数&请求方式&请求头
- spring学习(八)—AOP通过注解方式实现
- 如何整合Apache和Tomcat (两种方式1.Apache自带的proxy 2.mod_jk 1.21(mod_jk-apache-2.2.4.so))
- IDL 直接图像法绘制直方图(自定义坐标范围,图名、坐标轴支持中文字符)
- 学习xhtml的第六课(特殊字符,列表,图片
- OpenGL学习——函数语法(数据类型,函数命名方式,辅助库,平台独立性)