From b5f36154fc5deb0e9d4ca289b7662ecdc6ca59f6 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Thu, 19 Aug 2010 12:20:30 +0000 Subject: [PATCH] parse stroke properties separately from parsing a line symbolizer - setting up for being able to easily add strokes to other symbolizers --- src/load_map.cpp | 120 +++++++++++++++++++++++++---------------------- 1 file changed, 63 insertions(+), 57 deletions(-) diff --git a/src/load_map.cpp b/src/load_map.cpp index 09c1d02c8..2cb454acc 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -107,6 +107,7 @@ private: void parse_glyph_symbolizer(rule_type & rule, ptree const & sym ); void parse_raster_colorizer(raster_colorizer_ptr const& rc, ptree const& node ); + void parse_stroke(stroke & strk, ptree const & sym); void ensure_font_face( const std::string & face_name ); @@ -1471,68 +1472,73 @@ void map_parser::parse_shield_symbolizer( rule_type & rule, ptree const & sym ) } } +void map_parser::parse_stroke(stroke & strk, ptree const & sym) +{ + // stroke color + optional c = get_opt_attr(sym, "stroke"); + if (c) strk.set_color(*c); + // stroke-width + optional width = get_opt_attr(sym, "stroke-width"); + if (width) strk.set_width(*width); + // stroke-opacity + optional opacity = get_opt_attr(sym, "stroke-opacity"); + if (opacity) strk.set_opacity(*opacity); + // stroke-linejoin + optional line_join = get_opt_attr(sym, "stroke-linejoin"); + if (line_join) strk.set_line_join(*line_join); + // stroke-linecap + optional line_cap = get_opt_attr(sym, "stroke-linecap"); + if (line_cap) strk.set_line_cap(*line_cap); + // stroke-dashaffset + optional offset = get_opt_attr(sym, "stroke-dashoffet"); + if (offset) strk.set_dash_offset(*offset); + // stroke-dasharray + optional str = get_opt_attr(sym,"stroke-dasharray"); + if (str) + { + tokenizer<> tok (*str); + std::vector dash_array; + tokenizer<>::iterator itr = tok.begin(); + for (; itr != tok.end(); ++itr) + { + try + { + double f = boost::lexical_cast(*itr); + dash_array.push_back(f); + } + catch ( boost::bad_lexical_cast &) + { + throw config_error(std::string("Failed to parse dasharray ") + + "'. Expected a " + + "list of floats but got '" + (*str) + "'"); + } + } + if (dash_array.size()) + { + size_t size = dash_array.size(); + if ( size % 2) + { + for (size_t i=0; i < size ;++i) + { + dash_array.push_back(dash_array[i]); + } + } + std::vector::const_iterator pos = dash_array.begin(); + while (pos != dash_array.end()) + { + strk.add_dash(*pos,*(pos + 1)); + pos +=2; + } + } + } +} + void map_parser::parse_line_symbolizer( rule_type & rule, ptree const & sym ) { try { stroke strk; - // stroke color - optional c = get_opt_attr(sym, "stroke"); - if (c) strk.set_color(*c); - // stroke-width - optional width = get_opt_attr(sym, "stroke-width"); - if (width) strk.set_width(*width); - // stroke-opacity - optional opacity = get_opt_attr(sym, "stroke-opacity"); - if (opacity) strk.set_opacity(*opacity); - // stroke-linejoin - optional line_join = get_opt_attr(sym, "stroke-linejoin"); - if (line_join) strk.set_line_join(*line_join); - // stroke-linecap - optional line_cap = get_opt_attr(sym, "stroke-linecap"); - if (line_cap) strk.set_line_cap(*line_cap); - // stroke-dashaffset - optional offset = get_opt_attr(sym, "stroke-dashoffet"); - if (offset) strk.set_dash_offset(*offset); - // stroke-dasharray - optional str = get_opt_attr(sym,"stroke-dasharray"); - if (str) - { - tokenizer<> tok (*str); - std::vector dash_array; - tokenizer<>::iterator itr = tok.begin(); - for (; itr != tok.end(); ++itr) - { - try - { - double f = boost::lexical_cast(*itr); - dash_array.push_back(f); - } - catch ( boost::bad_lexical_cast &) - { - throw config_error(std::string("Failed to parse dasharray ") + - "'. Expected a " + - "list of floats but got '" + (*str) + "'"); - } - } - if (dash_array.size()) - { - size_t size = dash_array.size(); - if ( size % 2) - { - for (size_t i=0; i < size ;++i) - { - dash_array.push_back(dash_array[i]); - } - } - std::vector::const_iterator pos = dash_array.begin(); - while (pos != dash_array.end()) - { - strk.add_dash(*pos,*(pos + 1)); - pos +=2; - } - } - } + parse_stroke(strk,sym); line_symbolizer symbol = line_symbolizer(strk); parse_metawriter_in_symbolizer(symbol, sym);