From 3621283ca910075966f10535edb6c34fa33a7154 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Thu, 12 Aug 2010 07:47:13 +0000 Subject: [PATCH] mapnik2 forward compatibility for 0.7.2 XML syntax --- src/load_map.cpp | 117 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 2 deletions(-) diff --git a/src/load_map.cpp b/src/load_map.cpp index ad60086d5..f9308f44c 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -156,6 +156,11 @@ void map_parser::parse_map( Map & map, ptree const & pt ) try { optional bgcolor = get_opt_attr(map_node, "bgcolor"); + // mapnik2 forward compatibility + if (!bgcolor) + { + bgcolor = get_opt_attr(map_node, "background-color"); + } if (bgcolor) { map.set_background( * bgcolor ); } @@ -531,7 +536,7 @@ void map_parser::parse_layer( Map & map, ptree const & lay ) } catch (const config_error & ex) { if ( ! name.empty() ) { - ex.append_context(string("(encountered during parsing of layer '") + name + "')"); + ex.append_context(string("(encountered during parsing of layer '") + name + "' in map '" + filename_ + "')"); } throw; } @@ -643,7 +648,7 @@ void map_parser::parse_rule( feature_type_style & style, ptree const & r ) { if ( ! name.empty() ) { - ex.append_context(string("in rule '") + name + "'"); + ex.append_context(string("in rule '") + name + "' in map '" + filename_ + "')"); } throw; } @@ -884,6 +889,13 @@ void map_parser::parse_text_symbolizer( rule_type & rule, ptree const & sym ) { std::string name = get_attr(sym, "name"); + // mapnik2 forward compatibility + if (boost::algorithm::istarts_with(name,"[") && boost::algorithm::iends_with(name,"]")) + { + boost::algorithm::ireplace_first(name,"[",""); + boost::algorithm::ireplace_last(name,"]",""); + } + optional face_name = get_opt_attr(sym, "face_name"); @@ -1407,6 +1419,69 @@ void map_parser::parse_line_symbolizer( rule_type & rule, ptree const & sym ) "Expected 'CssParameter' but got '" + css_tag.first + "'"); } } + + // mapnik2 forward compatibility + // 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 + // not supported until mapnik2 + //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 + { + float 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; + } + } + } + + + rule.append(line_symbolizer(strk)); } catch (const config_error & ex) @@ -1462,6 +1537,18 @@ void map_parser::parse_polygon_symbolizer( rule_type & rule, ptree const & sym ) "Expected 'CssParameter' but got '" + css_tag.first + "'"); } } + + // mapnik2 forward compatibility + // fill + optional fill = get_opt_attr(sym, "fill"); + if (fill) poly_sym.set_fill(*fill); + // fill-opacity + optional opacity = get_opt_attr(sym, "fill-opacity"); + if (opacity) poly_sym.set_opacity(*opacity); + // gamma + optional gamma = get_opt_attr(sym, "gamma"); + if (gamma) poly_sym.set_gamma(*gamma); + rule.append(poly_sym); } @@ -1518,6 +1605,18 @@ void map_parser::parse_building_symbolizer( rule_type & rule, ptree const & sym "Expected 'CssParameter' but got '" + css_tag.first + "'"); } } + + // mapnik2 forward compatibility + // fill + optional fill = get_opt_attr(sym, "fill"); + if (fill) building_sym.set_fill(*fill); + // fill-opacity + optional opacity = get_opt_attr(sym, "fill-opacity"); + if (opacity) building_sym.set_opacity(*opacity); + // height + optional height = get_opt_attr(sym, "height"); + if (opacity) building_sym.set_height(*height); + rule.append(building_sym); } catch (const config_error & ex) @@ -1570,6 +1669,20 @@ void map_parser::parse_raster_symbolizer( rule_type & rule, ptree const & sym ) "Expected 'CssParameter' but got '" + css_tag.first + "'"); } } + + // mapnik2 forward compatibility + // mode + optional mode = get_opt_attr(sym, "mode"); + if (mode) raster_sym.set_mode(*mode); + + // scaling + optional scaling = get_opt_attr(sym, "scaling"); + if (scaling) raster_sym.set_scaling(*scaling); + + // opacity + optional opacity = get_opt_attr(sym, "opacity"); + if (opacity) raster_sym.set_opacity(*opacity); + rule.append(raster_sym); } catch (const config_error & ex)