1. 程式人生 > >AGG第三十六課 gsv_text_outline 渲染環繞的字符

AGG第三十六課 gsv_text_outline 渲染環繞的字符

text gsv outline

agg::rendering_buffer &rbuf = rbuf_window();

agg::pixfmt_bgr24 pixf(rbuf);


typedef agg::renderer_base<agg::pixfmt_bgr24> renderer_base_type;

renderer_base_type renb(pixf);


typedef agg::renderer_scanline_bin_solid<renderer_base_type> renderder_scanline_type;

renderder_scanline_type rensl(renb);


agg::rasterizer_scanline_aa<> ras;

agg::scanline_u8 sl;

ras.reset();


renb.clear(agg::rgba8(255,255,255));


agg::ellipse ell(400, 100, 100, 100);

agg::conv_stroke<agg::ellipse> stroke(ell);

ras.add_path(stroke);

agg::render_scanlines_aa_solid(ras,sl,renb,agg::rgba8(255, 0, 0));

ras.reset();


agg::gsv_text txt;

agg::trans_single_path transPath;

transPath.add_path(ell);

agg::gsv_text_outline<agg::trans_single_path> txtOutLine(txt, transPath);


txt.flip(true);

txt.size(10);

txt.start_point(100, -15);

txt.space(5);//字符之間的間距

txt.text("http://fengyuzaitu.blog.51cto.com");

ras.add_path(txtOutLine);

agg::render_scanlines_aa_solid(ras,sl,renb,agg::rgba8(255, 0, 0));

ras.reset();


註意:

1 start_point指定的方向不再是真實的屏幕坐標,而是相對於頂點源的起始渲染坐標,當前渲染的橢圓是從橢圓的最右邊的點,順時針開始渲染,第一個參數可以理解為在渲染的弧線上距離起點多遠的路程之後開始渲染字符,其中trans_single_path提供了total_length計算路徑的長度,可以方便部署每一個字符所在的位置(相對於起點),第二個參數是指定字符偏離路徑的寬度,正負數值分別是在內測還是外側進行偏離


AGG第三十六課 gsv_text_outline 渲染環繞的字符