more format_properties expessions

This commit is contained in:
artemp 2014-07-23 18:09:18 +01:00
parent e67f046a0e
commit 8502019310
8 changed files with 109 additions and 100 deletions

View file

@ -208,11 +208,11 @@ int main ( int argc , char** argv)
{
text_symbolizer text_sym;
text_placements_ptr placement_finder = std::make_shared<text_placements_dummy>();
placement_finder->defaults.format_properties.face_name = "DejaVu Sans Book";
placement_finder->defaults.format_properties.text_size = 10.0;
placement_finder->defaults.format_properties.fill = color(0,0,0);
placement_finder->defaults.format_properties.halo_fill = color(255,255,200);
placement_finder->defaults.format_properties.halo_radius = 1;
placement_finder->defaults.format_defaults.face_name = "DejaVu Sans Book";
placement_finder->defaults.format_defaults.text_size = 10.0;
placement_finder->defaults.format_defaults.fill = color(0,0,0);
placement_finder->defaults.format_defaults.halo_fill = color(255,255,200);
placement_finder->defaults.format_defaults.halo_radius = 1.0;
placement_finder->defaults.set_old_style_expression(parse_expression("[GEONAME]"));
put<text_placements_ptr>(text_sym, keys::text_placements_, placement_finder);
r.append(std::move(text_sym));

View file

@ -32,7 +32,8 @@
namespace mapnik { namespace formatting {
class MAPNIK_DECL format_node: public node {
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);
@ -45,14 +46,14 @@ public:
boost::optional<std::string> face_name;
boost::optional<symbolizer_base::value_type> text_size;
boost::optional<symbolizer_base::value_type> character_spacing;
boost::optional<unsigned> line_spacing;
boost::optional<double> text_opacity;
boost::optional<symbolizer_base::value_type> line_spacing;
boost::optional<symbolizer_base::value_type> text_opacity;
boost::optional<bool> wrap_before;
boost::optional<unsigned> wrap_char;
boost::optional<symbolizer_base::value_type> wrap_char;
boost::optional<text_transform_e> text_transform;
boost::optional<color> fill;
boost::optional<color> halo_fill;
boost::optional<double> halo_radius;
boost::optional<symbolizer_base::value_type> halo_radius;
private:
node_ptr child_;

View file

@ -68,18 +68,21 @@ struct MAPNIK_DECL format_properties
void from_xml(xml_node const& sym, fontset_map const& fontsets);
void to_xml(boost::property_tree::ptree & node, bool explicit_defaults,
format_properties const& dfl = format_properties()) const;
std::string face_name;
boost::optional<font_set> fontset;
// expressions
symbolizer_base::value_type text_size;
symbolizer_base::value_type character_spacing;
double line_spacing; //Largest total height (fontsize+line_spacing) per line is chosen
double text_opacity;
double halo_opacity;
unsigned wrap_char;
symbolizer_base::value_type line_spacing; //Largest total height (fontsize+line_spacing) per line is chosen
symbolizer_base::value_type text_opacity;
symbolizer_base::value_type halo_opacity;
symbolizer_base::value_type wrap_char;
symbolizer_base::value_type halo_radius;
//
std::string face_name;
boost::optional<font_set> fontset;
text_transform_e text_transform; //Per expression
color fill;
color halo_fill;
double halo_radius;
};
@ -162,7 +165,7 @@ struct MAPNIK_DECL text_symbolizer_properties
text_layout_properties layout_defaults;
// Default values for format_properties.
//char_properties_ptr format;
format_properties format_properties;
format_properties format_defaults;
private:
// A tree of formatting::nodes which contain text and formatting information.

View file

@ -1227,9 +1227,9 @@ void map_parser::parse_text_symbolizer(rule & rule, xml_node const& node)
}
if (strict_ &&
!placements->defaults.format_properties.fontset)
!placements->defaults.format_defaults.fontset)
{
ensure_font_face(placements->defaults.format_properties.face_name);
ensure_font_face(placements->defaults.format_defaults.face_name);
}
text_symbolizer sym;
parse_symbolizer_base(sym, node);
@ -1264,9 +1264,9 @@ void map_parser::parse_shield_symbolizer(rule & rule, xml_node const& node)
}
placements->defaults.from_xml(node, fontsets_);
if (strict_ &&
!placements->defaults.format_properties.fontset)
!placements->defaults.format_defaults.fontset)
{
ensure_font_face(placements->defaults.format_properties.face_name);
ensure_font_face(placements->defaults.format_defaults.face_name);
}
shield_symbolizer sym;

