mapnik-c-api icon indicating copy to clipboard operation
mapnik-c-api copied to clipboard

Render to Cairo?

Open systemed opened this issue 9 years ago • 1 comments

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?

systemed avatar Dec 10 '15 00:12 systemed

Ah, this works, albeit mostly copypasta. Not sure if both #includes 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;
}

systemed avatar Dec 10 '15 01:12 systemed