Modify all other files for new XML structure.

This commit is contained in:
Hermann Kraus 2012-03-07 02:23:16 +01:00
parent 7d3fd0755d
commit f214675c69
13 changed files with 81 additions and 74 deletions

View File

@ -51,7 +51,7 @@ public:
private:
node_ptr child_;
static expression_ptr get_expression(boost::property_tree::ptree const& xml, std::string name);
static expression_ptr get_expression(xml_node const& xml, std::string name);
};
} //ns formatting
} //ns mapnik

View File

@ -47,7 +47,7 @@ public:
registry();
~registry() {}
void register_name(std::string name, from_xml_function_ptr ptr, bool overwrite=false);
node_ptr from_xml(std::string name, xml_node const& xml);
node_ptr from_xml(xml_node const& xml);
private:
std::map<std::string, from_xml_function_ptr> map_;
};

View File

@ -39,7 +39,7 @@ namespace placements
{
typedef text_placements_ptr (*from_xml_function_ptr)(
boost::property_tree::ptree const& xml, fontset_map const & fontsets);
xml_node const& xml, fontset_map const & fontsets);
class registry : public singleton<registry, CreateStatic>,
private boost::noncopyable

View File

@ -23,6 +23,7 @@
#include <mapnik/formatting/base.hpp>
#include <mapnik/formatting/list.hpp>
#include <mapnik/formatting/registry.hpp>
#include <mapnik/xml_tree.hpp>
// boost
#include <boost/property_tree/ptree.hpp>
@ -38,18 +39,18 @@ void node::to_xml(boost::property_tree::ptree &xml) const
#endif
}
node_ptr node::from_xml(boost::property_tree::ptree const& xml)
node_ptr node::from_xml(xml_node const& xml)
{
list_node *list = new list_node();
node_ptr list_ptr(list);
boost::property_tree::ptree::const_iterator itr = xml.begin();
boost::property_tree::ptree::const_iterator end = xml.end();
xml_node::const_iterator itr = xml.begin();
xml_node::const_iterator end = xml.end();
for (; itr != end; ++itr) {
if (itr->first == "<xmlcomment>" || itr->first == "<xmlattr>" || itr->first == "Placement")
if (itr->name() == "Placement")
{
continue;
}
node_ptr n = registry::instance()->from_xml(itr->first, itr->second);
node_ptr n = registry::instance()->from_xml(*itr);
if (n) list->push_back(n);
}
if (list->get_children().size() == 1) {

View File

@ -27,6 +27,7 @@
#include <mapnik/expression_evaluator.hpp>
#include <mapnik/text_properties.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/xml_tree.hpp>
// boost
@ -51,7 +52,7 @@ void expression_format::to_xml(boost::property_tree::ptree &xml) const
if (child_) child_->to_xml(new_node);
}
node_ptr expression_format::from_xml(ptree const& xml)
node_ptr expression_format::from_xml(xml_node const& xml)
{
expression_format *n = new expression_format();
node_ptr np(n);
@ -72,9 +73,9 @@ node_ptr expression_format::from_xml(ptree const& xml)
return np;
}
expression_ptr expression_format::get_expression(ptree const& xml, std::string name)
expression_ptr expression_format::get_expression(xml_node const& xml, std::string name)
{
boost::optional<std::string> tmp = get_opt_attr<std::string>(xml, name);
boost::optional<std::string> tmp = xml.get_opt_attr<std::string>(name);
if (tmp) return parse_expression(*tmp);
return expression_ptr();
}

View File

@ -21,6 +21,7 @@
*****************************************************************************/
#include <mapnik/formatting/format.hpp>
#include <mapnik/ptree_helpers.hpp>
#include <mapnik/xml_tree.hpp>
namespace mapnik {
using boost::property_tree::ptree;
@ -44,7 +45,7 @@ void format_node::to_xml(ptree &xml) const
}
node_ptr format_node::from_xml(ptree const& xml)
node_ptr format_node::from_xml(xml_node const& xml)
{
format_node *n = new format_node();
node_ptr np(n);
@ -52,19 +53,19 @@ node_ptr format_node::from_xml(ptree const& xml)
node_ptr child = node::from_xml(xml);
n->set_child(child);
n->face_name = get_opt_attr<std::string>(xml, "face-name");
n->face_name = xml.get_opt_attr<std::string>("face-name");
/*TODO: Fontset is problematic. We don't have the fontsets pointer here... */
n->text_size = get_opt_attr<unsigned>(xml, "size");
n->character_spacing = get_opt_attr<unsigned>(xml, "character-spacing");
n->line_spacing = get_opt_attr<unsigned>(xml, "line-spacing");
n->text_opacity = get_opt_attr<double>(xml, "opactity");
boost::optional<boolean> wrap = get_opt_attr<boolean>(xml, "wrap-before");
n->text_size = xml.get_opt_attr<unsigned>("size");
n->character_spacing = xml.get_opt_attr<unsigned>("character-spacing");
n->line_spacing = xml.get_opt_attr<unsigned>("line-spacing");
n->text_opacity = xml.get_opt_attr<double>("opactity");
boost::optional<boolean> wrap = xml.get_opt_attr<boolean>("wrap-before");
if (wrap) n->wrap_before = *wrap;
n->wrap_char = get_opt_attr<unsigned>(xml, "wrap-character");
n->text_transform = get_opt_attr<text_transform_e>(xml, "text-transform");
n->fill = get_opt_attr<color>(xml, "fill");
n->halo_fill = get_opt_attr<color>(xml, "halo-fill");
n->halo_radius = get_opt_attr<double>(xml, "halo-radius");
n->wrap_char = xml.get_opt_attr<unsigned>("wrap-character");
n->text_transform = xml.get_opt_attr<text_transform_e>("text-transform");
n->fill = xml.get_opt_attr<color>("fill");
n->halo_fill = xml.get_opt_attr<color>("halo-fill");
n->halo_radius = xml.get_opt_attr<double>("halo-radius");
return np;
}

View File

@ -24,6 +24,7 @@
#include <mapnik/formatting/text.hpp>
#include <mapnik/formatting/format.hpp>
#include <mapnik/formatting/expression.hpp>
#include <mapnik/xml_tree.hpp>
namespace mapnik
{
@ -46,10 +47,10 @@ void registry::register_name(std::string name, from_xml_function_ptr ptr, bool o
}
}
node_ptr registry::from_xml(std::string name, const boost::property_tree::ptree &xml)
node_ptr registry::from_xml(xml_node const& xml)
{
std::map<std::string, from_xml_function_ptr>::const_iterator itr = map_.find(name);
if (itr == map_.end()) throw config_error("Unknown element '" + name + "'");
std::map<std::string, from_xml_function_ptr>::const_iterator itr = map_.find(xml.name());
if (itr == map_.end()) throw config_error("Unknown element '" + xml.name() + "'");
return itr->second(xml);
}
} //ns formatting

