From 958097600c7271d23f2433bbec4e99f530577eb4 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Mon, 6 Feb 2012 22:49:47 +0000 Subject: [PATCH 1/5] add wkt_parser class for grammar re-usage implement from_wkt in terms of wkt_parser --- include/mapnik/wkt/wkt_factory.hpp | 19 +++++++++++++++++++ src/wkt/wkt_factory.cpp | 22 ++++++++++++++++------ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/include/mapnik/wkt/wkt_factory.hpp b/include/mapnik/wkt/wkt_factory.hpp index 0ed4c1868..2b459495c 100644 --- a/include/mapnik/wkt/wkt_factory.hpp +++ b/include/mapnik/wkt/wkt_factory.hpp @@ -27,13 +27,32 @@ #include #include #include +#include // stl #include namespace mapnik { +namespace wkt { +template struct wkt_collection_grammar; +} + MAPNIK_DECL bool from_wkt(std::string const& wkt, boost::ptr_vector & paths); +#if BOOST_VERSION >= 104700 + +class wkt_parser +{ + typedef std::string::const_iterator iterator_type; +public: + wkt_parser(); + bool parse(std::string const& wkt, boost::ptr_vector & paths); +private: + boost::scoped_ptr > grammar_; +}; + +#endif + } diff --git a/src/wkt/wkt_factory.cpp b/src/wkt/wkt_factory.cpp index 17196af78..46f300ec9 100644 --- a/src/wkt/wkt_factory.cpp +++ b/src/wkt/wkt_factory.cpp @@ -34,15 +34,25 @@ namespace mapnik { +#if BOOST_VERSION >= 104700 +wkt_parser::wkt_parser() + : grammar_(new mapnik::wkt::wkt_collection_grammar) +{} + +bool wkt_parser::parse(std::string const& wkt, boost::ptr_vector & paths) +{ + using namespace boost::spirit; + iterator_type first = wkt.begin(); + iterator_type last = wkt.end(); + return qi::phrase_parse(first, last, *grammar_, ascii::space, paths); +} +#endif + bool from_wkt(std::string const& wkt, boost::ptr_vector & paths) { #if BOOST_VERSION >= 104700 - using namespace boost::spirit; - typedef std::string::const_iterator iterator_type; - iterator_type first = wkt.begin(); - iterator_type last = wkt.end(); - mapnik::wkt::wkt_collection_grammar grammar; - return qi::phrase_parse(first, last, grammar, ascii::space, paths); + wkt_parser parser; + return parser.parse(wkt,paths); #else // TODO - remove this after mapnik 2.0.0 release std::ostringstream s; From a00af6faf873cd994e204e8c566d7c71d8bf2eb1 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 7 Feb 2012 13:42:22 -0800 Subject: [PATCH 2/5] fix debug output name --- src/map.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/map.cpp b/src/map.cpp index fa81ecfe0..f46437989 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -587,7 +587,7 @@ featureset_ptr Map::query_point(unsigned index, double x, double y) const catch (...) { #ifdef MAPNIK_DEBUG - std::clog << "exception caught in \"query_map_point\"\n"; + std::clog << "exception caught in \"query_point\"\n"; #endif } } From 8e61d9a6d2a9904f77342e33c5a1fa27404c8d83 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 7 Feb 2012 13:42:45 -0800 Subject: [PATCH 3/5] remove used typedefs --- src/agg/process_building_symbolizer.cpp | 3 +-- src/cairo_renderer.cpp | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/agg/process_building_symbolizer.cpp b/src/agg/process_building_symbolizer.cpp index d081e1b32..d71b99045 100644 --- a/src/agg/process_building_symbolizer.cpp +++ b/src/agg/process_building_symbolizer.cpp @@ -47,8 +47,7 @@ void agg_renderer::process(building_symbolizer const& sym, mapnik::feature_ptr const& feature, proj_transform const& prj_trans) { - typedef coord_transform2 path_type; - typedef coord_transform3 path_type_roof; + typedef coord_transform2 path_type; typedef agg::renderer_base ren_base; typedef agg::renderer_scanline_aa_solid renderer; diff --git a/src/cairo_renderer.cpp b/src/cairo_renderer.cpp index ef4219a3b..025310373 100644 --- a/src/cairo_renderer.cpp +++ b/src/cairo_renderer.cpp @@ -745,7 +745,6 @@ void cairo_renderer_base::start_map_processing(Map const& map) proj_transform const& prj_trans) { typedef coord_transform2 path_type; - typedef coord_transform3 path_type_roof; cairo_context context(context_); From 16828ec16197add5f193f49c762508d15a74551a Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 7 Feb 2012 13:44:08 -0800 Subject: [PATCH 4/5] use row/col instead of x/y for clearer grid resolution function --- tests/python_tests/render_grid_test.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tests/python_tests/render_grid_test.py b/tests/python_tests/render_grid_test.py index 882c61beb..6f0150ea0 100644 --- a/tests/python_tests/render_grid_test.py +++ b/tests/python_tests/render_grid_test.py @@ -8,23 +8,18 @@ import os, mapnik try: import json except ImportError: - import simplejson + import simplejson as json grid_correct = {"keys": ["", "North West", "North East", "South West", "South East"], "data": {"South East": {"Name": "South East"}, "North East": {"Name": "North East"}, "North West": {"Name": "North West"}, "South West": {"Name": "South West"}}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !!! ### ", " !!!!! ##### ", " !!!!! ##### ", " !!! ### ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$$$ %%%% ", " $$$$$ %%%%% ", " $$$$$ %%%%% ", " $$$ %%% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]} grid_correct_new = {"keys": ["", "North West", "North East", "South West", "South East"], "data": {"South East": {"Name": "South East"}, "North East": {"Name": "North East"}, "North West": {"Name": "North West"}, "South West": {"Name": "South West"}}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !! ## ", " !!! ### ", " !! ## ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$$ %% ", " $$$ %%% ", " $$ %% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]} -def resolve(grid,x,y): +def resolve(grid,row,col): """ Resolve the attributes for a given pixel in a grid. - - js version: - https://github.com/mapbox/mbtiles-spec/blob/master/1.1/utfgrid.md - spec: - https://github.com/mapbox/wax/blob/master/control/lib/gridutil.js - """ - utf_val = grid['grid'][x][y] + row = grid['grid'][row] + utf_val = row[col] #http://docs.python.org/library/functions.html#ord codepoint = ord(utf_val) if (codepoint >= 93): From 1d50aa1b85087d4fbfdadde4530c026976f56e34 Mon Sep 17 00:00:00 2001 From: Hermann Kraus Date: Wed, 8 Feb 2012 01:16:37 +0100 Subject: [PATCH 5/5] Make interface consistent with similar classes. --- include/mapnik/text_processing.hpp | 35 +++----- src/text_processing.cpp | 131 ++++++++--------------------- 2 files changed, 45 insertions(+), 121 deletions(-) diff --git a/include/mapnik/text_processing.hpp b/include/mapnik/text_processing.hpp index d1ad66fc8..9807b835c 100644 --- a/include/mapnik/text_processing.hpp +++ b/include/mapnik/text_processing.hpp @@ -140,7 +140,6 @@ private: class format_node: public node { public: - format_node(); void to_xml(boost::property_tree::ptree &xml) const; static node_ptr from_xml(boost::property_tree::ptree const& xml); virtual void apply(char_properties const& p, Feature const& feature, processed_text &output) const; @@ -148,29 +147,19 @@ public: void set_child(node_ptr child); node_ptr get_child() const; - void set_face_name(boost::optional face_name); - void set_text_size(boost::optional text_size); - void set_character_spacing(boost::optional character_spacing); - void set_line_spacing(boost::optional line_spacing); - void set_text_opacity(boost::optional opacity); - void set_wrap_before(boost::optional wrap_before); - void set_wrap_char(boost::optional wrap_char); - void set_text_transform(boost::optional text_trans); - void set_fill(boost::optional fill); - void set_halo_fill(boost::optional halo_fill); - void set_halo_radius(boost::optional radius); + boost::optional face_name; + boost::optional text_size; + boost::optional character_spacing; + boost::optional line_spacing; + boost::optional text_opacity; + boost::optional wrap_before; + boost::optional wrap_char; + boost::optional text_transform; + boost::optional fill; + boost::optional halo_fill; + boost::optional halo_radius; + private: - boost::optional face_name_; - boost::optional text_size_; - boost::optional character_spacing_; - boost::optional line_spacing_; - boost::optional text_opacity_; - boost::optional wrap_before_; - boost::optional wrap_char_; - boost::optional text_transform_; - boost::optional fill_; - boost::optional halo_fill_; - boost::optional halo_radius_; node_ptr child_; }; diff --git a/src/text_processing.cpp b/src/text_processing.cpp index 82cd34c36..be352b6b2 100644 --- a/src/text_processing.cpp +++ b/src/text_processing.cpp @@ -198,28 +198,20 @@ expression_ptr text_node::get_text() const /************************************************************/ -format_node::format_node(): - node(), - fill_(), - child_() -{ - -} - void format_node::to_xml(ptree &xml) const { ptree &new_node = xml.push_back(ptree::value_type("Format", ptree()))->second; - if (face_name_) set_attr(new_node, "face-name", *face_name_); - if (text_size_) set_attr(new_node, "size", *text_size_); - if (character_spacing_) set_attr(new_node, "character-spacing", *character_spacing_); - if (line_spacing_) set_attr(new_node, "line-spacing", *line_spacing_); - if (text_opacity_) set_attr(new_node, "opacity", *text_opacity_); - if (wrap_before_) set_attr(new_node, "wrap-before", *wrap_before_); - if (wrap_char_) set_attr(new_node, "wrap-character", *wrap_char_); - if (text_transform_) set_attr(new_node, "text-transform", *text_transform_); - if (fill_) set_attr(new_node, "fill", *fill_); - if (halo_fill_) set_attr(new_node, "halo-fill", *halo_fill_); - if (halo_radius_) set_attr(new_node, "halo-radius", *halo_radius_); + if (face_name) set_attr(new_node, "face-name", *face_name); + if (text_size) set_attr(new_node, "size", *text_size); + if (character_spacing) set_attr(new_node, "character-spacing", *character_spacing); + if (line_spacing) set_attr(new_node, "line-spacing", *line_spacing); + if (text_opacity) set_attr(new_node, "opacity", *text_opacity); + if (wrap_before) set_attr(new_node, "wrap-before", *wrap_before); + if (wrap_char) set_attr(new_node, "wrap-character", *wrap_char); + if (text_transform) set_attr(new_node, "text-transform", *text_transform); + if (fill) set_attr(new_node, "fill", *fill); + if (halo_fill) set_attr(new_node, "halo-fill", *halo_fill); + if (halo_radius) set_attr(new_node, "halo-radius", *halo_radius); if (child_) child_->to_xml(new_node); } @@ -232,21 +224,19 @@ node_ptr format_node::from_xml(ptree const& xml) node_ptr child = node::from_xml(xml); n->set_child(child); - n->set_face_name(get_opt_attr(xml, "face-name")); + n->face_name = get_opt_attr(xml, "face-name"); /*TODO: Fontset is problematic. We don't have the fontsets pointer here... */ - n->set_text_size(get_opt_attr(xml, "size")); - n->set_character_spacing(get_opt_attr(xml, "character-spacing")); - n->set_line_spacing(get_opt_attr(xml, "line-spacing")); - n->set_text_opacity(get_opt_attr(xml, "opactity")); + n->text_size = get_opt_attr(xml, "size"); + n->character_spacing = get_opt_attr(xml, "character-spacing"); + n->line_spacing = get_opt_attr(xml, "line-spacing"); + n->text_opacity = get_opt_attr(xml, "opactity"); boost::optional wrap = get_opt_attr(xml, "wrap-before"); - boost::optional wrap_before; - if (wrap) wrap_before = *wrap; - n->set_wrap_before(wrap_before); - n->set_wrap_char(get_opt_attr(xml, "wrap-character")); - n->set_text_transform(get_opt_attr(xml, "text-transform")); - n->set_fill(get_opt_attr(xml, "fill")); - n->set_halo_fill(get_opt_attr(xml, "halo-fill")); - n->set_halo_radius(get_opt_attr(xml, "halo-radius")); + if (wrap) n->wrap_before = *wrap; + n->wrap_char = get_opt_attr(xml, "wrap-character"); + n->text_transform = get_opt_attr(xml, "text-transform"); + n->fill = get_opt_attr(xml, "fill"); + n->halo_fill = get_opt_attr(xml, "halo-fill"); + n->halo_radius = get_opt_attr(xml, "halo-radius"); return np; } @@ -254,17 +244,17 @@ node_ptr format_node::from_xml(ptree const& xml) void format_node::apply(char_properties const& p, const Feature &feature, processed_text &output) const { char_properties new_properties = p; - if (face_name_) new_properties.face_name = *face_name_; - if (text_size_) new_properties.text_size = *text_size_; - if (character_spacing_) new_properties.character_spacing = *character_spacing_; - if (line_spacing_) new_properties.line_spacing = *line_spacing_; - if (text_opacity_) new_properties.text_opacity = *text_opacity_; - if (wrap_before_) new_properties.wrap_before = *wrap_before_; - if (wrap_char_) new_properties.wrap_char = *wrap_char_; - if (text_transform_) new_properties.text_transform = *text_transform_; - if (fill_) new_properties.fill = *fill_; - if (halo_fill_) new_properties.halo_fill = *halo_fill_; - if (halo_radius_) new_properties.halo_radius = *halo_radius_; + if (face_name) new_properties.face_name = *face_name; + if (text_size) new_properties.text_size = *text_size; + if (character_spacing) new_properties.character_spacing = *character_spacing; + if (line_spacing) new_properties.line_spacing = *line_spacing; + if (text_opacity) new_properties.text_opacity = *text_opacity; + if (wrap_before) new_properties.wrap_before = *wrap_before; + if (wrap_char) new_properties.wrap_char = *wrap_char; + if (text_transform) new_properties.text_transform = *text_transform; + if (fill) new_properties.fill = *fill; + if (halo_fill) new_properties.halo_fill = *halo_fill; + if (halo_radius) new_properties.halo_radius = *halo_radius; if (child_) { child_->apply(new_properties, feature, output); @@ -287,61 +277,6 @@ node_ptr format_node::get_child() const return child_; } - -void format_node::set_face_name(optional face_name) -{ - face_name_ = face_name; -} - -void format_node::set_text_size(optional text_size) -{ - text_size_ = text_size; -} - -void format_node::set_character_spacing(optional character_spacing) -{ - character_spacing_ = character_spacing; -} - -void format_node::set_line_spacing(optional line_spacing) -{ - line_spacing_ = line_spacing; -} - -void format_node::set_text_opacity(optional text_opacity) -{ - text_opacity_ = text_opacity; -} - -void format_node::set_wrap_before(optional wrap_before) -{ - wrap_before_ = wrap_before; -} - -void format_node::set_wrap_char(optional wrap_char) -{ - wrap_char_ = wrap_char; -} - -void format_node::set_text_transform(optional text_transform) -{ - text_transform_ = text_transform; -} - -void format_node::set_fill(optional c) -{ - fill_ = c; -} - -void format_node::set_halo_fill(optional c) -{ - halo_fill_ = c; -} - -void format_node::set_halo_radius(optional radius) -{ - halo_radius_ = radius; -} } //namespace formating /************************************************************/