virtual void on_draw() { pixfmt pixf(rbuf_window()); renderer_base rb(pixf); renderer_solid r(rb); rb.clear(agg::rgba(1, 1, 1)); scanline_type sl; agg::rasterizer_scanline_aa<> ras; agg::simple_polygon_vertex_source path1(m_poly1.polygon(), m_poly1.num_points(), false, false); agg::simple_polygon_vertex_source path2(m_poly2.polygon(), m_poly2.num_points(), false, false); typedef agg::conv_bspline<agg::simple_polygon_vertex_source> conv_bspline_type; conv_bspline_type bspline1(path1); conv_bspline_type bspline2(path2); bspline1.interpolation_step(1.0 / m_num_points.value()); bspline2.interpolation_step(1.0 / m_num_points.value()); typedef agg::conv_curve<font_manager_type::path_adaptor_type> conv_font_curve_type; typedef agg::conv_segmentator<conv_font_curve_type> conv_font_segm_type; typedef agg::conv_transform<conv_font_segm_type, agg::trans_double_path> conv_font_trans_type; agg::trans_double_path tcurve; conv_font_curve_type fcurves(m_fman.path_adaptor()); conv_font_segm_type fsegm(fcurves); conv_font_trans_type ftrans(fsegm, tcurve); tcurve.preserve_x_scale(m_preserve_x_scale.status()); if(m_fixed_len.status()) tcurve.base_length(1140.0); tcurve.base_height(30.0); tcurve.add_paths(bspline1, bspline2); fsegm.approximation_scale(3.0); fcurves.approximation_scale(5.0); if(m_feng.load_font(full_file_name("timesi.ttf"), 0, agg::glyph_ren_outline)) { double x = 0.0; double y = 3.0; const char* p = text; m_feng.hinting(false); m_feng.height(40); while(*p) { const agg::glyph_cache* glyph = m_fman.glyph(*p); if(glyph) { if(x > tcurve.total_length1()) break; m_fman.add_kerning(&x, &y); m_fman.init_embedded_adaptors(glyph, x, y); if(glyph->data_type == agg::glyph_data_outline) { ras.reset(); ras.add_path(ftrans); r.color(agg::rgba8(0, 0, 0)); agg::render_scanlines(ras, sl, r); } // increment pen position x += glyph->advance_x; y += glyph->advance_y; } ++p; } } else { message("Please copy file timesi.ttf to the current directory\n" "or download it from http://www.antigrain.com/timesi.zip"); } typedef agg::conv_stroke<conv_bspline_type> conv_stroke_type; conv_stroke_type stroke1(bspline1); conv_stroke_type stroke2(bspline2); stroke1.width(2.0); stroke2.width(2.0); r.color(agg::rgba8(170, 50, 20, 100)); ras.add_path(stroke1); agg::render_scanlines(ras, sl, r); ras.add_path(stroke2); agg::render_scanlines(ras, sl, r); //-------------------------- // Render the "poly" tool and controls r.color(agg::rgba(0, 0.3, 0.5, 0.2)); ras.add_path(m_poly1); agg::render_scanlines(ras, sl, r); ras.add_path(m_poly2); agg::render_scanlines(ras, sl, r); agg::render_ctrl(ras, sl, rb, m_fixed_len); agg::render_ctrl(ras, sl, rb, m_preserve_x_scale); agg::render_ctrl(ras, sl, rb, m_animate); agg::render_ctrl(ras, sl, rb, m_num_points); //-------------------------- }
void MapPainterAgg::DrawContourLabel(const Projection& projection, const MapParameter& parameter, const PathTextStyle& style, const std::string& text, size_t transStart, size_t transEnd) { double fontSize=style.GetSize(); double r=style.GetTextColor().GetR(); double g=style.GetTextColor().GetG(); double b=style.GetTextColor().GetB(); double a=style.GetTextColor().GetA(); std::wstring wideText(UTF8StringToWString(text)); SetOutlineFont(projection, parameter, fontSize); //renderer_bin->color(agg::rgba(r,g,b,a)); renderer_aa->color(agg::rgba(r,g,b,a)); agg::path_storage path; double length=0; double xo=0; double yo=0; if (coordBuffer->buffer[transStart].GetX()<coordBuffer->buffer[transEnd].GetX()) { for (size_t j=transStart; j<=transEnd; j++) { if (j==transStart) { path.move_to(coordBuffer->buffer[j].GetX(), coordBuffer->buffer[j].GetY()); } else { path.line_to(coordBuffer->buffer[j].GetX(), coordBuffer->buffer[j].GetY()); length+=sqrt(pow(coordBuffer->buffer[j].GetX()-xo,2)+ pow(coordBuffer->buffer[j].GetY()-yo,2)); } xo=coordBuffer->buffer[j].GetX(); yo=coordBuffer->buffer[j].GetY(); } } else { for (size_t j=0; j<=transEnd-transStart; j++) { size_t idx=transEnd-j; if (j==0) { path.move_to(coordBuffer->buffer[idx].GetX(), coordBuffer->buffer[idx].GetY()); } else { path.line_to(coordBuffer->buffer[idx].GetX(), coordBuffer->buffer[idx].GetY()); length+=sqrt(pow(coordBuffer->buffer[idx].GetX()-xo,2)+ pow(coordBuffer->buffer[idx].GetY()-yo,2)); } xo=coordBuffer->buffer[idx].GetX(); yo=coordBuffer->buffer[idx].GetY(); } } double width; double height; GetTextDimension(wideText,width,height); if (width>length) { return; } /* typedef agg::conv_bspline<agg::path_storage> conv_bspline_type; conv_bspline_type bspline(path); bspline.interpolation_step(1.0 / path.total_vertices());*/ agg::trans_single_path tcurve; tcurve.add_path(path); // bspline typedef agg::conv_segmentator<AggTextCurveConverter> conv_font_segm_type; typedef agg::conv_transform<conv_font_segm_type, agg::trans_single_path> conv_font_trans_type; conv_font_segm_type fsegm(*convTextCurves); conv_font_trans_type ftrans(fsegm, tcurve); fsegm.approximation_scale(3.0); double x=(length-width)/2; double y=-height/2+fontEngine->ascender(); for (size_t i=0; i<wideText.length(); i++) { const agg::glyph_cache* glyph = fontCacheManager->glyph(wideText[i]); if (glyph!=NULL) { fontCacheManager->add_kerning(&x, &y); fontCacheManager->init_embedded_adaptors(glyph,x,y); if (glyph->data_type==agg::glyph_data_outline) { rasterizer->reset(); rasterizer->add_path(ftrans); renderer_aa->color(agg::rgba(r,g,b,a)); agg::render_scanlines(*rasterizer, *scanlineP8, *renderer_aa); } // increment pen position x += glyph->advance_x; y += glyph->advance_y; } } }
virtual void on_draw() { pixfmt pixf(rbuf_window()); renderer_base rb(pixf); renderer_solid r(rb); rb.clear(agg::rgba(1, 1, 1)); scanline_type sl; agg::rasterizer_scanline_aa<> ras; m_poly.close(m_close.status()); agg::simple_polygon_vertex_source path(m_poly.polygon(), m_poly.num_points(), false, m_close.status()); typedef agg::conv_bspline<agg::simple_polygon_vertex_source> conv_bspline_type; conv_bspline_type bspline(path); bspline.interpolation_step(1.0 / m_num_points.value()); agg::trans_single_path tcurve; tcurve.add_path(bspline); tcurve.preserve_x_scale(m_preserve_x_scale.status()); if(m_fixed_len.status()) tcurve.base_length(1120); typedef agg::conv_curve<font_manager_type::path_adaptor_type> conv_font_curve_type; typedef agg::conv_segmentator<conv_font_curve_type> conv_font_segm_type; typedef agg::conv_transform<conv_font_segm_type, agg::trans_single_path> conv_font_trans_type; conv_font_curve_type fcurves(m_fman.path_adaptor()); conv_font_segm_type fsegm(fcurves); conv_font_trans_type ftrans(fsegm, tcurve); fsegm.approximation_scale(3.0); fcurves.approximation_scale(2.0); m_feng.height(40.0); //m_feng.italic(true); if(m_feng.create_font("Times New Roman", agg::glyph_ren_outline)) { double x = 0.0; double y = 3.0; const char* p = text; while(*p) { const agg::glyph_cache* glyph = m_fman.glyph(*p); if(glyph) { if(x > tcurve.total_length()) break; m_fman.add_kerning(&x, &y); m_fman.init_embedded_adaptors(glyph, x, y); if(glyph->data_type == agg::glyph_data_outline) { ras.reset(); ras.add_path(ftrans); r.color(agg::rgba8(0, 0, 0)); agg::render_scanlines(ras, sl, r); } // increment pen position x += glyph->advance_x; y += glyph->advance_y; } ++p; } } typedef agg::conv_stroke<conv_bspline_type> conv_stroke_type; conv_stroke_type stroke(bspline); stroke.width(2.0); r.color(agg::rgba8(170, 50, 20, 100)); ras.add_path(stroke); agg::render_scanlines(ras, sl, r); //-------------------------- // Render the "poly" tool and controls r.color(agg::rgba(0, 0.3, 0.5, 0.3)); ras.add_path(m_poly); agg::render_scanlines(ras, sl, r); agg::render_ctrl(ras, sl, rb, m_close); agg::render_ctrl(ras, sl, rb, m_preserve_x_scale); agg::render_ctrl(ras, sl, rb, m_fixed_len); agg::render_ctrl(ras, sl, rb, m_animate); agg::render_ctrl(ras, sl, rb, m_num_points); //-------------------------- }