View file

@ -44,14 +44,19 @@ void format_node::to_xml(ptree & xml) const
if (text_size) serialize_property("size", *text_size, xml);
if (character_spacing) serialize_property("character-spacing", *character_spacing, xml);
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 (line_spacing) serialize_property("line-spacing", *line_spacing, xml);
if (text_opacity) serialize_property("opacity", *text_opacity, xml);
if (wrap_before) set_attr(new_node, "wrap-before", *wrap_before); // FIXME!!!
if (wrap_char) serialize_property("wrap_char", *wrap_char, xml);
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 (halo_radius) serialize_property("halo-radius", *halo_radius, xml);
if (child_) child_->to_xml(new_node);
}
@ -66,17 +71,19 @@ node_ptr format_node::from_xml(xml_node const& xml)
n->face_name = xml.get_opt_attr<std::string>("face-name");
//TODO: Fontset is problematic. We don't have the fontsets pointer here...
// exprs
set_property_from_xml<double>(n->text_size, "size", xml);
set_property_from_xml<double>(n->character_spacing, "character-spacing", xml);
n->line_spacing = xml.get_opt_attr<double>("line-spacing");
n->text_opacity = xml.get_opt_attr<double>("opacity");
n->wrap_char = xml.get_opt_attr<unsigned>("wrap-character");
set_property_from_xml<double>(n->line_spacing, "line-spacing", xml);
set_property_from_xml<double>(n->text_opacity, "opacity", xml);
//set_property_from_xml<double>(n->halo_opacity, "halo-opacity", xml); FIXME
set_property_from_xml<double>(n->halo_radius, "halo-radius", xml);
set_property_from_xml<std::string>(n->wrap_char, "wrap-character", xml);
//
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;
}
@ -84,18 +91,26 @@ node_ptr format_node::from_xml(xml_node const& xml)
void format_node::apply(char_properties_ptr p, feature_impl const& feature, attributes const& attrs, text_layout &output) const
{
char_properties_ptr new_properties = std::make_shared<char_properties>(*p);
if (face_name) new_properties->face_name = *face_name;
if (text_size) new_properties->text_size = boost::apply_visitor(extract_value<value_double>(feature,attrs), *text_size);
if (character_spacing) new_properties->character_spacing =boost::apply_visitor(extract_value<value_double>(feature,attrs), *character_spacing);
if (character_spacing) new_properties->character_spacing = boost::apply_visitor(extract_value<value_double>(feature,attrs), *character_spacing);
if (line_spacing) new_properties->line_spacing = boost::apply_visitor(extract_value<value_double>(feature,attrs), *line_spacing);
if (text_opacity) new_properties->text_opacity = boost::apply_visitor(extract_value<value_double>(feature,attrs), *text_opacity);
if (line_spacing) new_properties->line_spacing = *line_spacing;
if (text_opacity) new_properties->text_opacity = *text_opacity;
if (wrap_char) new_properties->wrap_char = *wrap_char;
if (wrap_char)
{
std::string str = boost::apply_visitor(extract_value<std::string>(feature,attrs), *wrap_char);
if (!str.empty())
{
new_properties->wrap_char = str[0];
}
}
if (halo_radius) new_properties->halo_radius = boost::apply_visitor(extract_value<value_double>(feature,attrs), *halo_radius);
if (face_name) new_properties->face_name = *face_name;
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, attrs, output);
else MAPNIK_LOG_WARN(format) << "Useless format: No text to format";

View file

