diff --git a/include/mapnik/svg/svg_path_attributes.hpp b/include/mapnik/svg/svg_path_attributes.hpp index 7e180fdce..57544ac21 100644 --- a/include/mapnik/svg/svg_path_attributes.hpp +++ b/include/mapnik/svg/svg_path_attributes.hpp @@ -79,8 +79,7 @@ struct path_attributes even_odd_flag(false), visibility_flag(true), display_flag(true) - { - } + {} // Copy constructor path_attributes(path_attributes const& attr) diff --git a/include/mapnik/svg/svg_renderer_agg.hpp b/include/mapnik/svg/svg_renderer_agg.hpp index ad574cc62..b7d41f5bd 100644 --- a/include/mapnik/svg/svg_renderer_agg.hpp +++ b/include/mapnik/svg/svg_renderer_agg.hpp @@ -60,12 +60,10 @@ namespace mapnik { namespace svg { +// Arbitrary linear gradient specified by two control points. Gradient +// value is taken as the normalised distance along the line segment +// represented by the two points. -/** - * Arbitrary linear gradient specified by two control points. Gradient - * value is taken as the normalised distance along the line segment - * represented by the two points. - */ class linear_gradient_from_segment { public: @@ -105,14 +103,14 @@ template ; - using curved_stroked_type = agg::conv_stroke ; + using curved_type = agg::conv_curve; + using curved_stroked_type = agg::conv_stroke; using curved_stroked_trans_type = agg::conv_transform; - using curved_trans_type = agg::conv_transform ; - using curved_trans_contour_type = agg::conv_contour ; - using renderer_base = agg::renderer_base ; - using vertex_source_type = VertexSource ; - using attribute_source_type = AttributeSource ; + using curved_trans_type = agg::conv_transform; + using curved_trans_contour_type = agg::conv_contour; + using renderer_base = agg::renderer_base; + using vertex_source_type = VertexSource; + using attribute_source_type = AttributeSource; svg_renderer_agg(VertexSource & source, AttributeSource const& attributes) : source_(source), @@ -191,11 +189,11 @@ public: // scale everything up since agg turns things into integers a bit too soon int scaleup=255; - radius*=scaleup; - x1*=scaleup; - y1*=scaleup; - x2*=scaleup; - y2*=scaleup; + radius *= scaleup; + x1 *= scaleup; + y1 *= scaleup; + x2 *= scaleup; + y2 *= scaleup; transform.scale(scaleup,scaleup); interpolator_type span_interpolator(transform); @@ -217,10 +215,10 @@ public: color_func_type>; // scale everything up since agg turns things into integers a bit too soon int scaleup=255; - x1*=scaleup; - y1*=scaleup; - x2*=scaleup; - y2*=scaleup; + x1 *= scaleup; + y1 *= scaleup; + x2 *= scaleup; + y2 *= scaleup; transform.scale(scaleup,scaleup); @@ -288,7 +286,8 @@ public: if(attr.fill_gradient.get_gradient_type() != NO_GRADIENT) { - render_gradient(ras, sl, ren, attr.fill_gradient, transform, attr.fill_opacity * attr.opacity * opacity, symbol_bbox, curved_trans, attr.index); + render_gradient(ras, sl, ren, attr.fill_gradient, transform, + attr.fill_opacity * attr.opacity * opacity, symbol_bbox, curved_trans, attr.index); } else { @@ -324,7 +323,8 @@ public: if(attr.stroke_gradient.get_gradient_type() != NO_GRADIENT) { - render_gradient(ras, sl, ren, attr.stroke_gradient, transform, attr.stroke_opacity * attr.opacity * opacity, symbol_bbox, curved_trans, attr.index); + render_gradient(ras, sl, ren, attr.stroke_gradient, transform, + attr.stroke_opacity * attr.opacity * opacity, symbol_bbox, curved_trans, attr.index); } else { diff --git a/include/mapnik/symbolizer.hpp b/include/mapnik/symbolizer.hpp index 40283b9d3..39d650d32 100644 --- a/include/mapnik/symbolizer.hpp +++ b/include/mapnik/symbolizer.hpp @@ -317,12 +317,8 @@ struct evaluate_expression_wrapper mapnik::value_type val = util::apply_visitor(mapnik::evaluate(feature,vars), expr); if (val.is_null()) return dash_array(); dash_array dash; - std::vector buf; std::string str = val.to_string(); - if (util::parse_dasharray(str,buf)) - { - util::add_dashes(buf,dash); - } + util::parse_dasharray(str,dash); return dash; } }; diff --git a/include/mapnik/symbolizer_utils.hpp b/include/mapnik/symbolizer_utils.hpp index 358628bd2..cea99000c 100644 --- a/include/mapnik/symbolizer_utils.hpp +++ b/include/mapnik/symbolizer_utils.hpp @@ -404,9 +404,8 @@ struct set_symbolizer_property_impl boost::optional str = node.get_opt_attr(name); if (str) { - std::vector buf; dash_array dash; - if (util::parse_dasharray(*str,buf) && util::add_dashes(buf,dash)) + if (util::parse_dasharray(*str,dash)) { put(sym,key,dash); } diff --git a/include/mapnik/util/dasharray_parser.hpp b/include/mapnik/util/dasharray_parser.hpp index 0ef1ae887..7c5d26711 100644 --- a/include/mapnik/util/dasharray_parser.hpp +++ b/include/mapnik/util/dasharray_parser.hpp @@ -23,32 +23,13 @@ #ifndef MAPNIK_UTIL_DASHARRAY_PARSER_HPP #define MAPNIK_UTIL_DASHARRAY_PARSER_HPP +#include #include #include namespace mapnik { namespace util { -bool parse_dasharray(std::string const& value, std::vector& dasharray); - -inline bool add_dashes(std::vector & buf, std::vector > & dash) -{ - if (buf.empty()) return false; - size_t size = buf.size(); - if (size % 2 == 1) - { - buf.insert(buf.end(),buf.begin(),buf.end()); - } - std::vector::const_iterator pos = buf.begin(); - while (pos != buf.end()) - { - if (*pos > 0.0 || *(pos+1) > 0.0) // avoid both dash and gap eq 0.0 - { - dash.emplace_back(*pos,*(pos + 1)); - } - pos +=2; - } - return !buf.empty(); -} +bool parse_dasharray(std::string const& value, dash_array & dash); }} diff --git a/src/dasharray_parser.cpp b/src/dasharray_parser.cpp index 760caea25..963a2905a 100644 --- a/src/dasharray_parser.cpp +++ b/src/dasharray_parser.cpp @@ -36,7 +36,29 @@ namespace mapnik { namespace util { -bool parse_dasharray(std::string const& value, std::vector& dasharray) +namespace { +inline bool setup_dashes(std::vector & buf, dash_array & dash) +{ + if (buf.empty()) return false; + size_t size = buf.size(); + if (size % 2 == 1) + { + buf.insert(buf.end(),buf.begin(),buf.end()); + } + std::vector::const_iterator pos = buf.begin(); + while (pos != buf.end()) + { + if (*pos > 0.0 || *(pos+1) > 0.0) // avoid both dash and gap eq 0.0 + { + dash.emplace_back(*pos,*(pos + 1)); + } + pos +=2; + } + return !buf.empty(); +} +} + +bool parse_dasharray(std::string const& value, dash_array & dash) { using namespace boost::spirit; qi::double_type double_; @@ -49,18 +71,19 @@ bool parse_dasharray(std::string const& value, std::vector& dasharray) // dasharray ::= (length | percentage) (comma-wsp dasharray)? // no support for 'percentage' as viewport is unknown at load_map // + std::vector buf; auto first = value.begin(); auto last = value.end(); bool r = qi::phrase_parse(first, last, - (double_[boost::phoenix::push_back(boost::phoenix::ref(dasharray), _1)] % + (double_[boost::phoenix::push_back(boost::phoenix::ref(buf), _1)] % no_skip[char_(", ")] | lit("none")), space); - if (first != last) + if (r && first == last) { - return false; + return setup_dashes(buf, dash); } - return r; + return false; } } // end namespace util