mapnik-c-api
mapnik-c-api copied to clipboard
Render to Cairo?
At present mapnik_map_render_to_file appears to be hardcoded to use agg:
mapnik_image_type buf(m->m->width(),m->m->height());
mapnik::agg_renderer<mapnik_image_type> ren(*m->m,buf);
ren.apply();
mapnik::save_to_file(buf,filepath);
What would it take to provide an equivalent method for Cairo?
Ah, this works, albeit mostly copypasta. Not sure if both #include
s are necessary.
#include <mapnik/cairo/cairo_renderer.hpp>
#include <mapnik/cairo_io.hpp>
int mapnik_map_render_to_cairo(mapnik_map_t * m, const char* filepath, double scale_factor, double scale_denominator) {
mapnik_map_reset_last_error(m);
if (m && m->m) {
try {
mapnik::save_to_cairo_file(*m->m, filepath, scale_factor, scale_denominator);
} catch (std::exception const& ex) {
m->err = new std::string(ex.what());
return -1;
}
return 0;
}
return -1;
}