Merge pull request #4029 from mapycz/svg-1.2
Cairo: set version of SVG to 1.2
This commit is contained in:
commit
653bd92ce9
3 changed files with 46 additions and 1 deletions
|
@ -82,6 +82,7 @@ void save_to_cairo_file(mapnik::Map const& map,
|
|||
else if (type == "svg")
|
||||
{
|
||||
surface = cairo_surface_ptr(cairo_svg_surface_create(filename.c_str(),width,height),cairo_surface_closer());
|
||||
cairo_svg_surface_restrict_to_version(surface.get(), CAIRO_SVG_VERSION_1_2);
|
||||
}
|
||||
#endif
|
||||
#ifdef CAIRO_HAS_PS_SURFACE
|
||||
|
|
34
test/unit/renderer/cairo_io.cpp
Normal file
34
test/unit/renderer/cairo_io.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
#include "catch.hpp"
|
||||
|
||||
#include <mapnik/cairo_io.hpp>
|
||||
#include <mapnik/util/fs.hpp>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#include <mapnik/warning_ignore.hpp>
|
||||
#include <boost/filesystem/convenience.hpp>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#if defined(HAVE_CAIRO)
|
||||
TEST_CASE("cairo_io") {
|
||||
|
||||
SECTION("save_to_cairo_file - SVG") {
|
||||
std::string directory_name("/tmp/mapnik-tests/");
|
||||
boost::filesystem::create_directories(directory_name);
|
||||
REQUIRE(mapnik::util::exists(directory_name));
|
||||
|
||||
std::string output_file(directory_name + "test_save_to_cairo_file.svg");
|
||||
|
||||
mapnik::Map map(256, 256);
|
||||
mapnik::save_to_cairo_file(map, output_file);
|
||||
|
||||
std::ifstream stream(output_file, std::ios_base::in | std::ios_base::binary);
|
||||
std::string actual_output(std::istreambuf_iterator<char>(stream.rdbuf()), std::istreambuf_iterator<char>());
|
||||
|
||||
// Check the Cairo SVG surface is using SVG 1.2
|
||||
CHECK(actual_output.find("version=\"1.2\"") != std::string::npos);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
|
@ -180,7 +180,17 @@ struct cairo_vector_renderer : vector_renderer_base
|
|||
};
|
||||
|
||||
#ifdef CAIRO_HAS_SVG_SURFACE
|
||||
struct cairo_svg_renderer : cairo_vector_renderer<cairo_svg_surface_create_for_stream>
|
||||
inline cairo_surface_t *create_svg_1_2(cairo_write_func_t write_func,
|
||||
void *closure,
|
||||
double width,
|
||||
double height)
|
||||
{
|
||||
cairo_surface_t * surface = cairo_svg_surface_create_for_stream(write_func, closure, width, height);
|
||||
cairo_svg_surface_restrict_to_version(surface, CAIRO_SVG_VERSION_1_2);
|
||||
return surface;
|
||||
}
|
||||
|
||||
struct cairo_svg_renderer : cairo_vector_renderer<create_svg_1_2>
|
||||
{
|
||||
static constexpr const char * name = "cairo-svg";
|
||||
static constexpr const char * ext = ".svg";
|
||||
|
|
Loading…
Reference in a new issue