From fafc751e427eb1385afaba544b5ecb181c2e4afa Mon Sep 17 00:00:00 2001 From: artemp Date: Tue, 20 Jun 2017 10:37:35 +0200 Subject: [PATCH] svg_parser - add support for "href" preserving deprecated (since SVG 2) "xlink:href" --- src/svg/svg_parser.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/svg/svg_parser.cpp b/src/svg/svg_parser.cpp index afb51e9c2..d6f020dc3 100644 --- a/src/svg/svg_parser.cpp +++ b/src/svg/svg_parser.cpp @@ -74,9 +74,10 @@ BOOST_FUSION_ADAPT_STRUCT ( (double, y1) ) + namespace mapnik { namespace svg { -namespace rapidxml = boost::property_tree::detail::rapidxml; + namespace rapidxml = boost::property_tree::detail::rapidxml; bool traverse_tree(svg_parser& parser, rapidxml::xml_node const* node); void end_element(svg_parser& parser, rapidxml::xml_node const* node); @@ -131,6 +132,13 @@ boost::property_tree::detail::rapidxml::xml_attribute const * parse_id(svg return id_attr; } +boost::property_tree::detail::rapidxml::xml_attribute const * parse_href(rapidxml::xml_node const* node) +{ + auto const* attr = node->first_attribute("xlink:href"); + if (attr == nullptr) attr = node->first_attribute("href"); + return attr; +} + template mapnik::color parse_color(T & err_handler, const char* str) { @@ -662,7 +670,7 @@ void parse_path(svg_parser & parser, rapidxml::xml_node const* node) void parse_use(svg_parser & parser, rapidxml::xml_node const* node) { - auto * attr = node->first_attribute("xlink:href"); + auto * attr = parse_href(node); if (attr) { auto const* value = attr->value(); @@ -1019,7 +1027,7 @@ void parse_gradient_stop(svg_parser & parser, mapnik::gradient& gr, rapidxml::xm bool parse_common_gradient(svg_parser & parser, std::string const& id, mapnik::gradient& gr, rapidxml::xml_node const* node) { // check if we should inherit from another tag - auto * attr = node->first_attribute("xlink:href"); + auto * attr = parse_href(node); if (attr != nullptr) { auto const* value = attr->value();