View File

@ -26,9 +26,7 @@
#include <mapnik/feature.hpp>
#include <mapnik/text_properties.hpp>
#include <mapnik/processed_text.hpp>
// boost
#include <boost/algorithm/string.hpp>
#include <mapnik/xml_tree.hpp>
namespace mapnik
{
@ -45,10 +43,9 @@ void text_node::to_xml(ptree &xml) const
}
node_ptr text_node::from_xml(boost::property_tree::ptree const& xml)
node_ptr text_node::from_xml(xml_node const& xml)
{
std::string data = xml.data();
boost::trim(data);
std::string data = xml.get_text();
if (data.empty()) return node_ptr(); //No text
return node_ptr(new text_node(parse_expression(data, "utf8")));
}

View File

@ -20,9 +20,14 @@
*
*****************************************************************************/
//mapnik
#include <mapnik/text_placements/list.hpp>
#include <mapnik/xml_tree.hpp>
//boost
#include <boost/make_shared.hpp>
namespace mapnik
{
@ -83,20 +88,19 @@ unsigned text_placements_list::size() const
return list_.size();
}
text_placements_ptr text_placements_list::from_xml(boost::property_tree::ptree const &xml, fontset_map const & fontsets)
text_placements_ptr text_placements_list::from_xml(xml_node const &xml, fontset_map const & fontsets)
{
using boost::property_tree::ptree;
text_placements_list *list = new text_placements_list;
text_placements_ptr ptr = text_placements_ptr(list);
list->defaults.from_xml(xml, fontsets);
ptree::const_iterator itr = xml.begin();
ptree::const_iterator end = xml.end();
xml_node::const_iterator itr = xml.begin();
xml_node::const_iterator end = xml.end();
for( ;itr != end; ++itr)
{
if ((itr->first.find('<') != std::string::npos) || (itr->first != "Placement")) continue;
//TODO: ensure_attrs(symIter->second, "TextSymbolizer/Placement", s_common.str());
if (itr->is_text() || itr->name() != "Placement") continue;
text_symbolizer_properties &p = list->add();
p.from_xml(itr->second, fontsets);
p.from_xml(*itr, fontsets);
//TODO: if (strict_ &&
// !p.format.fontset.size())
// ensure_font_face(p.format.face_name);

View File

@ -44,7 +44,7 @@ void registry::register_name(std::string name, from_xml_function_ptr ptr, bool o
}
}
text_placements_ptr registry::from_xml(std::string name, const boost::property_tree::ptree &xml, fontset_map const& fontsets)
text_placements_ptr registry::from_xml(std::string name, xml_node const& xml, fontset_map const& fontsets)
{
std::map<std::string, from_xml_function_ptr>::const_iterator itr = map_.find(name);
if (itr == map_.end()) throw config_error("Unknown placement-type '" + name + "'");

View File

@ -23,6 +23,7 @@
// mapnik
#include <mapnik/text_placements/simple.hpp>
#include <mapnik/ptree_helpers.hpp>
#include <mapnik/xml_tree.hpp>
// boost
#include <boost/spirit/include/qi.hpp>
@ -167,10 +168,10 @@ std::string text_placements_simple::get_positions()
return positions_; //TODO: Build string from data in direction_ and text_sizes_
}
text_placements_ptr text_placements_simple::from_xml(boost::property_tree::ptree const &xml, fontset_map const & fontsets)
text_placements_ptr text_placements_simple::from_xml(xml_node const &xml, fontset_map const & fontsets)
{
text_placements_ptr ptr = text_placements_ptr(boost::make_shared<text_placements_simple>(
get_attr<std::string>(xml, "placements", "X")));
xml.get_attr<std::string>("placements", "X")));
ptr->defaults.from_xml(xml, fontsets);
return ptr;
}