@ -49,7 +49,7 @@ bool text_placement_info_simple::next()
if (state > 0)
{
if (state > parent_->text_sizes_.size()) return false;
properties.format_properties.text_size = value_double(parent_->text_sizes_[state-1]);
properties.format_defaults.text_size = value_double(parent_->text_sizes_[state-1]);
}
if (!next_position_only())
{

View file

@ -53,7 +53,7 @@ text_symbolizer_properties::text_symbolizer_properties()
largest_bbox_only(true),
upright(UPRIGHT_AUTO),
layout_defaults(),
format_properties(),//std::make_shared<format_properties>()),
format_defaults(),//std::make_shared<format_defaults>()),
tree_() {}
void text_symbolizer_properties::process(text_layout & output, feature_impl const& feature, attributes const& attrs) const
@ -63,18 +63,25 @@ void text_symbolizer_properties::process(text_layout & output, feature_impl cons
{
//evaluate format properties
char_properties_ptr format = std::make_shared<char_properties>();
format->face_name = format_properties.face_name;
format->fontset = format_properties.fontset;
format->text_size = boost::apply_visitor(extract_value<value_double>(feature,attrs), format_properties.text_size);
format->character_spacing = boost::apply_visitor(extract_value<value_double>(feature,attrs), format_properties.character_spacing);
format->line_spacing = format_properties.line_spacing;
format->text_opacity = format_properties.text_opacity;
format->halo_opacity = format_properties.halo_opacity;
format->wrap_char = format_properties.wrap_char;
format->text_transform = format_properties.text_transform;
format->fill = format_properties.fill;
format->halo_fill = format_properties.halo_fill;
format->halo_radius = format_properties.halo_radius;
format->text_size = boost::apply_visitor(extract_value<value_double>(feature,attrs), format_defaults.text_size);
format->character_spacing = boost::apply_visitor(extract_value<value_double>(feature,attrs), format_defaults.character_spacing);
format->line_spacing = boost::apply_visitor(extract_value<value_double>(feature,attrs), format_defaults.line_spacing);
format->text_opacity = boost::apply_visitor(extract_value<value_double>(feature,attrs), format_defaults.text_opacity);
format->halo_opacity = boost::apply_visitor(extract_value<value_double>(feature,attrs), format_defaults.halo_opacity);
format->halo_radius = boost::apply_visitor(extract_value<value_double>(feature,attrs), format_defaults.halo_radius);
std::string const& wrap_char = boost::apply_visitor(extract_value<std::string>(feature,attrs), format_defaults.wrap_char);
if (!wrap_char.empty())
{
format->wrap_char = wrap_char[0];
}
format->face_name = format_defaults.face_name;
format->fontset = format_defaults.fontset;
format->text_transform = format_defaults.text_transform;
format->fill = format_defaults.fill;
format->halo_fill = format_defaults.halo_fill;
tree_->apply(format, feature, attrs, output);
}
@ -137,7 +144,7 @@ void text_symbolizer_properties::from_xml(xml_node const& node, fontset_map cons
set_old_style_expression(*name_);
}
format_properties.from_xml(node, fontsets);
format_defaults.from_xml(node, fontsets);
formatting::node_ptr n(formatting::node::from_xml(node));
if (n) set_format_tree(n);
}
@ -192,7 +199,7 @@ void text_symbolizer_properties::to_xml(boost::property_tree::ptree &node,
}
layout_defaults.to_xml(node, explicit_defaults, dfl.layout_defaults);
format_properties.to_xml(node, explicit_defaults, dfl.format_properties);
format_defaults.to_xml(node, explicit_defaults, dfl.format_defaults);
if (tree_) tree_->to_xml(node);
}
@ -200,6 +207,7 @@ void text_symbolizer_properties::to_xml(boost::property_tree::ptree &node,
void text_symbolizer_properties::add_expressions(expression_set & output) const
{
layout_defaults.add_expressions(output);
//format_defaults.add_expressions(output); FIXME
if (tree_) tree_->add_expressions(output);
}
@ -267,45 +275,41 @@ format_properties::format_properties()
fontset(),
text_size(10.0),
character_spacing(0.0),
line_spacing(0),
line_spacing(0.0),
text_opacity(1.0),
halo_opacity(1.0),
wrap_char(' '),
wrap_char(" "),
text_transform(NONE),
fill(color(0,0,0)),
halo_fill(color(255,255,255)),
halo_radius(0) {}
halo_radius(0.0) {}
void format_properties::from_xml(xml_node const& node, fontset_map const& fontsets)
{
set_property_from_xml<double>(text_size, "size", node);
set_property_from_xml<double>(character_spacing, "character-spacing", node);
set_property_from_xml<double>(line_spacing, "line-spacing", node);
set_property_from_xml<double>(halo_radius, "halo-radius", node);
set_property_from_xml<double>(text_opacity, "opacity", node);
set_property_from_xml<double>(halo_opacity, "halo-opacity", node);
set_property_from_xml<std::string>(wrap_char, "wrap-character", node);
//optional<double> character_spacing_ = node.get_opt_attr<double>("character-spacing");
//if (character_spacing_) character_spacing = *character_spacing_;
optional<color> fill_ = node.get_opt_attr<color>("fill");
if (fill_) fill = *fill_;
optional<color> halo_fill_ = node.get_opt_attr<color>("halo-fill");
if (halo_fill_) halo_fill = *halo_fill_;
optional<double> halo_radius_ = node.get_opt_attr<double>("halo-radius");
if (halo_radius_) halo_radius = *halo_radius_;
optional<text_transform_e> tconvert_ = node.get_opt_attr<text_transform_e>("text-transform");
if (tconvert_) text_transform = *tconvert_;
optional<double> line_spacing_ = node.get_opt_attr<double>("line-spacing");
if (line_spacing_) line_spacing = *line_spacing_;
optional<double> opacity_ = node.get_opt_attr<double>("opacity");
if (opacity_) text_opacity = *opacity_;
optional<double> halo_opacity_ = node.get_opt_attr<double>("halo-opacity");
if (halo_opacity_) halo_opacity = *halo_opacity_;
optional<std::string> wrap_char_ = node.get_opt_attr<std::string>("wrap-character");
if (wrap_char_ && (*wrap_char_).size() > 0) wrap_char = ((*wrap_char_)[0]);
optional<std::string> face_name_ = node.get_opt_attr<std::string>("face-name");
if (face_name_)
{
face_name = *face_name_;
}
optional<std::string> fontset_name_ = node.get_opt_attr<std::string>("fontset-name");
if (fontset_name_) {
if (fontset_name_)
{
std::map<std::string,font_set>::const_iterator itr = fontsets.find(*fontset_name_);
if (itr != fontsets.end())
{
@ -339,44 +343,30 @@ void format_properties::to_xml(boost::property_tree::ptree & node, bool explicit
}
if (!(text_size == dfl.text_size) || explicit_defaults) serialize_property("size", text_size, node);
if (!(character_spacing == dfl.character_spacing) || explicit_defaults) serialize_property("character-spacing", character_spacing, node);
if (!(line_spacing == dfl.line_spacing) || explicit_defaults) serialize_property("line-spacing", line_spacing, node);
if (!(halo_radius == dfl.halo_radius) || explicit_defaults) serialize_property("halo-radius", halo_radius, node);
if (!(wrap_char == dfl.wrap_char) || explicit_defaults) serialize_property("wrap-character", wrap_char, node);
// for shield_symbolizer this is later overridden -- FIXME
if (!(text_opacity == dfl.text_opacity) || explicit_defaults) serialize_property("opacity", text_opacity, node);
if (!(halo_opacity == dfl.halo_opacity) || explicit_defaults) serialize_property("halo-opacity", halo_opacity, node);
//
if (fill != dfl.fill || explicit_defaults)
{
set_attr(node, "fill", fill);
}
if (halo_radius != dfl.halo_radius || explicit_defaults)
{
set_attr(node, "halo-radius", halo_radius);
}
if (halo_fill != dfl.halo_fill || explicit_defaults)
{
set_attr(node, "halo-fill", halo_fill);
}
if (wrap_char != dfl.wrap_char || explicit_defaults)
{
set_attr(node, "wrap-character", std::string(1, wrap_char));
}
if (text_transform != dfl.text_transform || explicit_defaults)
{
set_attr(node, "text-transform", text_transform);
}
if (line_spacing != dfl.line_spacing || explicit_defaults)
{
set_attr(node, "line-spacing", line_spacing);
}
if (!(character_spacing == dfl.character_spacing) || explicit_defaults)
serialize_property("character-spacing", character_spacing, node);
// for shield_symbolizer this is later overridden
if (text_opacity != dfl.text_opacity || explicit_defaults)
{
set_attr(node, "opacity", text_opacity);
}
// for shield_symbolizer this is later overridden
if (halo_opacity != dfl.halo_opacity || explicit_defaults)
{
set_attr(node, "halo-opacity", halo_opacity);
}
}
} //ns mapnik

View file

@ -67,10 +67,10 @@ int main(int argc, char** argv)
mapnik::rule r;
mapnik::text_symbolizer text_sym;
mapnik::text_placements_ptr placement_finder = std::make_shared<mapnik::text_placements_dummy>();
placement_finder->defaults.format_properties.face_name = "DejaVu Sans Book";
placement_finder->defaults.format_properties.text_size = 10.0;
placement_finder->defaults.format_properties.fill = mapnik::color(0,0,0);
placement_finder->defaults.format_properties.fontset = fontset;
placement_finder->defaults.format_defaults.face_name = "DejaVu Sans Book";
placement_finder->defaults.format_defaults.text_size = 10.0;
placement_finder->defaults.format_defaults.fill = mapnik::color(0,0,0);
placement_finder->defaults.format_defaults.fontset = fontset;
placement_finder->defaults.set_old_style_expression(mapnik::parse_expression("[name]"));
mapnik::put<mapnik::text_placements_ptr>(text_sym, mapnik::keys::text_placements_, placement_finder);
r.append(std::move(text_sym));