From 9549a1cc0159fb8fdb3624f21523e039acc8587e Mon Sep 17 00:00:00 2001 From: jakepruitt Date: Thu, 30 Jul 2015 16:40:34 -0400 Subject: [PATCH] Adding tests for radial gradients with percentages --- test/data | 2 +- test/unit/svg/svg_parser_test.cpp | 45 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/test/data b/test/data index 28be586d7..3b714b97d 160000 --- a/test/data +++ b/test/data @@ -1 +1 @@ -Subproject commit 28be586d71b24fe1bcdf70bc9ba37dc4f63860fc +Subproject commit 3b714b97dcde432b7f3507cab0fe254e6af647af diff --git a/test/unit/svg/svg_parser_test.cpp b/test/unit/svg/svg_parser_test.cpp index 55ba5a376..551682ce3 100644 --- a/test/unit/svg/svg_parser_test.cpp +++ b/test/unit/svg/svg_parser_test.cpp @@ -63,6 +63,25 @@ TEST_CASE("SVG parser") { REQUIRE(marker->is()); } + SECTION("SVG syntax") + { + std::string svg_name("./test/data/svg/invalid.svg"); + std::ifstream in(svg_name.c_str()); + std::string svg_str((std::istreambuf_iterator(in)), + std::istreambuf_iterator()); + + using namespace mapnik::svg; + mapnik::svg_storage_type path; + vertex_stl_adapter stl_storage(path.source()); + svg_path_adapter svg_path(stl_storage); + svg_converter_type svg(svg_path, path.attributes()); + svg_parser p(svg); + + if (!p.parse_from_string(svg_str)) + { + } + } + SECTION("SVG parser color ") { @@ -681,6 +700,7 @@ TEST_CASE("SVG parser") { transform *= agg::trans_affine_translation(240,155); REQUIRE(attrs[1].fill_gradient.get_transform() == transform); } + SECTION("SVG with xlink:href") { std::string svg_name("./test/data/svg/gradient-xhref.svg"); @@ -699,4 +719,29 @@ TEST_CASE("SVG parser") { REQUIRE(attrs[1].fill_gradient.get_gradient_type() == mapnik::LINEAR); REQUIRE(attrs[1].fill_gradient.has_stop()); } + + SECTION("SVG with radial percents") + { + std::string svg_name("./test/data/svg/gradient-radial-percents.svg"); + std::shared_ptr marker = mapnik::marker_cache::instance().find(svg_name, false); + REQUIRE(marker); + REQUIRE(marker->is()); + mapnik::marker_svg const& svg = mapnik::util::get(*marker); + auto bbox = svg.bounding_box(); + REQUIRE(bbox == mapnik::box2d(0,0,200,200)); + auto storage = svg.get_data(); + REQUIRE(storage); + + double x1, x2, y1, y2, r; + auto const& attrs = storage->attributes(); + REQUIRE(attrs.size() == 1 ); + REQUIRE(attrs[0].fill_gradient.get_gradient_type() == mapnik::RADIAL); + REQUIRE(attrs[0].fill_gradient.has_stop()); + attrs[0].fill_gradient.get_control_points(x1, y1, x2, y2, r); + REQUIRE(x1 == 0); + REQUIRE(y1 == 25); + REQUIRE(x2 == 10); + REQUIRE(y2 == 10); + REQUIRE(r == 75); + } }