View File

@ -25,6 +25,7 @@
#include <mapnik/ptree_helpers.hpp>
#include <mapnik/expression_string.hpp>
#include <mapnik/formatting/text.hpp>
#include <mapnik/xml_tree.hpp>
namespace mapnik
{
@ -72,45 +73,45 @@ formatting::node_ptr text_symbolizer_properties::format_tree() const
return tree_;
}
void text_symbolizer_properties::from_xml(boost::property_tree::ptree const &sym, fontset_map const & fontsets)
void text_symbolizer_properties::from_xml(xml_node const &sym, fontset_map const & fontsets)
{
optional<label_placement_e> placement_ = get_opt_attr<label_placement_e>(sym, "placement");
optional<label_placement_e> placement_ = sym.get_opt_attr<label_placement_e>("placement");
if (placement_) label_placement = *placement_;
optional<vertical_alignment_e> valign_ = get_opt_attr<vertical_alignment_e>(sym, "vertical-alignment");
optional<vertical_alignment_e> valign_ = sym.get_opt_attr<vertical_alignment_e>("vertical-alignment");
if (valign_) valign = *valign_;
optional<unsigned> text_ratio_ = get_opt_attr<unsigned>(sym, "text-ratio");
optional<unsigned> text_ratio_ = sym.get_opt_attr<unsigned>("text-ratio");
if (text_ratio_) text_ratio = *text_ratio_;
optional<unsigned> wrap_width_ = get_opt_attr<unsigned>(sym, "wrap-width");
optional<unsigned> wrap_width_ = sym.get_opt_attr<unsigned>("wrap-width");
if (wrap_width_) wrap_width = *wrap_width_;
optional<unsigned> label_position_tolerance_ = get_opt_attr<unsigned>(sym, "label-position-tolerance");
optional<unsigned> label_position_tolerance_ = sym.get_opt_attr<unsigned>("label-position-tolerance");
if (label_position_tolerance_) label_position_tolerance = *label_position_tolerance_;
optional<unsigned> spacing_ = get_opt_attr<unsigned>(sym, "spacing");
optional<unsigned> spacing_ = sym.get_opt_attr<unsigned>("spacing");
if (spacing_) label_spacing = *spacing_;
optional<unsigned> minimum_distance_ = get_opt_attr<unsigned>(sym, "minimum-distance");
optional<unsigned> minimum_distance_ = sym.get_opt_attr<unsigned>("minimum-distance");
if (minimum_distance_) minimum_distance = *minimum_distance_;
optional<unsigned> min_padding_ = get_opt_attr<unsigned>(sym, "minimum-padding");
optional<unsigned> min_padding_ = sym.get_opt_attr<unsigned>("minimum-padding");
if (min_padding_) minimum_padding = *min_padding_;
optional<unsigned> min_path_length_ = get_opt_attr<unsigned>(sym, "minimum-path-length");
optional<unsigned> min_path_length_ = sym.get_opt_attr<unsigned>("minimum-path-length");
if (min_path_length_) minimum_path_length = *min_path_length_;
optional<boolean> avoid_edges_ = get_opt_attr<boolean>(sym, "avoid-edges");
optional<boolean> avoid_edges_ = sym.get_opt_attr<boolean>("avoid-edges");
if (avoid_edges_) avoid_edges = *avoid_edges_;
optional<boolean> allow_overlap_ = get_opt_attr<boolean>(sym, "allow-overlap");
optional<boolean> allow_overlap_ = sym.get_opt_attr<boolean>("allow-overlap");
if (allow_overlap_) allow_overlap = *allow_overlap_;
optional<horizontal_alignment_e> halign_ = get_opt_attr<horizontal_alignment_e>(sym, "horizontal-alignment");
optional<horizontal_alignment_e> halign_ = sym.get_opt_attr<horizontal_alignment_e>("horizontal-alignment");
if (halign_) halign = *halign_;
optional<justify_alignment_e> jalign_ = get_opt_attr<justify_alignment_e>(sym, "justify-alignment");
optional<justify_alignment_e> jalign_ = sym.get_opt_attr<justify_alignment_e>("justify-alignment");
if (jalign_) jalign = *jalign_;
/* Attributes needing special care */
optional<std::string> orientation_ = get_opt_attr<std::string>(sym, "orientation");
optional<std::string> orientation_ = sym.get_opt_attr<std::string>("orientation");
if (orientation_) orientation = parse_expression(*orientation_, "utf8");
optional<double> dx = get_opt_attr<double>(sym, "dx");
optional<double> dx = sym.get_opt_attr<double>("dx");
if (dx) displacement.first = *dx;
optional<double> dy = get_opt_attr<double>(sym, "dy");
optional<double> dy = sym.get_opt_attr<double>("dy");
if (dy) displacement.second = *dy;
optional<double> max_char_angle_delta_ = get_opt_attr<double>(sym, "max-char-angle-delta");
optional<double> max_char_angle_delta_ = sym.get_opt_attr<double>("max-char-angle-delta");
if (max_char_angle_delta_) max_char_angle_delta=(*max_char_angle_delta_)*(M_PI/180);
optional<std::string> name_ = get_opt_attr<std::string>(sym, "name");
optional<std::string> name_ = sym.get_opt_attr<std::string>("name");
if (name_) {
std::clog << "### WARNING: Using 'name' in TextSymbolizer/ShieldSymbolizer is deprecated!\n";
set_old_style_expression(parse_expression(*name_, "utf8"));
@ -230,34 +231,34 @@ char_properties::char_properties() :
}
void char_properties::from_xml(boost::property_tree::ptree const &sym, fontset_map const & fontsets)
void char_properties::from_xml(xml_node const& sym, fontset_map const& fontsets)
{
optional<double> text_size_ = get_opt_attr<double>(sym, "size");
optional<double> text_size_ = sym.get_opt_attr<double>("size");
if (text_size_) text_size = *text_size_;
optional<double> character_spacing_ = get_opt_attr<double>(sym, "character-spacing");
optional<double> character_spacing_ = sym.get_opt_attr<double>("character-spacing");
if (character_spacing_) character_spacing = *character_spacing_;
optional<color> fill_ = get_opt_attr<color>(sym, "fill");
optional<color> fill_ = sym.get_opt_attr<color>("fill");
if (fill_) fill = *fill_;
optional<color> halo_fill_ = get_opt_attr<color>(sym, "halo-fill");
optional<color> halo_fill_ = sym.get_opt_attr<color>("halo-fill");
if (halo_fill_) halo_fill = *halo_fill_;
optional<double> halo_radius_ = get_opt_attr<double>(sym, "halo-radius");
optional<double> halo_radius_ = sym.get_opt_attr<double>("halo-radius");
if (halo_radius_) halo_radius = *halo_radius_;
optional<boolean> wrap_before_ = get_opt_attr<boolean>(sym, "wrap-before");
optional<boolean> wrap_before_ = sym.get_opt_attr<boolean>("wrap-before");
if (wrap_before_) wrap_before = *wrap_before_;
optional<text_transform_e> tconvert_ = get_opt_attr<text_transform_e>(sym, "text-transform");
optional<text_transform_e> tconvert_ = sym.get_opt_attr<text_transform_e>("text-transform");
if (tconvert_) text_transform = *tconvert_;
optional<double> line_spacing_ = get_opt_attr<double>(sym, "line-spacing");
optional<double> line_spacing_ = sym.get_opt_attr<double>("line-spacing");
if (line_spacing_) line_spacing = *line_spacing_;
optional<double> opacity_ = get_opt_attr<double>(sym, "opacity");
optional<double> opacity_ = sym.get_opt_attr<double>("opacity");
if (opacity_) text_opacity = *opacity_;
optional<std::string> wrap_char_ = get_opt_attr<std::string>(sym, "wrap-character");
optional<std::string> wrap_char_ = sym.get_opt_attr<std::string>("wrap-character");
if (wrap_char_ && (*wrap_char_).size() > 0) wrap_char = ((*wrap_char_)[0]);
optional<std::string> face_name_ = get_opt_attr<std::string>(sym, "face-name");
optional<std::string> face_name_ = sym.get_opt_attr<std::string>("face-name");
if (face_name_)
{
face_name = *face_name_;
}
optional<std::string> fontset_name_ = get_opt_attr<std::string>(sym, "fontset-name");
optional<std::string> fontset_name_ = sym.get_opt_attr<std::string>("fontset-name");
if (fontset_name_) {
std::map<std::string,font_set>::const_iterator itr = fontsets.find(*fontset_name_);
if (itr != fontsets.end())

View File

@ -191,7 +191,7 @@ xml_node &xml_node::add_child(std::string const& name, unsigned line, bool text_
return children_.back();
}
xml_node & xml_node::get_child(std::string name)
xml_node & xml_node::get_child(std::string const& name)
{
std::list<xml_node>::iterator itr = children_.begin();
std::list<xml_node>::iterator end = children_.end();