start passing fontsets down to format and layout - refs #1900

This commit is contained in:
Dane Springmeyer 2014-07-29 18:28:56 -07:00
parent 8af453e77d
commit 8646ccc83f
12 changed files with 26 additions and 19 deletions

View file

@ -30,23 +30,29 @@
// boost
#include <boost/property_tree/ptree_fwd.hpp>
// stl
#include <memory>
#include <map>
namespace mapnik {
class text_layout;
class feature_impl;
class xml_node;
class font_set;
namespace formatting {
class node;
using node_ptr = std::shared_ptr<node>;
using fontset_map = std::map<std::string, font_set>;
class MAPNIK_DECL node
{
public:
virtual ~node() {}
virtual void to_xml(boost::property_tree::ptree & xml) const = 0;
static node_ptr from_xml(xml_node const& xml);
static node_ptr from_xml(xml_node const& xml, fontset_map const& fontsets);
virtual void apply(evaluated_format_properties_ptr p, feature_impl const& feature, attributes const& vars, text_layout & output) const = 0;
virtual void add_expressions(expression_set & output) const = 0;
};

View file

@ -36,7 +36,7 @@ class MAPNIK_DECL format_node: public node
{
public:
void to_xml(boost::property_tree::ptree & xml) const;
static node_ptr from_xml(xml_node const& xml);
static node_ptr from_xml(xml_node const& xml, fontset_map const& fontsets);
virtual void apply(evaluated_format_properties_ptr p, feature_impl const& feature, attributes const& vars, text_layout & output) const;
virtual void add_expressions(expression_set & output) const;

View file

@ -34,7 +34,7 @@ class MAPNIK_DECL layout_node: public node
{
public:
void to_xml(boost::property_tree::ptree &xml) const;
static node_ptr from_xml(xml_node const& xml);
static node_ptr from_xml(xml_node const& xml, fontset_map const& fontsets);
virtual void apply(evaluated_format_properties_ptr p, feature_impl const& feature, attributes const& vars, text_layout &output) const;
virtual void add_expressions(expression_set &output) const;
void set_child(node_ptr child);

View file

@ -25,6 +25,7 @@
// mapnik
#include <mapnik/utils.hpp>
#include <mapnik/text/formatting/base.hpp>
#include <mapnik/text/text_properties.hpp>
#include <mapnik/noncopyable.hpp>
// stl
@ -36,7 +37,7 @@ namespace mapnik
namespace formatting
{
using from_xml_function_ptr = node_ptr (*)(xml_node const&);
using from_xml_function_ptr = node_ptr (*) (xml_node const&, fontset_map const&) ;
class registry : public singleton<registry, CreateStatic>,
private mapnik::noncopyable
@ -45,7 +46,7 @@ public:
registry();
~registry() {}
void register_name(std::string const& name, from_xml_function_ptr ptr, bool overwrite=false);
node_ptr from_xml(xml_node const& xml);
node_ptr from_xml(xml_node const& xml, fontset_map const & fontsets);
private:
std::map<std::string, from_xml_function_ptr> map_;
};

View file

@ -35,7 +35,7 @@ public:
text_node(expression_ptr text): node(), text_(text) {}
text_node(std::string text): node(), text_(parse_expression(text)) {}
void to_xml(boost::property_tree::ptree &xml) const;
static node_ptr from_xml(xml_node const& xml);
static node_ptr from_xml(xml_node const& xml, fontset_map const& fontsets);
virtual void apply(evaluated_format_properties_ptr p, feature_impl const& feature, attributes const& vars, text_layout &output) const;
virtual void add_expressions(expression_set &output) const;

View file

@ -95,7 +95,7 @@ struct MAPNIK_DECL text_layout_properties
text_layout_properties();
// Load all values from XML ptree.
void from_xml(xml_node const &sym);
void from_xml(xml_node const &sym, fontset_map const& fontsets);
// Save all values to XML ptree (but does not create a new parent node!).
void to_xml(boost::property_tree::ptree & node, bool explicit_defaults,
text_layout_properties const& dfl = text_layout_properties()) const;

View file

@ -29,14 +29,14 @@
namespace mapnik { namespace formatting {
node_ptr node::from_xml(xml_node const& xml)
node_ptr node::from_xml(xml_node const& xml, fontset_map const& fontsets)
{
auto list = std::make_shared<list_node>();
for (auto const& node : xml)
{
if (node.name() == "Placement")
continue;
node_ptr n = registry::instance().from_xml(node);
node_ptr n = registry::instance().from_xml(node,fontsets);
if (n) list->push_back(n);
}
if (list->get_children().size() == 1)

View file

@ -57,10 +57,10 @@ void format_node::to_xml(ptree & xml) const
}
node_ptr format_node::from_xml(xml_node const& xml)
node_ptr format_node::from_xml(xml_node const& xml, fontset_map const& fontsets)
{
auto n = std::make_shared<format_node>();
node_ptr child = node::from_xml(xml);
node_ptr child = node::from_xml(xml,fontsets);
n->set_child(child);
//TODO: Fontset is problematic. We don't have the fontsets pointer here...

View file

@ -59,10 +59,10 @@ void layout_node::to_xml(ptree &xml) const
if (child_) child_->to_xml(new_node);
}
node_ptr layout_node::from_xml(xml_node const& xml)
node_ptr layout_node::from_xml(xml_node const& xml, fontset_map const& fontsets)
{
auto n = std::make_shared<layout_node>();
node_ptr child = node::from_xml(xml);
node_ptr child = node::from_xml(xml, fontsets);
n->set_child(child);
if (xml.has_attribute("dx")) set_property_from_xml<double>(n->dx, "dx", xml);

View file

@ -48,12 +48,12 @@ void registry::register_name(std::string const& name, from_xml_function_ptr ptr,
}
}
node_ptr registry::from_xml(xml_node const& xml)
node_ptr registry::from_xml(xml_node const& xml, fontset_map const& fontsets)
{
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() + "'", xml);
xml.set_processed(true);
return itr->second(xml);
return itr->second(xml, fontsets);
}
} //ns formatting
} //ns mapnik

View file

@ -44,7 +44,7 @@ void text_node::to_xml(ptree & xml) const
new_node.put_value(to_expression_string(*text_));
}
node_ptr text_node::from_xml(xml_node const& xml)
node_ptr text_node::from_xml(xml_node const& xml, fontset_map const& fontsets)
{
return std::make_shared<text_node>(xml.get_value<expression_ptr>());
}

View file

@ -130,7 +130,7 @@ void text_symbolizer_properties::text_properties_from_xml(xml_node const& node)
void text_symbolizer_properties::from_xml(xml_node const& node, fontset_map const& fontsets)
{
text_properties_from_xml(node);
layout_defaults.from_xml(node);
layout_defaults.from_xml(node,fontsets);
optional<expression_ptr> name_ = node.get_opt_attr<expression_ptr>("name");
if (name_)
{
@ -139,7 +139,7 @@ void text_symbolizer_properties::from_xml(xml_node const& node, fontset_map cons
}
format_defaults.from_xml(node, fontsets);
formatting::node_ptr n(formatting::node::from_xml(node));
formatting::node_ptr n(formatting::node::from_xml(node,fontsets));
if (n) set_format_tree(n);
}
@ -227,7 +227,7 @@ text_layout_properties::text_layout_properties()
jalign(enumeration_wrapper(J_AUTO)),
valign(enumeration_wrapper(V_AUTO)) {}
void text_layout_properties::from_xml(xml_node const &node)
void text_layout_properties::from_xml(xml_node const &node, fontset_map const& fontsets)
{
set_property_from_xml<double>(dx, "dx", node);
set_property_from_xml<double>(dy, "dy", node);