2011-02-28 14:17:46 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
* Copyright (C) 2013 Artem Pavlenko
|
2011-02-28 14:17:46 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-02-17 20:53:00 +01:00
|
|
|
// mapnik
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
#include <mapnik/text/text_properties.hpp>
|
2014-07-28 13:10:34 +02:00
|
|
|
#include <mapnik/text/text_layout.hpp>
|
2013-01-04 05:00:23 +01:00
|
|
|
#include <mapnik/debug.hpp>
|
|
|
|
#include <mapnik/feature.hpp>
|
2012-01-22 02:56:28 +01:00
|
|
|
#include <mapnik/ptree_helpers.hpp>
|
2012-02-17 20:53:00 +01:00
|
|
|
#include <mapnik/expression_string.hpp>
|
2013-11-08 05:09:22 +01:00
|
|
|
#include <mapnik/text/formatting/text.hpp>
|
2012-03-11 23:24:28 +01:00
|
|
|
#include <mapnik/xml_node.hpp>
|
2012-03-08 18:51:23 +01:00
|
|
|
#include <mapnik/config_error.hpp>
|
2014-07-18 12:14:28 +02:00
|
|
|
#include <mapnik/text/properties_util.hpp>
|
2014-07-23 04:36:39 +02:00
|
|
|
#include <mapnik/boolean.hpp>
|
2011-02-28 14:17:46 +01:00
|
|
|
|
2012-03-10 01:20:50 +01:00
|
|
|
// boost
|
2013-01-04 03:06:07 +01:00
|
|
|
#include <boost/property_tree/ptree.hpp>
|
2012-03-10 01:20:50 +01:00
|
|
|
|
2012-02-17 20:53:00 +01:00
|
|
|
namespace mapnik
|
|
|
|
{
|
2012-01-22 02:56:28 +01:00
|
|
|
using boost::optional;
|
|
|
|
|
2014-07-09 12:31:03 +02:00
|
|
|
text_symbolizer_properties::text_symbolizer_properties()
|
|
|
|
: label_placement(POINT_PLACEMENT),
|
|
|
|
label_spacing(0.0),
|
|
|
|
label_position_tolerance(0.0),
|
|
|
|
avoid_edges(false),
|
2014-08-21 01:43:36 +02:00
|
|
|
text_margin(0.0),
|
2014-08-03 22:10:21 +02:00
|
|
|
repeat_distance(0.0),
|
2014-07-09 12:31:03 +02:00
|
|
|
minimum_distance(0.0),
|
|
|
|
minimum_padding(0.0),
|
|
|
|
minimum_path_length(0.0),
|
|
|
|
max_char_angle_delta(22.5 * M_PI/180.0),
|
|
|
|
allow_overlap(false),
|
|
|
|
largest_bbox_only(true),
|
|
|
|
upright(UPRIGHT_AUTO),
|
|
|
|
layout_defaults(),
|
2014-07-29 15:43:26 +02:00
|
|
|
format_defaults(),
|
2014-07-11 15:43:56 +02:00
|
|
|
tree_() {}
|
2012-01-22 02:56:28 +01:00
|
|
|
|
2014-07-29 15:43:26 +02:00
|
|
|
|
|
|
|
void text_symbolizer_properties::evaluate_text_properties(feature_impl const& feature, attributes const& attrs)
|
|
|
|
{
|
2014-08-11 14:24:53 +02:00
|
|
|
label_placement = util::apply_visitor(extract_value<label_placement_enum>(feature,attrs), expressions.label_placement);
|
|
|
|
label_spacing = util::apply_visitor(extract_value<value_double>(feature,attrs), expressions.label_spacing);
|
|
|
|
label_position_tolerance = util::apply_visitor(extract_value<value_double>(feature,attrs), expressions.label_position_tolerance);
|
|
|
|
avoid_edges = util::apply_visitor(extract_value<value_bool>(feature,attrs), expressions.avoid_edges);
|
2014-08-22 02:49:00 +02:00
|
|
|
text_margin = util::apply_visitor(extract_value<value_double>(feature,attrs), expressions.text_margin);
|
2014-08-18 14:48:00 +02:00
|
|
|
repeat_distance = util::apply_visitor(extract_value<value_double>(feature,attrs), expressions.repeat_distance);
|
2014-08-11 14:24:53 +02:00
|
|
|
minimum_distance = util::apply_visitor(extract_value<value_double>(feature,attrs), expressions.minimum_distance);
|
|
|
|
minimum_padding = util::apply_visitor(extract_value<value_double>(feature,attrs), expressions.minimum_padding);
|
|
|
|
minimum_path_length = util::apply_visitor(extract_value<value_double>(feature,attrs), expressions.minimum_path_length);
|
|
|
|
max_char_angle_delta = util::apply_visitor(extract_value<value_double>(feature,attrs), expressions.max_char_angle_delta) * M_PI/180;
|
|
|
|
allow_overlap = util::apply_visitor(extract_value<value_bool>(feature,attrs), expressions.allow_overlap);
|
|
|
|
largest_bbox_only = util::apply_visitor(extract_value<value_bool>(feature,attrs), expressions.largest_bbox_only);
|
|
|
|
upright = util::apply_visitor(extract_value<text_upright_enum>(feature,attrs), expressions.upright);
|
2014-07-29 15:43:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void text_symbolizer_properties::process(text_layout & output, feature_impl const& feature, attributes const& attrs) //const
|
2012-01-31 16:24:58 +01:00
|
|
|
{
|
|
|
|
output.clear();
|
2014-07-29 15:43:26 +02:00
|
|
|
|
2014-07-23 17:19:14 +02:00
|
|
|
if (tree_)
|
|
|
|
{
|
2014-07-29 15:43:26 +02:00
|
|
|
evaluate_text_properties(feature, attrs);
|
2014-07-23 17:19:14 +02:00
|
|
|
//evaluate format properties
|
2014-07-28 18:22:32 +02:00
|
|
|
evaluated_format_properties_ptr format = std::make_shared<detail::evaluated_format_properties>();
|
2014-07-23 19:09:18 +02:00
|
|
|
|
2014-08-11 14:24:53 +02:00
|
|
|
format->text_size = util::apply_visitor(extract_value<value_double>(feature,attrs), format_defaults.text_size);
|
|
|
|
format->character_spacing = util::apply_visitor(extract_value<value_double>(feature,attrs), format_defaults.character_spacing);
|
|
|
|
format->line_spacing = util::apply_visitor(extract_value<value_double>(feature,attrs), format_defaults.line_spacing);
|
|
|
|
format->text_opacity = util::apply_visitor(extract_value<value_double>(feature,attrs), format_defaults.text_opacity);
|
|
|
|
format->halo_opacity = util::apply_visitor(extract_value<value_double>(feature,attrs), format_defaults.halo_opacity);
|
|
|
|
format->halo_radius = util::apply_visitor(extract_value<value_double>(feature,attrs), format_defaults.halo_radius);
|
|
|
|
format->fill = util::apply_visitor(extract_value<color>(feature,attrs), format_defaults.fill);
|
|
|
|
format->halo_fill = util::apply_visitor(extract_value<color>(feature,attrs), format_defaults.halo_fill);
|
|
|
|
format->text_transform = util::apply_visitor(extract_value<text_transform_enum>(feature,attrs), format_defaults.text_transform);
|
2014-07-23 19:09:18 +02:00
|
|
|
format->face_name = format_defaults.face_name;
|
|
|
|
format->fontset = format_defaults.fontset;
|
2014-07-23 17:19:14 +02:00
|
|
|
|
|
|
|
tree_->apply(format, feature, attrs, output);
|
|
|
|
}
|
2014-07-17 17:54:29 +02:00
|
|
|
else MAPNIK_LOG_WARN(text_properties) << "text_symbolizer_properties can't produce text: No formatting tree!";
|
2012-01-31 16:24:58 +01:00
|
|
|
}
|
|
|
|
|
2012-02-12 22:48:44 +01:00
|
|
|
void text_symbolizer_properties::set_format_tree(formatting::node_ptr tree)
|
2012-01-31 16:24:58 +01:00
|
|
|
{
|
|
|
|
tree_ = tree;
|
|
|
|
}
|
|
|
|
|
2012-02-12 22:48:44 +01:00
|
|
|
formatting::node_ptr text_symbolizer_properties::format_tree() const
|
2012-01-31 16:24:58 +01:00
|
|
|
{
|
|
|
|
return tree_;
|
|
|
|
}
|
|
|
|
|
2014-07-29 11:09:54 +02:00
|
|
|
void text_symbolizer_properties::text_properties_from_xml(xml_node const& node)
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2014-08-22 14:52:45 +02:00
|
|
|
// The options 'text-margin' and 'repeat-distance' replace 'minimum-distance'.
|
|
|
|
// Only allow one or the other to be defined here.
|
|
|
|
if (node.has_attribute("text-margin") || node.has_attribute("repeat-distance"))
|
|
|
|
{
|
|
|
|
if (node.has_attribute("minimum-distance"))
|
|
|
|
{
|
|
|
|
throw config_error(std::string("Cannot use deprecated option minimum-distance with "
|
|
|
|
"new options text-margin and repeat-distance."));
|
|
|
|
}
|
|
|
|
set_property_from_xml<value_double>(expressions.text_margin, "text-margin", node);
|
|
|
|
set_property_from_xml<value_double>(expressions.repeat_distance, "repeat-distance", node);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
set_property_from_xml<value_double>(expressions.minimum_distance, "minimum-distance", node);
|
|
|
|
}
|
2014-07-29 15:43:26 +02:00
|
|
|
set_property_from_xml<label_placement_e>(expressions.label_placement, "placement", node);
|
|
|
|
set_property_from_xml<value_double>(expressions.label_spacing, "spacing", node);
|
|
|
|
set_property_from_xml<value_double>(expressions.label_position_tolerance, "label-position-tolerance", node);
|
|
|
|
set_property_from_xml<value_double>(expressions.minimum_padding, "minimum-padding", node);
|
|
|
|
set_property_from_xml<value_double>(expressions.minimum_path_length, "minimum-path-length", node);
|
|
|
|
set_property_from_xml<boolean_type>(expressions.avoid_edges, "avoid-edges", node);
|
|
|
|
set_property_from_xml<boolean_type>(expressions.allow_overlap, "allow-overlap", node);
|
|
|
|
set_property_from_xml<boolean_type>(expressions.largest_bbox_only, "largest-bbox-only", node);
|
|
|
|
set_property_from_xml<value_double>(expressions.max_char_angle_delta, "max-char-angle-delta", node);
|
|
|
|
set_property_from_xml<text_upright_e>(expressions.upright, "upright", node);
|
2014-07-29 11:09:54 +02:00
|
|
|
}
|
2014-01-30 12:01:57 +01:00
|
|
|
|
2014-07-29 11:09:54 +02:00
|
|
|
void text_symbolizer_properties::from_xml(xml_node const& node, fontset_map const& fontsets)
|
|
|
|
{
|
|
|
|
text_properties_from_xml(node);
|
2014-07-30 03:28:56 +02:00
|
|
|
layout_defaults.from_xml(node,fontsets);
|
2014-07-15 17:31:43 +02:00
|
|
|
optional<expression_ptr> name_ = node.get_opt_attr<expression_ptr>("name");
|
2012-04-08 02:20:56 +02:00
|
|
|
if (name_)
|
|
|
|
{
|
2012-04-10 00:51:04 +02:00
|
|
|
MAPNIK_LOG_WARN(text_placements) << "Using 'name' in TextSymbolizer/ShieldSymbolizer is deprecated!";
|
2012-07-04 20:59:36 +02:00
|
|
|
set_old_style_expression(*name_);
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
2012-01-31 16:24:58 +01:00
|
|
|
|
2014-07-23 19:09:18 +02:00
|
|
|
format_defaults.from_xml(node, fontsets);
|
2014-07-30 03:28:56 +02:00
|
|
|
formatting::node_ptr n(formatting::node::from_xml(node,fontsets));
|
2012-01-31 16:24:58 +01:00
|
|
|
if (n) set_format_tree(n);
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
|
|
|
|
2012-03-05 20:31:58 +01:00
|
|
|
void text_symbolizer_properties::to_xml(boost::property_tree::ptree &node,
|
|
|
|
bool explicit_defaults,
|
|
|
|
text_symbolizer_properties const& dfl) const
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2014-07-29 15:43:26 +02:00
|
|
|
if (!(expressions.label_placement == dfl.expressions.label_placement) || explicit_defaults)
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2014-07-29 15:43:26 +02:00
|
|
|
serialize_property("placement", expressions.label_placement, node);
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
2014-07-29 15:43:26 +02:00
|
|
|
if (!(expressions.label_position_tolerance == dfl.expressions.label_position_tolerance) || explicit_defaults)
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2014-07-29 15:43:26 +02:00
|
|
|
serialize_property("label-position-tolerance", expressions.label_position_tolerance,node);
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
2014-07-29 15:43:26 +02:00
|
|
|
if (!(expressions.label_spacing == dfl.expressions.label_spacing) || explicit_defaults)
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2014-07-29 15:43:26 +02:00
|
|
|
serialize_property("spacing", expressions.label_spacing, node);
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
2014-08-21 01:43:36 +02:00
|
|
|
if (!(expressions.text_margin == dfl.expressions.text_margin) || explicit_defaults)
|
|
|
|
{
|
|
|
|
serialize_property("text-margin", expressions.text_margin, node);
|
|
|
|
}
|
2014-08-03 22:10:21 +02:00
|
|
|
if (!(expressions.repeat_distance == dfl.expressions.repeat_distance) || explicit_defaults)
|
|
|
|
{
|
|
|
|
serialize_property("repeat-distance", expressions.repeat_distance, node);
|
|
|
|
}
|
2014-07-29 15:43:26 +02:00
|
|
|
if (!(expressions.minimum_distance == dfl.expressions.minimum_distance) || explicit_defaults)
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2014-07-29 15:43:26 +02:00
|
|
|
serialize_property("minimum-distance", expressions.minimum_distance, node);
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
2014-07-29 15:43:26 +02:00
|
|
|
if (!(expressions.minimum_padding == dfl.expressions.minimum_padding) || explicit_defaults)
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2014-07-29 15:43:26 +02:00
|
|
|
serialize_property("minimum-padding", expressions.minimum_padding, node);
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
2014-07-29 15:43:26 +02:00
|
|
|
if (!(expressions.minimum_path_length == dfl.expressions.minimum_path_length) || explicit_defaults)
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2014-07-29 15:43:26 +02:00
|
|
|
serialize_property("minimum-path-length", expressions.minimum_path_length, node);
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
2014-07-29 15:43:26 +02:00
|
|
|
if (!(expressions.avoid_edges == dfl.expressions.avoid_edges) || explicit_defaults)
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2014-07-29 15:43:26 +02:00
|
|
|
serialize_property("avoid-edges", expressions.avoid_edges, node);
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
2014-07-29 15:43:26 +02:00
|
|
|
if (!(expressions.allow_overlap == dfl.expressions.allow_overlap) || explicit_defaults)
|
2012-06-25 16:00:53 +02:00
|
|
|
{
|
2014-07-29 15:43:26 +02:00
|
|
|
serialize_property("allow-overlap", expressions.allow_overlap, node);
|
2014-01-30 12:01:57 +01:00
|
|
|
}
|
2014-07-29 15:43:26 +02:00
|
|
|
if (!(expressions.largest_bbox_only == dfl.expressions.largest_bbox_only) || explicit_defaults)
|
2014-01-30 12:01:57 +01:00
|
|
|
{
|
2014-07-29 15:43:26 +02:00
|
|
|
serialize_property("largest-bbox-only", expressions.largest_bbox_only, node);
|
2012-06-25 16:00:53 +02:00
|
|
|
}
|
2014-07-29 15:43:26 +02:00
|
|
|
if (!(expressions.max_char_angle_delta == dfl.expressions.max_char_angle_delta) || explicit_defaults)
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2014-07-29 15:43:26 +02:00
|
|
|
serialize_property("max-char-angle-delta", expressions.max_char_angle_delta, node);
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
2014-07-29 15:43:26 +02:00
|
|
|
if (!(expressions.upright == dfl.expressions.upright) || explicit_defaults)
|
2014-01-30 12:01:57 +01:00
|
|
|
{
|
2014-07-29 15:43:26 +02:00
|
|
|
serialize_property("upright", expressions.upright, node);
|
2014-01-30 12:01:57 +01:00
|
|
|
}
|
|
|
|
|
2014-07-09 12:31:03 +02:00
|
|
|
layout_defaults.to_xml(node, explicit_defaults, dfl.layout_defaults);
|
2014-07-23 19:09:18 +02:00
|
|
|
format_defaults.to_xml(node, explicit_defaults, dfl.format_defaults);
|
2014-01-30 12:01:57 +01:00
|
|
|
if (tree_) tree_->to_xml(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-18 12:18:54 +02:00
|
|
|
void text_symbolizer_properties::add_expressions(expression_set & output) const
|
2014-01-30 12:01:57 +01:00
|
|
|
{
|
2014-08-11 14:24:53 +02:00
|
|
|
if (is_expression(expressions.label_placement)) output.insert(util::get<expression_ptr>(expressions.label_placement));
|
|
|
|
if (is_expression(expressions.label_spacing)) output.insert(util::get<expression_ptr>(expressions.label_spacing));
|
|
|
|
if (is_expression(expressions.label_position_tolerance)) output.insert(util::get<expression_ptr>(expressions.label_position_tolerance));
|
|
|
|
if (is_expression(expressions.avoid_edges)) output.insert(util::get<expression_ptr>(expressions.avoid_edges));
|
2014-08-21 01:43:36 +02:00
|
|
|
if (is_expression(expressions.text_margin)) output.insert(util::get<expression_ptr>(expressions.text_margin));
|
|
|
|
if (is_expression(expressions.repeat_distance)) output.insert(util::get<expression_ptr>(expressions.repeat_distance));
|
2014-08-11 14:24:53 +02:00
|
|
|
if (is_expression(expressions.minimum_distance)) output.insert(util::get<expression_ptr>(expressions.minimum_distance));
|
|
|
|
if (is_expression(expressions.minimum_padding)) output.insert(util::get<expression_ptr>(expressions.minimum_padding));
|
|
|
|
if (is_expression(expressions.minimum_path_length)) output.insert(util::get<expression_ptr>(expressions.minimum_path_length));
|
|
|
|
if (is_expression(expressions.max_char_angle_delta)) output.insert(util::get<expression_ptr>(expressions.max_char_angle_delta));
|
|
|
|
if (is_expression(expressions.allow_overlap)) output.insert(util::get<expression_ptr>(expressions.allow_overlap));
|
|
|
|
if (is_expression(expressions.largest_bbox_only)) output.insert(util::get<expression_ptr>(expressions.largest_bbox_only));
|
|
|
|
if (is_expression(expressions.upright)) output.insert(util::get<expression_ptr>(expressions.upright));
|
2014-07-29 15:43:26 +02:00
|
|
|
|
2014-07-09 12:31:03 +02:00
|
|
|
layout_defaults.add_expressions(output);
|
2014-07-24 13:00:46 +02:00
|
|
|
format_defaults.add_expressions(output);
|
2014-01-30 12:01:57 +01:00
|
|
|
if (tree_) tree_->add_expressions(output);
|
|
|
|
}
|
|
|
|
|
|
|
|
void text_symbolizer_properties::set_old_style_expression(expression_ptr expr)
|
|
|
|
{
|
|
|
|
tree_ = std::make_shared<formatting::text_node>(expr);
|
|
|
|
}
|
|
|
|
|
2014-07-11 15:43:56 +02:00
|
|
|
text_layout_properties::text_layout_properties()
|
2014-07-28 16:09:29 +02:00
|
|
|
: halign(enumeration_wrapper(H_AUTO)),
|
|
|
|
jalign(enumeration_wrapper(J_AUTO)),
|
|
|
|
valign(enumeration_wrapper(V_AUTO)) {}
|
2014-01-30 12:01:57 +01:00
|
|
|
|
2014-07-30 03:28:56 +02:00
|
|
|
void text_layout_properties::from_xml(xml_node const &node, fontset_map const& fontsets)
|
2014-01-30 12:01:57 +01:00
|
|
|
{
|
2014-07-15 11:15:56 +02:00
|
|
|
set_property_from_xml<double>(dx, "dx", node);
|
|
|
|
set_property_from_xml<double>(dy, "dy", node);
|
2014-07-16 17:34:42 +02:00
|
|
|
set_property_from_xml<double>(text_ratio, "text-ratio", node);
|
|
|
|
set_property_from_xml<double>(wrap_width, "wrap-width", node);
|
2014-07-29 15:43:26 +02:00
|
|
|
set_property_from_xml<boolean_type>(wrap_before, "wrap-before", node);
|
|
|
|
set_property_from_xml<boolean_type>(rotate_displacement, "rotate-displacement", node);
|
2014-07-16 17:34:42 +02:00
|
|
|
set_property_from_xml<double>(orientation, "orientation", node);
|
2014-07-28 16:09:29 +02:00
|
|
|
set_property_from_xml<vertical_alignment_e>(valign, "vertical-alignment", node);
|
|
|
|
set_property_from_xml<horizontal_alignment_e>(halign, "horizontal-alignment", node);
|
|
|
|
set_property_from_xml<justify_alignment_e>(jalign, "justify-alignment", node);
|
2014-01-30 12:01:57 +01:00
|
|
|
}
|
|
|
|
|
2014-07-14 17:08:58 +02:00
|
|
|
void text_layout_properties::to_xml(boost::property_tree::ptree & node,
|
2014-07-15 11:15:56 +02:00
|
|
|
bool explicit_defaults,
|
|
|
|
text_layout_properties const& dfl) const
|
2014-01-30 12:01:57 +01:00
|
|
|
{
|
2014-07-21 12:43:59 +02:00
|
|
|
if (!(dx == dfl.dx) || explicit_defaults) serialize_property("dx", dx, node);
|
|
|
|
if (!(dy == dfl.dy) || explicit_defaults) serialize_property("dy", dy, node);
|
2014-07-28 16:09:29 +02:00
|
|
|
if (!(valign == dfl.valign) || explicit_defaults) serialize_property("vertical-alignment", valign, node);
|
|
|
|
if (!(halign == dfl.halign) || explicit_defaults) serialize_property("horizontal-alignment", halign, node);
|
|
|
|
if (!(jalign == dfl.jalign) || explicit_defaults) serialize_property("justify-alignment", jalign, node);
|
2014-07-21 12:43:59 +02:00
|
|
|
if (!(text_ratio == dfl.text_ratio) || explicit_defaults) serialize_property("text-ratio", text_ratio, node);
|
|
|
|
if (!(wrap_width == dfl.wrap_width) || explicit_defaults) serialize_property("wrap-width", wrap_width, node);
|
|
|
|
if (!(wrap_before == dfl.wrap_before) || explicit_defaults) serialize_property("wrap-before", wrap_before, node);
|
|
|
|
if (!(rotate_displacement == dfl.rotate_displacement) || explicit_defaults)
|
|
|
|
serialize_property("rotate-displacement", rotate_displacement, node);
|
|
|
|
if (!(orientation == dfl.orientation) || explicit_defaults) serialize_property("orientation", orientation, node);
|
2012-01-31 16:24:58 +01:00
|
|
|
}
|
|
|
|
|
2014-07-25 15:19:41 +02:00
|
|
|
void text_layout_properties::add_expressions(expression_set & output) const
|
2012-01-31 16:24:58 +01:00
|
|
|
{
|
2014-08-11 14:24:53 +02:00
|
|
|
if (is_expression(dx)) output.insert(util::get<expression_ptr>(dx));
|
|
|
|
if (is_expression(dy)) output.insert(util::get<expression_ptr>(dy));
|
|
|
|
if (is_expression(orientation)) output.insert(util::get<expression_ptr>(orientation));
|
|
|
|
if (is_expression(wrap_width)) output.insert(util::get<expression_ptr>(wrap_width));
|
|
|
|
if (is_expression(wrap_before)) output.insert(util::get<expression_ptr>(wrap_before));
|
|
|
|
if (is_expression(rotate_displacement)) output.insert(util::get<expression_ptr>(rotate_displacement));
|
|
|
|
if (is_expression(text_ratio)) output.insert(util::get<expression_ptr>(text_ratio));
|
|
|
|
if (is_expression(halign)) output.insert(util::get<expression_ptr>(halign));
|
|
|
|
if (is_expression(valign)) output.insert(util::get<expression_ptr>(valign));
|
|
|
|
if (is_expression(jalign)) output.insert(util::get<expression_ptr>(jalign));
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
|
|
|
|
2014-07-23 17:19:14 +02:00
|
|
|
// text format properties
|
|
|
|
format_properties::format_properties()
|
2014-07-14 17:51:11 +02:00
|
|
|
: face_name(),
|
|
|
|
fontset(),
|
|
|
|
text_size(10.0),
|
2014-07-23 17:19:14 +02:00
|
|
|
character_spacing(0.0),
|
2014-07-23 19:09:18 +02:00
|
|
|
line_spacing(0.0),
|
2014-07-14 17:51:11 +02:00
|
|
|
text_opacity(1.0),
|
|
|
|
halo_opacity(1.0),
|
|
|
|
fill(color(0,0,0)),
|
|
|
|
halo_fill(color(255,255,255)),
|
2014-07-28 18:50:44 +02:00
|
|
|
halo_radius(0.0),
|
|
|
|
text_transform(enumeration_wrapper(NONE)) {}
|
2012-01-22 02:56:28 +01:00
|
|
|
|
2014-07-23 17:19:14 +02:00
|
|
|
void format_properties::from_xml(xml_node const& node, fontset_map const& fontsets)
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2014-07-23 17:19:14 +02:00
|
|
|
set_property_from_xml<double>(text_size, "size", node);
|
|
|
|
set_property_from_xml<double>(character_spacing, "character-spacing", node);
|
2014-07-23 19:09:18 +02:00
|
|
|
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);
|
2014-07-24 12:37:16 +02:00
|
|
|
set_property_from_xml<color>(fill, "fill", node);
|
|
|
|
set_property_from_xml<color>(halo_fill, "halo-fill", node);
|
2014-07-25 15:19:41 +02:00
|
|
|
set_property_from_xml<text_transform_e>(text_transform,"text-transform", node);
|
2014-07-23 19:09:18 +02:00
|
|
|
|
2014-06-16 12:00:19 +02:00
|
|
|
optional<std::string> face_name_ = node.get_opt_attr<std::string>("face-name");
|
2014-07-24 12:37:16 +02:00
|
|
|
if (face_name_) face_name = *face_name_;
|
2014-06-16 12:00:19 +02:00
|
|
|
optional<std::string> fontset_name_ = node.get_opt_attr<std::string>("fontset-name");
|
2014-07-23 19:09:18 +02:00
|
|
|
if (fontset_name_)
|
|
|
|
{
|
2012-01-22 02:56:28 +01:00
|
|
|
std::map<std::string,font_set>::const_iterator itr = fontsets.find(*fontset_name_);
|
|
|
|
if (itr != fontsets.end())
|
|
|
|
{
|
|
|
|
fontset = itr->second;
|
2012-03-05 20:31:58 +01:00
|
|
|
}
|
|
|
|
else
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2014-06-16 12:00:19 +02:00
|
|
|
throw config_error("Unable to find any fontset named '" + *fontset_name_ + "'", node);
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
|
|
|
}
|
2012-09-14 23:17:45 +02:00
|
|
|
if (!face_name.empty() && fontset)
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2014-06-16 12:00:19 +02:00
|
|
|
throw config_error("Can't have both face-name and fontset-name", node);
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
2012-09-14 23:17:45 +02:00
|
|
|
if (face_name.empty() && !fontset)
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2014-06-16 12:00:19 +02:00
|
|
|
throw config_error("Must have face-name or fontset-name", node);
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-23 17:19:14 +02:00
|
|
|
void format_properties::to_xml(boost::property_tree::ptree & node, bool explicit_defaults, format_properties const& dfl) const
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2012-09-14 23:17:45 +02:00
|
|
|
if (fontset)
|
2012-01-22 02:56:28 +01:00
|
|
|
{
|
2012-09-14 23:17:45 +02:00
|
|
|
set_attr(node, "fontset-name", fontset->get_name());
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (face_name != dfl.face_name || explicit_defaults)
|
|
|
|
{
|
|
|
|
set_attr(node, "face-name", face_name);
|
|
|
|
}
|
|
|
|
|
2014-07-23 17:19:14 +02:00
|
|
|
if (!(text_size == dfl.text_size) || explicit_defaults) serialize_property("size", text_size, node);
|
2014-07-23 19:09:18 +02:00
|
|
|
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);
|
|
|
|
// 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);
|
|
|
|
//
|
2014-07-24 12:37:16 +02:00
|
|
|
if (!(fill == dfl.fill) || explicit_defaults) serialize_property("fill", fill, node);
|
|
|
|
if (!(halo_fill == dfl.halo_fill) || explicit_defaults) serialize_property("halo-fill", halo_fill, node);
|
2014-07-25 15:19:41 +02:00
|
|
|
if (!(text_transform == dfl.text_transform) || explicit_defaults) serialize_property("text-transform", text_transform, node);
|
2012-01-22 02:56:28 +01:00
|
|
|
}
|
2011-02-28 14:17:46 +01:00
|
|
|
|
2014-07-24 13:00:46 +02:00
|
|
|
void format_properties::add_expressions(expression_set & output) const
|
|
|
|
{
|
2014-08-11 14:24:53 +02:00
|
|
|
if (is_expression(text_size)) output.insert(util::get<expression_ptr>(text_size));
|
|
|
|
if (is_expression(character_spacing)) output.insert(util::get<expression_ptr>(character_spacing));
|
|
|
|
if (is_expression(line_spacing)) output.insert(util::get<expression_ptr>(line_spacing));
|
|
|
|
if (is_expression(halo_radius)) output.insert(util::get<expression_ptr>(halo_radius));
|
|
|
|
if (is_expression(text_opacity)) output.insert(util::get<expression_ptr>(text_opacity));
|
|
|
|
if (is_expression(halo_opacity)) output.insert(util::get<expression_ptr>(halo_opacity));
|
|
|
|
if (is_expression(fill)) output.insert(util::get<expression_ptr>(fill));
|
|
|
|
if (is_expression(halo_fill)) output.insert(util::get<expression_ptr>(halo_fill));
|
|
|
|
if (is_expression(text_transform)) output.insert(util::get<expression_ptr>(text_transform));
|
2014-07-24 13:00:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-17 20:53:00 +01:00
|
|
|
} //ns mapnik
|