static void write_paths_transparent_rec(FILE *fout, potrace_path_t *tree) { potrace_path_t *p, *q; for (p=tree; p; p=p->sibling) { if (info.grouping == 2) { fprintf(fout, "<g>\n"); } if (info.grouping != 0) { column = fprintf(fout, "<path d=\""); newline = 1; lastop = 0; } if (info.debug == 1) { svg_jaggy_path(fout, p->priv->pt, p->priv->len, 1); } else { svg_path(fout, &p->curve, 1); } for (q=p->childlist; q; q=q->sibling) { if (info.debug == 1) { svg_jaggy_path(fout, q->priv->pt, q->priv->len, 0); } else { svg_path(fout, &q->curve, 0); } } if (info.grouping != 0) { fprintf(fout, "\"/>\n"); } for (q=p->childlist; q; q=q->sibling) { write_paths_transparent_rec(fout, q->childlist); } if (info.grouping == 2) { fprintf(fout, "</g>\n"); } } }
virtual void operator()(vector_marker_render_thunk const& thunk) { using blender_type = agg::comp_op_adaptor_rgba_pre<agg::rgba8, agg::order_rgba>; // comp blender using buf_type = agg::rendering_buffer; using pixfmt_comp_type = agg::pixfmt_custom_blend_rgba<blender_type, buf_type>; using renderer_base = agg::renderer_base<pixfmt_comp_type>; using renderer_type = agg::renderer_scanline_aa_solid<renderer_base>; using svg_attribute_type = agg::pod_bvector<svg::path_attributes>; using svg_renderer_type = svg::svg_renderer_agg<svg_path_adapter, svg_attribute_type, renderer_type, pixfmt_comp_type>; ras_ptr_->reset(); buf_type render_buffer(buf_->bytes(), buf_->width(), buf_->height(), buf_->row_size()); pixfmt_comp_type pixf(render_buffer); pixf.comp_op(static_cast<agg::comp_op_e>(thunk.comp_op_)); renderer_base renb(pixf); svg::vertex_stl_adapter<svg::svg_path_storage> stl_storage(thunk.src_->source()); svg_path_adapter svg_path(stl_storage); svg_renderer_type svg_renderer(svg_path, thunk.attrs_); agg::trans_affine offset_tr = thunk.tr_; offset_tr.translate(offset_.x, offset_.y); render_vector_marker(svg_renderer, *ras_ptr_, renb, thunk.src_->bounding_box(), offset_tr, thunk.opacity_, thunk.snap_to_pixels_); }
void render_pattern<image_rgba8>(rasterizer & ras, marker_svg const& marker, agg::trans_affine const& tr, double opacity, image_rgba8 & image) { using pixfmt = agg::pixfmt_rgba32_pre; using renderer_base = agg::renderer_base<pixfmt>; using renderer_solid = agg::renderer_scanline_aa_solid<renderer_base>; agg::scanline_u8 sl; mapnik::box2d<double> const& bbox = marker.bounding_box() * tr; mapnik::coord<double,2> c = bbox.center(); agg::trans_affine mtx = agg::trans_affine_translation(-c.x,-c.y); mtx.translate(0.5 * bbox.width(), 0.5 * bbox.height()); mtx = tr * mtx; agg::rendering_buffer buf(image.bytes(), image.width(), image.height(), image.row_size()); pixfmt pixf(buf); renderer_base renb(pixf); mapnik::svg::vertex_stl_adapter<mapnik::svg::svg_path_storage> stl_storage(marker.get_data()->source()); mapnik::svg::svg_path_adapter svg_path(stl_storage); mapnik::svg::svg_renderer_agg<mapnik::svg::svg_path_adapter, agg::pod_bvector<mapnik::svg::path_attributes>, renderer_solid, pixfmt > svg_renderer(svg_path, marker.get_data()->attributes()); svg_renderer.render(ras, sl, renb, mtx, opacity, bbox); }
cairo_surface_ptr operator()(marker_svg const & marker) const { box2d<double> bbox(marker.bounding_box()); agg::trans_affine tr(transform(bbox)); double width = std::max(1.0, std::round(bbox.width())); double height = std::max(1.0, std::round(bbox.height())); cairo_rectangle_t extent { 0, 0, width, height }; cairo_surface_ptr surface( cairo_recording_surface_create( CAIRO_CONTENT_COLOR_ALPHA, &extent), cairo_surface_closer()); cairo_ptr cairo = create_context(surface); cairo_context context(cairo); svg_storage_type & svg = *marker.get_data(); svg_attribute_type const& svg_attributes = svg.attributes(); svg::vertex_stl_adapter<svg::svg_path_storage> stl_storage( svg.source()); svg::svg_path_adapter svg_path(stl_storage); render_vector_marker(context, svg_path, svg_attributes, bbox, tr, opacity_); return surface; }
std::shared_ptr<image_data_32> render_pattern(rasterizer & ras, marker const& marker, agg::trans_affine const& tr, double opacity) { using pixfmt = agg::pixfmt_rgba32_pre; using renderer_base = agg::renderer_base<pixfmt>; using renderer_solid = agg::renderer_scanline_aa_solid<renderer_base>; agg::scanline_u8 sl; mapnik::box2d<double> const& bbox = (*marker.get_vector_data())->bounding_box() * tr; mapnik::coord<double,2> c = bbox.center(); agg::trans_affine mtx = agg::trans_affine_translation(-c.x,-c.y); mtx.translate(0.5 * bbox.width(), 0.5 * bbox.height()); mtx = tr * mtx; std::shared_ptr<mapnik::image_data_32> image = std::make_shared<mapnik::image_data_32>(bbox.width(), bbox.height()); agg::rendering_buffer buf(image->getBytes(), image->width(), image->height(), image->width() * 4); pixfmt pixf(buf); renderer_base renb(pixf); mapnik::svg::vertex_stl_adapter<mapnik::svg::svg_path_storage> stl_storage((*marker.get_vector_data())->source()); mapnik::svg::svg_path_adapter svg_path(stl_storage); mapnik::svg::svg_renderer_agg<mapnik::svg::svg_path_adapter, agg::pod_bvector<mapnik::svg::path_attributes>, renderer_solid, agg::pixfmt_rgba32_pre > svg_renderer(svg_path, (*marker.get_vector_data())->attributes()); svg_renderer.render(ras, sl, renb, mtx, opacity, bbox); return image; }
int operator() (mapnik::marker_svg const& marker) { using pixfmt = agg::pixfmt_rgba32_pre; using renderer_base = agg::renderer_base<pixfmt>; using renderer_solid = agg::renderer_scanline_aa_solid<renderer_base>; agg::rasterizer_scanline_aa<> ras_ptr; agg::scanline_u8 sl; double opacity = 1; int w = marker.width(); int h = marker.height(); if (verbose_) { std::clog << "found width of '" << w << "' and height of '" << h << "'\n"; } // 10 pixel buffer to avoid edge clipping of 100% svg's mapnik::image_rgba8 im(w+0,h+0); agg::rendering_buffer buf(im.bytes(), im.width(), im.height(), im.row_size()); pixfmt pixf(buf); renderer_base renb(pixf); mapnik::box2d<double> const& bbox = marker.get_data()->bounding_box(); mapnik::coord<double,2> c = bbox.center(); // center the svg marker on '0,0' agg::trans_affine mtx = agg::trans_affine_translation(-c.x,-c.y); // render the marker at the center of the marker box mtx.translate(0.5 * im.width(), 0.5 * im.height()); mapnik::svg::vertex_stl_adapter<mapnik::svg::svg_path_storage> stl_storage(marker.get_data()->source()); mapnik::svg::svg_path_adapter svg_path(stl_storage); mapnik::svg::svg_renderer_agg<mapnik::svg::svg_path_adapter, agg::pod_bvector<mapnik::svg::path_attributes>, renderer_solid, agg::pixfmt_rgba32_pre > svg_renderer_this(svg_path, marker.get_data()->attributes()); svg_renderer_this.render(ras_ptr, sl, renb, mtx, opacity, bbox); std::string png_name(svg_name_); boost::algorithm::ireplace_last(png_name,".svg",".png"); demultiply_alpha(im); mapnik::save_to_file<mapnik::image_rgba8>(im,png_name,"png"); int status = 0; if (auto_open_) { std::ostringstream s; #ifdef DARWIN s << "open " << png_name; #else s << "xdg-open " << png_name; #endif int ret = std::system(s.str().c_str()); if (ret != 0) status = ret; } std::clog << "rendered to: " << png_name << "\n"; return status; }
void grid_renderer<T>::render_marker(Feature const& feature, unsigned int step, const int x, const int y, marker &marker, const agg::trans_affine & tr, double opacity) { if (marker.is_vector()) { typedef coord_transform2<CoordTransform,geometry_type> path_type; typedef agg::renderer_base<mapnik::pixfmt_gray16> ren_base; typedef agg::renderer_scanline_bin_solid<ren_base> renderer; agg::scanline_bin sl; grid_rendering_buffer buf(pixmap_.raw_data(), width_, height_, width_); mapnik::pixfmt_gray16 pixf(buf); ren_base renb(pixf); renderer ren(renb); ras_ptr->reset(); box2d<double> const& bbox = (*marker.get_vector_data())->bounding_box(); coord<double,2> c = bbox.center(); // center the svg marker on '0,0' agg::trans_affine mtx = agg::trans_affine_translation(-c.x,-c.y); // apply symbol transformation to get to map space mtx *= tr; mtx *= agg::trans_affine_scaling(scale_factor_*(1.0/step)); // render the marker at the center of the marker box mtx.translate(x+0.5 * marker.width(), y+0.5 * marker.height()); vertex_stl_adapter<svg_path_storage> stl_storage((*marker.get_vector_data())->source()); svg_path_adapter svg_path(stl_storage); svg_renderer<svg_path_adapter, agg::pod_bvector<path_attributes>, renderer, mapnik::pixfmt_gray16> svg_renderer(svg_path, (*marker.get_vector_data())->attributes()); svg_renderer.render_id(*ras_ptr, sl, renb, feature.id(), mtx, opacity, bbox); } else { image_data_32 const& data = **marker.get_bitmap_data(); if (step == 1 && scale_factor_ == 1.0) { pixmap_.set_rectangle(feature.id(), data, x, y); } else { double ratio = (1.0/step); image_data_32 target(ratio * data.width(), ratio * data.height()); mapnik::scale_image_agg<image_data_32>(target,data, SCALING_NEAR, scale_factor_, 0.0, 0.0, 1.0, ratio); pixmap_.set_rectangle(feature.id(), target, x, y); } } pixmap_.add_feature(feature); }
static void write_paths_opaque(FILE *fout, potrace_path_t *tree) { potrace_path_t *p, *q; int c; for (p=tree; p; p=p->sibling) { if (info.group) { fprintf(fout, "<g>\n"); fprintf(fout, "<g>\n"); } c = fprintf(fout, "<path fill=\"#%06x\" stroke=\"none\" d=\"", info.color); column = c; newline = 1; lastop = 0; if (info.debug == 1) { svg_jaggy_path(fout, p->priv->pt, p->priv->len, 1); } else { svg_path(fout, &p->curve, 1); } fprintf(fout, "\"/>\n"); for (q=p->childlist; q; q=q->sibling) { c = fprintf(fout, "<path fill=\"#%06x\" stroke=\"none\" d=\"", info.fillcolor); column = c; newline = 1; lastop = 0; if (info.debug == 1) { svg_jaggy_path(fout, q->priv->pt, q->priv->len, 1); } else { svg_path(fout, &q->curve, 1); } fprintf(fout, "\"/>\n"); } if (info.group) { fprintf(fout, "</g>\n"); } for (q=p->childlist; q; q=q->sibling) { write_paths_opaque(fout, q->childlist); } if (info.group) { fprintf(fout, "</g>\n"); } } }
void operator() (marker_svg const& marker) { mapnik::svg_path_ptr vmarker = marker.get_data(); if (vmarker) { box2d<double> bbox = vmarker->bounding_box(); agg::trans_affine marker_tr = tr_; if (recenter_) { coord<double,2> c = bbox.center(); marker_tr = agg::trans_affine_translation(-c.x,-c.y); marker_tr *= tr_; } marker_tr *= agg::trans_affine_scaling(common_.scale_factor_); agg::pod_bvector<svg::path_attributes> const & attributes = vmarker->attributes(); svg::vertex_stl_adapter<svg::svg_path_storage> stl_storage(vmarker->source()); svg::svg_path_adapter svg_path(stl_storage); marker_tr.translate(pos_.x, pos_.y); render_vector_marker(context_, svg_path, attributes, bbox, marker_tr, opacity_); } }
virtual void operator()(vector_marker_render_thunk const& thunk) { using buf_type = grid_rendering_buffer; using pixfmt_type = typename grid_renderer_base_type::pixfmt_type; using renderer_type = agg::renderer_scanline_bin_solid<grid_renderer_base_type>; using svg_renderer_type = svg::renderer_agg<svg_path_adapter, svg_attribute_type, renderer_type, pixfmt_type>; buf_type render_buf(pixmap_.raw_data(), common_.width_, common_.height_, common_.width_); ras_.reset(); pixfmt_type pixf(render_buf); grid_renderer_base_type renb(pixf); renderer_type ren(renb); svg::vertex_stl_adapter<svg::svg_path_storage> stl_storage(thunk.src_->source()); svg_path_adapter svg_path(stl_storage); svg_renderer_type svg_renderer(svg_path, thunk.attrs_); agg::trans_affine offset_tr = thunk.tr_; offset_tr.translate(offset_.x, offset_.y); agg::scanline_bin sl; svg_renderer.render_id(ras_, sl, renb, feature_.id(), offset_tr, thunk.opacity_, thunk.src_->bounding_box()); pixmap_.add_feature(feature_); }
int main (int argc,char** argv) { namespace po = boost::program_options; bool verbose=false; std::vector<std::string> svg_files; try { po::options_description desc("svg2png utility"); desc.add_options() ("help,h", "produce usage message") ("version,V","print version string") ("verbose,v","verbose output") ("svg",po::value<std::vector<std::string> >(),"svg file to read") ; po::positional_options_description p; p.add("svg",-1); po::variables_map vm; po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm); po::notify(vm); if (vm.count("version")) { std::clog<<"version 0.3.0" << std::endl; return 1; } if (vm.count("help")) { std::clog << desc << std::endl; return 1; } if (vm.count("verbose")) { verbose = true; } if (vm.count("svg")) { svg_files=vm["svg"].as< std::vector<std::string> >(); } else { std::clog << "please provide an svg file!" << std::endl; return -1; } std::vector<std::string>::const_iterator itr = svg_files.begin(); if (itr == svg_files.end()) { std::clog << "no svg files to render" << std::endl; return 0; } while (itr != svg_files.end()) { std::string svg_name (*itr++); boost::optional<mapnik::marker_ptr> marker_ptr = mapnik::marker_cache::instance()->find(svg_name, false); if (marker_ptr) { mapnik::marker marker = **marker_ptr; if (marker.is_vector()) { typedef agg::pixfmt_rgba32_plain pixfmt; typedef agg::renderer_base<pixfmt> renderer_base; typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_solid; agg::rasterizer_scanline_aa<> ras_ptr; agg::scanline_u8 sl; double opacity = 1; double scale_factor_ = .95; int w = marker.width(); int h = marker.height(); mapnik::image_32 im(w,h); agg::rendering_buffer buf(im.raw_data(), w, h, w * 4); pixfmt pixf(buf); renderer_base renb(pixf); mapnik::box2d<double> const& bbox = (*marker.get_vector_data())->bounding_box(); mapnik::coord<double,2> c = bbox.center(); // center the svg marker on '0,0' agg::trans_affine mtx = agg::trans_affine_translation(-c.x,-c.y); // apply symbol transformation to get to map space mtx *= agg::trans_affine_scaling(scale_factor_); // render the marker at the center of the marker box mtx.translate(0.5 * w, 0.5 * h); mapnik::svg::vertex_stl_adapter<mapnik::svg::svg_path_storage> stl_storage((*marker.get_vector_data())->source()); mapnik::svg::svg_path_adapter svg_path(stl_storage); mapnik::svg::svg_renderer<mapnik::svg::svg_path_adapter, agg::pod_bvector<mapnik::svg::path_attributes>, renderer_solid, agg::pixfmt_rgba32_plain > svg_renderer_this(svg_path, (*marker.get_vector_data())->attributes()); svg_renderer_this.render(ras_ptr, sl, renb, mtx, opacity, bbox); boost::algorithm::ireplace_last(svg_name,".svg",".png"); mapnik::save_to_file<mapnik::image_data_32>(im.data(),svg_name,"png"); std::ostringstream s; s << "open " << svg_name; return system(s.str().c_str()); } } } } catch (...) { std::clog << "Exception of unknown type!" << std::endl; return -1; } return 0; }
int main (int argc,char** argv) { namespace po = boost::program_options; bool verbose = false; bool auto_open = false; int return_value = 0; std::vector<std::string> svg_files; mapnik::logger::instance().set_severity(mapnik::logger::error); try { po::options_description desc("svg2png utility"); desc.add_options() ("help,h", "produce usage message") ("version,V","print version string") ("verbose,v","verbose output") ("open","automatically open the file after rendering (os x only)") ("svg",po::value<std::vector<std::string> >(),"svg file to read") ; po::positional_options_description p; p.add("svg",-1); po::variables_map vm; po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm); po::notify(vm); if (vm.count("version")) { std::clog <<"version " << MAPNIK_VERSION_STRING << std::endl; return 1; } if (vm.count("help")) { std::clog << desc << std::endl; return 1; } if (vm.count("verbose")) { verbose = true; } if (vm.count("open")) { auto_open = true; } if (vm.count("svg")) { svg_files=vm["svg"].as< std::vector<std::string> >(); } else { std::clog << "please provide an svg file!" << std::endl; return -1; } std::vector<std::string>::const_iterator itr = svg_files.begin(); if (itr == svg_files.end()) { std::clog << "no svg files to render" << std::endl; return 0; } xmlInitParser(); while (itr != svg_files.end()) { std::string svg_name (*itr++); if (verbose) { std::clog << "found: " << svg_name << "\n"; } boost::optional<mapnik::marker_ptr> marker_ptr = mapnik::marker_cache::instance().find(svg_name, false); if (!marker_ptr) { std::clog << "svg2png error: could not open: '" << svg_name << "'\n"; return_value = -1; continue; } mapnik::marker marker = **marker_ptr; if (!marker.is_vector()) { std::clog << "svg2png error: '" << svg_name << "' is not a valid vector!\n"; return_value = -1; continue; } using pixfmt = agg::pixfmt_rgba32_pre; using renderer_base = agg::renderer_base<pixfmt>; using renderer_solid = agg::renderer_scanline_aa_solid<renderer_base>; agg::rasterizer_scanline_aa<> ras_ptr; agg::scanline_u8 sl; double opacity = 1; int w = marker.width(); int h = marker.height(); if (verbose) { std::clog << "found width of '" << w << "' and height of '" << h << "'\n"; } // 10 pixel buffer to avoid edge clipping of 100% svg's mapnik::image_32 im(w+0,h+0); agg::rendering_buffer buf(im.raw_data(), im.width(), im.height(), im.width() * 4); pixfmt pixf(buf); renderer_base renb(pixf); mapnik::box2d<double> const& bbox = (*marker.get_vector_data())->bounding_box(); mapnik::coord<double,2> c = bbox.center(); // center the svg marker on '0,0' agg::trans_affine mtx = agg::trans_affine_translation(-c.x,-c.y); // render the marker at the center of the marker box mtx.translate(0.5 * im.width(), 0.5 * im.height()); mapnik::svg::vertex_stl_adapter<mapnik::svg::svg_path_storage> stl_storage((*marker.get_vector_data())->source()); mapnik::svg::svg_path_adapter svg_path(stl_storage); mapnik::svg::svg_renderer_agg<mapnik::svg::svg_path_adapter, agg::pod_bvector<mapnik::svg::path_attributes>, renderer_solid, agg::pixfmt_rgba32_pre > svg_renderer_this(svg_path, (*marker.get_vector_data())->attributes()); svg_renderer_this.render(ras_ptr, sl, renb, mtx, opacity, bbox); boost::algorithm::ireplace_last(svg_name,".svg",".png"); im.demultiply(); mapnik::save_to_file<mapnik::image_data_rgba8>(im.data(),svg_name,"png"); if (auto_open) { std::ostringstream s; #ifdef DARWIN s << "open " << svg_name; #else s << "xdg-open " << svg_name; #endif int ret = system(s.str().c_str()); if (ret != 0) return_value = ret; } std::clog << "rendered to: " << svg_name << "\n"; } } catch (...) { std::clog << "Exception of unknown type!" << std::endl; xmlCleanupParser(); return -1; } // only call this once, on exit // to make sure valgrind output is clean // http://xmlsoft.org/xmlmem.html xmlCleanupParser(); return return_value; }